From c08739396a7a5e21c2a387063cae3f68549d8298 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 20 Dec 2019 21:35:23 +0800 Subject: [PATCH 001/852] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsearch=5Fview?= =?UTF-8?q?=E8=8E=B7=E5=BE=97=E7=84=A6=E7=82=B9=E6=97=B6=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E6=A3=80=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/search/SearchActivity.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 0ffefda51..d6eb7f836 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -49,6 +49,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se private var menu: Menu? = null private var precisionSearchMenuItem: MenuItem? = null private var groups = hashSetOf() + private var queryText: String? = null override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.callBack = this @@ -107,8 +108,9 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } override fun onQueryTextChange(newText: String?): Boolean { - if (newText.isNullOrBlank()) viewModel.stop() - upHistory(newText) + queryText = newText + if (queryText.isNullOrBlank()) viewModel.stop() + upHistory(queryText) return false } }) @@ -180,7 +182,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se private fun openOrCloseHistory(open: Boolean) { if (open) { - upHistory("") + upHistory(queryText) ll_history.visibility = VISIBLE } else { ll_history.visibility = GONE From 083113ceec715d158f6ffd693517a56719719a8b Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Dec 2019 20:53:50 +0800 Subject: [PATCH 002/852] up --- .../ui/book/read/page/delegate/SimulationPageDelegate.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 0f2c62475..d120f7d2c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -130,13 +130,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi bitmap?.let { if (direction === Direction.NEXT) { calcPoints() - drawCurrentPageArea(canvas, it, mPath0!!) //绘制翻页时的正面页 + drawCurrentPageArea(canvas, it, mPath0) //绘制翻页时的正面页 // drawNextPageAreaAndShadow(canvas, it) drawCurrentPageShadow(canvas) drawCurrentBackArea(canvas, it) } else { calcPoints() - drawCurrentPageArea(canvas, it, mPath0!!) + drawCurrentPageArea(canvas, it, mPath0) // drawNextPageAreaAndShadow(canvas, it) drawCurrentPageShadow(canvas) drawCurrentBackArea(canvas, it) @@ -218,7 +218,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } } catch (ignored: Exception) { } - mPaint!!.colorFilter = mColorMatrixFilter + mPaint.colorFilter = mColorMatrixFilter val dis = hypot( mCornerX - mBezierControl1.x.toDouble(), mBezierControl2.y - mCornerY.toDouble() From 09243b6faa44dc4977ad59cebc119f047a0c2063 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 30 Dec 2019 20:57:58 +0800 Subject: [PATCH 003/852] up --- .../read/page/delegate/SimulationPageDelegate.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index d120f7d2c..8d7112056 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -434,15 +434,15 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi * 计算拖拽点对应的拖拽脚 */ private fun calcCornerXY(x: Float, y: Float) { - if (x <= pageView.width / 2.0) { - mCornerX = 0 + mCornerX = if (x <= pageView.width / 2.0) { + 0 } else { - mCornerX = pageView.width + pageView.width } - if (y <= pageView.height / 2.0) { - mCornerY = 0 + mCornerY = if (y <= pageView.height / 2.0) { + 0 } else { - mCornerY = pageView.height + pageView.height } mIsRT_LB = (mCornerX == 0 && mCornerY == pageView.height || mCornerX == pageView.width && mCornerY == 0) From 35efe8768dc1cc9d36ac2e9660541206b564444b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 31 Dec 2019 11:30:46 +0800 Subject: [PATCH 004/852] up --- .../app/ui/book/read/page/delegate/SimulationPageDelegate.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 8d7112056..ac3f00283 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -131,13 +131,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi if (direction === Direction.NEXT) { calcPoints() drawCurrentPageArea(canvas, it, mPath0) //绘制翻页时的正面页 -// drawNextPageAreaAndShadow(canvas, it) + drawNextPageAreaAndShadow(canvas, it) drawCurrentPageShadow(canvas) drawCurrentBackArea(canvas, it) } else { calcPoints() drawCurrentPageArea(canvas, it, mPath0) -// drawNextPageAreaAndShadow(canvas, it) + drawNextPageAreaAndShadow(canvas, it) drawCurrentPageShadow(canvas) drawCurrentBackArea(canvas, it) } From dafbb6d895e1e5b11d1f21a64283881688dad8cb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 31 Dec 2019 15:05:20 +0800 Subject: [PATCH 005/852] up --- .../ui/book/read/page/delegate/HorizontalPageDelegate.kt | 6 +----- .../app/ui/book/read/page/delegate/ScrollPageDelegate.kt | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index ef43b929e..ebb76100c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -39,11 +39,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie } } if (isMoved) { - isCancel = if (pageView.isScrollDelegate) { - if (direction == Direction.NEXT) distanceY < 0 else distanceY > 0 - } else { - if (direction == Direction.NEXT) distanceX < 0 else distanceX > 0 - } + isCancel = if (direction == Direction.NEXT) distanceX < 0 else distanceX > 0 isRunning = true //设置触摸点 setTouchPoint(e2.x, e2.y) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index bf8a51a02..5b25392a2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -109,11 +109,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { curPage?.dispatchTouchEvent(e2) } if (isMoved) { - isCancel = if (pageView.isScrollDelegate) { - if (direction == Direction.NEXT) distanceY < 0 else distanceY > 0 - } else { - if (direction == Direction.NEXT) distanceX < 0 else distanceX > 0 - } + isCancel = if (direction == Direction.NEXT) distanceY < 0 else distanceY > 0 isRunning = true //设置触摸点 setTouchPoint(e2.x, e2.y) From cea6795de7e121cad86391e5b5e1c8cfc4e86f2f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 31 Dec 2019 16:14:26 +0800 Subject: [PATCH 006/852] up --- .../io/legado/app/ui/book/source/manage/BookSourceViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 982476466..67b22be3f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -194,7 +194,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) else -> "格式不对" } }.onError { - finally(it.localizedMessage) + finally(it.localizedMessage ?: "") }.onSuccess { finally(it ?: "导入完成") } From dab8cb781b25584de81adc55cc49537e1e71e68c Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 31 Dec 2019 17:18:08 +0800 Subject: [PATCH 007/852] up --- .../io/legado/app/ui/main/MainViewModel.kt | 26 +++++++++++++++++++ .../io/legado/app/ui/main/rss/RssFragment.kt | 5 ++++ 2 files changed, 31 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 647b0bac2..6f282ef09 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -4,7 +4,14 @@ import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.constant.Bus +import io.legado.app.data.api.IHttpGetApi +import io.legado.app.data.entities.RssSource +import io.legado.app.help.http.HttpHelper +import io.legado.app.help.storage.Restore import io.legado.app.model.WebBook +import io.legado.app.utils.GSON +import io.legado.app.utils.NetworkUtils +import io.legado.app.utils.fromJsonObject import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.delay @@ -48,4 +55,23 @@ class MainViewModel(application: Application) : BaseViewModel(application) { } } + fun initRss() { + execute { + val url = "https://gitee.com/alanskycn/yuedu/raw/master/JS/RSS/rssSource" + NetworkUtils.getBaseUrl(url)?.let { + val response = HttpHelper.getApiService(it).get(url, mapOf()).execute() + response.body()?.let { body -> + val sources = mutableListOf() + val items: List> = Restore.jsonPath.parse(body).read("$") + for (item in items) { + val jsonItem = Restore.jsonPath.parse(item) + GSON.fromJsonObject(jsonItem.jsonString())?.let { source -> + sources.add(source) + } + } + App.db.rssSourceDao().insert(*sources.toTypedArray()) + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 13ac93c20..0ec49f315 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -11,8 +11,10 @@ import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.data.entities.RssSource import io.legado.app.lib.theme.ATH +import io.legado.app.ui.main.MainViewModel import io.legado.app.ui.rss.article.RssArticlesActivity import io.legado.app.ui.rss.source.manage.RssSourceActivity +import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_rss.* import kotlinx.android.synthetic.main.view_title_bar.* @@ -50,6 +52,9 @@ class RssFragment : BaseFragment(R.layout.fragment_rss), private fun initData() { App.db.rssSourceDao().liveEnabled().observe(viewLifecycleOwner, Observer { + if (it.isEmpty()) { + getViewModelOfActivity(MainViewModel::class.java).initRss() + } adapter.setItems(it) }) } From 788f5ce365fef4927f26ed389f33631d0386f756 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 12:42:34 +0800 Subject: [PATCH 008/852] up --- app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 6f282ef09..27b37fe1a 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -59,7 +59,8 @@ class MainViewModel(application: Application) : BaseViewModel(application) { execute { val url = "https://gitee.com/alanskycn/yuedu/raw/master/JS/RSS/rssSource" NetworkUtils.getBaseUrl(url)?.let { - val response = HttpHelper.getApiService(it).get(url, mapOf()).execute() + val response = + HttpHelper.getApiService(it).getAsync(url, mapOf()).await() response.body()?.let { body -> val sources = mutableListOf() val items: List> = Restore.jsonPath.parse(body).read("$") From 8d8a2321787456ba8afda38e14281dd82da9cd2b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 12:43:40 +0800 Subject: [PATCH 009/852] up --- .../rss/source/manage/RssSourceViewModel.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 0e458b3aa..6ee254029 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -60,19 +60,20 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) } } - fun exportSelection(ids: LinkedHashSet) { - execute { - App.db.rssSourceDao().getRssSources(*ids.toTypedArray()).let { - val json = GSON.toJson(it) - val file = FileHelp.getFile(Backup.exportPath + File.separator + "exportRssSource.json") - file.writeText(json) - } - }.onSuccess { - context.toast("成功导出至\n${Backup.exportPath}") - }.onError { - context.toast("导出失败\n${it.localizedMessage}") - } - } + fun exportSelection(ids: LinkedHashSet) { + execute { + App.db.rssSourceDao().getRssSources(*ids.toTypedArray()).let { + val json = GSON.toJson(it) + val file = + FileHelp.getFile(Backup.exportPath + File.separator + "exportRssSource.json") + file.writeText(json) + } + }.onSuccess { + context.toast("成功导出至\n${Backup.exportPath}") + }.onError { + context.toast("导出失败\n${it.localizedMessage}") + } + } fun addGroup(group: String) { execute { @@ -165,7 +166,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) else -> "格式不对" } }.onError { - finally(it.localizedMessage) + finally(it.localizedMessage ?: "") }.onSuccess { finally(it ?: "导入完成") } From 9258598adc7aa86ad3b504e13a87111355eec9ea Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 17:45:10 +0800 Subject: [PATCH 010/852] up --- app/src/main/res/menu/download.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/menu/download.xml b/app/src/main/res/menu/download.xml index 50dfdbeaa..cf4375f09 100644 --- a/app/src/main/res/menu/download.xml +++ b/app/src/main/res/menu/download.xml @@ -5,6 +5,7 @@ \ No newline at end of file From d81bb4c403d79c40784f4ace780b378b50cc9e63 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 17:58:00 +0800 Subject: [PATCH 011/852] up --- .../java/io/legado/app/service/DownloadService.kt | 1 + .../io/legado/app/ui/download/DownloadActivity.kt | 14 ++++++++++++-- app/src/main/res/menu/download.xml | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 798fcdfb8..d8bfae260 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -62,6 +62,7 @@ class DownloadService : BaseService() { searchPool.close() handler.removeCallbacks(runnable) super.onDestroy() + postEvent(Bus.UP_DOWNLOAD, false) } private fun download(bookUrl: String?, start: Int, end: Int) { diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt index 9789bc273..a2ff5d99e 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt @@ -12,6 +12,7 @@ import io.legado.app.base.BaseActivity import io.legado.app.constant.Bus import io.legado.app.data.entities.Book import io.legado.app.service.help.Download +import io.legado.app.utils.applyTint import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.activity_download.* import kotlinx.coroutines.Dispatchers.IO @@ -22,6 +23,7 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) { lateinit var adapter: DownloadAdapter private var bookshelfLiveData: LiveData>? = null + private var menu: Menu? = null override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() @@ -30,12 +32,13 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) { override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.download, menu) + this.menu = menu return super.onCompatCreateOptionsMenu(menu) } override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_download_start -> launch(IO) { + R.id.menu_download -> launch(IO) { App.db.bookDao().webBooks.forEach { book -> Download.start( this@DownloadActivity, @@ -65,7 +68,14 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) { override fun observeLiveBus() { observeEvent(Bus.UP_DOWNLOAD) { - adapter.notifyItemRangeChanged(0, adapter.itemCount, true) + if (it) { + menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp) + menu?.applyTint(this) + adapter.notifyItemRangeChanged(0, adapter.itemCount, true) + } else { + menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_play_24dp) + menu?.applyTint(this) + } } } } \ No newline at end of file diff --git a/app/src/main/res/menu/download.xml b/app/src/main/res/menu/download.xml index cf4375f09..452269d37 100644 --- a/app/src/main/res/menu/download.xml +++ b/app/src/main/res/menu/download.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> From 6326a28a1c35af709a70c195ad0cca99be34e373 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 18:08:02 +0800 Subject: [PATCH 012/852] up --- .../legado/app/ui/book/source/manage/BookSourceViewModel.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 67b22be3f..6ae3bd977 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -149,9 +149,11 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) importSource(file.readText(), finally) } else { withContext(Dispatchers.Main) { - finally("文件无法打开") + finally("打开文件出错") } } + }.onError { + finally(it.localizedMessage ?: "打开文件出错") } } From 549156d6526ed8187e092f2fdaaaaf5ef22348b1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 18:09:02 +0800 Subject: [PATCH 013/852] up --- .../io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fa6ca7ea4..aeb83a093 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 @@ -91,7 +91,7 @@ class BookSourceEditActivity : GSON.toJson(getSource())?.let { sourceStr -> try { val textIntent = Intent(Intent.ACTION_SEND) - textIntent.setType("text/plain") + textIntent.type = "text/plain" textIntent.putExtra(Intent.EXTRA_TEXT, sourceStr) startActivity(Intent.createChooser(textIntent, "Source Share")) } catch (e: Exception) { From 7aa349bf39cdae94f4942763b184a1ea96183ccb Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 18:36:24 +0800 Subject: [PATCH 014/852] up --- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_config_web_dav.xml | 40 +++++++++++--------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2d0ecb87c..2d16b399c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -96,6 +96,7 @@ 自动下载最新章节 更新书籍时自动下载最新章节 备份与恢复 + WebDav设置 WebDav设置/导入旧版本数据 备份 恢复 diff --git a/app/src/main/res/xml/pref_config_web_dav.xml b/app/src/main/res/xml/pref_config_web_dav.xml index 42733f458..0b4a84e09 100644 --- a/app/src/main/res/xml/pref_config_web_dav.xml +++ b/app/src/main/res/xml/pref_config_web_dav.xml @@ -2,23 +2,29 @@ - - - - - + + + + + + + + + From dadce9f8a70ef556894f95265f4248f98f88d049 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 18:42:33 +0800 Subject: [PATCH 015/852] up --- app/src/main/res/values-night/colors.xml | 8 +++++--- app/src/main/res/values/colors.xml | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index f9c4c4f7c..4933cfa2b 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -13,9 +13,11 @@ #30ffffff #363636 - #804D4D4D - #80686868 - #80C7C7C7 + + #634D4D4D + #63686868 + #63C7C7C7 + #66666666 #737373 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index da1e3c9b0..d150286a4 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -23,9 +23,9 @@ #d3321b - #80ACACAC - #80858585 - #802C2C2C + #63ACACAC + #63858585 + #632C2C2C #737373 #adadad From 66ff502e1f6f5e4af63a0156b35af54ca008a0ac Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 19:27:45 +0800 Subject: [PATCH 016/852] up --- .../app/ui/config/WebDavConfigFragment.kt | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 9eb761712..2cb612578 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.config +import android.content.Intent import android.os.Build import android.os.Bundle import android.text.InputType @@ -26,6 +27,8 @@ import io.legado.app.utils.getPrefString class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { + private val oldDataRequestCode = 23156 + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { fun bindPreferenceSummaryToValue(preference: Preference?) { preference?.apply { @@ -105,7 +108,18 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference WebDavHelp.showRestoreDialog(requireContext()) } .request() - "import_old" -> needInstallApps { + "import_old" -> importOldData() + } + return super.onPreferenceTreeClick(preference) + } + + private fun importOldData() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, oldDataRequestCode) + } catch (e: Exception) { + needInstallApps { alert(title = "导入") { message = "是否导入旧版本数据" yesButton { @@ -122,7 +136,6 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference }.show().applyTint() } } - return super.onPreferenceTreeClick(preference) } private fun needInstallApps(callback: () -> Unit) { @@ -147,4 +160,13 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference callback() } } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + oldDataRequestCode -> { + + } + } + } } \ No newline at end of file From d41a19bb1329d090b64ee6bf99e010f26ec3de82 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 20:28:32 +0800 Subject: [PATCH 017/852] up --- .../java/io/legado/app/ui/config/WebDavConfigFragment.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 2cb612578..88b5109f3 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.config +import android.app.Activity.RESULT_OK import android.content.Intent import android.os.Build import android.os.Bundle @@ -164,8 +165,10 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { - oldDataRequestCode -> { + oldDataRequestCode -> if (resultCode == RESULT_OK) { + data?.data?.let { + } } } } From b6691472bf336d42d10fedda01bbdd7e5595051e Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 21:18:17 +0800 Subject: [PATCH 018/852] up --- .../app/ui/config/WebDavConfigFragment.kt | 3 ++ .../java/io/legado/app/utils/DocumentUtils.kt | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 app/src/main/java/io/legado/app/utils/DocumentUtils.kt diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 88b5109f3..3cfe0af2e 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -6,6 +6,7 @@ import android.os.Build import android.os.Bundle import android.text.InputType import android.view.View +import androidx.documentfile.provider.DocumentFile import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference @@ -167,7 +168,9 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference when (requestCode) { oldDataRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { + DocumentFile.fromTreeUri(requireContext(), it)?.listFiles()?.forEach { + } } } } diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt new file mode 100644 index 000000000..276cfa473 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -0,0 +1,31 @@ +package io.legado.app.utils + +import android.content.Context +import android.net.Uri + +object DocumentUtils { + + fun readText(context: Context, uri: Uri): String? { + readBytes(context, uri)?.let { + return String(it) + } + return null + } + + fun readBytes(context: Context, uri: Uri): ByteArray? { + try { + context.contentResolver.openInputStream(uri)?.let { + val len: Int = it.available() + val buffer = ByteArray(len) + it.read(buffer) + it.close() + return buffer + } + } catch (e: Exception) { + e.printStackTrace() + } + return null + } + + +} \ No newline at end of file From 45d74ba7c1b9a32e580922e0fd33289f7fe76a14 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 21:23:22 +0800 Subject: [PATCH 019/852] up --- .../java/io/legado/app/utils/DocumentUtils.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 276cfa473..e10170892 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -5,6 +5,23 @@ import android.net.Uri object DocumentUtils { + fun writeText(context: Context, data: String, fileUri: Uri): Boolean { + return writeBytes(context, data.toByteArray(), fileUri) + } + + fun writeBytes(context: Context, data: ByteArray, fileUri: Uri): Boolean { + try { + context.contentResolver.openOutputStream(fileUri)?.let { + it.write(data) + it.close() + return true + } + } catch (e: java.lang.Exception) { + e.printStackTrace() + } + return false + } + fun readText(context: Context, uri: Uri): String? { readBytes(context, uri)?.let { return String(it) From a64d5b8cfb38654bde3c5f3f665cc6838521dbea Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 1 Jan 2020 21:52:13 +0800 Subject: [PATCH 020/852] up --- .../io/legado/app/help/storage/OldRule.kt | 1 + .../io/legado/app/help/storage/Restore.kt | 157 ++++++++++-------- .../app/ui/config/WebDavConfigFragment.kt | 25 ++- 3 files changed, 108 insertions(+), 75 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index 0c9baa659..14b4a9c53 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.kt @@ -205,4 +205,5 @@ object OldRule { return GSON.toJson(map) } + } diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index b2e34783e..920d61c0d 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -111,47 +111,12 @@ object Restore { fun importYueDuData(context: Context) { GlobalScope.launch(IO) { try {// 导入书架 - val shelfFile = FileHelp.getFile(Backup.defaultPath + File.separator + "myBookShelf.json") - val books = mutableListOf() - val items: List> = jsonPath.parse(shelfFile.readText()).read("$") - val existingBooks = App.db.bookDao().allBookUrls.toSet() - for (item in items) { - val jsonItem = jsonPath.parse(item) - val book = Book() - book.bookUrl = jsonItem.readString("$.noteUrl") ?: "" - if (book.bookUrl.isBlank()) continue - book.name = jsonItem.readString("$.bookInfoBean.name") ?: "" - if (book.bookUrl in existingBooks) { - Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}") - continue - } - book.origin = jsonItem.readString("$.tag") ?: "" - book.originName = jsonItem.readString("$.bookInfoBean.origin") ?: "" - book.author = jsonItem.readString("$.bookInfoBean.author") ?: "" - book.type = - if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0 - book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl - book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl") - book.customCoverUrl = jsonItem.readString("$.customCoverPath") - book.lastCheckTime = jsonItem.readLong("$.bookInfoBean.finalRefreshData") ?: 0 - book.canUpdate = jsonItem.readBool("$.allowUpdate") == true - book.totalChapterNum = jsonItem.readInt("$.chapterListSize") ?: 0 - book.durChapterIndex = jsonItem.readInt("$.durChapter") ?: 0 - book.durChapterTitle = jsonItem.readString("$.durChapterName") - book.durChapterPos = jsonItem.readInt("$.durChapterPage") ?: 0 - book.durChapterTime = jsonItem.readLong("$.finalDate") ?: 0 - book.group = jsonItem.readInt("$.group") ?: 0 - book.intro = jsonItem.readString("$.bookInfoBean.introduce") - book.latestChapterTitle = jsonItem.readString("$.lastChapterName") - book.lastCheckCount = jsonItem.readInt("$.newChapters") ?: 0 - book.order = jsonItem.readInt("$.serialNumber") ?: 0 - book.useReplaceRule = jsonItem.readBool("$.useReplaceRule") == true - book.variable = jsonItem.readString("$.variable") - books.add(book) - } - App.db.bookDao().insert(*books.toTypedArray()) + val shelfFile = + FileHelp.getFile(Backup.defaultPath + File.separator + "myBookShelf.json") + val json = shelfFile.readText() + val importCount = importOldBookshelf(json) withContext(Main) { - context.toast("成功导入书籍${books.size}") + context.toast("成功导入书籍${importCount}") } } catch (e: Exception) { withContext(Main) { @@ -162,17 +127,10 @@ object Restore { try {// Book source val sourceFile = FileHelp.getFile(Backup.defaultPath + File.separator + "myBookSource.json") - val bookSources = mutableListOf() - val items: List> = jsonPath.parse(sourceFile.readText()).read("$") - for (item in items) { - val jsonItem = jsonPath.parse(item) - OldRule.jsonToBookSource(jsonItem.jsonString())?.let { - bookSources.add(it) - } - } - App.db.bookSourceDao().insert(*bookSources.toTypedArray()) + val json = sourceFile.readText() + val importCount = importOldSource(json) withContext(Main) { - context.toast("成功导入书源${bookSources.size}") + context.toast("成功导入书源${importCount}") } } catch (e: Exception) { withContext(Main) { @@ -183,26 +141,10 @@ object Restore { try {// Replace rules val ruleFile = FileHelp.getFile(Backup.defaultPath + File.separator + "myBookReplaceRule.json") - val replaceRules = mutableListOf() - val items: List> = jsonPath.parse(ruleFile.readText()).read("$") - val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet() - for ((index: Int, item: Map) in items.withIndex()) { - val jsonItem = jsonPath.parse(item) - val rule = ReplaceRule() - rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis().plus(index) - rule.pattern = jsonItem.readString("$.regex") ?: "" - if (rule.pattern.isEmpty() || rule.pattern in existingRules) continue - rule.name = jsonItem.readString("$.replaceSummary") ?: "" - rule.replacement = jsonItem.readString("$.replacement") ?: "" - rule.isRegex = jsonItem.readBool("$.isRegex") == true - rule.scope = jsonItem.readString("$.useTo") - rule.isEnabled = jsonItem.readBool("$.enable") == true - rule.order = jsonItem.readInt("$.serialNumber") ?: index - replaceRules.add(rule) - } - App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) + val json = ruleFile.readText() + val importCount = importOldReplaceRule(json) withContext(Main) { - context.toast("成功导入替换规则${replaceRules.size}") + context.toast("成功导入替换规则${importCount}") } } catch (e: Exception) { withContext(Main) { @@ -211,4 +153,81 @@ object Restore { } } } + + fun importOldBookshelf(json: String): Int { + val books = mutableListOf() + val items: List> = jsonPath.parse(json).read("$") + val existingBooks = App.db.bookDao().allBookUrls.toSet() + for (item in items) { + val jsonItem = jsonPath.parse(item) + val book = Book() + book.bookUrl = jsonItem.readString("$.noteUrl") ?: "" + if (book.bookUrl.isBlank()) continue + book.name = jsonItem.readString("$.bookInfoBean.name") ?: "" + if (book.bookUrl in existingBooks) { + Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}") + continue + } + book.origin = jsonItem.readString("$.tag") ?: "" + book.originName = jsonItem.readString("$.bookInfoBean.origin") ?: "" + book.author = jsonItem.readString("$.bookInfoBean.author") ?: "" + book.type = + if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0 + book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl + book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl") + book.customCoverUrl = jsonItem.readString("$.customCoverPath") + book.lastCheckTime = jsonItem.readLong("$.bookInfoBean.finalRefreshData") ?: 0 + book.canUpdate = jsonItem.readBool("$.allowUpdate") == true + book.totalChapterNum = jsonItem.readInt("$.chapterListSize") ?: 0 + book.durChapterIndex = jsonItem.readInt("$.durChapter") ?: 0 + book.durChapterTitle = jsonItem.readString("$.durChapterName") + book.durChapterPos = jsonItem.readInt("$.durChapterPage") ?: 0 + book.durChapterTime = jsonItem.readLong("$.finalDate") ?: 0 + book.group = jsonItem.readInt("$.group") ?: 0 + book.intro = jsonItem.readString("$.bookInfoBean.introduce") + book.latestChapterTitle = jsonItem.readString("$.lastChapterName") + book.lastCheckCount = jsonItem.readInt("$.newChapters") ?: 0 + book.order = jsonItem.readInt("$.serialNumber") ?: 0 + book.useReplaceRule = jsonItem.readBool("$.useReplaceRule") == true + book.variable = jsonItem.readString("$.variable") + books.add(book) + } + App.db.bookDao().insert(*books.toTypedArray()) + return books.size + } + + fun importOldSource(json: String): Int { + val bookSources = mutableListOf() + val items: List> = jsonPath.parse(json).read("$") + for (item in items) { + val jsonItem = jsonPath.parse(item) + OldRule.jsonToBookSource(jsonItem.jsonString())?.let { + bookSources.add(it) + } + } + App.db.bookSourceDao().insert(*bookSources.toTypedArray()) + return bookSources.size + } + + fun importOldReplaceRule(json: String): Int { + val replaceRules = mutableListOf() + val items: List> = jsonPath.parse(json).read("$") + val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet() + for ((index: Int, item: Map) in items.withIndex()) { + val jsonItem = jsonPath.parse(item) + val rule = ReplaceRule() + rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis().plus(index) + rule.pattern = jsonItem.readString("$.regex") ?: "" + if (rule.pattern.isEmpty() || rule.pattern in existingRules) continue + rule.name = jsonItem.readString("$.replaceSummary") ?: "" + rule.replacement = jsonItem.readString("$.replacement") ?: "" + rule.isRegex = jsonItem.readBool("$.isRegex") == true + rule.scope = jsonItem.readString("$.useTo") + rule.isEnabled = jsonItem.readBool("$.enable") == true + rule.order = jsonItem.readInt("$.serialNumber") ?: index + replaceRules.add(rule) + } + App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) + return replaceRules.size + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 3cfe0af2e..0ccf98f7c 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -23,6 +23,7 @@ import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.DocumentUtils import io.legado.app.utils.LogUtils import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString @@ -142,7 +143,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference private fun needInstallApps(callback: () -> Unit) { - fun canRequestPackageInstalls() :Boolean { + fun canRequestPackageInstalls(): Boolean { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { return requireContext().packageManager.canRequestPackageInstalls() } @@ -158,7 +159,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference } }.show().applyTint() } else { - LogUtils.d("xxx","import old") + LogUtils.d("xxx", "import old") callback() } } @@ -166,13 +167,25 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { - oldDataRequestCode -> if (resultCode == RESULT_OK) { - data?.data?.let { - DocumentFile.fromTreeUri(requireContext(), it)?.listFiles()?.forEach { - + oldDataRequestCode -> if (resultCode == RESULT_OK) data?.data?.let { uri -> + DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { + when (it.name) { + "myBookShelf.json" -> + DocumentUtils.readText(requireContext(), it.uri)?.let { json -> + Restore.importOldBookshelf(json) + } + "myBookSource.json" -> + DocumentUtils.readText(requireContext(), it.uri)?.let { json -> + Restore.importOldSource(json) + } + "myBookReplaceRule.json" -> + DocumentUtils.readText(requireContext(), it.uri)?.let { json -> + Restore.importOldReplaceRule(json) + } } } } + } } } \ No newline at end of file From d3541b7e536e24be7642f8554868a39045ee38de Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 2 Jan 2020 10:34:42 +0800 Subject: [PATCH 021/852] up --- .../legado/app/base/BasePreferenceFragment.kt | 27 +++++++ .../app/ui/config/WebDavConfigFragment.kt | 78 ++++++++++++++----- 2 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt diff --git a/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt b/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt new file mode 100644 index 000000000..b2c07d63f --- /dev/null +++ b/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt @@ -0,0 +1,27 @@ +package io.legado.app.base + +import android.os.Bundle +import androidx.preference.PreferenceFragmentCompat +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlin.coroutines.CoroutineContext + + +abstract class BasePreferenceFragment : PreferenceFragmentCompat(), CoroutineScope { + + lateinit var job: Job + + override val coroutineContext: CoroutineContext + get() = job + Dispatchers.Main + + override fun onCreate(savedInstanceState: Bundle?) { + job = Job() + super.onCreate(savedInstanceState) + } + + override fun onDestroy() { + super.onDestroy() + job.cancel() + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 0ccf98f7c..68fc6780a 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.config import android.app.Activity.RESULT_OK import android.content.Intent +import android.net.Uri import android.os.Build import android.os.Bundle import android.text.InputType @@ -10,8 +11,8 @@ import androidx.documentfile.provider.DocumentFile import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.base.BasePreferenceFragment import io.legado.app.help.IntentHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat @@ -27,8 +28,13 @@ import io.legado.app.utils.DocumentUtils import io.legado.app.utils.LogUtils import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import org.jetbrains.anko.toast -class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { +class WebDavConfigFragment : BasePreferenceFragment(), Preference.OnPreferenceChangeListener { private val oldDataRequestCode = 23156 @@ -141,6 +147,54 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference } } + private fun importOldData(uri: Uri) { + launch(IO) { + DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { + when (it.name) { + "myBookShelf.json" -> + try { + DocumentUtils.readText(requireContext(), it.uri)?.let { json -> + val importCount = Restore.importOldBookshelf(json) + withContext(Dispatchers.Main) { + requireContext().toast("成功导入书籍${importCount}") + } + } + } catch (e: java.lang.Exception) { + withContext(Dispatchers.Main) { + requireContext().toast("导入书籍失败\n${e.localizedMessage}") + } + } + "myBookSource.json" -> + try { + DocumentUtils.readText(requireContext(), it.uri)?.let { json -> + val importCount = Restore.importOldSource(json) + withContext(Dispatchers.Main) { + requireContext().toast("成功导入书源${importCount}") + } + } + } catch (e: Exception) { + withContext(Dispatchers.Main) { + requireContext().toast("导入源失败\n${e.localizedMessage}") + } + } + "myBookReplaceRule.json" -> + try { + DocumentUtils.readText(requireContext(), it.uri)?.let { json -> + val importCount = Restore.importOldReplaceRule(json) + withContext(Dispatchers.Main) { + requireContext().toast("成功导入替换规则${importCount}") + } + } + } catch (e: Exception) { + withContext(Dispatchers.Main) { + requireContext().toast("导入替换规则失败\n${e.localizedMessage}") + } + } + } + } + } + } + private fun needInstallApps(callback: () -> Unit) { fun canRequestPackageInstalls(): Boolean { @@ -167,24 +221,10 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreference override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { - oldDataRequestCode -> if (resultCode == RESULT_OK) data?.data?.let { uri -> - DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { - when (it.name) { - "myBookShelf.json" -> - DocumentUtils.readText(requireContext(), it.uri)?.let { json -> - Restore.importOldBookshelf(json) - } - "myBookSource.json" -> - DocumentUtils.readText(requireContext(), it.uri)?.let { json -> - Restore.importOldSource(json) - } - "myBookReplaceRule.json" -> - DocumentUtils.readText(requireContext(), it.uri)?.let { json -> - Restore.importOldReplaceRule(json) - } - } + oldDataRequestCode -> + if (resultCode == RESULT_OK) data?.data?.let { uri -> + importOldData(uri) } - } } } From b972679f6a14375065652284a16adeef1a98b598 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 2 Jan 2020 16:16:41 +0800 Subject: [PATCH 022/852] up --- .../legado/app/base/BasePreferenceFragment.kt | 27 ----- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../ui/book/read/config/ReadStyleDialog.kt | 17 +-- .../app/ui/config/WebDavConfigFragment.kt | 22 +++- .../app/ui/widget/font/FontSelectDialog.kt | 108 +++++++++++------- .../java/io/legado/app/utils/DocumentUtils.kt | 4 + .../main/res/layout/dialog_font_select.xml | 16 ++- 7 files changed, 102 insertions(+), 93 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt diff --git a/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt b/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt deleted file mode 100644 index b2c07d63f..000000000 --- a/app/src/main/java/io/legado/app/base/BasePreferenceFragment.kt +++ /dev/null @@ -1,27 +0,0 @@ -package io.legado.app.base - -import android.os.Bundle -import androidx.preference.PreferenceFragmentCompat -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job -import kotlin.coroutines.CoroutineContext - - -abstract class BasePreferenceFragment : PreferenceFragmentCompat(), CoroutineScope { - - lateinit var job: Job - - override val coroutineContext: CoroutineContext - get() = job + Dispatchers.Main - - override fun onCreate(savedInstanceState: Bundle?) { - job = Job() - super.onCreate(savedInstanceState) - } - - override fun onDestroy() { - super.onDestroy() - job.cancel() - } -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index c777fdb9a..bc74ed1ab 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -16,4 +16,5 @@ object PreferKey { const val lastGroup = "lastGroup" const val pageAnim = "pageAnim" const val readBookFont = "readBookFont" + const val fontFolder = "fontFolder" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 098edad43..e19231b4a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -20,7 +20,10 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.widget.font.FontSelectDialog -import io.legado.app.utils.* +import io.legado.app.utils.getPrefInt +import io.legado.app.utils.postEvent +import io.legado.app.utils.progressAdd +import io.legado.app.utils.putPrefInt import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.dialog_read_book_style.* import org.jetbrains.anko.sdk27.listeners.onCheckedChange @@ -86,17 +89,7 @@ class ReadStyleDialog : DialogFragment() { postEvent(Bus.UP_CONFIG, false) } tv_text_font.onClick { - FontSelectDialog(requireContext()).apply { - curPath = requireContext().getPrefString(PreferKey.readBookFont) - defaultFont = { - requireContext().putPrefString(PreferKey.readBookFont, "") - postEvent(Bus.UP_CONFIG, true) - } - selectFile = { - requireContext().putPrefString(PreferKey.readBookFont, it) - postEvent(Bus.UP_CONFIG, true) - } - }.show() + FontSelectDialog().show(childFragmentManager, "fontSelectDialog") } tv_text_indent.onClick { selector( diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 68fc6780a..28f9c825d 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -11,8 +11,8 @@ import androidx.documentfile.provider.DocumentFile import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat import io.legado.app.R -import io.legado.app.base.BasePreferenceFragment import io.legado.app.help.IntentHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat @@ -28,17 +28,22 @@ import io.legado.app.utils.DocumentUtils import io.legado.app.utils.LogUtils import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString -import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.jetbrains.anko.toast +import kotlin.coroutines.CoroutineContext -class WebDavConfigFragment : BasePreferenceFragment(), Preference.OnPreferenceChangeListener { - +class WebDavConfigFragment : PreferenceFragmentCompat(), + Preference.OnPreferenceChangeListener, + CoroutineScope { + lateinit var job: Job private val oldDataRequestCode = 23156 + override val coroutineContext: CoroutineContext + get() = job + Dispatchers.Main + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + job = Job() fun bindPreferenceSummaryToValue(preference: Preference?) { preference?.apply { onPreferenceChangeListener = this@WebDavConfigFragment @@ -76,6 +81,11 @@ class WebDavConfigFragment : BasePreferenceFragment(), Preference.OnPreferenceCh ATH.applyEdgeEffectColor(listView) } + override fun onDestroy() { + super.onDestroy() + job.cancel() + } + override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { when { preference?.key == "web_dav_password" -> if (newValue == null) { diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index b276072b4..f95923f1e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -1,68 +1,83 @@ package io.legado.app.ui.widget.font import android.annotation.SuppressLint -import android.content.Context -import android.os.Environment +import android.app.Activity.RESULT_OK +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View -import androidx.appcompat.app.AlertDialog +import android.view.ViewGroup +import androidx.documentfile.provider.DocumentFile +import androidx.fragment.app.DialogFragment import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R -import io.legado.app.lib.dialogs.AlertBuilder -import io.legado.app.lib.dialogs.alert -import io.legado.app.utils.applyTint -import io.legado.app.utils.invisible -import io.legado.app.utils.visible -import kotlinx.android.synthetic.main.dialog_font_select.view.* +import io.legado.app.constant.PreferKey +import io.legado.app.help.FileHelp +import io.legado.app.utils.DocumentUtils +import io.legado.app.utils.getPrefString +import kotlinx.android.synthetic.main.dialog_font_select.* import java.io.File -class FontSelectDialog(context: Context) : FontAdapter.CallBack { - - private val defaultFolder = - Environment.getExternalStorageDirectory().absolutePath + File.separator + "Fonts" +class FontSelectDialog : DialogFragment(), FontAdapter.CallBack { + private val fontFolderRequestCode = 35485 private lateinit var adapter: FontAdapter - private var builder: AlertBuilder - private var dialog: AlertDialog? = null - @SuppressLint("InflateParams") - private var view: View = LayoutInflater.from(context).inflate(R.layout.dialog_font_select, null) var curPath: String? = null - var fontFolder: String? = null + val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator var defaultFont: (() -> Unit)? = null var selectFile: ((path: String) -> Unit)? = null - init { - builder = context.alert(title = context.getString(R.string.select_font)) { - customView = view - positiveButton(R.string.default_font) { defaultFont?.invoke() } - negativeButton(R.string.cancel) - } - initData() + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt()) } - fun show() { - dialog = builder.show().applyTint() + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_font_select, container) } - private fun initData() = with(view) { - adapter = FontAdapter(context, this@FontSelectDialog) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + tool_bar.setTitle(R.string.select_font) + adapter = FontAdapter(requireContext(), this) recycler_view.layoutManager = LinearLayoutManager(context) recycler_view.adapter = adapter - val files = getFontFiles() - if (files.isNullOrEmpty()) { - tv_no_data.visible() - } else { - tv_no_data.invisible() - adapter.setItems(files.toList()) + + val fontPath = getPrefString(PreferKey.fontFolder) + if (fontPath.isNullOrEmpty()) { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, fontFolderRequestCode) + } catch (e: java.lang.Exception) { + + } + } + } + + @SuppressLint("DefaultLocale") + private fun getFontFiles(uri: Uri) { + DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { file -> + if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { + DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { + FileHelp.getFile(fontFolder + file.name).writeBytes(it) + } + } } } @SuppressLint("DefaultLocale") private fun getFontFiles(): Array? { - val path = if (fontFolder.isNullOrEmpty()) { - defaultFolder - } else fontFolder return try { - val file = File(path) + val file = File(fontFolder) file.listFiles { pathName -> pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) } @@ -83,4 +98,19 @@ class FontSelectDialog(context: Context) : FontAdapter.CallBack { override fun curFilePath(): String { return curPath ?: "" } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + fontFolderRequestCode -> if (resultCode == RESULT_OK) { + data?.data?.let { uri -> + getFontFiles(uri) + } + } + } + } + + interface CallBack { + fun selectFile(uri: Uri) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index e10170892..dcb128a8e 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -5,10 +5,12 @@ import android.net.Uri object DocumentUtils { + @JvmStatic fun writeText(context: Context, data: String, fileUri: Uri): Boolean { return writeBytes(context, data.toByteArray(), fileUri) } + @JvmStatic fun writeBytes(context: Context, data: ByteArray, fileUri: Uri): Boolean { try { context.contentResolver.openOutputStream(fileUri)?.let { @@ -22,6 +24,7 @@ object DocumentUtils { return false } + @JvmStatic fun readText(context: Context, uri: Uri): String? { readBytes(context, uri)?.let { return String(it) @@ -29,6 +32,7 @@ object DocumentUtils { return null } + @JvmStatic fun readBytes(context: Context, uri: Uri): ByteArray? { try { context.contentResolver.openInputStream(uri)?.let { diff --git a/app/src/main/res/layout/dialog_font_select.xml b/app/src/main/res/layout/dialog_font_select.xml index 08e33c0a9..60f080003 100644 --- a/app/src/main/res/layout/dialog_font_select.xml +++ b/app/src/main/res/layout/dialog_font_select.xml @@ -1,20 +1,18 @@ - - - + android:layout_height="match_parent" /> - \ No newline at end of file + \ No newline at end of file From 82dce02541c09c561bfe1d540ae355b84a4e4df0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 2 Jan 2020 16:35:55 +0800 Subject: [PATCH 023/852] up --- .../main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index f95923f1e..5934bd08f 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -25,7 +25,8 @@ class FontSelectDialog : DialogFragment(), FontAdapter.CallBack { private val fontFolderRequestCode = 35485 private lateinit var adapter: FontAdapter var curPath: String? = null - val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator + private val fontFolder = + App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator var defaultFont: (() -> Unit)? = null var selectFile: ((path: String) -> Unit)? = null From e49a512185399b887b37747827441ed8a7eba1b7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 2 Jan 2020 16:45:42 +0800 Subject: [PATCH 024/852] up --- .../app/ui/widget/font/FontSelectDialog.kt | 53 +++++++++++++------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 5934bd08f..eb1f7eeb6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -18,10 +18,21 @@ import io.legado.app.constant.PreferKey import io.legado.app.help.FileHelp import io.legado.app.utils.DocumentUtils import io.legado.app.utils.getPrefString +import io.legado.app.utils.toast import kotlinx.android.synthetic.main.dialog_font_select.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import java.io.File +import kotlin.coroutines.CoroutineContext -class FontSelectDialog : DialogFragment(), FontAdapter.CallBack { +class FontSelectDialog : DialogFragment(), + CoroutineScope, + FontAdapter.CallBack { + lateinit var job: Job private val fontFolderRequestCode = 35485 private lateinit var adapter: FontAdapter var curPath: String? = null @@ -29,6 +40,8 @@ class FontSelectDialog : DialogFragment(), FontAdapter.CallBack { App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator var defaultFont: (() -> Unit)? = null var selectFile: ((path: String) -> Unit)? = null + override val coroutineContext: CoroutineContext + get() = job + Main override fun onStart() { super.onStart() @@ -42,6 +55,7 @@ class FontSelectDialog : DialogFragment(), FontAdapter.CallBack { container: ViewGroup?, savedInstanceState: Bundle? ): View? { + job = Job() return inflater.inflate(R.layout.dialog_font_select, container) } @@ -64,26 +78,33 @@ class FontSelectDialog : DialogFragment(), FontAdapter.CallBack { } } + override fun onDestroy() { + super.onDestroy() + job.cancel() + } + @SuppressLint("DefaultLocale") private fun getFontFiles(uri: Uri) { - DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { file -> - if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { - DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { - FileHelp.getFile(fontFolder + file.name).writeBytes(it) + launch(IO) { + DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { file -> + if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { + DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { + FileHelp.getFile(fontFolder + file.name).writeBytes(it) + } } } - } - } - - @SuppressLint("DefaultLocale") - private fun getFontFiles(): Array? { - return try { - val file = File(fontFolder) - file.listFiles { pathName -> - pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) + try { + val file = File(fontFolder) + file.listFiles { pathName -> + pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) + }?.let { + withContext(Main) { + adapter.setItems(it.toList()) + } + } + } catch (e: Exception) { + toast(e.localizedMessage ?: "") } - } catch (e: Exception) { - null } } From 30ddbec3a64e881ef7494ba4a14d9a911c6f9bc6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 10:30:56 +0800 Subject: [PATCH 025/852] up --- .../main/java/io/legado/app/ui/about/DonateActivity.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt index 107be8809..18c8730e4 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt @@ -34,10 +34,10 @@ class DonateActivity : BaseActivity(R.layout.activity_donate) { toast(R.string.copy_complete) } } - vw_zfb_hb.setOnClickListener { openActionViewIntent("https://gedoor.github.io/MyBookshelf/zfbhbrwm.png") } - vw_zfb_rwm.setOnClickListener { openActionViewIntent("https://gedoor.github.io/MyBookshelf/zfbskrwm.jpg") } - vw_wx_rwm.setOnClickListener { openActionViewIntent("https://gedoor.github.io/MyBookshelf/wxskrwm.jpg") } - vw_qq_rwm.setOnClickListener { openActionViewIntent("https://gedoor.github.io/MyBookshelf/qqskrwm.jpg") } + vw_zfb_hb.setOnClickListener { openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/zfbhbrwm.png") } + vw_zfb_rwm.setOnClickListener { openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/zfbskrwm.jpg") } + vw_wx_rwm.setOnClickListener { openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/wxskrwm.jpg") } + vw_qq_rwm.setOnClickListener { openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/qqskrwm.jpg") } vw_zfb_hb_ssm.setOnClickListener { getZfbHb(this) } } From 7629542e1d669bdcbe85cef8232421ac54a6e6ef Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 10:41:14 +0800 Subject: [PATCH 026/852] up --- app/src/main/java/io/legado/app/ui/about/DonateActivity.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt index 18c8730e4..870f85f53 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt @@ -75,9 +75,10 @@ class DonateActivity : BaseActivity(R.layout.activity_donate) { private fun aliDonate(context: Context) { try { - val qrCode = URLEncoder.encode("tsx06677nwdk3javroq4ef0", "utf-8") - val aliPayQr = - "alipayqr://platformapi/startapp?saId=10000007&qrcode=https://qr.alipay.com/$qrCode" + var qrCode = URLEncoder.encode("https://qr.alipay.com/tsx06677nwdk3javroq4ef0", "utf-8") + qrCode = "qrcode=$qrCode%3F_s%3Dweb-other" + qrCode = "saId=10000007&$qrCode&_t=${System.currentTimeMillis()}" + val aliPayQr = "alipayqr://platformapi/startapp?$qrCode" val intent = Intent(Intent.ACTION_VIEW, Uri.parse(aliPayQr)) context.startActivity(intent) } catch (e: Exception) { From 776ce45ef28be5ed65e96fa53418ecc88166b88c Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 10:52:50 +0800 Subject: [PATCH 027/852] up --- .../main/java/io/legado/app/ui/about/DonateActivity.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt index 870f85f53..61cf11177 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt @@ -75,10 +75,12 @@ class DonateActivity : BaseActivity(R.layout.activity_donate) { private fun aliDonate(context: Context) { try { - var qrCode = URLEncoder.encode("https://qr.alipay.com/tsx06677nwdk3javroq4ef0", "utf-8") - qrCode = "qrcode=$qrCode%3F_s%3Dweb-other" - qrCode = "saId=10000007&$qrCode&_t=${System.currentTimeMillis()}" - val aliPayQr = "alipayqr://platformapi/startapp?$qrCode" + val qrCode = URLEncoder.encode( + "https://qr.alipay.com/fkx03463i8oppupkpsoo1f?_s=Dweb-other", + "utf-8" + ) + val aliPayQr = + "alipayqr://platformapi/startapp?saId=10000007&qrcode=$qrCode&_t=${System.currentTimeMillis()}" val intent = Intent(Intent.ACTION_VIEW, Uri.parse(aliPayQr)) context.startActivity(intent) } catch (e: Exception) { From 215cc82b8aa6a2153798748cff59354c7f2ddbf9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 10:56:27 +0800 Subject: [PATCH 028/852] up --- app/src/main/java/io/legado/app/ui/about/DonateActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt index 61cf11177..19e950ec8 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateActivity.kt @@ -76,7 +76,7 @@ class DonateActivity : BaseActivity(R.layout.activity_donate) { private fun aliDonate(context: Context) { try { val qrCode = URLEncoder.encode( - "https://qr.alipay.com/fkx03463i8oppupkpsoo1f?_s=Dweb-other", + "https://qr.alipay.com/tsx06677nwdk3javroq4ef0?_s=Dweb-other", "utf-8" ) val aliPayQr = From 8e0f4c7f81f660f963343ac0cfe4a28da6e601af Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 15:40:53 +0800 Subject: [PATCH 029/852] up --- .../io/legado/app/ui/widget/font/FontSelectDialog.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index eb1f7eeb6..714111062 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -18,6 +18,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.help.FileHelp import io.legado.app.utils.DocumentUtils import io.legado.app.utils.getPrefString +import io.legado.app.utils.putPrefString import io.legado.app.utils.toast import kotlinx.android.synthetic.main.dialog_font_select.* import kotlinx.coroutines.CoroutineScope @@ -38,7 +39,6 @@ class FontSelectDialog : DialogFragment(), var curPath: String? = null private val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator - var defaultFont: (() -> Unit)? = null var selectFile: ((path: String) -> Unit)? = null override val coroutineContext: CoroutineContext get() = job + Main @@ -75,6 +75,9 @@ class FontSelectDialog : DialogFragment(), } catch (e: java.lang.Exception) { } + } else { + val uri = Uri.parse(fontPath) + getFontFiles(uri) } } @@ -126,6 +129,11 @@ class FontSelectDialog : DialogFragment(), when (requestCode) { fontFolderRequestCode -> if (resultCode == RESULT_OK) { data?.data?.let { uri -> + putPrefString(PreferKey.fontFolder, uri.toString()) + context?.contentResolver?.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION + ) getFontFiles(uri) } } From fbd2e4573dfc248d68b90f28e30ad4f34ee811a3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 15:52:56 +0800 Subject: [PATCH 030/852] up --- .../app/ui/widget/font/FontSelectDialog.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 714111062..194007e6c 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -16,6 +16,8 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.FileHelp +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat import io.legado.app.utils.DocumentUtils import io.legado.app.utils.getPrefString import io.legado.app.utils.putPrefString @@ -73,7 +75,11 @@ class FontSelectDialog : DialogFragment(), intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) startActivityForResult(intent, fontFolderRequestCode) } catch (e: java.lang.Exception) { - + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { getFontFilesOld() } + .request() } } else { val uri = Uri.parse(fontPath) @@ -111,6 +117,20 @@ class FontSelectDialog : DialogFragment(), } } + @SuppressLint("DefaultLocale") + private fun getFontFilesOld() { + try { + val file = File(fontFolder) + file.listFiles { pathName -> + pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) + }?.let { + adapter.setItems(it.toList()) + } + } catch (e: Exception) { + toast(e.localizedMessage ?: "") + } + } + override fun onClick(file: File) { file.absolutePath.let { if (it != curPath) { From d1e25c9772ccd6610630d2968382456050139b6c Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 16:23:13 +0800 Subject: [PATCH 031/852] up --- .../app/ui/widget/font/FontSelectDialog.kt | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 194007e6c..ca154a4ea 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -70,20 +70,14 @@ class FontSelectDialog : DialogFragment(), val fontPath = getPrefString(PreferKey.fontFolder) if (fontPath.isNullOrEmpty()) { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, fontFolderRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { getFontFilesOld() } - .request() - } + openFolder() } else { val uri = Uri.parse(fontPath) - getFontFiles(uri) + if (DocumentFile.fromTreeUri(requireContext(), uri)?.canRead() == true) { + getFontFiles(uri) + } else { + openFolder() + } } } @@ -92,6 +86,20 @@ class FontSelectDialog : DialogFragment(), job.cancel() } + private fun openFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, fontFolderRequestCode) + } catch (e: java.lang.Exception) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { getFontFilesOld() } + .request() + } + } + @SuppressLint("DefaultLocale") private fun getFontFiles(uri: Uri) { launch(IO) { From 572c5957a24f36cbdfe7f8ff6267d9f73c4c3ed1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 16:47:58 +0800 Subject: [PATCH 032/852] up --- .../app/ui/widget/font/FontSelectDialog.kt | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index ca154a4ea..4d726d973 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -38,10 +38,8 @@ class FontSelectDialog : DialogFragment(), lateinit var job: Job private val fontFolderRequestCode = 35485 private lateinit var adapter: FontAdapter - var curPath: String? = null private val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator - var selectFile: ((path: String) -> Unit)? = null override val coroutineContext: CoroutineContext get() = job + Main @@ -141,15 +139,32 @@ class FontSelectDialog : DialogFragment(), override fun onClick(file: File) { file.absolutePath.let { - if (it != curPath) { - selectFile?.invoke(it) - dialog?.dismiss() + val pf = parentFragment + if (pf is CallBack) { + if (it != pf.curPath) { + pf.selectFile(it) + } + } + val activity = activity + if (activity is CallBack) { + if (it != activity.curPath) { + activity.selectFile(it) + } } } + dialog?.dismiss() } override fun curFilePath(): String { - return curPath ?: "" + val pf = parentFragment + if (pf is CallBack) { + return pf.curPath + } + val activity = activity + if (activity is CallBack) { + return activity.curPath + } + return "" } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { @@ -169,6 +184,7 @@ class FontSelectDialog : DialogFragment(), } interface CallBack { - fun selectFile(uri: Uri) + fun selectFile(path: String) + val curPath: String } } \ No newline at end of file From c2df639f949a2ebdf0333bc96814b37240b37604 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 17:07:32 +0800 Subject: [PATCH 033/852] up --- .../app/ui/book/read/config/ReadStyleDialog.kt | 15 ++++++++++----- .../legado/app/ui/widget/font/FontSelectDialog.kt | 10 +++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index e19231b4a..3bc5060b0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -20,17 +20,14 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.widget.font.FontSelectDialog -import io.legado.app.utils.getPrefInt -import io.legado.app.utils.postEvent -import io.legado.app.utils.progressAdd -import io.legado.app.utils.putPrefInt +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.dialog_read_book_style.* import org.jetbrains.anko.sdk27.listeners.onCheckedChange import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick -class ReadStyleDialog : DialogFragment() { +class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { override fun onStart() { super.onStart() @@ -263,4 +260,12 @@ class ReadStyleDialog : DialogFragment() { else -> bg0.borderColor = requireContext().accentColor } } + + override val curFontPath: String + get() = requireContext().getPrefString(PreferKey.readBookFont) ?: "" + + override fun selectFile(path: String) { + requireContext().putPrefString(PreferKey.readBookFont, path) + postEvent(Bus.UP_CONFIG, true) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 4d726d973..7b7a97e9b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -141,13 +141,13 @@ class FontSelectDialog : DialogFragment(), file.absolutePath.let { val pf = parentFragment if (pf is CallBack) { - if (it != pf.curPath) { + if (it != pf.curFontPath) { pf.selectFile(it) } } val activity = activity if (activity is CallBack) { - if (it != activity.curPath) { + if (it != activity.curFontPath) { activity.selectFile(it) } } @@ -158,11 +158,11 @@ class FontSelectDialog : DialogFragment(), override fun curFilePath(): String { val pf = parentFragment if (pf is CallBack) { - return pf.curPath + return pf.curFontPath } val activity = activity if (activity is CallBack) { - return activity.curPath + return activity.curFontPath } return "" } @@ -185,6 +185,6 @@ class FontSelectDialog : DialogFragment(), interface CallBack { fun selectFile(path: String) - val curPath: String + val curFontPath: String } } \ No newline at end of file From 7533cff6f742721725352c9222b4542de4ab4476 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 20:47:21 +0800 Subject: [PATCH 034/852] up --- .../app/ui/widget/font/FontSelectDialog.kt | 26 +++++++++++++++++++ app/src/main/res/menu/font_select.xml | 15 +++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 42 insertions(+) create mode 100644 app/src/main/res/menu/font_select.xml diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 7b7a97e9b..d15d07aeb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -7,8 +7,10 @@ import android.net.Uri 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.documentfile.provider.DocumentFile import androidx.fragment.app.DialogFragment import androidx.recyclerview.widget.LinearLayoutManager @@ -33,6 +35,7 @@ import java.io.File import kotlin.coroutines.CoroutineContext class FontSelectDialog : DialogFragment(), + Toolbar.OnMenuItemClickListener, CoroutineScope, FontAdapter.CallBack { lateinit var job: Job @@ -62,6 +65,8 @@ class FontSelectDialog : DialogFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) tool_bar.setTitle(R.string.select_font) + tool_bar.inflateMenu(R.menu.font_select) + tool_bar.setOnMenuItemClickListener(this) adapter = FontAdapter(requireContext(), this) recycler_view.layoutManager = LinearLayoutManager(context) recycler_view.adapter = adapter @@ -79,6 +84,27 @@ class FontSelectDialog : DialogFragment(), } } + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_default -> { + val pf = parentFragment + if (pf is CallBack) { + if ("" != pf.curFontPath) { + pf.selectFile("") + } + } + val activity = activity + if (activity is CallBack) { + if ("" != activity.curFontPath) { + activity.selectFile("") + } + } + dismiss() + } + } + return true + } + override fun onDestroy() { super.onDestroy() job.cancel() diff --git a/app/src/main/res/menu/font_select.xml b/app/src/main/res/menu/font_select.xml new file mode 100644 index 000000000..44a366ef8 --- /dev/null +++ b/app/src/main/res/menu/font_select.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2d16b399c..5036723df 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -578,5 +578,6 @@ 未分组 上一句 下一句 + 其它目录 From 16bceeffc2045e80ec9297d3c79d5a29d8864fcc Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 20:59:20 +0800 Subject: [PATCH 035/852] up --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 06c0bcaac..aa334f827 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,6 +4,10 @@ * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 * 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。MIUI11也需要此权限。 +**2020/01/03** +* 导入旧版本配置不在需要存储权限 +* 选择字体不在需要存储权限 + **2019/12/30** * 修改书源调试 - 调试搜索>>输入关键字,如:`系统` From 8cd1b1af1200606f12d093ae42b9dc62d8b8e046 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 21:00:47 +0800 Subject: [PATCH 036/852] up --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index aa334f827..2d01b7c58 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ * 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。MIUI11也需要此权限。 **2020/01/03** +* 适配Android 10 权限 * 导入旧版本配置不在需要存储权限 * 选择字体不在需要存储权限 From ebad3c04a1563a7c77432bf9928b9ae16bdec9c5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 21:08:04 +0800 Subject: [PATCH 037/852] up --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index fdc95233d..6a143f542 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -203,6 +203,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo return super.dispatchKeyEvent(event) } + /** + * 按键事件 + */ override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_VOLUME_UP -> { From fd4b2d6e332cdd3386416cd29bbcdbff1871521a Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 21:14:53 +0800 Subject: [PATCH 038/852] up --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 6a143f542..4066ed269 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -16,6 +16,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus +import io.legado.app.constant.PreferKey import io.legado.app.constant.Status import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter @@ -220,6 +221,19 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } KeyEvent.KEYCODE_SPACE -> { page_view.moveToNextPage() + return true + } + getPrefInt(PreferKey.prevKey) -> { + if (keyCode != 0) { + page_view.moveToPrevPage() + return true + } + } + getPrefInt(PreferKey.nextKey) -> { + if (keyCode != 0) { + page_view.moveToNextPage() + return true + } } } return super.onKeyDown(keyCode, event) From 86049f4208b48bb8fa999bc5b23d94cf3003107b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 21:16:13 +0800 Subject: [PATCH 039/852] up --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 4066ed269..a25a6554b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -224,13 +224,13 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo return true } getPrefInt(PreferKey.prevKey) -> { - if (keyCode != 0) { + if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { page_view.moveToPrevPage() return true } } getPrefInt(PreferKey.nextKey) -> { - if (keyCode != 0) { + if (keyCode != KeyEvent.KEYCODE_UNKNOWN) { page_view.moveToNextPage() return true } From 3c22a6a02f7fdfaf30c2d7d75fdb3a0a06823023 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 3 Jan 2020 21:19:22 +0800 Subject: [PATCH 040/852] up --- .../java/io/legado/app/ui/book/read/ReadBookActivity.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index a25a6554b..3a2523293 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -239,6 +239,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo return super.onKeyDown(keyCode, event) } + /** + * 长按事件 + */ override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_BACK -> { @@ -249,6 +252,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo return super.onKeyLongPress(keyCode, event) } + /** + * 松开按键事件 + */ override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN -> { @@ -274,6 +280,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo return super.onKeyUp(keyCode, event) } + /** + * 音量键翻页 + */ private fun volumeKeyPage(direction: PageDelegate.Direction): Boolean { if (!read_menu.isVisible) { if (getPrefBoolean("volumeKeyPage", true)) { From c38da3abf161cf0df38eb9422f904ea2026945ac Mon Sep 17 00:00:00 2001 From: ca1e Date: Fri, 3 Jan 2020 21:44:11 +0800 Subject: [PATCH 041/852] =?UTF-8?q?commit=20=E4=BF=AE=E6=94=B9web=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3json=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=8E=B7=E5=8F=96=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/web/bookshelf.js | 28 +++++++++---------- app/src/main/assets/web/index.html | 1 + .../app/ui/book/search/SearchViewModel.kt | 5 +--- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/main/assets/web/bookshelf.js b/app/src/main/assets/web/bookshelf.js index 22c8ff87e..c182f49fa 100644 --- a/app/src/main/assets/web/bookshelf.js +++ b/app/src/main/assets/web/bookshelf.js @@ -45,15 +45,15 @@ var init = () => { books.forEach(book => { let bookDiv = $c("div"); let img = $c("img"); - img.src = book.bookInfoBean.coverUrl || randomImg; + img.src = book.coverUrl || randomImg; img.setAttribute("data-series-num", book.serialNumber); bookDiv.appendChild(img); bookDiv.innerHTML += ` - - - - - + + + + +
书名:${book.bookInfoBean.name}
作者:${book.bookInfoBean.author}
阅读:${book.durChapterName}
${formatTime(book.finalDate)}
更新:${book.lastChapterName}
${formatTime(book.finalRefreshData)}
来源:${book.bookInfoBean.origin}
书名:${book.name}
作者:${book.author}
阅读:${book.durChapterTitle}
${formatTime(book.durChapterTime)}
更新:${book.latestChapterTitle}
${formatTime(book.latestChapterTime)}
来源:${book.origin}
`; $('#books').appendChild(bookDiv); }); @@ -62,19 +62,19 @@ var init = () => { $('#allcontent').classList.add("read"); var book = books[bookImg.getAttribute("data-series-num")]; $("#info").innerHTML = ` -

  来源:${book.bookInfoBean.origin}

-

  书名:${book.bookInfoBean.name}

-

  作者:${book.bookInfoBean.author}

+

  来源:${book.origin}

+

  书名:${book.name}

+

  作者:${book.author}

阅读章节:${book.durChapterName}

-

阅读时间:${formatTime(book.finalDate)}

-

最新章节:${book.lastChapterName}

-

检查时间:${formatTime(book.finalRefreshData)}

-

  简介:${book.bookInfoBean.introduce.trim().replace(/\n/g, "
")}

`; +

阅读时间:${formatTime(book.durChapterTime)}

+

最新章节:${book.latestChapterTitle}

+

检查时间:${formatTime(book.lastCheckTime)}

+

  简介:${book.intro.trim().replace(/\n/g, "
")}

`; window.location.hash = ""; window.location.hash = "#info"; $("#content").innerHTML = "章节列表加载中..."; $("#chapter").innerHTML = ""; - fetch(apiAddress("getChapterList", book.noteUrl), { mode: "cors" }) + fetch(apiAddress("getChapterList", book.bookUrl), { mode: "cors" }) .then(res => res.json()) .then(data => { if (!data.isSuccess) { diff --git a/app/src/main/assets/web/index.html b/app/src/main/assets/web/index.html index 2c47adb7f..452e521f3 100644 --- a/app/src/main/assets/web/index.html +++ b/app/src/main/assets/web/index.html @@ -294,6 +294,7 @@
(?i) 前缀表示忽略大小写 代码在线运行工具 + 阅读书架(测试) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index b02414b29..6bca4a5f4 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -93,9 +93,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { //存在 for (temp in newDataS) { var hasSame = false - var i = 0 - val size = copyDataS.size - while (i < size) { + for (i in copyDataS.indices) { val searchBook = copyDataS[i] if (temp.name == searchBook.name && temp.author == searchBook.author @@ -104,7 +102,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { searchBook.addOrigin(temp.bookUrl) break } - i++ } if (!hasSame) { searchBooksAdd.add(temp) From ab4672a5433759625c3a8973dca8d5a0ceaa1637 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 4 Jan 2020 14:53:46 +0800 Subject: [PATCH 042/852] up --- .../io/legado/app/service/TTSReadAloudService.kt | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index cdfd05581..977e8b0ac 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -45,16 +45,10 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener override fun onInit(status: Int) { launch { if (status == TextToSpeech.SUCCESS) { - val result = textToSpeech?.setLanguage(Locale.CHINA) - if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { - toast(R.string.tts_fix) - IntentHelp.toTTSSetting(this@TTSReadAloudService) - stopSelf() - } else { - textToSpeech?.setOnUtteranceProgressListener(TTSUtteranceListener()) - ttsIsSuccess = true - play() - } + textToSpeech?.language = Locale.CHINA + textToSpeech?.setOnUtteranceProgressListener(TTSUtteranceListener()) + ttsIsSuccess = true + play() } else { toast(R.string.tts_init_failed) } From 676bfea8f7aaacd0d967445f2aee14dd54ccf054 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 4 Jan 2020 17:18:27 +0800 Subject: [PATCH 043/852] up --- .../main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index d15d07aeb..4f28f5b06 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -101,6 +101,9 @@ class FontSelectDialog : DialogFragment(), } dismiss() } + R.id.menu_other -> { + openFolder() + } } return true } From 2ce2434e7f272fddc8b2dd02706e1197403f2b73 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 4 Jan 2020 18:30:28 +0800 Subject: [PATCH 044/852] up --- .../io/legado/app/ui/main/MainActivity.kt | 22 ++++++++++++++++-- .../io/legado/app/ui/main/my/MyFragment.kt | 23 ++++++++----------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index a059e380d..1655152b6 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -13,7 +13,10 @@ import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud @@ -137,6 +140,22 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } } + fun backup() { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { Backup.backup() } + .request() + } + + fun restore() { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { WebDavHelp.showRestoreDialog(this) } + .request() + } + private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { @@ -153,5 +172,4 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } } -} - +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index e19d68ec5..5b2a24114 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -13,10 +13,6 @@ import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.constant.Bus import io.legado.app.help.BookHelp -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat -import io.legado.app.help.storage.Backup -import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity @@ -24,6 +20,7 @@ import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel +import io.legado.app.ui.main.MainActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_title_bar.* @@ -46,16 +43,14 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCompatOptionsItemSelected(item: MenuItem) { when (item.itemId) { R.id.menu_help -> startActivity() - R.id.menu_backup -> PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { Backup.backup() } - .request() - R.id.menu_restore -> PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { WebDavHelp.showRestoreDialog(requireContext()) } - .request() + R.id.menu_backup -> { + val activity = activity as? MainActivity + activity?.backup() + } + R.id.menu_restore -> { + val activity = activity as? MainActivity + activity?.restore() + } } } From 62e354572898580cb968ea05cd42fb254b071606 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 4 Jan 2020 19:11:10 +0800 Subject: [PATCH 045/852] up --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../io/legado/app/ui/main/MainActivity.kt | 33 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index bc74ed1ab..0d8cad7cf 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -17,4 +17,5 @@ object PreferKey { const val pageAnim = "pageAnim" const val readBookFont = "readBookFont" const val fontFolder = "fontFolder" + const val backupPath = "backupUri" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 1655152b6..5ff86cb80 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -1,5 +1,7 @@ package io.legado.app.ui.main +import android.app.Activity +import android.content.Intent import android.os.Bundle import android.view.KeyEvent import android.view.MenuItem @@ -13,6 +15,7 @@ import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus +import io.legado.app.constant.PreferKey import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup @@ -31,7 +34,7 @@ import kotlinx.android.synthetic.main.activity_main.* class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { - + private val backupSelectRequestCode = 4567489 override val viewModel: MainViewModel get() = getViewModel(MainViewModel::class.java) @@ -141,6 +144,10 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } fun backup() { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isEmpty() == null) { + + } PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) @@ -156,6 +163,30 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), .request() } + fun selectBackupFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, backupSelectRequestCode) + } catch (e: java.lang.Exception) { + + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + backupSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { + data?.data?.let { uri -> + contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + } + } + } + } + private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { From e0c8322ae53bd3623a4a83165046d82777f3dbcf Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 4 Jan 2020 21:16:53 +0800 Subject: [PATCH 046/852] up --- .../io/legado/app/ui/main/MainActivity.kt | 42 +++++++++++++++---- .../app/ui/widget/font/FontSelectDialog.kt | 4 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 5ff86cb80..47cd4a252 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -2,9 +2,11 @@ package io.legado.app.ui.main import android.app.Activity import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.KeyEvent import android.view.MenuItem +import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter @@ -35,6 +37,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { private val backupSelectRequestCode = 4567489 + private val restoreSelectRequestCode = 654872 override val viewModel: MainViewModel get() = getViewModel(MainViewModel::class.java) @@ -145,14 +148,21 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), fun backup() { val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isEmpty() == null) { - + if (backupPath?.isEmpty() == true) { + selectBackupFolder() + } else { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(this, uri) + if (doc?.canWrite() == true) { + backup(uri) + } else { + selectBackupFolder() + } } - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { Backup.backup() } - .request() + } + + private fun backup(uri: Uri) { + } fun restore() { @@ -163,13 +173,17 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), .request() } - fun selectBackupFolder() { + private fun selectBackupFolder() { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) startActivityForResult(intent, backupSelectRequestCode) } catch (e: java.lang.Exception) { - + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { Backup.backup() } + .request() } } @@ -182,6 +196,16 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) + backup(uri) + } + } + restoreSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { + data?.data?.let { uri -> + contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 4f28f5b06..1fba2ce2e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -5,6 +5,7 @@ import android.app.Activity.RESULT_OK import android.content.Intent import android.net.Uri import android.os.Bundle +import android.os.Environment import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.MenuItem @@ -155,7 +156,8 @@ class FontSelectDialog : DialogFragment(), @SuppressLint("DefaultLocale") private fun getFontFilesOld() { try { - val file = File(fontFolder) + val file = + File(Environment.getExternalStorageDirectory().absolutePath + File.separator + "Fonts") file.listFiles { pathName -> pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) }?.let { From c106782995c3ea63f0b361746de94183120b2ac6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 4 Jan 2020 21:58:24 +0800 Subject: [PATCH 047/852] up --- .../io/legado/app/ui/main/MainActivity.kt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 47cd4a252..e9a139283 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -18,9 +18,11 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey +import io.legado.app.help.ReadBookConfig import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.Restore import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService @@ -162,7 +164,31 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } private fun backup(uri: Uri) { + DocumentFile.fromTreeUri(this, uri)?.listFiles()?.forEach { doc -> + when (doc.name) { + "bookshelf.json" -> { + } + "bookGroup.json" -> { + + } + "bookSource.json" -> { + + } + "rssSource.json" -> { + + } + "replaceRule.json" -> { + + } + ReadBookConfig.readConfigFileName -> { + + } + "config.xml" -> { + + } + } + } } fun restore() { @@ -173,6 +199,10 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), .request() } + fun restore(uri: Uri) { + + } + private fun selectBackupFolder() { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) @@ -187,6 +217,20 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } } + private fun selectRestoreFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, restoreSelectRequestCode) + } catch (e: java.lang.Exception) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { Restore.restore() } + .request() + } + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { From 75d69cb249510f24c3ee38b44cf558bbaabeaea4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 4 Jan 2020 22:02:17 +0800 Subject: [PATCH 048/852] up --- .../java/io/legado/app/help/storage/Backup.kt | 31 +++++++++++++++++ .../io/legado/app/ui/main/MainActivity.kt | 33 ++----------------- 2 files changed, 33 insertions(+), 31 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 529deb629..f6c7a4953 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 @@ -1,5 +1,8 @@ package io.legado.app.help.storage +import android.content.Context +import android.net.Uri +import androidx.documentfile.provider.DocumentFile import io.legado.app.App import io.legado.app.R import io.legado.app.help.FileHelp @@ -27,6 +30,34 @@ object Backup { legadoPath + File.separator + "Export" } + fun backup(context: Context, uri: Uri) { + DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { doc -> + when (doc.name) { + "bookshelf.json" -> { + + } + "bookGroup.json" -> { + + } + "bookSource.json" -> { + + } + "rssSource.json" -> { + + } + "replaceRule.json" -> { + + } + ReadBookConfig.readConfigFileName -> { + + } + "config.xml" -> { + + } + } + } + } + private fun pBackup(path: String = legadoPath) { backupBookshelf(path) backupBookGroup(path) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index e9a139283..88cc89b8a 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -18,7 +18,6 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey -import io.legado.app.help.ReadBookConfig import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup @@ -156,41 +155,13 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(this, uri) if (doc?.canWrite() == true) { - backup(uri) + Backup.backup(this, uri) } else { selectBackupFolder() } } } - private fun backup(uri: Uri) { - DocumentFile.fromTreeUri(this, uri)?.listFiles()?.forEach { doc -> - when (doc.name) { - "bookshelf.json" -> { - - } - "bookGroup.json" -> { - - } - "bookSource.json" -> { - - } - "rssSource.json" -> { - - } - "replaceRule.json" -> { - - } - ReadBookConfig.readConfigFileName -> { - - } - "config.xml" -> { - - } - } - } - } - fun restore() { PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) @@ -240,7 +211,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) - backup(uri) + Backup.backup(this, uri) } } restoreSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { From be233f56156dd2f62d246b96def50f84fb08cd05 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 4 Jan 2020 22:32:04 +0800 Subject: [PATCH 049/852] up --- .../java/io/legado/app/help/storage/Backup.kt | 40 +++++++++++++------ .../io/legado/app/ui/main/MainActivity.kt | 3 +- 2 files changed, 30 insertions(+), 13 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 f6c7a4953..53d9a4279 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 @@ -7,6 +7,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig +import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON import org.jetbrains.anko.defaultSharedPreferences @@ -33,23 +34,38 @@ object Backup { fun backup(context: Context, uri: Uri) { DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { doc -> when (doc.name) { - "bookshelf.json" -> { - + "bookshelf.json" -> App.db.bookDao().allBooks.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + DocumentUtils.writeText(context, json, doc.uri) + } } - "bookGroup.json" -> { - + "bookGroup.json" -> App.db.bookGroupDao().all().let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + DocumentUtils.writeText(context, json, doc.uri) + } } - "bookSource.json" -> { - + "bookSource.json" -> App.db.bookSourceDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + DocumentUtils.writeText(context, json, doc.uri) + } } - "rssSource.json" -> { - + "rssSource.json" -> App.db.rssSourceDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + DocumentUtils.writeText(context, json, doc.uri) + } } - "replaceRule.json" -> { - + "replaceRule.json" -> App.db.replaceRuleDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + DocumentUtils.writeText(context, json, doc.uri) + } } - ReadBookConfig.readConfigFileName -> { - + ReadBookConfig.readConfigFileName -> GSON.toJson(ReadBookConfig.configList)?.let { + DocumentUtils.writeText(context, it, doc.uri) } "config.xml" -> { diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 88cc89b8a..76874e612 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -211,6 +211,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) + putPrefString(PreferKey.backupPath, uri.toString()) Backup.backup(this, uri) } } @@ -220,7 +221,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) - + putPrefString(PreferKey.backupPath, uri.toString()) } } } From b51097722249d1a1689513b4d977aad3a6e65e0e Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 5 Jan 2020 14:46:02 +0800 Subject: [PATCH 050/852] =?UTF-8?q?=E4=BC=98=E5=8C=96bookshelf=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=95=88=E6=9E=9C=E4=BB=A5=E5=8F=8A=E5=8E=BB=E9=99=A4?= =?UTF-8?q?tabs=E7=82=B9=E5=87=BB=E9=BB=91=E8=89=B2=E8=83=8C=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/item_bookshelf_list.xml | 2 ++ app/src/main/res/layout/view_tab_layout_min.xml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/src/main/res/layout/item_bookshelf_list.xml b/app/src/main/res/layout/item_bookshelf_list.xml index ce882085b..56f40ab41 100644 --- a/app/src/main/res/layout/item_bookshelf_list.xml +++ b/app/src/main/res/layout/item_bookshelf_list.xml @@ -180,6 +180,8 @@ diff --git a/app/src/main/res/layout/view_tab_layout_min.xml b/app/src/main/res/layout/view_tab_layout_min.xml index b44dbd7c7..badf89a01 100644 --- a/app/src/main/res/layout/view_tab_layout_min.xml +++ b/app/src/main/res/layout/view_tab_layout_min.xml @@ -5,5 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:theme="?attr/actionBarStyle" + app:tabBackground="@android:color/transparent" + app:tabRippleColor="@android:color/transparent" app:tabMaxWidth="100dp" app:tabMinWidth="10dp" /> \ No newline at end of file From 75cac24f226f57c19e216dea82401645589a6cbc Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 5 Jan 2020 15:24:10 +0800 Subject: [PATCH 051/852] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=89=8B=E6=9C=BAtv=5Ftitle=E4=BA=8C=E8=A1=8C=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E5=85=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/item_rss_article.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/layout/item_rss_article.xml b/app/src/main/res/layout/item_rss_article.xml index 9196e88ad..f67f4d694 100644 --- a/app/src/main/res/layout/item_rss_article.xml +++ b/app/src/main/res/layout/item_rss_article.xml @@ -10,7 +10,6 @@ android:id="@+id/tv_title" android:layout_width="0dp" android:layout_height="0dp" - android:layout_marginBottom="10dp" android:text="@string/app_name" android:textColor="@color/tv_text_default" android:textSize="16sp" From f7d0a4748d77b09d43e11517aa97a622d10ac11c Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 5 Jan 2020 17:37:45 +0800 Subject: [PATCH 052/852] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=A1=B5tabs=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/chapterlist/ChapterListActivity.kt | 1 + app/src/main/res/layout/view_tab_layout.xml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index 86db52459..a7876f8e4 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -25,6 +25,7 @@ class ChapterListActivity : VMBaseActivity(R.layout.activi private var searchView: SearchView? = null override fun onActivityCreated(savedInstanceState: Bundle?) { + tab_layout.isTabIndicatorFullWidth = false tab_layout.setSelectedTabIndicatorColor(accentColor) viewModel.bookUrl = intent.getStringExtra("bookUrl") viewModel.loadBook { diff --git a/app/src/main/res/layout/view_tab_layout.xml b/app/src/main/res/layout/view_tab_layout.xml index 877d7616f..5efc6cd26 100644 --- a/app/src/main/res/layout/view_tab_layout.xml +++ b/app/src/main/res/layout/view_tab_layout.xml @@ -1,6 +1,9 @@ \ No newline at end of file From cde3e5688fa58a81514dc9131b8aecd0971b396b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 5 Jan 2020 21:46:07 +0800 Subject: [PATCH 053/852] up --- .../java/io/legado/app/help/storage/Backup.kt | 141 +++++------------- .../io/legado/app/ui/main/MainActivity.kt | 15 +- 2 files changed, 49 insertions(+), 107 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 53d9a4279..a7fce4b21 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 @@ -4,21 +4,19 @@ import android.content.Context import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.App -import io.legado.app.R import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON import org.jetbrains.anko.defaultSharedPreferences -import org.jetbrains.anko.doAsync -import org.jetbrains.anko.toast -import org.jetbrains.anko.uiThread import java.io.File object Backup { + val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" + val defaultPath by lazy { FileUtils.getSdCardPath() + File.separator + "YueDu" } @@ -31,134 +29,42 @@ object Backup { legadoPath + File.separator + "Export" } - fun backup(context: Context, uri: Uri) { - DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { doc -> - when (doc.name) { - "bookshelf.json" -> App.db.bookDao().allBooks.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - DocumentUtils.writeText(context, json, doc.uri) - } - } - "bookGroup.json" -> App.db.bookGroupDao().all().let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - DocumentUtils.writeText(context, json, doc.uri) - } - } - "bookSource.json" -> App.db.bookSourceDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - DocumentUtils.writeText(context, json, doc.uri) - } - } - "rssSource.json" -> App.db.rssSourceDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - DocumentUtils.writeText(context, json, doc.uri) - } - } - "replaceRule.json" -> App.db.replaceRuleDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - DocumentUtils.writeText(context, json, doc.uri) - } - } - ReadBookConfig.readConfigFileName -> GSON.toJson(ReadBookConfig.configList)?.let { - DocumentUtils.writeText(context, it, doc.uri) - } - "config.xml" -> { - - } - } - } - } - - private fun pBackup(path: String = legadoPath) { - backupBookshelf(path) - backupBookGroup(path) - backupBookSource(path) - backupRssSource(path) - backupReplaceRule(path) - backupReadConfig(path) - backupPreference(path) - WebDavHelp.backUpWebDav(path) - } - - fun backup() { - doAsync { - pBackup() - uiThread { - App.INSTANCE.toast(R.string.backup_success) - } - } - } - - fun autoBackup() { - doAsync { - pBackup() - } - } - - private fun backupBookshelf(path: String) { + fun backup(context: Context, uri: Uri?) { App.db.bookDao().allBooks.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - val file = FileHelp.getFile(path + File.separator + "bookshelf.json") - file.writeText(json) + FileHelp.getFile(backupPath + File.separator + "bookshelf.json").writeText(json) } } - } - - private fun backupBookGroup(path: String) { App.db.bookGroupDao().all().let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - val file = FileHelp.getFile(path + File.separator + "bookGroup.json") - file.writeText(json) + FileHelp.getFile(backupPath + File.separator + "bookGroup.json").writeText(json) } } - } - - private fun backupBookSource(path: String) { App.db.bookSourceDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - val file = FileHelp.getFile(path + File.separator + "bookSource.json") - file.writeText(json) + FileHelp.getFile(backupPath + File.separator + "bookSource.json").writeText(json) } } - } - - private fun backupRssSource(path: String) { App.db.rssSourceDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - val file = FileHelp.getFile(path + File.separator + "rssSource.json") - file.writeText(json) + FileHelp.getFile(backupPath + File.separator + "rssSource.json").writeText(json) } } - } - - private fun backupReplaceRule(path: String) { App.db.replaceRuleDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - val file = FileHelp.getFile(path + File.separator + "replaceRule.json") - file.writeText(json) + FileHelp.getFile(backupPath + File.separator + "replaceRule.json").writeText(json) } } - } - - private fun backupReadConfig(path: String) { GSON.toJson(ReadBookConfig.configList)?.let { - FileHelp.getFile(path + File.separator + ReadBookConfig.readConfigFileName) + FileHelp.getFile(backupPath + File.separator + ReadBookConfig.readConfigFileName) .writeText(it) } - } - - private fun backupPreference(path: String) { - Preferences.getSharedPreferences(App.INSTANCE, path, "config")?.let { sp -> + Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> val edit = sp.edit() App.INSTANCE.defaultSharedPreferences.all.map { when (val value = it.value) { @@ -172,6 +78,33 @@ object Backup { } edit.commit() } + WebDavHelp.backUpWebDav(backupPath) + if (uri != null) { + copyBackup(context, uri) + } + } + + private fun copyBackup(context: Context, uri: Uri) { + DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> + val fileNames = arrayOf( + "bookshelf.json", + "bookGroup.json", + "bookSource.json", + "rssSource.json", + "replaceRule.json", + ReadBookConfig.readConfigFileName, + "config.xml" + ) + for (fileName in fileNames) { + treeDoc.createFile("text/plain", fileName)?.let { doc -> + DocumentUtils.writeText( + context, + FileHelp.getFile(backupPath + File.separator + fileName).readText(), + doc.uri + ) + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 76874e612..0a6ca93c1 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -33,6 +33,9 @@ import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.rss.RssFragment import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, @@ -123,9 +126,15 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun finish() { if (!BuildConfig.DEBUG) { - Backup.autoBackup() + launch { + withContext(IO) { + backup() + } + super.finish() + } + } else { + super.finish() } - super.finish() } override fun onDestroy() { @@ -183,7 +192,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) - .onGranted { Backup.backup() } + .onGranted { Backup.backup(this, null) } .request() } } From 2645bfeaea0a0e7d11e12ee6b7802799c0aecce0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 5 Jan 2020 21:54:09 +0800 Subject: [PATCH 054/852] up --- .../java/io/legado/app/help/storage/Backup.kt | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 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 a7fce4b21..462bc445a 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 @@ -15,7 +15,7 @@ import java.io.File object Backup { - val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" + private val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" val defaultPath by lazy { FileUtils.getSdCardPath() + File.separator + "YueDu" @@ -29,6 +29,18 @@ object Backup { legadoPath + File.separator + "Export" } + val backupFileNames by lazy { + arrayOf( + "bookshelf.json", + "bookGroup.json", + "bookSource.json", + "rssSource.json", + "replaceRule.json", + ReadBookConfig.readConfigFileName, + "config.xml" + ) + } + fun backup(context: Context, uri: Uri?) { App.db.bookDao().allBooks.let { if (it.isNotEmpty()) { @@ -81,21 +93,14 @@ object Backup { WebDavHelp.backUpWebDav(backupPath) if (uri != null) { copyBackup(context, uri) + } else { + copyBackup() } } private fun copyBackup(context: Context, uri: Uri) { DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> - val fileNames = arrayOf( - "bookshelf.json", - "bookGroup.json", - "bookSource.json", - "rssSource.json", - "replaceRule.json", - ReadBookConfig.readConfigFileName, - "config.xml" - ) - for (fileName in fileNames) { + for (fileName in backupFileNames) { treeDoc.createFile("text/plain", fileName)?.let { doc -> DocumentUtils.writeText( context, @@ -107,4 +112,10 @@ object Backup { } } + private fun copyBackup() { + for (fileName in backupFileNames) { + FileHelp.getFile(backupPath + File.separator + "bookshelf.json") + .copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json")) + } + } } \ No newline at end of file From 447397d47a1072506f781237b270cc633e52e558 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 5 Jan 2020 21:54:25 +0800 Subject: [PATCH 055/852] up --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 462bc445a..3f8e65dd7 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 @@ -29,7 +29,7 @@ object Backup { legadoPath + File.separator + "Export" } - val backupFileNames by lazy { + private val backupFileNames by lazy { arrayOf( "bookshelf.json", "bookGroup.json", From 96c839f580f15f19c389c34485e928e7e88b6ee6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 10:54:05 +0800 Subject: [PATCH 056/852] up --- .../io/legado/app/help/storage/Restore.kt | 2 +- .../app/ui/config/WebDavConfigFragment.kt | 54 +++++++++++++++---- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 920d61c0d..116419a63 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -33,7 +33,7 @@ object Restore { ) } - fun restore(path: String = Backup.legadoPath) { + fun restore(path: String = Backup.defaultPath) { doAsync { try { val file = FileHelp.getFile(path + File.separator + "bookshelf.json") diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 28f9c825d..4dea5e0e7 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -13,6 +13,7 @@ import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.constant.PreferKey import io.legado.app.help.IntentHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat @@ -24,10 +25,7 @@ import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor -import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.LogUtils -import io.legado.app.utils.applyTint -import io.legado.app.utils.getPrefString +import io.legado.app.utils.* import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO import org.jetbrains.anko.toast @@ -38,6 +36,8 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), CoroutineScope { lateinit var job: Job private val oldDataRequestCode = 23156 + private val backupSelectRequestCode = 4567489 + private val restoreSelectRequestCode = 654872 override val coroutineContext: CoroutineContext get() = job + Dispatchers.Main @@ -115,11 +115,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - "web_dav_backup" -> PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { Backup.backup() } - .request() + "web_dav_backup" -> backup() "web_dav_restore" -> PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) @@ -132,6 +128,35 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), return super.onPreferenceTreeClick(preference) } + private fun backup() { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isEmpty() == true) { + selectBackupFolder() + } else { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(requireContext(), uri) + if (doc?.canWrite() == true) { + Backup.backup(requireContext(), uri) + } else { + selectBackupFolder() + } + } + } + + private fun selectBackupFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, backupSelectRequestCode) + } catch (e: java.lang.Exception) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { Backup.backup(requireContext(), null) } + .request() + } + } + private fun importOldData() { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) @@ -235,7 +260,16 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), if (resultCode == RESULT_OK) data?.data?.let { uri -> importOldData(uri) } - + backupSelectRequestCode -> if (resultCode == RESULT_OK) { + data?.data?.let { uri -> + requireContext().contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + putPrefString(PreferKey.backupPath, uri.toString()) + Backup.backup(requireContext(), uri) + } + } } } } \ No newline at end of file From 75b1b3fe898d046365325715993e876e2905c231 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 20:50:48 +0800 Subject: [PATCH 057/852] up --- .../io/legado/app/help/storage/Restore.kt | 5 ++ .../io/legado/app/help/storage/WebDavHelp.kt | 24 ++++----- .../app/ui/config/WebDavConfigFragment.kt | 51 ++++++++++++++++--- .../io/legado/app/ui/main/MainActivity.kt | 28 ++++++---- 4 files changed, 78 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 116419a63..ea1bf5392 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -1,6 +1,7 @@ package io.legado.app.help.storage import android.content.Context +import android.net.Uri import android.util.Log import com.jayway.jsonpath.Configuration import com.jayway.jsonpath.JsonPath @@ -33,6 +34,10 @@ object Restore { ) } + fun restore(context: Context, uri: Uri) { + + } + fun restore(path: String = Backup.defaultPath) { doAsync { try { diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index a4ac7fbcc..6be8c205d 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -8,9 +8,10 @@ import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth import io.legado.app.utils.ZipUtils import io.legado.app.utils.getPrefString +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.withContext import org.jetbrains.anko.doAsync import org.jetbrains.anko.selector -import org.jetbrains.anko.uiThread import java.io.File import java.text.SimpleDateFormat import java.util.* @@ -54,20 +55,17 @@ object WebDavHelp { return names } - fun showRestoreDialog(context: Context) { - doAsync { - val names = getWebDavFileNames() - if (names.isNotEmpty()) { - uiThread { - context.selector(title = "选择恢复文件", items = names) { _, index -> - if (index in 0 until names.size) { - restoreWebDav(names[index]) - } - } + suspend fun showRestoreDialog(context: Context): Boolean { + val names = withContext(IO) { getWebDavFileNames() } + return if (names.isNotEmpty()) { + context.selector(title = "选择恢复文件", items = names) { _, index -> + if (index in 0 until names.size) { + restoreWebDav(names[index]) } - } else { - Restore.restore() } + true + } else { + false } } diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 4dea5e0e7..763491d54 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -116,13 +116,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { "web_dav_backup" -> backup() - "web_dav_restore" -> PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - WebDavHelp.showRestoreDialog(requireContext()) - } - .request() + "web_dav_restore" -> restore() "import_old" -> importOldData() } return super.onPreferenceTreeClick(preference) @@ -157,6 +151,39 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), } } + fun restore() { + launch { + if (!WebDavHelp.showRestoreDialog(requireContext())) { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isEmpty() == true) { + selectRestoreFolder() + } else { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(requireContext(), uri) + if (doc?.canWrite() == true) { + Restore.restore(requireContext(), uri) + } else { + selectBackupFolder() + } + } + } + } + } + + private fun selectRestoreFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, restoreSelectRequestCode) + } catch (e: java.lang.Exception) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { Restore.restore(Backup.legadoPath) } + .request() + } + } + private fun importOldData() { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) @@ -270,6 +297,16 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Backup.backup(requireContext(), uri) } } + restoreSelectRequestCode -> if (resultCode == RESULT_OK) { + data?.data?.let { uri -> + requireContext().contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + putPrefString(PreferKey.backupPath, uri.toString()) + Restore.restore(requireContext(), uri) + } + } } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 0a6ca93c1..6c1287adc 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -172,15 +172,22 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } fun restore() { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { WebDavHelp.showRestoreDialog(this) } - .request() - } - - fun restore(uri: Uri) { - + launch { + if (!WebDavHelp.showRestoreDialog(this@MainActivity)) { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isEmpty() == true) { + selectRestoreFolder() + } else { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(this@MainActivity, uri) + if (doc?.canWrite() == true) { + Restore.restore(this@MainActivity, uri) + } else { + selectBackupFolder() + } + } + } + } } private fun selectBackupFolder() { @@ -206,7 +213,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) - .onGranted { Restore.restore() } + .onGranted { Restore.restore(Backup.legadoPath) } .request() } } @@ -231,6 +238,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.backupPath, uri.toString()) + Restore.restore(this, uri) } } } From a433637e3cd4e8a0e3f242d329a364d760697295 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 21:17:50 +0800 Subject: [PATCH 058/852] up --- .../java/io/legado/app/data/AppDatabase.kt | 5 +++- .../java/io/legado/app/help/storage/Backup.kt | 4 +-- .../io/legado/app/help/storage/Restore.kt | 25 +++++++++++++------ .../io/legado/app/help/storage/WebDavHelp.kt | 5 ++-- .../app/ui/config/WebDavConfigFragment.kt | 13 ++++++++-- .../io/legado/app/ui/main/MainActivity.kt | 14 +++++++++-- 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index cab698fbd..0b43afd10 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -7,7 +7,10 @@ import androidx.room.RoomDatabase import androidx.sqlite.db.SupportSQLiteDatabase import io.legado.app.data.dao.* import io.legado.app.data.entities.* +import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch @Database( @@ -28,7 +31,7 @@ abstract class AppDatabase : RoomDatabase() { .fallbackToDestructiveMigration() .addCallback(object : Callback() { override fun onDestructiveMigration(db: SupportSQLiteDatabase) { - Restore.restore() + GlobalScope.launch { Restore.restore(Backup.defaultPath) } } }) .build() 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 3f8e65dd7..1eee3d582 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 @@ -15,7 +15,7 @@ import java.io.File object Backup { - private val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" + val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" val defaultPath by lazy { FileUtils.getSdCardPath() + File.separator + "YueDu" @@ -29,7 +29,7 @@ object Backup { legadoPath + File.separator + "Export" } - private val backupFileNames by lazy { + val backupFileNames by lazy { arrayOf( "bookshelf.json", "bookGroup.json", diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index ea1bf5392..801d27f01 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -3,12 +3,12 @@ package io.legado.app.help.storage import android.content.Context import android.net.Uri import android.util.Log +import androidx.documentfile.provider.DocumentFile import com.jayway.jsonpath.Configuration import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.Option import com.jayway.jsonpath.ParseContext import io.legado.app.App -import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.data.entities.* import io.legado.app.help.FileHelp @@ -20,9 +20,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.jetbrains.anko.defaultSharedPreferences -import org.jetbrains.anko.doAsync import org.jetbrains.anko.toast -import org.jetbrains.anko.uiThread import java.io.File object Restore { @@ -34,12 +32,24 @@ object Restore { ) } - fun restore(context: Context, uri: Uri) { - + suspend fun restore(context: Context, uri: Uri) { + withContext(IO) { + DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { doc -> + for (fileName in Backup.backupFileNames) { + if (doc.name == fileName) { + DocumentUtils.readText(context, doc.uri)?.let { + FileHelp.getFile(Backup.backupPath + File.separator + fileName) + .writeText(it) + } + } + } + } + } + restore(Backup.defaultPath) } - fun restore(path: String = Backup.defaultPath) { - doAsync { + suspend fun restore(path: String) { + withContext(IO) { try { val file = FileHelp.getFile(path + File.separator + "bookshelf.json") val json = file.readText() @@ -109,7 +119,6 @@ object Restore { } edit.commit() } - uiThread { App.INSTANCE.toast(R.string.restore_success) } } } diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 6be8c205d..4a0f3e152 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -4,13 +4,13 @@ import android.content.Context import io.legado.app.App import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig +import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth import io.legado.app.utils.ZipUtils import io.legado.app.utils.getPrefString import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.withContext -import org.jetbrains.anko.doAsync import org.jetbrains.anko.selector import java.io.File import java.text.SimpleDateFormat @@ -70,10 +70,11 @@ object WebDavHelp { } private fun restoreWebDav(name: String) { - doAsync { + Coroutine.async { getWebDavUrl()?.let { val file = WebDav(it + "legado/" + name) file.downloadTo(zipFilePath, true) + @Suppress("BlockingMethodInNonBlockingContext") ZipUtils.unzipFile(zipFilePath, unzipFilesPath) Restore.restore(unzipFilesPath) } diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 763491d54..490b82e67 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -162,6 +162,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), val doc = DocumentFile.fromTreeUri(requireContext(), uri) if (doc?.canWrite() == true) { Restore.restore(requireContext(), uri) + toast(R.string.restore_success) } else { selectBackupFolder() } @@ -179,7 +180,12 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) - .onGranted { Restore.restore(Backup.legadoPath) } + .onGranted { + launch { + Restore.restore(Backup.legadoPath) + toast(R.string.restore_success) + } + } .request() } } @@ -304,7 +310,10 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.backupPath, uri.toString()) - Restore.restore(requireContext(), uri) + launch { + Restore.restore(requireContext(), uri) + toast(R.string.restore_success) + } } } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 6c1287adc..fd1188e77 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -36,6 +36,7 @@ import kotlinx.android.synthetic.main.activity_main.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import org.jetbrains.anko.toast class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, @@ -182,6 +183,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), val doc = DocumentFile.fromTreeUri(this@MainActivity, uri) if (doc?.canWrite() == true) { Restore.restore(this@MainActivity, uri) + toast(R.string.restore_success) } else { selectBackupFolder() } @@ -213,7 +215,12 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) - .onGranted { Restore.restore(Backup.legadoPath) } + .onGranted { + launch { + Restore.restore(Backup.legadoPath) + toast(R.string.restore_success) + } + } .request() } } @@ -238,7 +245,10 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.backupPath, uri.toString()) - Restore.restore(this, uri) + launch { + Restore.restore(this@MainActivity, uri) + toast(R.string.restore_success) + } } } } From fd649bc73bf69e022ba3be0bbb9ad31468e2d058 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 21:41:07 +0800 Subject: [PATCH 059/852] up --- .../java/io/legado/app/help/storage/Backup.kt | 100 ++++++++++-------- .../io/legado/app/ui/main/MainActivity.kt | 20 ++-- 2 files changed, 65 insertions(+), 55 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 1eee3d582..e0efa4b9e 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 @@ -9,6 +9,8 @@ import io.legado.app.help.ReadBookConfig import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.withContext import org.jetbrains.anko.defaultSharedPreferences import java.io.File @@ -41,60 +43,64 @@ object Backup { ) } - fun backup(context: Context, uri: Uri?) { - App.db.bookDao().allBooks.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "bookshelf.json").writeText(json) + suspend fun backup(context: Context, uri: Uri?) { + withContext(IO) { + App.db.bookDao().allBooks.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + FileHelp.getFile(backupPath + File.separator + "bookshelf.json").writeText(json) + } } - } - App.db.bookGroupDao().all().let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "bookGroup.json").writeText(json) + App.db.bookGroupDao().all().let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + FileHelp.getFile(backupPath + File.separator + "bookGroup.json").writeText(json) + } } - } - App.db.bookSourceDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "bookSource.json").writeText(json) + App.db.bookSourceDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + FileHelp.getFile(backupPath + File.separator + "bookSource.json") + .writeText(json) + } } - } - App.db.rssSourceDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "rssSource.json").writeText(json) + App.db.rssSourceDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + FileHelp.getFile(backupPath + File.separator + "rssSource.json").writeText(json) + } } - } - App.db.replaceRuleDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "replaceRule.json").writeText(json) + App.db.replaceRuleDao().all.let { + if (it.isNotEmpty()) { + val json = GSON.toJson(it) + FileHelp.getFile(backupPath + File.separator + "replaceRule.json") + .writeText(json) + } } - } - GSON.toJson(ReadBookConfig.configList)?.let { - FileHelp.getFile(backupPath + File.separator + ReadBookConfig.readConfigFileName) - .writeText(it) - } - Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> - val edit = sp.edit() - App.INSTANCE.defaultSharedPreferences.all.map { - when (val value = it.value) { - is Int -> edit.putInt(it.key, value) - is Boolean -> edit.putBoolean(it.key, value) - is Long -> edit.putLong(it.key, value) - is Float -> edit.putFloat(it.key, value) - is String -> edit.putString(it.key, value) - else -> Unit + GSON.toJson(ReadBookConfig.configList)?.let { + FileHelp.getFile(backupPath + File.separator + ReadBookConfig.readConfigFileName) + .writeText(it) + } + Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> + val edit = sp.edit() + App.INSTANCE.defaultSharedPreferences.all.map { + when (val value = it.value) { + is Int -> edit.putInt(it.key, value) + is Boolean -> edit.putBoolean(it.key, value) + is Long -> edit.putLong(it.key, value) + is Float -> edit.putFloat(it.key, value) + is String -> edit.putString(it.key, value) + else -> Unit + } } + edit.commit() + } + WebDavHelp.backUpWebDav(backupPath) + if (uri != null) { + copyBackup(context, uri) + } else { + copyBackup() } - edit.commit() - } - WebDavHelp.backUpWebDav(backupPath) - if (uri != null) { - copyBackup(context, uri) - } else { - copyBackup() } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index fd1188e77..c37e93149 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -33,9 +33,7 @@ import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.rss.RssFragment import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.jetbrains.anko.toast class MainActivity : VMBaseActivity(R.layout.activity_main), @@ -128,9 +126,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun finish() { if (!BuildConfig.DEBUG) { launch { - withContext(IO) { - backup() - } + backup() super.finish() } } else { @@ -165,7 +161,9 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(this, uri) if (doc?.canWrite() == true) { - Backup.backup(this, uri) + launch { + Backup.backup(this@MainActivity, uri) + } } else { selectBackupFolder() } @@ -201,7 +199,11 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) - .onGranted { Backup.backup(this, null) } + .onGranted { + launch { + Backup.backup(this@MainActivity, null) + } + } .request() } } @@ -235,7 +237,9 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.backupPath, uri.toString()) - Backup.backup(this, uri) + launch { + Backup.backup(this@MainActivity, uri) + } } } restoreSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { From 4e0aa155510e10212bbbea3be6a3a87627d0d1e6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 21:48:12 +0800 Subject: [PATCH 060/852] up --- .../legado/app/ui/config/WebDavConfigFragment.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 490b82e67..0f70be7ef 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -130,7 +130,9 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(requireContext(), uri) if (doc?.canWrite() == true) { - Backup.backup(requireContext(), uri) + launch { + Backup.backup(requireContext(), uri) + } } else { selectBackupFolder() } @@ -146,7 +148,11 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) - .onGranted { Backup.backup(requireContext(), null) } + .onGranted { + launch { + Backup.backup(requireContext(), null) + } + } .request() } } @@ -300,7 +306,9 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.backupPath, uri.toString()) - Backup.backup(requireContext(), uri) + launch { + Backup.backup(requireContext(), uri) + } } } restoreSelectRequestCode -> if (resultCode == RESULT_OK) { From 61345f3b676624402668e18ff41529cdb249f2b0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 21:57:45 +0800 Subject: [PATCH 061/852] up --- .../io/legado/app/ui/config/WebDavConfigFragment.kt | 12 ++++++------ .../main/java/io/legado/app/ui/main/MainActivity.kt | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index 0f70be7ef..b269f7a95 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -124,9 +124,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), private fun backup() { val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isEmpty() == true) { - selectBackupFolder() - } else { + if (backupPath?.isNotEmpty() == true) { val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(requireContext(), uri) if (doc?.canWrite() == true) { @@ -136,6 +134,8 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), } else { selectBackupFolder() } + } else { + selectBackupFolder() } } @@ -161,9 +161,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), launch { if (!WebDavHelp.showRestoreDialog(requireContext())) { val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isEmpty() == true) { - selectRestoreFolder() - } else { + if (backupPath?.isNotEmpty() == true) { val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(requireContext(), uri) if (doc?.canWrite() == true) { @@ -172,6 +170,8 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), } else { selectBackupFolder() } + } else { + selectRestoreFolder() } } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index c37e93149..80db372ca 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -155,9 +155,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), fun backup() { val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isEmpty() == true) { - selectBackupFolder() - } else { + if (backupPath?.isNotEmpty() == true) { val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(this, uri) if (doc?.canWrite() == true) { @@ -167,6 +165,8 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } else { selectBackupFolder() } + } else { + selectBackupFolder() } } @@ -174,9 +174,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), launch { if (!WebDavHelp.showRestoreDialog(this@MainActivity)) { val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isEmpty() == true) { - selectRestoreFolder() - } else { + if (backupPath?.isNotEmpty() == true) { val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(this@MainActivity, uri) if (doc?.canWrite() == true) { @@ -185,6 +183,8 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } else { selectBackupFolder() } + } else { + selectRestoreFolder() } } } From df3cfe08996226492d7dd9d95f27e667466b1fdd Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 22:00:39 +0800 Subject: [PATCH 062/852] up --- app/src/main/java/io/legado/app/data/AppDatabase.kt | 2 +- app/src/main/java/io/legado/app/help/storage/Restore.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 0b43afd10..d65b43ada 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -31,7 +31,7 @@ abstract class AppDatabase : RoomDatabase() { .fallbackToDestructiveMigration() .addCallback(object : Callback() { override fun onDestructiveMigration(db: SupportSQLiteDatabase) { - GlobalScope.launch { Restore.restore(Backup.defaultPath) } + GlobalScope.launch { Restore.restore(Backup.backupPath) } } }) .build() diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 801d27f01..a95626228 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -45,7 +45,7 @@ object Restore { } } } - restore(Backup.defaultPath) + restore(Backup.backupPath) } suspend fun restore(path: String) { From 3178d9b893d0a6878bc923ec88752e602972e0d5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 22:05:47 +0800 Subject: [PATCH 063/852] up --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e0efa4b9e..995ff8fdd 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 @@ -121,7 +121,7 @@ object Backup { private fun copyBackup() { for (fileName in backupFileNames) { FileHelp.getFile(backupPath + File.separator + "bookshelf.json") - .copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json")) + .copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json"), true) } } } \ No newline at end of file From ecc11a584788625376e8ea01d2d7b8148b6b8e1d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 22:08:14 +0800 Subject: [PATCH 064/852] up --- .../java/io/legado/app/ui/config/WebDavConfigFragment.kt | 8 ++++---- app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt index b269f7a95..446c93f68 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt @@ -34,10 +34,10 @@ import kotlin.coroutines.CoroutineContext class WebDavConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, CoroutineScope { - lateinit var job: Job - private val oldDataRequestCode = 23156 - private val backupSelectRequestCode = 4567489 - private val restoreSelectRequestCode = 654872 + private lateinit var job: Job + private val oldDataRequestCode = 11 + private val backupSelectRequestCode = 22 + private val restoreSelectRequestCode = 33 override val coroutineContext: CoroutineContext get() = job + Dispatchers.Main diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 80db372ca..30e72a0dd 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -39,8 +39,8 @@ import org.jetbrains.anko.toast class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { - private val backupSelectRequestCode = 4567489 - private val restoreSelectRequestCode = 654872 + private val backupSelectRequestCode = 11 + private val restoreSelectRequestCode = 22 override val viewModel: MainViewModel get() = getViewModel(MainViewModel::class.java) @@ -195,7 +195,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) startActivityForResult(intent, backupSelectRequestCode) - } catch (e: java.lang.Exception) { + } catch (e: Exception) { PermissionsCompat.Builder(this) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) From 92f0ce90df971e18e220dc67d3dc44b8f95f322b Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 22:12:39 +0800 Subject: [PATCH 065/852] up --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 2d01b7c58..9312c54e0 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,6 +4,10 @@ * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 * 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。MIUI11也需要此权限。 +**2020/01/06** +* 适配Android 10 权限 +* 备份恢复不再需要存储权限 + **2020/01/03** * 适配Android 10 权限 * 导入旧版本配置不在需要存储权限 From 70a3f8fc1fb5fe41330a2ccb55d9029fa4b67045 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 6 Jan 2020 22:16:26 +0800 Subject: [PATCH 066/852] up --- app/src/main/assets/updateLog.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 9312c54e0..b9780bb44 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -1,8 +1,7 @@ ## 更新日志 * 旧版数据导入教程: -* 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】,提示存储权限,选择允许即可导入成功。 -* 注意:由于安卓10更改了权限策略,还需要给「允许安装其他应用」的权限才能导入源。MIUI11也需要此权限。 +* 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 **2020/01/06** * 适配Android 10 权限 From a6e3489e256eb76a81e4d27523dcd58519849a06 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 07:58:28 +0800 Subject: [PATCH 067/852] up --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 995ff8fdd..b6960c41e 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 @@ -107,7 +107,8 @@ object Backup { private fun copyBackup(context: Context, uri: Uri) { DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> for (fileName in backupFileNames) { - treeDoc.createFile("text/plain", fileName)?.let { doc -> + val doc = treeDoc.findFile(fileName) ?: treeDoc.createFile("text/plain", fileName) + doc?.let { DocumentUtils.writeText( context, FileHelp.getFile(backupPath + File.separator + fileName).readText(), From 74dc25b99f1697a7c0a713c00a7b08d61b3a30b1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 08:32:52 +0800 Subject: [PATCH 068/852] up --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b6960c41e..7f5b726ae 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 @@ -107,7 +107,7 @@ object Backup { private fun copyBackup(context: Context, uri: Uri) { DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> for (fileName in backupFileNames) { - val doc = treeDoc.findFile(fileName) ?: treeDoc.createFile("text/plain", fileName) + val doc = treeDoc.findFile(fileName) ?: treeDoc.createFile("", fileName) doc?.let { DocumentUtils.writeText( context, From 0e67bbb8a1bb04e5111cc1761d0d7c1b4743f39b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 08:36:39 +0800 Subject: [PATCH 069/852] up --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index b9780bb44..e38e525d7 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/07** +* 修复备份问题 + **2020/01/06** * 适配Android 10 权限 * 备份恢复不再需要存储权限 From a6275b5af91b073cd7ccaaef52734c33c591f95c Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 08:53:39 +0800 Subject: [PATCH 070/852] up --- .../io/legado/app/ui/main/MainActivity.kt | 117 ---------------- .../io/legado/app/ui/main/my/MyFragment.kt | 126 +++++++++++++++++- 2 files changed, 119 insertions(+), 124 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 30e72a0dd..39a5ad05f 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -1,12 +1,8 @@ package io.legado.app.ui.main -import android.app.Activity -import android.content.Intent -import android.net.Uri import android.os.Bundle import android.view.KeyEvent import android.view.MenuItem -import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter @@ -17,12 +13,6 @@ import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus -import io.legado.app.constant.PreferKey -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat -import io.legado.app.help.storage.Backup -import io.legado.app.help.storage.Restore -import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud @@ -34,7 +24,6 @@ import io.legado.app.ui.main.rss.RssFragment import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_main.* import kotlinx.coroutines.launch -import org.jetbrains.anko.toast class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, @@ -126,7 +115,6 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun finish() { if (!BuildConfig.DEBUG) { launch { - backup() super.finish() } } else { @@ -153,111 +141,6 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } } - fun backup() { - val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(this, uri) - if (doc?.canWrite() == true) { - launch { - Backup.backup(this@MainActivity, uri) - } - } else { - selectBackupFolder() - } - } else { - selectBackupFolder() - } - } - - fun restore() { - launch { - if (!WebDavHelp.showRestoreDialog(this@MainActivity)) { - val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(this@MainActivity, uri) - if (doc?.canWrite() == true) { - Restore.restore(this@MainActivity, uri) - toast(R.string.restore_success) - } else { - selectBackupFolder() - } - } else { - selectRestoreFolder() - } - } - } - } - - private fun selectBackupFolder() { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, backupSelectRequestCode) - } catch (e: Exception) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - Backup.backup(this@MainActivity, null) - } - } - .request() - } - } - - private fun selectRestoreFolder() { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, restoreSelectRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - Restore.restore(Backup.legadoPath) - toast(R.string.restore_success) - } - } - .request() - } - } - - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - when (requestCode) { - backupSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { - data?.data?.let { uri -> - contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - putPrefString(PreferKey.backupPath, uri.toString()) - launch { - Backup.backup(this@MainActivity, uri) - } - } - } - restoreSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { - data?.data?.let { uri -> - contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - putPrefString(PreferKey.backupPath, uri.toString()) - launch { - Restore.restore(this@MainActivity, uri) - toast(R.string.restore_success) - } - } - } - } - } - private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 5b2a24114..6d79f55d4 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -1,10 +1,14 @@ package io.legado.app.ui.main.my +import android.app.Activity +import android.content.Intent import android.content.SharedPreferences +import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View +import androidx.documentfile.provider.DocumentFile import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference @@ -12,7 +16,13 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.constant.Bus +import io.legado.app.constant.PreferKey import io.legado.app.help.BookHelp +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat +import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.Restore +import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity @@ -20,13 +30,15 @@ import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel -import io.legado.app.ui.main.MainActivity import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_title_bar.* +import kotlinx.coroutines.launch import org.jetbrains.anko.startActivity class MyFragment : BaseFragment(R.layout.fragment_my_config) { + private val backupSelectRequestCode = 22 + private val restoreSelectRequestCode = 33 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) @@ -43,13 +55,113 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCompatOptionsItemSelected(item: MenuItem) { when (item.itemId) { R.id.menu_help -> startActivity() - R.id.menu_backup -> { - val activity = activity as? MainActivity - activity?.backup() + R.id.menu_backup -> backup() + R.id.menu_restore -> restore() + } + } + + + private fun backup() { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isNotEmpty() == true) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(requireContext(), uri) + if (doc?.canWrite() == true) { + launch { + Backup.backup(requireContext(), uri) + } + } else { + selectBackupFolder() + } + } else { + selectBackupFolder() + } + } + + private fun selectBackupFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, backupSelectRequestCode) + } catch (e: java.lang.Exception) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + launch { + Backup.backup(requireContext(), null) + } + } + .request() + } + } + + fun restore() { + launch { + if (!WebDavHelp.showRestoreDialog(requireContext())) { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isNotEmpty() == true) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(requireContext(), uri) + if (doc?.canWrite() == true) { + Restore.restore(requireContext(), uri) + toast(R.string.restore_success) + } else { + selectBackupFolder() + } + } else { + selectRestoreFolder() + } } - R.id.menu_restore -> { - val activity = activity as? MainActivity - activity?.restore() + } + } + + private fun selectRestoreFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, restoreSelectRequestCode) + } catch (e: java.lang.Exception) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + launch { + Restore.restore(Backup.legadoPath) + toast(R.string.restore_success) + } + } + .request() + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + backupSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { + data?.data?.let { uri -> + requireContext().contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + putPrefString(PreferKey.backupPath, uri.toString()) + launch { + Backup.backup(requireContext(), uri) + } + } + } + restoreSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { + data?.data?.let { uri -> + requireContext().contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + putPrefString(PreferKey.backupPath, uri.toString()) + launch { + Restore.restore(requireContext(), uri) + toast(R.string.restore_success) + } + } } } } From 65bdc5541cd2686445ed5d4d0ec9fab6d1ff3325 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 08:57:41 +0800 Subject: [PATCH 071/852] up --- .../java/io/legado/app/help/storage/Backup.kt | 10 +++++++--- .../io/legado/app/ui/main/MainActivity.kt | 20 +++++++++++++++++-- 2 files changed, 25 insertions(+), 5 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 7f5b726ae..90bf3b9e2 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 @@ -120,9 +120,13 @@ object Backup { } private fun copyBackup() { - for (fileName in backupFileNames) { - FileHelp.getFile(backupPath + File.separator + "bookshelf.json") - .copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json"), true) + try { + for (fileName in backupFileNames) { + FileHelp.getFile(backupPath + File.separator + "bookshelf.json") + .copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json"), true) + } + } catch (e: Exception) { + e.printStackTrace() } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 39a5ad05f..571b32139 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -1,8 +1,10 @@ package io.legado.app.ui.main +import android.net.Uri import android.os.Bundle import android.view.KeyEvent import android.view.MenuItem +import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter @@ -13,6 +15,8 @@ import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus +import io.legado.app.constant.PreferKey +import io.legado.app.help.storage.Backup import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud @@ -28,8 +32,6 @@ import kotlinx.coroutines.launch class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, ViewPager.OnPageChangeListener by ViewPager.SimpleOnPageChangeListener() { - private val backupSelectRequestCode = 11 - private val restoreSelectRequestCode = 22 override val viewModel: MainViewModel get() = getViewModel(MainViewModel::class.java) @@ -115,6 +117,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun finish() { if (!BuildConfig.DEBUG) { launch { + backup() super.finish() } } else { @@ -122,6 +125,19 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } } + private suspend fun backup() { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isNotEmpty() == true) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(this, uri) + if (doc?.canWrite() == true) { + Backup.backup(this@MainActivity, uri) + } + } else { + Backup.backup(this@MainActivity, null) + } + } + override fun onDestroy() { super.onDestroy() ReadAloud.stop(this) From fc1d36d1c8655c6ad5812420c8cdb00ec45ae635 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 09:20:30 +0800 Subject: [PATCH 072/852] up --- .../io/legado/app/ui/book/read/page/ContentView.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 903cc3abc..f5d329356 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 @@ -17,6 +17,7 @@ import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_book_page.view.* import org.jetbrains.anko.matchParent import org.jetbrains.anko.sdk27.listeners.onScrollChange +import java.io.File import java.util.* @@ -83,10 +84,13 @@ class ContentView : FrameLayout { } context.getPrefString(PreferKey.readBookFont)?.let { if (it.isNotEmpty()) { - content_text_view.typeface = Typeface.createFromFile(it) - } else { - content_text_view.typeface = Typeface.DEFAULT + val file = File(it) + if (file.exists()) { + content_text_view.typeface = Typeface.createFromFile(it) + return@let + } } + content_text_view.typeface = Typeface.DEFAULT } } From 3a9d9e33e28e0202d5fa6ecf98a84476ebad7f3b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 09:24:17 +0800 Subject: [PATCH 073/852] up --- .../main/java/io/legado/app/ui/book/read/page/ContentView.kt | 2 ++ 1 file changed, 2 insertions(+) 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 f5d329356..cc9e9e666 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 @@ -88,6 +88,8 @@ class ContentView : FrameLayout { if (file.exists()) { content_text_view.typeface = Typeface.createFromFile(it) return@let + } else { + context.putPrefString(PreferKey.readBookFont, "") } } content_text_view.typeface = Typeface.DEFAULT From 71bb578cdf6531badf5eeda41c0cfc4a6085fe46 Mon Sep 17 00:00:00 2001 From: Administrator Date: Tue, 7 Jan 2020 16:23:41 +0800 Subject: [PATCH 074/852] =?UTF-8?q?=E4=BD=BF=E4=B9=A6=E7=B1=8D=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E8=83=BD=E5=A4=9F=E6=A8=A1=E7=B3=8A=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookChapterDao.kt | 3 +++ .../app/ui/chapterlist/ChapterListActivity.kt | 6 ++++++ .../app/ui/chapterlist/ChapterListFragment.kt | 19 ++++++++++++++++++- .../ui/chapterlist/ChapterListViewModel.kt | 9 +++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt index 9a4db0cb1..a67d12f03 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt @@ -13,6 +13,9 @@ interface BookChapterDao { @Query("select * from chapters where bookUrl = :bookUrl") fun observeByBook(bookUrl: String): LiveData> + @Query("SELECT * FROM chapters where title like '%'||:key||'%'") + fun liveDataSearch(key: String): LiveData> + @Query("select * from chapters where bookUrl = :bookUrl") fun getChapterList(bookUrl: String): List diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index a7876f8e4..1aab97a4b 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -18,6 +18,7 @@ import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_chapter_list.* import kotlinx.android.synthetic.main.view_tab_layout.* + class ChapterListActivity : VMBaseActivity(R.layout.activity_chapter_list) { override val viewModel: ChapterListViewModel get() = getViewModel(ChapterListViewModel::class.java) @@ -52,6 +53,11 @@ class ChapterListActivity : VMBaseActivity(R.layout.activi } override fun onQueryTextChange(newText: String): Boolean { + if (tab_layout.selectedTabPosition == 1) { + + } else { + viewModel.startChapterListSearch(newText) + } return false } }) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index c8860f021..509e514ba 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Bundle import android.view.View import android.widget.LinearLayout +import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager @@ -19,11 +20,13 @@ import kotlinx.android.synthetic.main.fragment_chapter_list.* import org.jetbrains.anko.sdk27.listeners.onClick class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list), - ChapterListAdapter.Callback { + ChapterListAdapter.Callback, + ChapterListViewModel.CallBack { override val viewModel: ChapterListViewModel get() = getViewModelOfActivity(ChapterListViewModel::class.java) lateinit var adapter: ChapterListAdapter + private var chapterData: LiveData>? = null private var durChapterIndex = 0 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -71,6 +74,20 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme recycler_view.scrollToPosition(it.durChapterIndex) } } + viewModel.callBack = this + } + + override fun startSearch(newText: String?) { + chapterData?.removeObservers(this) + if (newText.isNullOrBlank()) { + initData() + } else { + chapterData = App.db.bookChapterDao().liveDataSearch(newText) + chapterData?.observe(viewLifecycleOwner, Observer { + adapter.setItems(it) + }) + recycler_view.scrollToPosition(0) + } } override fun durChapterIndex(): Int { diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt index d11aa73dc..abbc81b01 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book class ChapterListViewModel(application: Application) : BaseViewModel(application) { var bookUrl: String? = null var book: Book? = null + var callBack: CallBack? = null fun loadBook(success: () -> Unit) { execute { @@ -19,4 +20,12 @@ class ChapterListViewModel(application: Application) : BaseViewModel(application success() } } + + fun startChapterListSearch(newText: String?) { + callBack?.startSearch(newText) + } + + interface CallBack { + fun startSearch(newText: String?) + } } \ No newline at end of file From aea8171fae2a4697ba578dfed07175937ddad7dd Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 17:04:34 +0800 Subject: [PATCH 075/852] up --- .../book/source/manage/BookSourceActivity.kt | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) 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 d2cc149e1..a6c2b7e05 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 @@ -9,6 +9,7 @@ import android.view.MenuItem import android.view.SubMenu import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat +import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil @@ -49,7 +50,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity get() = getViewModel(BookSourceViewModel::class.java) private val qrRequestCode = 101 - private val importSource = 13141 + private val importSource = 132 private lateinit var adapter: BookSourceAdapter private var bookSourceLiveDate: LiveData>? = null private var groups = hashSetOf() @@ -82,7 +83,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity supportFragmentManager, "groupManage" ) - R.id.menu_import_source_local -> selectFile() + R.id.menu_import_source_local -> selectFileSys() R.id.menu_select_all -> adapter.selectAll() R.id.menu_revert_selection -> adapter.revertSelection() R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds()) @@ -219,10 +220,15 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } private fun selectFileSys() { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.addCategory(Intent.CATEGORY_OPENABLE) - intent.type = "text/*"//设置类型 - startActivityForResult(intent, importSource) + try { + val intent = Intent(Intent.ACTION_GET_CONTENT) + intent.addCategory(Intent.CATEGORY_OPENABLE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + intent.type = "text/*"//设置类型 + startActivityForResult(intent, importSource) + } catch (e: Exception) { + selectFile() + } } override fun onMenuClick(menu: String) { @@ -284,16 +290,24 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } } importSource -> if (resultCode == Activity.RESULT_OK) { - data?.data?.let { - val path = FileUtils.getPath(this, it) - if (path != null) { - Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) - .show() - viewModel.importSourceFromFilePath(path) { msg -> - title_bar.snackbar(msg) - } + data?.data?.let { uri -> + if (DocumentFile.isDocumentUri(this, uri)) { + DocumentUtils.readText(this, uri)?.let { + viewModel.importSource(it) { msg -> + title_bar.snackbar(msg) + } + } ?: toast("读取文件失败") } else { - toast(R.string.uri_to_path_fail) + val path = FileUtils.getPath(this, uri) + if (path != null) { + Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) + .show() + viewModel.importSourceFromFilePath(path) { msg -> + title_bar.snackbar(msg) + } + } else { + toast(R.string.uri_to_path_fail) + } } } } From c8f2ece30f0d0e882216967a2162ce3565b7841b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 20:21:48 +0800 Subject: [PATCH 076/852] up --- .../ui/book/read/config/BgTextConfigDialog.kt | 55 +++++++++++++------ .../java/io/legado/app/utils/DocumentUtils.kt | 32 +++++------ 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 82e7113a0..b19b86c91 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -12,6 +12,7 @@ import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.DialogFragment import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -20,11 +21,13 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Bus +import io.legado.app.help.FileHelp import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.ui.book.read.Help +import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils import io.legado.app.utils.getCompatColor import io.legado.app.utils.postEvent @@ -32,6 +35,7 @@ import kotlinx.android.synthetic.main.dialog_read_bg_text.* import kotlinx.android.synthetic.main.item_bg_image.view.* import org.jetbrains.anko.sdk27.listeners.onCheckedChange import org.jetbrains.anko.sdk27.listeners.onClick +import java.io.File class BgTextConfigDialog : DialogFragment() { @@ -133,17 +137,10 @@ class BgTextConfigDialog : DialogFragment() { } private fun selectImage() { - PermissionsCompat.Builder(this) - .addPermissions(Permissions.READ_EXTERNAL_STORAGE, Permissions.WRITE_EXTERNAL_STORAGE) - .rationale(R.string.bg_image_per) - .onGranted { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.addCategory(Intent.CATEGORY_OPENABLE) - intent.type = "image/*" - startActivityForResult(intent, resultSelectBg) - Unit - } - .request() + val intent = Intent(Intent.ACTION_GET_CONTENT) + intent.addCategory(Intent.CATEGORY_OPENABLE) + intent.type = "image/*" + startActivityForResult(intent, resultSelectBg) } class BgAdapter(context: Context) : @@ -170,11 +167,37 @@ class BgTextConfigDialog : DialogFragment() { when (requestCode) { resultSelectBg -> { if (resultCode == RESULT_OK) { - data?.data?.let { - FileUtils.getPath(requireContext(), it)?.let { path -> - ReadBookConfig.getConfig().setBg(2, path) - ReadBookConfig.upBg() - postEvent(Bus.UP_CONFIG, false) + data?.data?.let { uri -> + if (DocumentFile.isDocumentUri(requireContext(), uri)) { + val doc = DocumentFile.fromSingleUri(requireContext(), uri) + doc?.let { + var file = requireContext().getExternalFilesDir(null) + ?: requireContext().filesDir + file = + FileHelp.getFile(file.absolutePath + File.separator + "bg" + File.separator + doc.name) + DocumentUtils.readBytes(requireContext(), uri)?.let { + file.writeBytes(it) + ReadBookConfig.getConfig().setBg(2, file.absolutePath) + ReadBookConfig.upBg() + postEvent(Bus.UP_CONFIG, false) + } + } + } else { + PermissionsCompat.Builder(this) + .addPermissions( + Permissions.READ_EXTERNAL_STORAGE, + Permissions.WRITE_EXTERNAL_STORAGE + ) + .rationale(R.string.bg_image_per) + .onGranted { + FileUtils.getPath(requireContext(), uri)?.let { path -> + ReadBookConfig.getConfig().setBg(2, path) + ReadBookConfig.upBg() + postEvent(Bus.UP_CONFIG, false) + } + Unit + } + .request() } } } diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index dcb128a8e..3929874ef 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -6,25 +6,24 @@ import android.net.Uri object DocumentUtils { @JvmStatic + @Throws(Exception::class) fun writeText(context: Context, data: String, fileUri: Uri): Boolean { return writeBytes(context, data.toByteArray(), fileUri) } @JvmStatic + @Throws(Exception::class) fun writeBytes(context: Context, data: ByteArray, fileUri: Uri): Boolean { - try { - context.contentResolver.openOutputStream(fileUri)?.let { - it.write(data) - it.close() - return true - } - } catch (e: java.lang.Exception) { - e.printStackTrace() + context.contentResolver.openOutputStream(fileUri)?.let { + it.write(data) + it.close() + return true } return false } @JvmStatic + @Throws(Exception::class) fun readText(context: Context, uri: Uri): String? { readBytes(context, uri)?.let { return String(it) @@ -33,17 +32,14 @@ object DocumentUtils { } @JvmStatic + @Throws(Exception::class) fun readBytes(context: Context, uri: Uri): ByteArray? { - try { - context.contentResolver.openInputStream(uri)?.let { - val len: Int = it.available() - val buffer = ByteArray(len) - it.read(buffer) - it.close() - return buffer - } - } catch (e: Exception) { - e.printStackTrace() + context.contentResolver.openInputStream(uri)?.let { + val len: Int = it.available() + val buffer = ByteArray(len) + it.read(buffer) + it.close() + return buffer } return null } From b06dd0e1224ac674f63bb9153954881f8bf65882 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 20:23:33 +0800 Subject: [PATCH 077/852] up --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index e38e525d7..985505281 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/01/07** * 修复备份问题 +* 设置背景不再需要存储权限 **2020/01/06** * 适配Android 10 权限 From 2f0ac01959bf3f4748f3a7bafe6f9a3a3ed2fa41 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 21:33:14 +0800 Subject: [PATCH 078/852] up --- .../book/source/manage/BookSourceActivity.kt | 20 ++--- .../app/ui/replacerule/ReplaceRuleActivity.kt | 84 ++++++++++++++++++- .../ui/replacerule/ReplaceRuleViewModel.kt | 13 ++- .../java/io/legado/app/utils/UriExtensions.kt | 61 ++++++++++++++ 4 files changed, 160 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/UriExtensions.kt 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 a6c2b7e05..314eb3621 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 @@ -9,7 +9,6 @@ import android.view.MenuItem import android.view.SubMenu import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat -import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil @@ -291,23 +290,16 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } importSource -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - if (DocumentFile.isDocumentUri(this, uri)) { - DocumentUtils.readText(this, uri)?.let { - viewModel.importSource(it) { msg -> - title_bar.snackbar(msg) - } - } ?: toast("读取文件失败") - } else { - val path = FileUtils.getPath(this, uri) - if (path != null) { + try { + uri.readText(this)?.let { Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) .show() - viewModel.importSourceFromFilePath(path) { msg -> - title_bar.snackbar(msg) + viewModel.importSource(it) { msg -> + toast(msg) } - } else { - toast(R.string.uri_to_path_fail) } + } catch (e: Exception) { + e.localizedMessage?.let { toast(it) } } } } 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 806336698..9ba3a5a0f 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 @@ -1,6 +1,8 @@ package io.legado.app.ui.replacerule +import android.annotation.SuppressLint import android.app.Activity +import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -13,18 +15,25 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager +import com.google.android.material.snackbar.Snackbar import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.ReplaceRule 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.ATH import io.legado.app.lib.theme.primaryTextColor +import io.legado.app.lib.theme.view.ATEAutoCompleteTextView import io.legado.app.ui.replacerule.edit.ReplaceEditDialog -import io.legado.app.utils.getViewModel -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_replace_rule.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* +import org.jetbrains.anko.toast class ReplaceRuleActivity : VMBaseActivity(R.layout.activity_replace_rule), @@ -32,7 +41,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi ReplaceRuleAdapter.CallBack { override val viewModel: ReplaceRuleViewModel get() = getViewModel(ReplaceRuleViewModel::class.java) - + private val importSource = 132 private lateinit var adapter: ReplaceRuleAdapter private var groups = hashSetOf() private var groupMenu: SubMenu? = null @@ -68,6 +77,8 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds()) R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) + R.id.menu_import_source_onLine -> showImportDialog() + R.id.menu_import_source_local -> selectFileSys() R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) } return super.onCompatOptionsItemSelected(item) @@ -134,6 +145,52 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi } } + @SuppressLint("InflateParams") + private fun showImportDialog() { + val aCache = ACache.get(this, cacheDir = false) + val cacheUrls: MutableList = aCache + .getAsString("replaceRuleUrl") + ?.splitNotBlank(",") + ?.toMutableList() ?: mutableListOf() + alert(titleResource = R.string.import_replace_rule_on_line) { + var editText: ATEAutoCompleteTextView? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view + edit_view.setFilterValues(cacheUrls) { + cacheUrls.remove(it) + aCache.put("replaceRuleUrl", cacheUrls.joinToString(",")) + } + } + } + okButton { + val text = editText?.text?.toString() + text?.let { + if (!cacheUrls.contains(it)) { + cacheUrls.add(0, it) + aCache.put("replaceRuleUrl", cacheUrls.joinToString(",")) + } + Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() + viewModel.importSource(it) { msg -> + title_bar.snackbar(msg) + } + } + } + cancelButton() + }.show().applyTint() + } + + private fun selectFileSys() { + try { + val intent = Intent(Intent.ACTION_GET_CONTENT) + intent.addCategory(Intent.CATEGORY_OPENABLE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + intent.type = "text/*"//设置类型 + startActivityForResult(intent, importSource) + } catch (e: Exception) { + + } + } override fun onQueryTextChange(newText: String?): Boolean { observeReplaceRuleData("%$newText%") @@ -144,6 +201,27 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi return false } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + importSource -> if (resultCode == Activity.RESULT_OK) { + data?.data?.let { uri -> + try { + uri.readText(this)?.let { + Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) + .show() + viewModel.importSource(it) { msg -> + toast(msg) + } + } + } catch (e: Exception) { + e.localizedMessage?.let { toast(it) } + } + } + } + } + } + override fun update(vararg rule: ReplaceRule) { viewModel.update(*rule) } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 7b80d5475..5c5f0e6a5 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.replacerule import android.app.Application import android.text.TextUtils import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.FileHelp @@ -14,6 +15,15 @@ import java.io.File class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) { + fun importSource(text: String, toast: (msg: String) -> Unit) { + execute { + + }.onError { + toast(it.localizedMessage ?: "ERROR") + }.onSuccess { + toast(context.getString(R.string.success)) + } + } fun update(vararg rule: ReplaceRule) { execute { @@ -68,7 +78,8 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application App.db.replaceRuleDao().findById(it) }.let { val json = GSON.toJson(it) - val file = FileHelp.getFile(Backup.exportPath + File.separator + "exportReplaceRule.json") + val file = + FileHelp.getFile(Backup.exportPath + File.separator + "exportReplaceRule.json") file.writeText(json) } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/utils/UriExtensions.kt b/app/src/main/java/io/legado/app/utils/UriExtensions.kt new file mode 100644 index 000000000..297a5a612 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/UriExtensions.kt @@ -0,0 +1,61 @@ +package io.legado.app.utils + +import android.content.Context +import android.net.Uri +import androidx.documentfile.provider.DocumentFile +import java.io.File + + +@Throws(Exception::class) +fun Uri.readBytes(context: Context): ByteArray? { + if (DocumentFile.isDocumentUri(context, this)) { + return DocumentUtils.readBytes(context, this) + } else { + val path = FileUtils.getPath(context, this) + if (path?.isNotEmpty() == true) { + return File(path).readBytes() + } + } + return null +} + +@Throws(Exception::class) +fun Uri.readText(context: Context): String? { + if (DocumentFile.isDocumentUri(context, this)) { + return DocumentUtils.readText(context, this) + } else { + val path = FileUtils.getPath(context, this) + if (path?.isNotEmpty() == true) { + return File(path).readText() + } + } + return null +} + +@Throws(Exception::class) +fun Uri.writeBytes(context: Context, byteArray: ByteArray): Boolean { + if (DocumentFile.isDocumentUri(context, this)) { + return DocumentUtils.writeBytes(context, byteArray, this) + } else { + val path = FileUtils.getPath(context, this) + if (path?.isNotEmpty() == true) { + File(path).writeBytes(byteArray) + return true + } + } + return false +} + +@Throws(Exception::class) +fun Uri.writeText(context: Context, text: String): Boolean { + if (DocumentFile.isDocumentUri(context, this)) { + return DocumentUtils.writeText(context, text, this) + } else { + val path = FileUtils.getPath(context, this) + if (path?.isNotEmpty() == true) { + File(path).writeText(text) + return true + } + } + return false +} \ No newline at end of file From 7305f80b77ef564d804cbf5f1e5135e76900a8f4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 21:49:05 +0800 Subject: [PATCH 079/852] up --- .../io/legado/app/help/storage/OldRule.kt | 25 ++++++++++++++++++- .../io/legado/app/help/storage/Restore.kt | 15 +++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index 14b4a9c53..c8036e559 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.kt @@ -3,6 +3,7 @@ package io.legado.app.help.storage import io.legado.app.constant.AppConst import io.legado.app.constant.BookType import io.legado.app.data.entities.BookSource +import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.rule.* import io.legado.app.help.storage.Restore.jsonPath import io.legado.app.utils.* @@ -205,5 +206,27 @@ object OldRule { return GSON.toJson(map) } - + fun jsonToReplaceRule(json: String): ReplaceRule? { + var replaceRule: ReplaceRule? = null + runCatching { + replaceRule = GSON.fromJsonObject(json.trim()) + } + runCatching { + if (replaceRule == null || replaceRule?.pattern.isNullOrBlank()) { + val jsonItem = jsonPath.parse(json.trim()) + val rule = ReplaceRule() + rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis() + rule.pattern = jsonItem.readString("$.regex") ?: "" + if (rule.pattern.isEmpty()) return null + rule.name = jsonItem.readString("$.replaceSummary") ?: "" + rule.replacement = jsonItem.readString("$.replacement") ?: "" + rule.isRegex = jsonItem.readBool("$.isRegex") == true + rule.scope = jsonItem.readString("$.useTo") + rule.isEnabled = jsonItem.readBool("$.enable") == true + rule.order = jsonItem.readInt("$.serialNumber") ?: 0 + return rule + } + } + return replaceRule + } } diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index a95626228..d7de379d4 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -226,20 +226,11 @@ object Restore { fun importOldReplaceRule(json: String): Int { val replaceRules = mutableListOf() val items: List> = jsonPath.parse(json).read("$") - val existingRules = App.db.replaceRuleDao().all.map { it.pattern }.toSet() for ((index: Int, item: Map) in items.withIndex()) { val jsonItem = jsonPath.parse(item) - val rule = ReplaceRule() - rule.id = jsonItem.readLong("$.id") ?: System.currentTimeMillis().plus(index) - rule.pattern = jsonItem.readString("$.regex") ?: "" - if (rule.pattern.isEmpty() || rule.pattern in existingRules) continue - rule.name = jsonItem.readString("$.replaceSummary") ?: "" - rule.replacement = jsonItem.readString("$.replacement") ?: "" - rule.isRegex = jsonItem.readBool("$.isRegex") == true - rule.scope = jsonItem.readString("$.useTo") - rule.isEnabled = jsonItem.readBool("$.enable") == true - rule.order = jsonItem.readInt("$.serialNumber") ?: index - replaceRules.add(rule) + OldRule.jsonToReplaceRule(jsonItem.jsonString())?.let { + replaceRules.add(it) + } } App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) return replaceRules.size From 059433320f3201732aa01d289c778e131011f6d2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 21:50:45 +0800 Subject: [PATCH 080/852] up --- app/src/main/java/io/legado/app/help/storage/Restore.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index d7de379d4..15c14051c 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -226,7 +226,7 @@ object Restore { fun importOldReplaceRule(json: String): Int { val replaceRules = mutableListOf() val items: List> = jsonPath.parse(json).read("$") - for ((index: Int, item: Map) in items.withIndex()) { + for (item in items) { val jsonItem = jsonPath.parse(item) OldRule.jsonToReplaceRule(jsonItem.jsonString())?.let { replaceRules.add(it) From 454e5395ee8d18cb478148b891ac9347633425eb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 7 Jan 2020 21:52:31 +0800 Subject: [PATCH 081/852] up --- .../java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 5c5f0e6a5..540900eec 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -8,6 +8,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.FileHelp import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.Restore import io.legado.app.utils.GSON import io.legado.app.utils.splitNotBlank import org.jetbrains.anko.toast @@ -17,7 +18,7 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application fun importSource(text: String, toast: (msg: String) -> Unit) { execute { - + Restore.importOldReplaceRule(text) }.onError { toast(it.localizedMessage ?: "ERROR") }.onSuccess { From 2d74a38d08682fec5f159825eedf165804b12280 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 08:27:24 +0800 Subject: [PATCH 082/852] up --- .../ui/rss/source/manage/RssSourceActivity.kt | 20 +++++++++++-------- .../rss/source/manage/RssSourceViewModel.kt | 1 - 2 files changed, 12 insertions(+), 9 deletions(-) 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 a75134288..c8232669d 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 @@ -80,7 +80,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) - R.id.menu_import_source_local -> selectFile() + R.id.menu_import_source_local -> selectFileSys() R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_qr -> startActivityForResult(qrRequestCode) R.id.menu_group_manage -> GroupManageDialog() @@ -203,10 +203,14 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r } private fun selectFileSys() { - val intent = Intent(Intent.ACTION_GET_CONTENT) - intent.addCategory(Intent.CATEGORY_OPENABLE) - intent.type = "text/*"//设置类型 - startActivityForResult(intent, importSource) + try { + val intent = Intent(Intent.ACTION_GET_CONTENT) + intent.addCategory(Intent.CATEGORY_OPENABLE) + intent.type = "text/*"//设置类型 + startActivityForResult(intent, importSource) + } catch (e: Exception) { + selectFile() + } } override fun onMenuClick(menu: String) { @@ -229,11 +233,11 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r super.onActivityResult(requestCode, resultCode, data) when (requestCode) { importSource -> if (resultCode == Activity.RESULT_OK) { - data?.data?.let { - FileUtils.getPath(this, it)?.let { path -> + data?.data?.let { uri -> + uri.readText(this)?.let { Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) .show() - viewModel.importSourceFromFilePath(path) { msg -> + viewModel.importSource(it) { msg -> title_bar.snackbar(msg) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 6ee254029..c47bb8c9d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -115,7 +115,6 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) } } - fun importSourceFromFilePath(path: String, finally: (msg: String) -> Unit) { execute { val file = File(path) From 0c061ac37917e983305a48bfa269d0f5e5a2326c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 15:07:20 +0800 Subject: [PATCH 083/852] up --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 985505281..48dc30c5b 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/08** +* 导入本地源不再需要存储权限 + **2020/01/07** * 修复备份问题 * 设置背景不再需要存储权限 From 676fdd4d47a20c80e28fbdbd70ffc2b6e804e2be Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 15:26:19 +0800 Subject: [PATCH 084/852] up --- .../java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9ba3a5a0f..be97fcacd 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 @@ -211,7 +211,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) .show() viewModel.importSource(it) { msg -> - toast(msg) + title_bar.snackbar(msg) } } } catch (e: Exception) { From 8446fe356eeab0e5f585a026b2fd8504322bf992 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 15:38:39 +0800 Subject: [PATCH 085/852] up --- .../ui/book/read/config/BgTextConfigDialog.kt | 1 - .../book/source/manage/BookSourceActivity.kt | 18 ++++++++++-- .../app/ui/replacerule/ReplaceRuleActivity.kt | 16 +++++++++- .../ui/rss/source/manage/RssSourceActivity.kt | 29 +++++++++++++++---- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index b19b86c91..2b4a7dc4f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -195,7 +195,6 @@ class BgTextConfigDialog : DialogFragment() { ReadBookConfig.upBg() postEvent(Bus.UP_CONFIG, false) } - Unit } .request() } 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 314eb3621..af1231556 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 @@ -21,6 +21,8 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.BookSource import io.legado.app.help.ItemTouchCallback +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.customView @@ -40,6 +42,7 @@ import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startService import org.jetbrains.anko.toast +import java.io.FileNotFoundException class BookSourceActivity : VMBaseActivity(R.layout.activity_book_source), BookSourceAdapter.CallBack, @@ -295,11 +298,22 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) .show() viewModel.importSource(it) { msg -> - toast(msg) + title_bar.snackbar(msg) } } + } catch (e: FileNotFoundException) { + PermissionsCompat.Builder(this) + .addPermissions( + Permissions.READ_EXTERNAL_STORAGE, + Permissions.WRITE_EXTERNAL_STORAGE + ) + .rationale(R.string.bg_image_per) + .onGranted { + selectFileSys() + } + .request() } catch (e: Exception) { - e.localizedMessage?.let { toast(it) } + toast(e.localizedMessage ?: "ERROR") } } } 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 be97fcacd..00dfd3f34 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,6 +21,8 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.ItemTouchCallback +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.customView @@ -34,6 +36,7 @@ import kotlinx.android.synthetic.main.activity_replace_rule.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* import org.jetbrains.anko.toast +import java.io.FileNotFoundException class ReplaceRuleActivity : VMBaseActivity(R.layout.activity_replace_rule), @@ -214,8 +217,19 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi title_bar.snackbar(msg) } } + } catch (e: FileNotFoundException) { + PermissionsCompat.Builder(this) + .addPermissions( + Permissions.READ_EXTERNAL_STORAGE, + Permissions.WRITE_EXTERNAL_STORAGE + ) + .rationale(R.string.bg_image_per) + .onGranted { + selectFileSys() + } + .request() } catch (e: Exception) { - e.localizedMessage?.let { toast(it) } + toast(e.localizedMessage ?: "ERROR") } } } 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 c8232669d..883acbb8c 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 @@ -21,6 +21,8 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.RssSource import io.legado.app.help.ItemTouchCallback +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.customView @@ -37,6 +39,8 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult +import org.jetbrains.anko.toast +import java.io.FileNotFoundException class RssSourceActivity : VMBaseActivity(R.layout.activity_rss_source), @@ -234,12 +238,27 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r when (requestCode) { importSource -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - uri.readText(this)?.let { - Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) - .show() - viewModel.importSource(it) { msg -> - title_bar.snackbar(msg) + try { + uri.readText(this)?.let { + Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE) + .show() + viewModel.importSource(it) { msg -> + title_bar.snackbar(msg) + } } + } catch (e: FileNotFoundException) { + PermissionsCompat.Builder(this) + .addPermissions( + Permissions.READ_EXTERNAL_STORAGE, + Permissions.WRITE_EXTERNAL_STORAGE + ) + .rationale(R.string.bg_image_per) + .onGranted { + selectFileSys() + } + .request() + } catch (e: Exception) { + toast(e.localizedMessage ?: "ERROR") } } } From a145933b1618d9dfc99e823ffd462c9c56b9ff7d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 8 Jan 2020 15:46:55 +0800 Subject: [PATCH 086/852] up --- .../book/source/manage/BookSourceActivity.kt | 29 ++++++++++--------- .../app/ui/replacerule/ReplaceRuleActivity.kt | 28 ++++++++++++++++++ .../ui/replacerule/ReplaceRuleViewModel.kt | 6 ++-- .../ui/rss/source/manage/RssSourceActivity.kt | 29 ++++++++++--------- 4 files changed, 61 insertions(+), 31 deletions(-) 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 af1231556..52b433a32 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 @@ -213,14 +213,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity }.show().applyTint() } - private fun selectFile() { - FileChooserDialog.show( - supportFragmentManager, importSource, - allowExtensions = arrayOf("txt", "json"), - menus = arrayOf(getString(R.string.sys_file_picker)) - ) - } - private fun selectFileSys() { try { val intent = Intent(Intent.ACTION_GET_CONTENT) @@ -229,15 +221,24 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity intent.type = "text/*"//设置类型 startActivityForResult(intent, importSource) } catch (e: Exception) { - selectFile() + PermissionsCompat.Builder(this) + .addPermissions( + Permissions.READ_EXTERNAL_STORAGE, + Permissions.WRITE_EXTERNAL_STORAGE + ) + .rationale(R.string.bg_image_per) + .onGranted { + selectFile() + } + .request() } } - override fun onMenuClick(menu: String) { - super.onMenuClick(menu) - when (menu) { - getString(R.string.sys_file_picker) -> selectFileSys() - } + private fun selectFile() { + FileChooserDialog.show( + supportFragmentManager, importSource, + allowExtensions = arrayOf("txt", "json") + ) } override fun onFilePicked(requestCode: Int, currentPath: String) { 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 00dfd3f34..5c53e91e1 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 @@ -30,17 +30,20 @@ import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView +import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.replacerule.edit.ReplaceEditDialog import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_replace_rule.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* import org.jetbrains.anko.toast +import java.io.File import java.io.FileNotFoundException class ReplaceRuleActivity : VMBaseActivity(R.layout.activity_replace_rule), SearchView.OnQueryTextListener, + FileChooserDialog.CallBack, ReplaceRuleAdapter.CallBack { override val viewModel: ReplaceRuleViewModel get() = getViewModel(ReplaceRuleViewModel::class.java) @@ -191,7 +194,32 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi intent.type = "text/*"//设置类型 startActivityForResult(intent, importSource) } catch (e: Exception) { + PermissionsCompat.Builder(this) + .addPermissions( + Permissions.READ_EXTERNAL_STORAGE, + Permissions.WRITE_EXTERNAL_STORAGE + ) + .rationale(R.string.bg_image_per) + .onGranted { + selectFile() + } + .request() + } + } + private fun selectFile() { + FileChooserDialog.show( + supportFragmentManager, importSource, + allowExtensions = arrayOf("txt", "json") + ) + } + + override fun onFilePicked(requestCode: Int, currentPath: String) { + if (requestCode == importSource) { + Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() + viewModel.importSource(File(currentPath).readText()) { msg -> + title_bar.snackbar(msg) + } } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 540900eec..ba6bc2a61 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -16,13 +16,13 @@ import java.io.File class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) { - fun importSource(text: String, toast: (msg: String) -> Unit) { + fun importSource(text: String, showMsg: (msg: String) -> Unit) { execute { Restore.importOldReplaceRule(text) }.onError { - toast(it.localizedMessage ?: "ERROR") + showMsg(it.localizedMessage ?: "ERROR") }.onSuccess { - toast(context.getString(R.string.success)) + showMsg(context.getString(R.string.success)) } } 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 883acbb8c..b536a0b84 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 @@ -198,14 +198,6 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r }.show().applyTint() } - private fun selectFile() { - FileChooserDialog.show( - supportFragmentManager, importSource, - allowExtensions = arrayOf("txt", "json"), - menus = arrayOf(getString(R.string.sys_file_picker)) - ) - } - private fun selectFileSys() { try { val intent = Intent(Intent.ACTION_GET_CONTENT) @@ -213,15 +205,24 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r intent.type = "text/*"//设置类型 startActivityForResult(intent, importSource) } catch (e: Exception) { - selectFile() + PermissionsCompat.Builder(this) + .addPermissions( + Permissions.READ_EXTERNAL_STORAGE, + Permissions.WRITE_EXTERNAL_STORAGE + ) + .rationale(R.string.bg_image_per) + .onGranted { + selectFile() + } + .request() } } - override fun onMenuClick(menu: String) { - super.onMenuClick(menu) - when (menu) { - getString(R.string.sys_file_picker) -> selectFileSys() - } + private fun selectFile() { + FileChooserDialog.show( + supportFragmentManager, importSource, + allowExtensions = arrayOf("txt", "json") + ) } override fun onFilePicked(requestCode: Int, currentPath: String) { From 1bfd273ee73f585b838b3dd397fe613135fb1030 Mon Sep 17 00:00:00 2001 From: Administrator Date: Wed, 8 Jan 2020 17:09:18 +0800 Subject: [PATCH 087/852] =?UTF-8?q?=E4=BF=AE=E6=94=B9bookshelf=20grid?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/bookshelf/books/BooksAdapterGrid.kt | 7 +++- .../ui/main/bookshelf/books/BooksFragment.kt | 2 +- .../main/res/layout/item_bookshelf_grid.xml | 38 ++++++++++--------- app/src/main/res/values/arrays.xml | 2 +- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt index c6d1cbba4..6bb5509ae 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt @@ -12,15 +12,18 @@ import kotlinx.android.synthetic.main.item_bookshelf_grid.view.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick -class BooksAdapterGrid(context: Context, private val callBack: CallBack) : +class BooksAdapterGrid(context: Context, private val span: Int, private val callBack: CallBack) : BooksAdapter(context, R.layout.item_bookshelf_grid) { override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { if (payloads.isEmpty()) { ATH.applyBackgroundTint(this) + tv_name.textSize = (16 - span).toFloat() + bv_author.textSize = (10 - span).toFloat() + bv_unread.textSize = (10 - span).toFloat() tv_name.text = item.name - tv_author.text = item.author + bv_author.text = item.author item.getDisplayCover()?.let { ImageLoader.load(context, it)//Glide自动识别http://和file:// .placeholder(R.drawable.image_cover_default) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index fe2363b5c..3ccb39105 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -71,7 +71,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), booksAdapter = BooksAdapterList(requireContext(), this) } else { rv_bookshelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2) - booksAdapter = BooksAdapterGrid(requireContext(), this) + booksAdapter = BooksAdapterGrid(requireContext(), bookshelfLayout, this) } rv_bookshelf.adapter = booksAdapter } diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 4ed7e8158..58eb839a2 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -49,13 +49,33 @@ tools:ignore="RtlHardcoded" /> + + + + + + - - \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 7534dcab1..b873165ff 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -40,7 +40,7 @@ @string/layout_grid3 @string/layout_grid4 @string/layout_grid5 - @string/layout_grid6 + From e0659cc9a26d24e55b148b6d604c4c4a461cc576 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 9 Jan 2020 10:08:18 +0800 Subject: [PATCH 088/852] =?UTF-8?q?=E4=BF=AE=E6=94=B9bookshelf=20grid?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=95=88=E6=9E=9C2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/main/bookshelf/books/BooksAdapterGrid.kt | 5 +---- .../app/ui/main/bookshelf/books/BooksFragment.kt | 2 +- app/src/main/java/io/legado/app/ui/widget/BadgeView.kt | 6 +++++- app/src/main/res/layout/item_bookshelf_grid.xml | 10 +++++----- app/src/main/res/values/arrays.xml | 2 +- app/src/main/res/values/attrs.xml | 4 ++++ 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt index 6bb5509ae..f6761ce78 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt @@ -12,16 +12,13 @@ import kotlinx.android.synthetic.main.item_bookshelf_grid.view.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick -class BooksAdapterGrid(context: Context, private val span: Int, private val callBack: CallBack) : +class BooksAdapterGrid(context: Context, private val callBack: CallBack) : BooksAdapter(context, R.layout.item_bookshelf_grid) { override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { if (payloads.isEmpty()) { ATH.applyBackgroundTint(this) - tv_name.textSize = (16 - span).toFloat() - bv_author.textSize = (10 - span).toFloat() - bv_unread.textSize = (10 - span).toFloat() tv_name.text = item.name bv_author.text = item.author item.getDisplayCover()?.let { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 3ccb39105..765c06697 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -71,7 +71,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), booksAdapter = BooksAdapterList(requireContext(), this) } else { rv_bookshelf.layoutManager = GridLayoutManager(context, bookshelfLayout + 2) - booksAdapter = BooksAdapterGrid(requireContext(), bookshelfLayout, this) + booksAdapter = BooksAdapterGrid(requireContext(),this) } rv_bookshelf.adapter = booksAdapter } diff --git a/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt b/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt index d9d5e1ee8..a0764724e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt @@ -74,6 +74,10 @@ class BadgeView @JvmOverloads constructor( } init { + val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BadgeView) + val radios = + typedArray.getDimensionPixelOffset(R.styleable.BadgeView_bv_radius, 8) + if (layoutParams !is LayoutParams) { val layoutParams = LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, @@ -88,7 +92,7 @@ class BadgeView @JvmOverloads constructor( //setTypeface(Typeface.DEFAULT_BOLD); setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f) setPadding(dip2Px(5f), dip2Px(1f), dip2Px(5f), dip2Px(1f)) - radius = 8f + radius = radios.toFloat() // set default background setBackground(radius, context.accentColor) diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 58eb839a2..c36b288c5 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -51,19 +51,19 @@ @@ -78,7 +78,7 @@ android:ellipsize="end" android:text="@string/book_name" android:textColor="@color/tv_text_default" - android:textSize="16sp" + android:textSize="12sp" app:layout_constraintLeft_toLeftOf="@+id/iv_cover" app:layout_constraintRight_toRightOf="@+id/iv_cover" app:layout_constraintTop_toBottomOf="@+id/iv_cover" diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index b873165ff..7534dcab1 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -40,7 +40,7 @@ @string/layout_grid3 @string/layout_grid4 @string/layout_grid5 - + @string/layout_grid6 diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 0bf3c2f05..de2fe5dc5 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -140,4 +140,8 @@ + + + + \ No newline at end of file From cad80b60b15a417d447563cdab5cb10d2cc024fc Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 9 Jan 2020 11:18:13 +0800 Subject: [PATCH 089/852] up --- .../main/res/layout/item_bookshelf_grid.xml | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index c36b288c5..212c160fd 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -49,24 +49,17 @@ tools:ignore="RtlHardcoded" /> - - - - - + app:layout_constraintBottom_toBottomOf="@id/iv_cover" + tools:ignore="RtlHardcoded" /> Date: Thu, 9 Jan 2020 11:19:05 +0800 Subject: [PATCH 090/852] up --- app/src/main/res/layout/item_bookshelf_grid.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 212c160fd..ca639edd4 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -44,7 +44,6 @@ android:layout_height="26dp" android:layout_gravity="right" android:visibility="invisible" - app:loading_color="@color/colorAccent" app:loading_width="2dp" tools:ignore="RtlHardcoded" /> From 530c9b176d14dbd856a2fe4bfb7ccc5e7f6087df Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 9 Jan 2020 11:26:29 +0800 Subject: [PATCH 091/852] up --- app/src/main/java/io/legado/app/ui/widget/BadgeView.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt b/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt index a0764724e..3a2eeed57 100644 --- a/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt @@ -77,6 +77,7 @@ class BadgeView @JvmOverloads constructor( val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BadgeView) val radios = typedArray.getDimensionPixelOffset(R.styleable.BadgeView_bv_radius, 8) + typedArray.recycle() if (layoutParams !is LayoutParams) { val layoutParams = LayoutParams( From f5873c6070438909948c72e746bfe25b144b2033 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 9 Jan 2020 11:35:07 +0800 Subject: [PATCH 092/852] up --- .../main/java/io/legado/app/ui/widget/BadgeView.kt | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt b/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt index 3a2eeed57..b644ad5fb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt @@ -108,17 +108,9 @@ class BadgeView @JvmOverloads constructor( } fun setBackground(dipRadius: Float, badgeColor: Int) { - val radius = dip2Px(dipRadius) - val radiusArray = floatArrayOf( - radius.toFloat(), - radius.toFloat(), - radius.toFloat(), - radius.toFloat(), - radius.toFloat(), - radius.toFloat(), - radius.toFloat(), - radius.toFloat() - ) + val radius = dip2Px(dipRadius).toFloat() + val radiusArray = + floatArrayOf(radius, radius, radius, radius, radius, radius, radius, radius) val roundRect = RoundRectShape(radiusArray, null, null) val bgDrawable = ShapeDrawable(roundRect) From d7a9de736c78b6df74e498d49135ab5de8869ab6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 9 Jan 2020 11:42:02 +0800 Subject: [PATCH 093/852] up --- .../io/legado/app/ui/main/MainActivity.kt | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 571b32139..ddb8b3f10 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -16,6 +16,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey +import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.storage.Backup import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService @@ -27,7 +28,6 @@ import io.legado.app.ui.main.my.MyFragment import io.legado.app.ui.main.rss.RssFragment import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.coroutines.launch class MainActivity : VMBaseActivity(R.layout.activity_main), BottomNavigationView.OnNavigationItemSelectedListener, @@ -116,25 +116,23 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun finish() { if (!BuildConfig.DEBUG) { - launch { - backup() - super.finish() - } - } else { - super.finish() + backup() } + super.finish() } - private suspend fun backup() { - val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(this, uri) - if (doc?.canWrite() == true) { - Backup.backup(this@MainActivity, uri) + private fun backup() { + Coroutine.async { + val backupPath = getPrefString(PreferKey.backupPath) + if (backupPath?.isNotEmpty() == true) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(this@MainActivity, uri) + if (doc?.canWrite() == true) { + Backup.backup(this@MainActivity, uri) + } + } else { + Backup.backup(this@MainActivity, null) } - } else { - Backup.backup(this@MainActivity, null) } } From e36afc427eee4dd3ec9dec2d2d1802a93f4af1af Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 08:13:11 +0800 Subject: [PATCH 094/852] up --- app/build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 18d4ac8ed..356d95bb4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,6 +38,14 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" project.ext.set("archivesBaseName", name + "_" + version) multiDexEnabled true + javaCompileOptions { + annotationProcessorOptions { + arguments = [ + "room.incremental" : "true", + "room.expandProjection": "true" + ] + } + } } buildTypes { release { From db38c6be0a83edf064e93a94560b22e5d0b7c78f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 08:22:07 +0800 Subject: [PATCH 095/852] up --- .../java/io/legado/app/ui/widget/font/FontSelectDialog.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 1fba2ce2e..a0a4170d8 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -41,11 +41,11 @@ class FontSelectDialog : DialogFragment(), FontAdapter.CallBack { lateinit var job: Job private val fontFolderRequestCode = 35485 - private lateinit var adapter: FontAdapter private val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator override val coroutineContext: CoroutineContext get() = job + Main + private var adapter: FontAdapter? = null override fun onStart() { super.onStart() @@ -144,7 +144,7 @@ class FontSelectDialog : DialogFragment(), pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) }?.let { withContext(Main) { - adapter.setItems(it.toList()) + adapter?.setItems(it.toList()) } } } catch (e: Exception) { @@ -161,7 +161,7 @@ class FontSelectDialog : DialogFragment(), file.listFiles { pathName -> pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) }?.let { - adapter.setItems(it.toList()) + adapter?.setItems(it.toList()) } } catch (e: Exception) { toast(e.localizedMessage ?: "") From df70ca8f56362cc58f4d39e252bc6106088c55b4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 09:00:08 +0800 Subject: [PATCH 096/852] up --- .../app/ui/widget/font/FontSelectDialog.kt | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index a0a4170d8..c16c5d138 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -88,16 +88,14 @@ class FontSelectDialog : DialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_default -> { - val pf = parentFragment - if (pf is CallBack) { - if ("" != pf.curFontPath) { - pf.selectFile("") + parentFragment?.let { + if (it is CallBack && it.curFontPath != "") { + it.selectFile("") } } - val activity = activity - if (activity is CallBack) { - if ("" != activity.curFontPath) { - activity.selectFile("") + activity?.let { + if (it is CallBack && it.curFontPath != "") { + it.selectFile("") } } dismiss() @@ -131,7 +129,7 @@ class FontSelectDialog : DialogFragment(), @SuppressLint("DefaultLocale") private fun getFontFiles(uri: Uri) { launch(IO) { - DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { file -> + DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { file -> if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { FileHelp.getFile(fontFolder + file.name).writeBytes(it) @@ -169,17 +167,15 @@ class FontSelectDialog : DialogFragment(), } override fun onClick(file: File) { - file.absolutePath.let { - val pf = parentFragment - if (pf is CallBack) { - if (it != pf.curFontPath) { - pf.selectFile(it) + file.absolutePath.let { path -> + parentFragment?.let { + if (it is CallBack && it.curFontPath != path) { + it.selectFile(path) } } - val activity = activity - if (activity is CallBack) { - if (it != activity.curFontPath) { - activity.selectFile(it) + activity?.let { + if (it is CallBack && it.curFontPath != path) { + it.selectFile(path) } } } @@ -187,13 +183,15 @@ class FontSelectDialog : DialogFragment(), } override fun curFilePath(): String { - val pf = parentFragment - if (pf is CallBack) { - return pf.curFontPath + parentFragment?.let { + if (it is CallBack) { + return it.curFontPath + } } - val activity = activity - if (activity is CallBack) { - return activity.curFontPath + activity?.let { + if (it is CallBack) { + return it.curFontPath + } } return "" } From 22c17683fdc6faf9a2b41c6edd5e35829ce8d5d9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 09:06:39 +0800 Subject: [PATCH 097/852] up --- .../app/ui/widget/font/FontSelectDialog.kt | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index c16c5d138..6ff51d379 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -88,13 +88,13 @@ class FontSelectDialog : DialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_default -> { - parentFragment?.let { - if (it is CallBack && it.curFontPath != "") { + (parentFragment as? CallBack)?.let { + if (it.curFontPath != "") { it.selectFile("") } } - activity?.let { - if (it is CallBack && it.curFontPath != "") { + (activity as? CallBack)?.let { + if (it.curFontPath != "") { it.selectFile("") } } @@ -168,13 +168,13 @@ class FontSelectDialog : DialogFragment(), override fun onClick(file: File) { file.absolutePath.let { path -> - parentFragment?.let { - if (it is CallBack && it.curFontPath != path) { + (parentFragment as? CallBack)?.let { + if (it.curFontPath != path) { it.selectFile(path) } } - activity?.let { - if (it is CallBack && it.curFontPath != path) { + (activity as? CallBack)?.let { + if (it.curFontPath != path) { it.selectFile(path) } } @@ -183,17 +183,9 @@ class FontSelectDialog : DialogFragment(), } override fun curFilePath(): String { - parentFragment?.let { - if (it is CallBack) { - return it.curFontPath - } - } - activity?.let { - if (it is CallBack) { - return it.curFontPath - } - } - return "" + return (parentFragment as? CallBack)?.curFontPath + ?: (activity as? CallBack)?.curFontPath + ?: "" } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { From 899a362ea0d8a963960958a5187e1f0e1b677498 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 10 Jan 2020 09:26:57 +0800 Subject: [PATCH 098/852] =?UTF-8?q?BadgeView=E6=94=AF=E6=8C=81=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E6=88=90=E4=B8=8A=E5=B9=B3=E8=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/widget/BadgeView.kt | 4 ++++ app/src/main/res/layout/item_bookshelf_grid.xml | 1 + app/src/main/res/values/attrs.xml | 1 + 3 files changed, 6 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt b/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt index b644ad5fb..3f1572164 100644 --- a/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/BadgeView.kt @@ -36,6 +36,7 @@ class BadgeView @JvmOverloads constructor( text = text } private var radius: Float = 0.toFloat() + private var flatangle: Boolean val badgeCount: Int? get() { @@ -77,6 +78,8 @@ class BadgeView @JvmOverloads constructor( val typedArray = context.obtainStyledAttributes(attrs, R.styleable.BadgeView) val radios = typedArray.getDimensionPixelOffset(R.styleable.BadgeView_bv_radius, 8) + flatangle = + typedArray.getBoolean(R.styleable.BadgeView_up_flat_angle, false) typedArray.recycle() if (layoutParams !is LayoutParams) { @@ -111,6 +114,7 @@ class BadgeView @JvmOverloads constructor( val radius = dip2Px(dipRadius).toFloat() val radiusArray = floatArrayOf(radius, radius, radius, radius, radius, radius, radius, radius) + if (flatangle) { radiusArray.fill(0f, 0, 3) } val roundRect = RoundRectShape(radiusArray, null, null) val bgDrawable = ShapeDrawable(roundRect) diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index ca639edd4..20d5ab3e2 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -56,6 +56,7 @@ android:includeFontPadding="false" android:singleLine="true" app:bv_radius="1dp" + app:up_flat_angle="true" app:layout_constraintLeft_toLeftOf="@id/iv_cover" app:layout_constraintBottom_toBottomOf="@id/iv_cover" tools:ignore="RtlHardcoded" /> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index de2fe5dc5..297ba1065 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -143,5 +143,6 @@ + \ No newline at end of file From 23b5a47190789d21e1ad78c18fa96e0f4c964dd1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 10:11:18 +0800 Subject: [PATCH 099/852] up --- app/src/main/res/menu/rss_read.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/res/menu/rss_read.xml b/app/src/main/res/menu/rss_read.xml index 15463f64d..f32d01d2e 100644 --- a/app/src/main/res/menu/rss_read.xml +++ b/app/src/main/res/menu/rss_read.xml @@ -14,4 +14,10 @@ android:icon="@drawable/ic_menu_share" app:showAsAction="ifRoom" /> + + \ No newline at end of file From 8218c66cbf6c9f64ed3ec84ccd9f49883848ac86 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 10:53:30 +0800 Subject: [PATCH 100/852] up --- app/src/main/java/io/legado/app/help/BookHelp.kt | 2 +- .../main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 1ea320505..c117c61ed 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -86,7 +86,7 @@ object BookHelp { } private fun getBookFolder(book: Book): String { - val bookFolder = formatFolderName(book.name + book.bookUrl) + val bookFolder = formatFolderName(book.name + MD5Utils.md5Encode16(book.bookUrl)) return "${getBookCachePath()}${File.separator}$bookFolder" } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 037364296..0cab40e01 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -47,6 +47,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r R.id.menu_share_it -> viewModel.rssArticle?.let { shareText("链接分享", it.link) } + R.id.menu_aloud -> readAloud() } return super.onCompatOptionsItemSelected(item) } @@ -121,6 +122,10 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r return super.onKeyUp(keyCode, event) } + private fun readAloud() { + + } + private fun shareText(title: String, text: String) { try { val textIntent = Intent(Intent.ACTION_SEND) From 4609e87254799f5948e05b9b828f65ee7f44cb20 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 11:01:54 +0800 Subject: [PATCH 101/852] up --- app/src/main/java/io/legado/app/help/BookHelp.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index c117c61ed..ff5ee0b7d 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -108,6 +108,9 @@ object BookHelp { ?: "" } + /** + * 找到相似度最高的章节 + */ fun getDurChapterIndexByChapterTitle( title: String?, index: Int, From f7a02cf14193c4190b0414b08fef5fce7b89de3a Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 11:16:53 +0800 Subject: [PATCH 102/852] up --- .../source/edit/BookSourceEditActivity.kt | 14 +++----------- .../legado/app/ui/rss/read/ReadRssActivity.kt | 13 +------------ .../rss/source/edit/RssSourceEditActivity.kt | 4 ++++ .../io/legado/app/utils/ContextExtensions.kt | 19 +++++++++++++++++-- 4 files changed, 25 insertions(+), 25 deletions(-) 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 aeb83a093..4bab3e780 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 @@ -29,6 +29,7 @@ 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.shareText import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -87,17 +88,8 @@ class BookSourceEditActivity : } } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } - R.id.menu_share_str -> { - GSON.toJson(getSource())?.let { sourceStr -> - try { - val textIntent = Intent(Intent.ACTION_SEND) - textIntent.type = "text/plain" - textIntent.putExtra(Intent.EXTRA_TEXT, sourceStr) - startActivity(Intent.createChooser(textIntent, "Source Share")) - } catch (e: Exception) { - toast(R.string.can_not_share) - } - } + R.id.menu_share_str -> GSON.toJson(getSource())?.let { sourceStr -> + shareText("分享书源", sourceStr) } R.id.menu_rule_summary -> { try { diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 0cab40e01..951d190f7 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -1,7 +1,6 @@ package io.legado.app.ui.rss.read import android.annotation.SuppressLint -import android.content.Intent import android.os.Bundle import android.view.KeyEvent import android.view.Menu @@ -15,8 +14,8 @@ import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getViewModel +import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_read.* -import org.jetbrains.anko.toast class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_read), ReadRssViewModel.CallBack { @@ -126,14 +125,4 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } - private fun shareText(title: String, text: String) { - try { - val textIntent = Intent(Intent.ACTION_SEND) - textIntent.type = "text/plain" - textIntent.putExtra(Intent.EXTRA_TEXT, text) - startActivity(Intent.createChooser(textIntent, title)) - } catch (e: Exception) { - toast(R.string.can_not_share) - } - } } \ No newline at end of file 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 d1704848e..2b5d88b7a 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 @@ -25,6 +25,7 @@ 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.shareText import kotlinx.android.synthetic.main.activity_rss_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -103,6 +104,9 @@ class RssSourceEditActivity : } } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } + R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> + shareText("分享RSS源", sourceStr) + } } return super.onCompatOptionsItemSelected(item) } 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 f47a0a2a8..ff917b09f 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -1,13 +1,16 @@ package io.legado.app.utils import android.content.Context +import android.content.Intent import android.content.res.ColorStateList import android.graphics.drawable.Drawable import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.content.edit +import io.legado.app.R import org.jetbrains.anko.defaultSharedPreferences +import org.jetbrains.anko.toast fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) @@ -48,7 +51,8 @@ fun Context.getCompatColor(@ColorRes id: Int): Int = ContextCompat.getColor(this fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.getDrawable(this, id) -fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = ContextCompat.getColorStateList(this, id) +fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = + ContextCompat.getColorStateList(this, id) fun Context.getStatusBarHeight(): Int { val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") @@ -60,6 +64,17 @@ fun Context.getNavigationBarHeight(): Int { return resources.getDimensionPixelSize(resourceId) } +fun Context.shareText(title: String, text: String) { + try { + val textIntent = Intent(Intent.ACTION_SEND) + textIntent.type = "text/plain" + textIntent.putExtra(Intent.EXTRA_TEXT, text) + startActivity(Intent.createChooser(textIntent, title)) + } catch (e: Exception) { + toast(R.string.can_not_share) + } +} + val Context.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") @@ -67,4 +82,4 @@ val Context.isTransparentStatusBar: Boolean get() = getPrefBoolean("transparentStatusBar", true) val Context.isShowRSS: Boolean - get() = getPrefBoolean("showRss", true) \ No newline at end of file + get() = getPrefBoolean("showRss", true) \ No newline at end of file From 797c6eb9c811177caeb6c6b06a37db0f3f8abe00 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 14:28:15 +0800 Subject: [PATCH 103/852] up --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 48dc30c5b..a067a90e9 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/10 +* 合并KKL369提交的代码 + **2020/01/08** * 导入本地源不再需要存储权限 From ec1d335c57623c01d327b6e5951d67b724069ece Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 15:25:00 +0800 Subject: [PATCH 104/852] up --- .../legado/app/ui/rss/read/ReadRssActivity.kt | 4 +- .../app/ui/rss/read/ReadRssViewModel.kt | 53 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 951d190f7..138ede020 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -122,7 +122,9 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } private fun readAloud() { - + webView.evaluateJavascript("document.documentElement.outerHTML") { + viewModel.readAloud(it) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 98355d7d8..db9d7bb82 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -2,21 +2,28 @@ package io.legado.app.ui.rss.read import android.app.Application import android.content.Intent +import android.speech.tts.TextToSpeech +import android.speech.tts.UtteranceProgressListener import androidx.lifecycle.MutableLiveData import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.model.Rss import io.legado.app.model.analyzeRule.AnalyzeUrl +import kotlinx.coroutines.launch +import java.util.* -class ReadRssViewModel(application: Application) : BaseViewModel(application) { +class ReadRssViewModel(application: Application) : BaseViewModel(application), + TextToSpeech.OnInitListener { var callBack: CallBack? = null var rssSource: RssSource? = null var rssArticle: RssArticle? = null val contentLiveData = MutableLiveData() val urlLiveData = MutableLiveData() var star = false + var textToSpeech: TextToSpeech = TextToSpeech(context, this) fun initData(intent: Intent) { execute { @@ -91,6 +98,50 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { } } + override fun onInit(status: Int) { + launch { + if (status == TextToSpeech.SUCCESS) { + textToSpeech.language = Locale.CHINA + textToSpeech.setOnUtteranceProgressListener(TTSUtteranceListener()) + } else { + toast(R.string.tts_init_failed) + } + } + } + + fun readAloud(text: String) { + + } + + override fun onCleared() { + super.onCleared() + textToSpeech.stop() + textToSpeech.shutdown() + } + + /** + * 朗读监听 + */ + private inner class TTSUtteranceListener : UtteranceProgressListener() { + + override fun onStart(s: String) { + + } + + override fun onDone(s: String) { + + } + + override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) { + super.onRangeStart(utteranceId, start, end, frame) + + } + + override fun onError(s: String) { + + } + + } interface CallBack { fun upStarMenu() } From 1e3f5ec23bacb139bb5d33aac77ca290f8419e85 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 15:29:48 +0800 Subject: [PATCH 105/852] up --- app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index db9d7bb82..98b79b708 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -110,7 +110,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } fun readAloud(text: String) { - + textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, "rss") } override fun onCleared() { From 528c8b42bbe1769272ccda6eb827118d6a66420b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 16:55:29 +0800 Subject: [PATCH 106/852] up --- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 13 +++++++++++++ .../io/legado/app/ui/rss/read/ReadRssViewModel.kt | 11 ++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 138ede020..24b49a5c6 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -24,6 +24,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r get() = getViewModel(ReadRssViewModel::class.java) private var starMenuItem: MenuItem? = null + private var ttsMenuItem: MenuItem? = null override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.callBack = this @@ -36,6 +37,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.rss_read, menu) starMenuItem = menu.findItem(R.id.menu_rss_star) + ttsMenuItem = menu.findItem(R.id.menu_aloud) upStarMenu() return super.onCompatCreateOptionsMenu(menu) } @@ -97,6 +99,17 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r DrawableUtils.setTint(starMenuItem?.icon, primaryTextColor) } + override fun upTtsMenu(isPlaying: Boolean) { + if (isPlaying) { + ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) + ttsMenuItem?.setTitle(R.string.aloud_stop) + } else { + ttsMenuItem?.setIcon(R.drawable.ic_volume_up) + ttsMenuItem?.setTitle(R.string.read_aloud) + } + DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor) + } + override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_BACK -> { diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 98b79b708..83a88091e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -125,16 +125,11 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), private inner class TTSUtteranceListener : UtteranceProgressListener() { override fun onStart(s: String) { - + callBack?.upTtsMenu(true) } override fun onDone(s: String) { - - } - - override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) { - super.onRangeStart(utteranceId, start, end, frame) - + callBack?.upTtsMenu(false) } override fun onError(s: String) { @@ -142,7 +137,9 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } } + interface CallBack { fun upStarMenu() + fun upTtsMenu(isPlaying: Boolean) } } \ No newline at end of file From fbe6a6cbc54678ba4b2e36e86a0c74c7e811e62e Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 19:55:56 +0800 Subject: [PATCH 107/852] up --- .../source/edit/BookSourceEditActivity.kt | 10 ++--- .../rss/source/edit/RssSourceEditActivity.kt | 10 ++--- .../io/legado/app/utils/ContextExtensions.kt | 40 +++++++++++++++++++ app/src/main/res/menu/source_edit.xml | 2 +- app/src/main/res/values/strings.xml | 3 ++ 5 files changed, 54 insertions(+), 11 deletions(-) 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 4bab3e780..cc63c93d4 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 @@ -26,10 +26,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.source.debug.BookSourceDebugActivity 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.shareText +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -89,7 +86,10 @@ class BookSourceEditActivity : } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_share_str -> GSON.toJson(getSource())?.let { sourceStr -> - shareText("分享书源", sourceStr) + shareText(getString(R.string.share_book_source), sourceStr) + } + R.id.menu_share_qr -> GSON.toJson(getSource())?.let { sourceStr -> + shareWithQr(getString(R.string.share_book_source), sourceStr) } R.id.menu_rule_summary -> { try { 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 2b5d88b7a..1ae70df5d 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 @@ -22,10 +22,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH 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.shareText +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_rss_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -105,7 +102,10 @@ class RssSourceEditActivity : } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> - shareText("分享RSS源", sourceStr) + shareText(getString(R.string.share_rss_source), sourceStr) + } + R.id.menu_share_qr -> GSON.toJson(getRssSource())?.let { sourceStr -> + shareWithQr(getString(R.string.share_rss_source), sourceStr) } } return super.onCompatOptionsItemSelected(item) 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 ff917b09f..2ab88b481 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -1,16 +1,25 @@ package io.legado.app.utils +import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.content.res.ColorStateList +import android.graphics.Bitmap import android.graphics.drawable.Drawable import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat +import androidx.core.content.FileProvider import androidx.core.content.edit +import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder +import com.google.zxing.EncodeHintType +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel +import io.legado.app.BuildConfig import io.legado.app.R import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.toast +import java.io.File +import java.io.FileOutputStream fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) @@ -75,6 +84,37 @@ fun Context.shareText(title: String, text: String) { } } +@SuppressLint("SetWorldReadable") +fun Context.shareWithQr(title: String, text: String) { + QRCodeEncoder.HINTS[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L + val bitmap = QRCodeEncoder.syncEncodeQRCode(text, 600) + QRCodeEncoder.HINTS[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H + if (bitmap == null) { + toast(R.string.text_too_long_qr_error) + } else { + try { + val file = File(externalCacheDir, "qr.png") + val fOut = FileOutputStream(file) + bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut) + fOut.flush() + fOut.close() + file.setReadable(true, false) + val contentUri = FileProvider.getUriForFile( + this, + "${BuildConfig.APPLICATION_ID}.fileProvider", + file + ) + val intent = Intent(Intent.ACTION_SEND) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + intent.putExtra(Intent.EXTRA_STREAM, contentUri) + intent.type = "image/png" + startActivity(Intent.createChooser(intent, title)) + } catch (e: Exception) { + toast(e.localizedMessage ?: "ERROR") + } + } +} + val Context.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") diff --git a/app/src/main/res/menu/source_edit.xml b/app/src/main/res/menu/source_edit.xml index ec8739c11..2fd9678c4 100644 --- a/app/src/main/res/menu/source_edit.xml +++ b/app/src/main/res/menu/source_edit.xml @@ -35,7 +35,7 @@ app:showAsAction="never" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5036723df..3ceda2af3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -579,5 +579,8 @@ 上一句 下一句 其它目录 + 文字太多,生成二维码失败 + 分享RSS源 + 分享书源 From de10ebca2a154bd0fb566a8b7f1f9dcc9dc84c6d Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 20:15:24 +0800 Subject: [PATCH 108/852] up --- app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt | 2 +- .../main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt index b3605e3e9..5335a6830 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt @@ -15,7 +15,7 @@ import io.legado.app.R * @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid) */ class ThemeStore @SuppressLint("CommitPrefEdits") -private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeStoreInterface { +private constructor(private val mContext: Context) : ThemeStoreInterface { private val mEditor: SharedPreferences.Editor init { diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt index 4fd4540fc..c934ef176 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt @@ -3,8 +3,7 @@ package io.legado.app.lib.theme /** * @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid) */ -internal interface ThemeStorePrefKeys { - companion object { +object ThemeStorePrefKeys { const val CONFIG_PREFS_KEY_DEFAULT = "app_themes" const val IS_CONFIGURED_KEY = "is_configured" @@ -27,5 +26,4 @@ internal interface ThemeStorePrefKeys { const val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar" const val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar" const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark" - } } \ No newline at end of file From 91a5def2cc21e59ebb051277cff64d42daa8be33 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 21:09:30 +0800 Subject: [PATCH 109/852] up --- app/src/main/AndroidManifest.xml | 1 + .../app/ui/importbook/ImportBookActivity.kt | 19 +++++++++++++++++++ .../app/ui/importbook/ImportBookViewModel.kt | 10 ++++++++++ .../main/res/layout/activity_import_book.xml | 7 +++++++ 4 files changed, 37 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt create mode 100644 app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt create mode 100644 app/src/main/res/layout/activity_import_book.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bc92ac136..23f5edd36 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -98,6 +98,7 @@ + diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt new file mode 100644 index 000000000..8cbce52f8 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -0,0 +1,19 @@ +package io.legado.app.ui.importbook + +import android.os.Bundle +import io.legado.app.R +import io.legado.app.base.VMBaseActivity +import io.legado.app.utils.getViewModel + + +class ImportBookActivity : VMBaseActivity(R.layout.activity_import_book) { + + override val viewModel: ImportBookViewModel + get() = getViewModel(ImportBookViewModel::class.java) + + + override fun onActivityCreated(savedInstanceState: Bundle?) { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt new file mode 100644 index 000000000..1865f1be8 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt @@ -0,0 +1,10 @@ +package io.legado.app.ui.importbook + +import android.app.Application +import io.legado.app.base.BaseViewModel + + +class ImportBookViewModel(application: Application) : BaseViewModel(application) { + + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml new file mode 100644 index 000000000..d829e291c --- /dev/null +++ b/app/src/main/res/layout/activity_import_book.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file From ede7b0a62b5bfce98794d2ac2a44c586c7ecf972 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 08:57:47 +0800 Subject: [PATCH 110/852] up --- app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt index 44f4f9974..902a5bfae 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt @@ -20,7 +20,7 @@ class FontAdapter(context: Context, val callBack: CallBack) : tv_font.typeface = typeface tv_font.text = item.name this.onClick { callBack.onClick(item) } - if (item.absolutePath == callBack.curFilePath()) { + if (item.name == callBack.curFilePath().substringAfterLast(File.separator)) { iv_checked.visible() } else { iv_checked.invisible() From a7d157db34c9fd6d432d87260ce5da11819d9c15 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 09:06:52 +0800 Subject: [PATCH 111/852] up --- .../io/legado/app/ui/widget/font/FontSelectDialog.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 6ff51d379..8d3deef08 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -43,6 +43,8 @@ class FontSelectDialog : DialogFragment(), private val fontFolderRequestCode = 35485 private val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator + private val fontCacheFolder = + App.INSTANCE.cacheDir.absolutePath + File.separator + "Fonts" + File.separator override val coroutineContext: CoroutineContext get() = job + Main private var adapter: FontAdapter? = null @@ -129,15 +131,16 @@ class FontSelectDialog : DialogFragment(), @SuppressLint("DefaultLocale") private fun getFontFiles(uri: Uri) { launch(IO) { + FileHelp.deleteFile(fontCacheFolder) DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { file -> if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { - FileHelp.getFile(fontFolder + file.name).writeBytes(it) + FileHelp.getFile(fontCacheFolder + file.name).writeBytes(it) } } } try { - val file = File(fontFolder) + val file = File(fontCacheFolder) file.listFiles { pathName -> pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) }?.let { @@ -167,7 +170,7 @@ class FontSelectDialog : DialogFragment(), } override fun onClick(file: File) { - file.absolutePath.let { path -> + file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path -> (parentFragment as? CallBack)?.let { if (it.curFontPath != path) { it.selectFile(path) From b032acca6ab083d1d66ecdcc7b94a91c55808cea Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 09:20:37 +0800 Subject: [PATCH 112/852] up --- .../app/ui/widget/font/FontSelectDialog.kt | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 8d3deef08..0f5ce1e32 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -90,12 +90,8 @@ class FontSelectDialog : DialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_default -> { - (parentFragment as? CallBack)?.let { - if (it.curFontPath != "") { - it.selectFile("") - } - } - (activity as? CallBack)?.let { + val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) + cb?.let { if (it.curFontPath != "") { it.selectFile("") } @@ -170,19 +166,19 @@ class FontSelectDialog : DialogFragment(), } override fun onClick(file: File) { - file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path -> - (parentFragment as? CallBack)?.let { - if (it.curFontPath != path) { - it.selectFile(path) - } - } - (activity as? CallBack)?.let { - if (it.curFontPath != path) { - it.selectFile(path) + launch(IO) { + file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path -> + val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) + cb?.let { + if (it.curFontPath != path) { + withContext(Main) { + it.selectFile(path) + } + } } } + dialog?.dismiss() } - dialog?.dismiss() } override fun curFilePath(): String { From 3fdcdec074cf6572b71b63d066383caebf6f4ac3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 09:28:38 +0800 Subject: [PATCH 113/852] up --- .../main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 0f5ce1e32..420bc9233 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -167,7 +167,7 @@ class FontSelectDialog : DialogFragment(), override fun onClick(file: File) { launch(IO) { - file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path -> + file.copyTo(FileHelp.getFile(fontFolder + file.name), true).absolutePath.let { path -> val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) cb?.let { if (it.curFontPath != path) { From 39ce729ac283e0edb12f6538116aa7e4f47d0a91 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:08:56 +0800 Subject: [PATCH 114/852] up --- .../java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 24b49a5c6..9296537e4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -14,8 +14,11 @@ import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getViewModel +import io.legado.app.utils.htmlFormat import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_read.* +import org.apache.commons.text.StringEscapeUtils +import org.jsoup.Jsoup class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_read), ReadRssViewModel.CallBack { @@ -134,9 +137,12 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r return super.onKeyUp(keyCode, event) } + @SuppressLint("SetJavaScriptEnabled") private fun readAloud() { + webView.settings.javaScriptEnabled = true webView.evaluateJavascript("document.documentElement.outerHTML") { - viewModel.readAloud(it) + val html = StringEscapeUtils.unescapeJson(it) + viewModel.readAloud(Jsoup.parse(html).body().html().htmlFormat()) } } From 1eef27eba962ad2220675992ede9d5ec88a0e1a7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:15:38 +0800 Subject: [PATCH 115/852] up --- .../legado/app/ui/rss/read/ReadRssActivity.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 9296537e4..26ede2867 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -17,6 +17,7 @@ import io.legado.app.utils.getViewModel import io.legado.app.utils.htmlFormat import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_read.* +import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils import org.jsoup.Jsoup @@ -103,14 +104,16 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } override fun upTtsMenu(isPlaying: Boolean) { - if (isPlaying) { - ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) - ttsMenuItem?.setTitle(R.string.aloud_stop) - } else { - ttsMenuItem?.setIcon(R.drawable.ic_volume_up) - ttsMenuItem?.setTitle(R.string.read_aloud) + launch { + if (isPlaying) { + ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) + ttsMenuItem?.setTitle(R.string.aloud_stop) + } else { + ttsMenuItem?.setIcon(R.drawable.ic_volume_up) + ttsMenuItem?.setTitle(R.string.read_aloud) + } + DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor) } - DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor) } override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { From f3564f86d06c17b88f65760fff46a121f5a10f14 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:26:29 +0800 Subject: [PATCH 116/852] up --- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 26ede2867..2caf40524 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -142,10 +142,15 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r @SuppressLint("SetJavaScriptEnabled") private fun readAloud() { - webView.settings.javaScriptEnabled = true - webView.evaluateJavascript("document.documentElement.outerHTML") { - val html = StringEscapeUtils.unescapeJson(it) - viewModel.readAloud(Jsoup.parse(html).body().html().htmlFormat()) + if (viewModel.textToSpeech.isSpeaking) { + viewModel.textToSpeech.stop() + upTtsMenu(false) + } else { + webView.settings.javaScriptEnabled = true + webView.evaluateJavascript("document.documentElement.outerHTML") { + val html = StringEscapeUtils.unescapeJson(it) + viewModel.readAloud(Jsoup.parse(html).body().html().htmlFormat()) + } } } From 225e1ee005abdcac2a91bd4feb1395b26b8085ab Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:31:21 +0800 Subject: [PATCH 117/852] up --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index a067a90e9..633759c8c 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/11 +* RSS阅读界面添加朗读功能 + **2020/01/10 * 合并KKL369提交的代码 From 641e751edf3217a367c2678afd23e370cb3b07fb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:32:24 +0800 Subject: [PATCH 118/852] up --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 633759c8c..847d2c5cd 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/01/11 * RSS阅读界面添加朗读功能 +* 其它一些优化 **2020/01/10 * 合并KKL369提交的代码 From e4882100cf6e39153980b9dcf6965a1a61a71b88 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sat, 11 Jan 2020 17:33:56 +0800 Subject: [PATCH 119/852] =?UTF-8?q?=E9=87=8D=E5=86=99LinearLayoutManager?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=B9=A6=E7=B1=8D=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E6=A8=A1=E7=B3=8A=E6=90=9C=E7=B4=A2=E5=90=8EscrollToPosition?= =?UTF-8?q?=E5=9C=A8=E5=8F=AF=E8=A7=81=E8=8C=83=E5=9B=B4=E4=B8=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/chapterlist/ChapterListFragment.kt | 16 ++++--- .../widget/recycler/UpLinearLayoutManager.kt | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 509e514ba..6853a1f07 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -8,13 +8,13 @@ import android.widget.LinearLayout import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.lib.theme.backgroundColor +import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.utils.getViewModelOfActivity import kotlinx.android.synthetic.main.fragment_chapter_list.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -28,6 +28,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme lateinit var adapter: ChapterListAdapter private var chapterData: LiveData>? = null private var durChapterIndex = 0 + private lateinit var mLayoutManager: UpLinearLayoutManager override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -38,7 +39,8 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme private fun initRecyclerView() { adapter = ChapterListAdapter(requireContext(), this) - recycler_view.layoutManager = LinearLayoutManager(requireContext()) + mLayoutManager = UpLinearLayoutManager(requireContext()) + recycler_view.layoutManager = mLayoutManager recycler_view.addItemDecoration( DividerItemDecoration( requireContext(), @@ -55,7 +57,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme viewModel.book?.let { book -> durChapterIndex = book.durChapterIndex tv_current_chapter_info.text = book.durChapterTitle - recycler_view.scrollToPosition(durChapterIndex) + mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) } }) } @@ -63,15 +65,15 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme private fun initView() { ll_chapter_base_info.setBackgroundColor(backgroundColor) - iv_chapter_top.onClick { recycler_view.scrollToPosition(0) } + iv_chapter_top.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } iv_chapter_bottom.onClick { if (adapter.itemCount > 0) { - recycler_view.scrollToPosition(adapter.itemCount - 1) + mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0) } } tv_current_chapter_info.onClick { viewModel.book?.let { - recycler_view.scrollToPosition(it.durChapterIndex) + mLayoutManager.scrollToPositionWithOffset(it.durChapterIndex, 0) } } viewModel.callBack = this @@ -86,7 +88,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme chapterData?.observe(viewLifecycleOwner, Observer { adapter.setItems(it) }) - recycler_view.scrollToPosition(0) + mLayoutManager.scrollToPositionWithOffset(0, 0) } } 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 new file mode 100644 index 000000000..0df53aba7 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt @@ -0,0 +1,43 @@ +package io.legado.app.ui.widget.recycler + +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 + } + + fun smoothScrollToPosition(position: Int) { + smoothScrollToPosition(position, 0) + } + + fun smoothScrollToPosition(position: Int, offset: Int) { + val scroller = UpLinearSmoothScroller(context) + scroller.targetPosition = position + scroller.offset = offset + startSmoothScroll(scroller) + } +} + +class UpLinearSmoothScroller(context: Context?): LinearSmoothScroller(context) { + var offset = 0 + + override fun getVerticalSnapPreference(): Int { + return SNAP_TO_START + } + + override fun getHorizontalSnapPreference(): Int { + return SNAP_TO_START + } + + override fun calculateDtToFit(viewStart: Int, viewEnd: Int, boxStart: Int, boxEnd: Int, snapPreference: Int): Int { + if (snapPreference == SNAP_TO_START) { + return boxStart - viewStart + offset + } + throw IllegalArgumentException("snap preference should be SNAP_TO_START") + } +} \ No newline at end of file From 291777b8560f7b693522065a2f32fe033e892d99 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 20:10:28 +0800 Subject: [PATCH 120/852] up --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 847d2c5cd..171c3d744 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ **2020/01/11 * RSS阅读界面添加朗读功能 * 其它一些优化 +* 合并KKL369提交的代码,重写LinearLayoutManager,修复书籍目录模糊搜索后scrollToPosition在可见范围不置顶 **2020/01/10 * 合并KKL369提交的代码 From 890488aa0c5910b0631b81a4c2d26956bd481761 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 20:53:56 +0800 Subject: [PATCH 121/852] up --- .../main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 2caf40524..a8ca32fdd 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -14,12 +14,12 @@ import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getViewModel -import io.legado.app.utils.htmlFormat import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_read.* import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils import org.jsoup.Jsoup +import org.jsoup.safety.Whitelist class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_read), ReadRssViewModel.CallBack { @@ -149,7 +149,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r webView.settings.javaScriptEnabled = true webView.evaluateJavascript("document.documentElement.outerHTML") { val html = StringEscapeUtils.unescapeJson(it) - viewModel.readAloud(Jsoup.parse(html).body().html().htmlFormat()) + viewModel.readAloud(Jsoup.clean(html, Whitelist())) } } } From 92dd37ac4edef2e04f75771c6c54c4cb36daecf2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 21:16:05 +0800 Subject: [PATCH 122/852] up --- .../main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 83a88091e..ba9903de4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -110,7 +110,10 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } fun readAloud(text: String) { - textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, "rss") + textToSpeech.stop() + text.split(" ").forEach { + textToSpeech.speak(it, TextToSpeech.QUEUE_ADD, null, "rss") + } } override fun onCleared() { From 628f3b0a7ca04a8b9f5cae05a968d8127cf8d358 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 21:28:38 +0800 Subject: [PATCH 123/852] up --- app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index ba9903de4..5af6841e9 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -111,7 +111,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), fun readAloud(text: String) { textToSpeech.stop() - text.split(" ").forEach { + text.split("\n", " ", "  ").forEach { textToSpeech.speak(it, TextToSpeech.QUEUE_ADD, null, "rss") } } From 403a89e5c4527c81dbd3c90eafe4b8a33a43a29f Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 12 Jan 2020 17:36:02 +0800 Subject: [PATCH 124/852] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E9=80=BB=E8=BE=91=E5=B9=B6=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E6=A8=A1=E7=B3=8A=E6=90=9C=E7=B4=A2=E5=87=86=E7=A1=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookChapterDao.kt | 4 ++-- .../app/ui/chapterlist/ChapterListFragment.kt | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt index a67d12f03..9dda87c0e 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt @@ -13,8 +13,8 @@ interface BookChapterDao { @Query("select * from chapters where bookUrl = :bookUrl") fun observeByBook(bookUrl: String): LiveData> - @Query("SELECT * FROM chapters where title like '%'||:key||'%'") - fun liveDataSearch(key: String): LiveData> + @Query("SELECT * FROM chapters where bookUrl = :bookUrl and title like '%'||:key||'%'") + fun liveDataSearch(bookUrl: String, key: String): LiveData> @Query("select * from chapters where bookUrl = :bookUrl") fun getChapterList(bookUrl: String): List diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 6853a1f07..bc002f56e 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -5,7 +5,6 @@ import android.content.Intent import android.os.Bundle import android.view.View import android.widget.LinearLayout -import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.DividerItemDecoration import io.legado.app.App @@ -26,7 +25,6 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme get() = getViewModelOfActivity(ChapterListViewModel::class.java) lateinit var adapter: ChapterListAdapter - private var chapterData: LiveData>? = null private var durChapterIndex = 0 private lateinit var mLayoutManager: UpLinearLayoutManager @@ -56,7 +54,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme adapter.setItems(it) viewModel.book?.let { book -> durChapterIndex = book.durChapterIndex - tv_current_chapter_info.text = book.durChapterTitle + tv_current_chapter_info.text = it[durChapterIndex()].title mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) } }) @@ -80,15 +78,15 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } override fun startSearch(newText: String?) { - chapterData?.removeObservers(this) if (newText.isNullOrBlank()) { initData() } else { - chapterData = App.db.bookChapterDao().liveDataSearch(newText) - chapterData?.observe(viewLifecycleOwner, Observer { - adapter.setItems(it) - }) - mLayoutManager.scrollToPositionWithOffset(0, 0) + viewModel.bookUrl?.let { bookUrl -> + App.db.bookChapterDao().liveDataSearch(bookUrl, newText).observe(viewLifecycleOwner, Observer { + adapter.setItems(it) + mLayoutManager.scrollToPositionWithOffset(0, 0) + }) + } } } From 13eea77aba5592f5fe84ccfaf7b543d80e85afee Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 13 Jan 2020 15:17:51 +0800 Subject: [PATCH 125/852] up --- .../app/ui/importbook/ImportBookAdapter.kt | 18 ++++++++++++++++++ app/src/main/res/layout/item_import_book.xml | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt create mode 100644 app/src/main/res/layout/item_import_book.xml diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt new file mode 100644 index 000000000..29ac7e579 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -0,0 +1,18 @@ +package io.legado.app.ui.importbook + +import android.content.Context +import androidx.documentfile.provider.DocumentFile +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter + + +class ImportBookAdapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_import_book) { + + + override fun convert(holder: ItemViewHolder, item: DocumentFile, payloads: MutableList) { + + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/item_import_book.xml b/app/src/main/res/layout/item_import_book.xml new file mode 100644 index 000000000..f14841ad0 --- /dev/null +++ b/app/src/main/res/layout/item_import_book.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file From cf41c2d162f1b00c424d88541311f921c8fe066d Mon Sep 17 00:00:00 2001 From: Administrator Date: Wed, 15 Jan 2020 09:44:32 +0800 Subject: [PATCH 126/852] =?UTF-8?q?=E5=BC=80=E5=90=AF=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookmarkDao.kt | 8 ++++ .../io/legado/app/data/entities/Bookmark.kt | 4 +- .../app/ui/book/read/ReadBookActivity.kt | 41 +++++++++++++++++-- .../app/ui/book/read/ReadBookViewModel.kt | 4 +- .../app/ui/chapterlist/BookmarkAdapter.kt | 13 ++++-- .../app/ui/chapterlist/BookmarkFragment.kt | 22 +++++++++- 6 files changed, 79 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt index eb757c547..9010aa950 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt @@ -2,6 +2,8 @@ package io.legado.app.data.dao import androidx.paging.DataSource import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy import androidx.room.Query import io.legado.app.data.entities.Bookmark @@ -15,4 +17,10 @@ interface BookmarkDao { @Query("select * from bookmarks where bookUrl = :bookUrl") fun observeByBook(bookUrl: String): DataSource.Factory + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(vararg bookmark: Bookmark) + + @Query("delete from bookmarks where bookUrl = :bookUrl and chapterName like '%'||:chapterName||'%'") + fun delByBookmark(bookUrl: String, chapterName: String) + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/Bookmark.kt b/app/src/main/java/io/legado/app/data/entities/Bookmark.kt index c1f638137..acd6005a3 100644 --- a/app/src/main/java/io/legado/app/data/entities/Bookmark.kt +++ b/app/src/main/java/io/legado/app/data/entities/Bookmark.kt @@ -7,15 +7,15 @@ import androidx.room.PrimaryKey import kotlinx.android.parcel.Parcelize @Parcelize -@Entity(tableName = "bookmarks", indices = [(Index(value = ["bookUrl"], unique = true))]) +@Entity(tableName = "bookmarks", indices = [(Index(value = ["time"], unique = true))]) data class Bookmark( @PrimaryKey var time: Long = System.currentTimeMillis(), var bookUrl: String = "", var bookName: String = "", - var chapterName: String = "", var chapterIndex: Int = 0, var pageIndex: Int = 0, + var chapterName: String = "", var content: String = "" ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 3a2523293..3125f70d0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -4,15 +4,18 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.net.Uri +import android.os.AsyncTask.execute import android.os.Bundle import android.text.SpannableStringBuilder import android.view.KeyEvent import android.view.Menu import android.view.MenuItem import android.view.View +import android.widget.EditText import androidx.core.view.isVisible import androidx.lifecycle.Observer import com.jaredrummler.android.colorpicker.ColorPickerDialogListener +import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus @@ -20,6 +23,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.constant.Status import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter +import io.legado.app.data.entities.Bookmark import io.legado.app.help.ReadBookConfig import io.legado.app.lib.dialogs.* import io.legado.app.receiver.TimeElectricityReceiver @@ -41,6 +45,7 @@ import io.legado.app.ui.replacerule.edit.ReplaceEditDialog import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.dialog_download_choice.view.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_book_page.* import kotlinx.android.synthetic.main.view_read_menu.* import kotlinx.coroutines.Dispatchers.IO @@ -174,7 +179,35 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo }.show().applyTint() } R.id.menu_add_bookmark -> { - + val book = ReadBook.book + val textChapter = ReadBook.curTextChapter + alert(title = getString(R.string.bookmark_add)) { + var editText: EditText? = null + message = book?.name + " • " + textChapter?.title + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view.apply { + hint = "备注内容" + } + } + } + yesButton { + editText?.text?.toString()?.let { editContent -> + execute { + val bookmark = Bookmark( + book!!.durChapterTime, + book!!.bookUrl, + book!!.name, + ReadBook.durChapterIndex, + ReadBook.durPageIndex, + textChapter!!.title, + editContent) + App.db.bookmarkDao().insert(bookmark) + } + } + } + noButton() + }.show().applyTint().requestInputMethod() } R.id.menu_copy_text -> { @@ -438,8 +471,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo when (requestCode) { requestCodeEditSource -> viewModel.upBookSource() requestCodeChapterList -> - data?.getIntExtra("index", ReadBook.durChapterIndex)?.let { - viewModel.openChapter(it) + data?.getIntExtra("index", ReadBook.durChapterIndex)?.let { index -> + viewModel.openChapter(index, data?.getIntExtra("pageIndex", ReadBook.durPageIndex)) } requestCodeReplace -> ReadBook.loadContent() } @@ -476,7 +509,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo observeEvent(Bus.TIME_CHANGED) { page_view.upTime() } observeEvent(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEvent(Bus.OPEN_CHAPTER) { - viewModel.openChapter(it.index) + viewModel.openChapter(it.index, ReadBook.durPageIndex) page_view.upContent() } observeEvent(Bus.MEDIA_BUTTON) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 8ee7b8e47..959068a8a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -154,14 +154,14 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } - fun openChapter(index: Int) { + fun openChapter(index: Int, pageIndex: Int) { ReadBook.prevTextChapter = null ReadBook.curTextChapter = null ReadBook.nextTextChapter = null ReadBook.callBack?.upContent() if (index != ReadBook.durChapterIndex) { ReadBook.durChapterIndex = index - ReadBook.durPageIndex = 0 + ReadBook.durPageIndex = pageIndex } ReadBook.saveRead() ReadBook.loadContent() diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt index 6eff6e223..ea3f41801 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.chapterlist +import android.os.AsyncTask.execute import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -10,9 +11,10 @@ import io.legado.app.R import io.legado.app.data.entities.Bookmark import kotlinx.android.synthetic.main.item_bookmark.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.sdk27.listeners.onLongClick -class BookmarkAdapter : PagedListAdapter(DIFF_CALLBACK) { +class BookmarkAdapter(val callback: Callback) : PagedListAdapter(DIFF_CALLBACK) { companion object { @@ -29,8 +31,6 @@ class BookmarkAdapter : PagedListAdapter } } - var callback: Callback? = null - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookmark, parent, false)) } @@ -49,10 +49,17 @@ class BookmarkAdapter : PagedListAdapter itemView.onClick { callback?.open(bookmark) } + itemView.onLongClick { + execute { + callback?.delBookmark(bookmark) + } + true + } } } interface Callback { fun open(bookmark: Bookmark) + fun delBookmark(bookmark: Bookmark) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt index 0d42b5600..31efa44c3 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt @@ -1,5 +1,7 @@ package io.legado.app.ui.chapterlist +import android.app.Activity +import android.content.Intent import android.os.Bundle import android.view.View import android.widget.LinearLayout @@ -17,7 +19,9 @@ import io.legado.app.lib.theme.ATH import io.legado.app.utils.getViewModelOfActivity import kotlinx.android.synthetic.main.fragment_bookmark.* -class BookmarkFragment : VMBaseFragment(R.layout.fragment_bookmark) { + +class BookmarkFragment : VMBaseFragment(R.layout.fragment_bookmark), + BookmarkAdapter.Callback { override val viewModel: ChapterListViewModel get() = getViewModelOfActivity(ChapterListViewModel::class.java) @@ -32,7 +36,7 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) - adapter = BookmarkAdapter() + adapter = BookmarkAdapter(this) recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration( DividerItemDecoration( @@ -48,4 +52,18 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ bookmarkLiveData = LivePagedListBuilder(App.db.bookmarkDao().observeByBook(viewModel.bookUrl ?: ""), 20).build() bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) } + + override fun open(bookmark: Bookmark) { + val bookmarkData = Intent() + bookmarkData.putExtra("index", bookmark.chapterIndex) + bookmarkData.putExtra("pageIndex", bookmark.pageIndex) + activity?.setResult(Activity.RESULT_OK, bookmarkData) + activity?.finish() + } + + override fun delBookmark(bookmark: Bookmark) { + bookmark?.let { + App.db.bookmarkDao().delByBookmark(it.bookUrl, it.chapterName) + } + } } \ No newline at end of file From 527b8f25a065c09304a17a98cf2610e89611046f Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 16 Jan 2020 13:42:12 +0800 Subject: [PATCH 127/852] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E2=80=9C=E7=B2=BE=E5=87=86=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/search/SearchViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 6bca4a5f4..1a695cccd 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -72,8 +72,8 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { val books = arrayListOf() searchBooks.forEach { searchBook -> if (context.getPrefBoolean(PreferKey.precisionSearch)) { - if (searchBook.name.contains(searchKey) - || searchBook.author.contains(searchKey) + if (searchBook.name.equals(searchKey, true) + || searchBook.author.equals(searchKey, true) ) books.add(searchBook) } else books.add(searchBook) From 5ed5352634b49555e7a1bebba7f861ddcc441885 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 16 Jan 2020 14:03:54 +0800 Subject: [PATCH 128/852] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E9=9A=8FmenuItem=E7=82=B9=E5=87=BB=E5=88=B7?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/search/SearchActivity.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 2cf9cae3d..ae44ddaad 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -76,6 +76,9 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se !getPrefBoolean(PreferKey.precisionSearch) ) precisionSearchMenuItem?.isChecked = getPrefBoolean(PreferKey.precisionSearch) + search_view.query.toString().trim()?.let { + search_view.setQuery(it, true) + } } R.id.menu_source_manage -> startActivity() else -> if (item.groupId == R.id.source_group) { @@ -85,6 +88,9 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } else { putPrefString("searchGroup", item.title.toString()) } + search_view.query.toString().trim()?.let { + search_view.setQuery(it, true) + } } } return super.onCompatOptionsItemSelected(item) From 445c1084506368b5468167aae1ae99402a256e45 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 16 Jan 2020 16:05:19 +0800 Subject: [PATCH 129/852] =?UTF-8?q?=E5=BC=80=E5=90=AF=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/dao/BookmarkDao.kt | 3 +++ .../app/ui/chapterlist/BookmarkFragment.kt | 14 +++++++++++++- .../app/ui/chapterlist/ChapterListActivity.kt | 2 +- .../app/ui/chapterlist/ChapterListFragment.kt | 16 +++++++--------- .../app/ui/chapterlist/ChapterListViewModel.kt | 17 +++++++++++++---- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt index 9010aa950..568714e2f 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookmarkDao.kt @@ -17,6 +17,9 @@ interface BookmarkDao { @Query("select * from bookmarks where bookUrl = :bookUrl") fun observeByBook(bookUrl: String): DataSource.Factory + @Query("SELECT * FROM bookmarks where bookUrl = :bookUrl and chapterName like '%'||:key||'%' or content like '%'||:key||'%'") + fun liveDataSearch(bookUrl: String, key: String): DataSource.Factory + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookmark: Bookmark) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt index 31efa44c3..803fe2e11 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt @@ -21,7 +21,8 @@ import kotlinx.android.synthetic.main.fragment_bookmark.* class BookmarkFragment : VMBaseFragment(R.layout.fragment_bookmark), - BookmarkAdapter.Callback { + BookmarkAdapter.Callback, + ChapterListViewModel.BookmarkCallBack { override val viewModel: ChapterListViewModel get() = getViewModelOfActivity(ChapterListViewModel::class.java) @@ -30,6 +31,7 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + viewModel.bookMarkCallBack = this initRecyclerView() initData() } @@ -53,6 +55,16 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) } + override fun startBookmarkSearch(newText: String?) { + if (newText.isNullOrBlank()) { + initData() + } else { + bookmarkLiveData?.removeObservers(viewLifecycleOwner) + bookmarkLiveData = LivePagedListBuilder(App.db.bookmarkDao().liveDataSearch(viewModel.bookUrl ?: "", newText), 20).build() + bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) + } + } + override fun open(bookmark: Bookmark) { val bookmarkData = Intent() bookmarkData.putExtra("index", bookmark.chapterIndex) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index 1aab97a4b..920b0dd24 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -54,7 +54,7 @@ class ChapterListActivity : VMBaseActivity(R.layout.activi override fun onQueryTextChange(newText: String): Boolean { if (tab_layout.selectedTabPosition == 1) { - + viewModel.startBookmarkSearch(newText) } else { viewModel.startChapterListSearch(newText) } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index bc002f56e..22092493a 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -20,7 +20,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list), ChapterListAdapter.Callback, - ChapterListViewModel.CallBack { + ChapterListViewModel.ChapterListCallBack{ override val viewModel: ChapterListViewModel get() = getViewModelOfActivity(ChapterListViewModel::class.java) @@ -30,6 +30,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + viewModel.chapterCallBack = this initRecyclerView() initView() initData() @@ -74,19 +75,16 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme mLayoutManager.scrollToPositionWithOffset(it.durChapterIndex, 0) } } - viewModel.callBack = this } - override fun startSearch(newText: String?) { + override fun startChapterListSearch(newText: String?) { if (newText.isNullOrBlank()) { initData() } else { - viewModel.bookUrl?.let { bookUrl -> - App.db.bookChapterDao().liveDataSearch(bookUrl, newText).observe(viewLifecycleOwner, Observer { - adapter.setItems(it) - mLayoutManager.scrollToPositionWithOffset(0, 0) - }) - } + App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl ?: "", newText).observe(viewLifecycleOwner, Observer { + adapter.setItems(it) + mLayoutManager.scrollToPositionWithOffset(0, 0) + }) } } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt index abbc81b01..5ac2e68d9 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt @@ -9,7 +9,8 @@ import io.legado.app.data.entities.Book class ChapterListViewModel(application: Application) : BaseViewModel(application) { var bookUrl: String? = null var book: Book? = null - var callBack: CallBack? = null + var chapterCallBack: ChapterListCallBack? = null + var bookMarkCallBack: BookmarkCallBack? = null fun loadBook(success: () -> Unit) { execute { @@ -22,10 +23,18 @@ class ChapterListViewModel(application: Application) : BaseViewModel(application } fun startChapterListSearch(newText: String?) { - callBack?.startSearch(newText) + chapterCallBack?.startChapterListSearch(newText) } - interface CallBack { - fun startSearch(newText: String?) + fun startBookmarkSearch(newText: String?) { + bookMarkCallBack?.startBookmarkSearch(newText) + } + + interface ChapterListCallBack { + fun startChapterListSearch(newText: String?) + } + + interface BookmarkCallBack { + fun startBookmarkSearch(newText: String?) } } \ No newline at end of file From e672e82c21b06a1e636f323aa5e9538af8869241 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 16 Jan 2020 20:31:00 +0800 Subject: [PATCH 130/852] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=95=BF=E6=8C=89TAB?= =?UTF-8?q?S=E8=AE=BE=E7=BD=AE=E4=B8=BA=E9=BB=98=E8=AE=A4=E9=A1=B5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/constant/Bus.kt | 1 + .../java/io/legado/app/constant/PreferKey.kt | 1 + .../app/ui/main/bookshelf/BookshelfFragment.kt | 18 ++++++++++++++---- .../ui/main/bookshelf/books/BooksFragment.kt | 2 ++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 7795773e6..eb1dd14dd 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -20,4 +20,5 @@ object Bus { const val SHOW_RSS = "showRss" const val WEB_SERVICE_STOP = "webServiceStop" const val UP_DOWNLOAD = "upDownload" + const val UP_TABS = "upTabs" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 0d8cad7cf..ac1ba5ce5 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -14,6 +14,7 @@ object PreferKey { const val processText = "process_text" const val cleanCache = "cleanCache" const val lastGroup = "lastGroup" + const val saveTabPosition = "saveTabPosition" const val pageAnim = "pageAnim" const val readBookFont = "readBookFont" const val fontFolder = "fontFolder" diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 15a494694..401685b55 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -13,22 +13,23 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.constant.AppConst +import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey +import io.legado.app.constant.PreferKey.saveTabPosition import io.legado.app.data.entities.BookGroup import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.download.DownloadActivity -import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getViewModel -import io.legado.app.utils.putPrefInt -import io.legado.app.utils.startActivity +import io.legado.app.utils.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* import kotlinx.android.synthetic.main.view_title_bar.* +import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.startActivity + class BookshelfFragment : VMBaseFragment(R.layout.fragment_bookshelf), SearchView.OnQueryTextListener, GroupManageDialog.CallBack, @@ -82,7 +83,16 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b view_pager_bookshelf.adapter = BookshelfAdapter(this, this) TabLayoutMediator(tab_layout, view_pager_bookshelf) { tab, position -> tab.text = bookGroups[position].groupName + tab.view?.onLongClick { + tab.select() + putPrefInt(saveTabPosition, position) + toast("该分组<" + bookGroups[position].groupName + ">已成为默认页。") + true + } }.attach() + observeEvent(Bus.UP_TABS) { + tab_layout.getTabAt(it)?.select() + } } private fun initBookGroupData() { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 765c06697..bff9586ff 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -24,6 +24,7 @@ import io.legado.app.ui.main.MainViewModel import io.legado.app.utils.getPrefInt import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.observeEvent +import io.legado.app.utils.postEvent import kotlinx.android.synthetic.main.fragment_books.* import org.jetbrains.anko.startActivity @@ -56,6 +57,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), observeEvent(Bus.UP_BOOK) { booksAdapter.notification(it) } + postEvent(Bus.UP_TABS, getPrefInt(PreferKey.saveTabPosition, 0)) } private fun initRecyclerView() { From a7b055974c98b85455f5b29ab65d4adaa80bdc43 Mon Sep 17 00:00:00 2001 From: Administrator Date: Fri, 17 Jan 2020 21:14:56 +0800 Subject: [PATCH 131/852] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E6=80=BB=E6=98=AF=E7=BF=BB=E4=B8=8B=E4=B8=80=E9=A1=B5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 + .../io/legado/app/ui/book/read/config/MoreConfigDialog.kt | 1 + .../legado/app/ui/book/read/page/delegate/PageDelegate.kt | 5 ++++- app/src/main/res/xml/pref_config_read.xml | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index ac1ba5ce5..b869927e6 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -4,6 +4,7 @@ object PreferKey { const val downloadPath = "downloadPath" const val hideStatusBar = "hideStatusBar" + const val clickAllNext = "clickAllNext" const val hideNavigationBar = "hideNavigationBar" const val precisionSearch = "precisionSearch" const val prevKey = "prevKeyCode" diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index c1954a4e1..899d58d63 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -94,6 +94,7 @@ class MoreConfigDialog : DialogFragment() { when (key) { PreferKey.hideStatusBar -> postEvent(Bus.UP_CONFIG, true) PreferKey.hideNavigationBar -> postEvent(Bus.UP_CONFIG, true) + PreferKey.clickAllNext -> postEvent(Bus.UP_CONFIG, true) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 3f78253b6..db1250c3d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -9,8 +9,10 @@ import android.widget.Scroller import androidx.annotation.CallSuper import androidx.interpolator.view.animation.FastOutLinearInInterpolator import com.google.android.material.snackbar.Snackbar +import io.legado.app.constant.PreferKey import io.legado.app.ui.book.read.page.ContentView import io.legado.app.ui.book.read.page.PageView +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.screenshot import io.legado.app.utils.snackbar import kotlin.math.abs @@ -256,7 +258,8 @@ abstract class PageDelegate(protected val pageView: PageView) { pageView.callBack?.clickCenter() setTouchPoint(x, y) } else { - bitmap = if (x > viewWidth / 2) { + bitmap = if (x > viewWidth / 2 || + pageView.context.getPrefBoolean(PreferKey.clickAllNext, false)) { //设置动画方向 if (!hasNext()) { return true diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 4d996bd8d..b24a16a71 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -20,6 +20,12 @@ android:key="volumeKeyPage" app:iconSpaceReserved="false" /> + + Date: Wed, 22 Jan 2020 18:04:36 +0800 Subject: [PATCH 132/852] up --- app/build.gradle | 4 ++-- .../java/io/legado/app/help/storage/WebDavHelp.kt | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 356d95bb4..7eac96051 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -96,7 +96,7 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" //fireBase - implementation 'com.google.firebase:firebase-core:17.2.1' + implementation 'com.google.firebase:firebase-core:17.2.2' implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' //androidX @@ -107,7 +107,7 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' - implementation 'com.google.android.material:material:1.2.0-alpha03' + implementation 'com.google.android.material:material:1.2.0-alpha04' implementation 'com.google.android:flexbox:1.1.0' //lifecycle diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 4a0f3e152..7d905299d 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -3,7 +3,6 @@ package io.legado.app.help.storage import android.content.Context import io.legado.app.App import io.legado.app.help.FileHelp -import io.legado.app.help.ReadBookConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth @@ -83,14 +82,10 @@ object WebDavHelp { fun backUpWebDav(path: String) { if (initWebDav()) { - val paths = arrayListOf( - path + File.separator + "bookshelf.json", - path + File.separator + "bookSource.json", - path + File.separator + "rssSource.json", - path + File.separator + "replaceRule.json", - path + File.separator + "config.xml", - path + File.separator + ReadBookConfig.readConfigFileName - ) + val paths = arrayListOf(*Backup.backupFileNames) + for (i in 0 until paths.size) { + paths[i] = path + File.separator + paths[i] + } FileHelp.deleteFile(zipFilePath) if (ZipUtils.zipFiles(paths, zipFilePath)) { WebDav(getWebDavUrl() + "legado").makeAsDir() From 985f484b29e935bb13020f51b5fcd7a42cf00165 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 22 Jan 2020 19:10:57 +0800 Subject: [PATCH 133/852] up --- app/src/main/java/io/legado/app/data/AppDatabase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index d65b43ada..eb44e9381 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -17,7 +17,7 @@ import kotlinx.coroutines.launch entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, RssSource::class, Bookmark::class, RssArticle::class, RssStar::class], - version = 5, + version = 6, exportSchema = true ) abstract class AppDatabase : RoomDatabase() { From 6423f91798ae9edd7bc7689071d05d9c87f748c9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 23 Jan 2020 09:13:42 +0800 Subject: [PATCH 134/852] up --- ...WebDavConfigFragment.kt => BackupConfigFragment.kt} | 10 ++++++---- .../java/io/legado/app/ui/config/ConfigActivity.kt | 4 ++-- ...{pref_config_web_dav.xml => pref_config_backup.xml} | 5 +++++ 3 files changed, 13 insertions(+), 6 deletions(-) rename app/src/main/java/io/legado/app/ui/config/{WebDavConfigFragment.kt => BackupConfigFragment.kt} (97%) rename app/src/main/res/xml/{pref_config_web_dav.xml => pref_config_backup.xml} (89%) diff --git a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt rename to app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 446c93f68..d403324fe 100644 --- a/app/src/main/java/io/legado/app/ui/config/WebDavConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -31,7 +31,7 @@ import kotlinx.coroutines.Dispatchers.IO import org.jetbrains.anko.toast import kotlin.coroutines.CoroutineContext -class WebDavConfigFragment : PreferenceFragmentCompat(), +class BackupConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, CoroutineScope { private lateinit var job: Job @@ -46,14 +46,14 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), job = Job() fun bindPreferenceSummaryToValue(preference: Preference?) { preference?.apply { - onPreferenceChangeListener = this@WebDavConfigFragment + onPreferenceChangeListener = this@BackupConfigFragment onPreferenceChange( this, context.getPrefString(key) ) } } - addPreferencesFromResource(R.xml.pref_config_web_dav) + addPreferencesFromResource(R.xml.pref_config_backup) findPreference("web_dav_url")?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) @@ -74,6 +74,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), } bindPreferenceSummaryToValue(it) } + bindPreferenceSummaryToValue(findPreference(PreferKey.backupPath)) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -115,6 +116,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { + PreferKey.backupPath -> selectBackupFolder() "web_dav_backup" -> backup() "web_dav_restore" -> restore() "import_old" -> importOldData() @@ -206,7 +208,7 @@ class WebDavConfigFragment : PreferenceFragmentCompat(), alert(title = "导入") { message = "是否导入旧版本数据" yesButton { - PermissionsCompat.Builder(this@WebDavConfigFragment) + PermissionsCompat.Builder(this@BackupConfigFragment) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) .onGranted { diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt index 838b5c31d..a79e3f6a9 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt @@ -36,9 +36,9 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) } ConfigViewModel.TYPE_WEB_DAV_CONFIG -> { title_bar.title = getString(R.string.backup_restore) - val fTag = "webDavFragment" + val fTag = "backupFragment" var configFragment = supportFragmentManager.findFragmentByTag(fTag) - if (configFragment == null) configFragment = WebDavConfigFragment() + if (configFragment == null) configFragment = BackupConfigFragment() supportFragmentManager.beginTransaction() .replace(R.id.configFrameLayout, configFragment, fTag) .commit() diff --git a/app/src/main/res/xml/pref_config_web_dav.xml b/app/src/main/res/xml/pref_config_backup.xml similarity index 89% rename from app/src/main/res/xml/pref_config_web_dav.xml rename to app/src/main/res/xml/pref_config_backup.xml index 0b4a84e09..d70d7145d 100644 --- a/app/src/main/res/xml/pref_config_web_dav.xml +++ b/app/src/main/res/xml/pref_config_backup.xml @@ -28,6 +28,11 @@ + + Date: Thu, 23 Jan 2020 11:18:22 +0800 Subject: [PATCH 135/852] up --- .../io/legado/app/ui/config/ConfigActivity.kt | 6 ++-- ...nfigFragment.kt => OtherConfigFragment.kt} | 29 ++++++++++--------- app/src/main/res/values/strings.xml | 4 +-- ...{pref_config.xml => pref_config_other.xml} | 24 +++++++++------ 4 files changed, 36 insertions(+), 27 deletions(-) rename app/src/main/java/io/legado/app/ui/config/{ConfigFragment.kt => OtherConfigFragment.kt} (84%) rename app/src/main/res/xml/{pref_config.xml => pref_config_other.xml} (88%) diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt index a79e3f6a9..a685ccd13 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt @@ -18,9 +18,9 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) when (viewModel.configType) { ConfigViewModel.TYPE_CONFIG -> { title_bar.title = getString(R.string.other_setting) - val fTag = "configFragment" + val fTag = "otherConfigFragment" var configFragment = supportFragmentManager.findFragmentByTag(fTag) - if (configFragment == null) configFragment = ConfigFragment() + if (configFragment == null) configFragment = OtherConfigFragment() supportFragmentManager.beginTransaction() .replace(R.id.configFrameLayout, configFragment, fTag) .commit() @@ -36,7 +36,7 @@ class ConfigActivity : VMBaseActivity(R.layout.activity_config) } ConfigViewModel.TYPE_WEB_DAV_CONFIG -> { title_bar.title = getString(R.string.backup_restore) - val fTag = "backupFragment" + val fTag = "backupConfigFragment" var configFragment = supportFragmentManager.findFragmentByTag(fTag) if (configFragment == null) configFragment = BackupConfigFragment() supportFragmentManager.beginTransaction() diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt similarity index 84% rename from app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt rename to app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 74d517b20..f4c38eb70 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -19,7 +19,7 @@ import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.utils.* -class ConfigFragment : PreferenceFragmentCompat(), +class OtherConfigFragment : PreferenceFragmentCompat(), FileChooserDialog.CallBack, Preference.OnPreferenceChangeListener, SharedPreferences.OnSharedPreferenceChangeListener { @@ -33,8 +33,9 @@ class ConfigFragment : PreferenceFragmentCompat(), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { putPrefBoolean("process_text", isProcessTextEnabled()) - addPreferencesFromResource(R.xml.pref_config) + addPreferencesFromResource(R.xml.pref_config_other) bindPreferenceSummaryToValue(findPreference(PreferKey.downloadPath)) + bindPreferenceSummaryToValue(findPreference("threadCount")) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -58,7 +59,7 @@ class ConfigFragment : PreferenceFragmentCompat(), childFragmentManager, downloadPath, mode = FileChooserDialog.DIRECTORY, - initPath = getPreferenceString(PreferKey.downloadPath) + initPath = getPreferenceString(PreferKey.downloadPath).toString() ) PreferKey.cleanCache -> { BookHelp.clearCache() @@ -72,7 +73,7 @@ class ConfigFragment : PreferenceFragmentCompat(), when (key) { PreferKey.downloadPath -> { BookHelp.upDownloadPath() - findPreference(key)?.summary = getPreferenceString(key) + findPreference(key)?.summary = getPreferenceString(key).toString() } PreferKey.recordLog -> LogUtils.upLevel() PreferKey.processText -> sharedPreferences?.let { @@ -84,14 +85,15 @@ class ConfigFragment : PreferenceFragmentCompat(), override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { val stringValue = newValue.toString() - - if (preference is ListPreference) { - val index = preference.findIndexOfValue(stringValue) - // Set the summary to reflect the new value. - preference.setSummary(if (index >= 0) preference.entries[index] else null) - } else { - // For all other preferences, set the summary to the value's - preference?.summary = stringValue + when { + preference is ListPreference -> { + val index = preference.findIndexOfValue(stringValue) + // Set the summary to reflect the new value. + preference.setSummary(if (index >= 0) preference.entries[index] else null) + } + preference?.key == "threadCount" -> preference.summary = + getString(R.string.threads_num, stringValue) + else -> preference?.summary = stringValue } return true } @@ -106,11 +108,12 @@ class ConfigFragment : PreferenceFragmentCompat(), } } - private fun getPreferenceString(key: String): String { + private fun getPreferenceString(key: String): Any { return when (key) { PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath + "threadCount" -> getPrefInt("threadCount", 6) else -> getPrefString(key) ?: "" } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ceda2af3..12ceceb6d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -211,7 +211,7 @@ 暂无任务 已下载 %d/%d 导入选择书籍 - 更新和搜索线程数,如感觉卡顿请减小线程数,量力而行 + 更新和搜索线程数,太多会卡顿 切换图标 删除书籍 开始阅读 @@ -316,7 +316,7 @@ 替换范围,选填书名或者源名 分组 内容缓存路径 - 清理缓存 + 清理缓存 系统文件选择器 新版本 下载更新 diff --git a/app/src/main/res/xml/pref_config.xml b/app/src/main/res/xml/pref_config_other.xml similarity index 88% rename from app/src/main/res/xml/pref_config.xml rename to app/src/main/res/xml/pref_config_other.xml index 55f0f6021..6c38cf624 100644 --- a/app/src/main/res/xml/pref_config.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -22,6 +22,21 @@ android:title="显示订阅" app:iconSpaceReserved="false" /> + + + + + + - - -
\ No newline at end of file From 5c9438f3e10400a42be178f97f299ab106754ef8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 23 Jan 2020 11:31:51 +0800 Subject: [PATCH 136/852] up --- .../main/java/io/legado/app/help/PrefExtensions.kt | 12 ++++++++++++ .../io/legado/app/ui/config/OtherConfigFragment.kt | 3 ++- .../main/java/io/legado/app/ui/main/MainActivity.kt | 1 + .../java/io/legado/app/utils/ContextExtensions.kt | 3 --- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/legado/app/help/PrefExtensions.kt diff --git a/app/src/main/java/io/legado/app/help/PrefExtensions.kt b/app/src/main/java/io/legado/app/help/PrefExtensions.kt new file mode 100644 index 000000000..3f6de591c --- /dev/null +++ b/app/src/main/java/io/legado/app/help/PrefExtensions.kt @@ -0,0 +1,12 @@ +package io.legado.app.help + +import android.content.Context +import io.legado.app.utils.getPrefBoolean +import io.legado.app.utils.getPrefInt + + +val Context.isShowRSS: Boolean + get() = getPrefBoolean("showRss", true) + +val Context.threadCount: Int + get() = getPrefInt("threadCount", 6) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index f4c38eb70..4795b56bb 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -13,6 +13,7 @@ import io.legado.app.R import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey import io.legado.app.help.BookHelp +import io.legado.app.help.threadCount import io.legado.app.lib.theme.ATH import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.ui.filechooser.FileChooserDialog @@ -113,7 +114,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath - "threadCount" -> getPrefInt("threadCount", 6) + "threadCount" -> requireContext().threadCount else -> getPrefString(key) ?: "" } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index ddb8b3f10..0b47b24f6 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -17,6 +17,7 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.isShowRSS import io.legado.app.help.storage.Backup import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService 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 2ab88b481..7f4be23c0 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -120,6 +120,3 @@ val Context.isNightTheme: Boolean val Context.isTransparentStatusBar: Boolean get() = getPrefBoolean("transparentStatusBar", true) - -val Context.isShowRSS: Boolean - get() = getPrefBoolean("showRss", true) \ No newline at end of file From bf2504b61c08bdcebee85e8ac275848fbbe3fb97 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 23 Jan 2020 11:44:53 +0800 Subject: [PATCH 137/852] up --- app/src/main/java/io/legado/app/help/PrefExtensions.kt | 2 +- app/src/main/java/io/legado/app/service/DownloadService.kt | 4 +++- .../main/java/io/legado/app/ui/book/search/SearchViewModel.kt | 4 +++- .../io/legado/app/ui/changesource/ChangeSourceViewModel.kt | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/PrefExtensions.kt b/app/src/main/java/io/legado/app/help/PrefExtensions.kt index 3f6de591c..b9392ef7a 100644 --- a/app/src/main/java/io/legado/app/help/PrefExtensions.kt +++ b/app/src/main/java/io/legado/app/help/PrefExtensions.kt @@ -9,4 +9,4 @@ val Context.isShowRSS: Boolean get() = getPrefBoolean("showRss", true) val Context.threadCount: Int - get() = getPrefInt("threadCount", 6) \ No newline at end of file + get() = getPrefInt("threadCount", 16) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index d8bfae260..6770f7db7 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -12,6 +12,7 @@ import io.legado.app.constant.Bus import io.legado.app.help.BookHelp import io.legado.app.help.IntentHelp import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.threadCount import io.legado.app.model.WebBook import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO @@ -19,7 +20,8 @@ import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors class DownloadService : BaseService() { - private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher() + private var searchPool = + Executors.newFixedThreadPool(App.INSTANCE.threadCount).asCoroutineDispatcher() private var tasks: ArrayList> = arrayListOf() private val handler = Handler() private var runnable: Runnable = Runnable { upDownload() } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 1a695cccd..00148a7fd 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -7,6 +7,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchKeyword import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.threadCount import io.legado.app.model.WebBook import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefString @@ -16,7 +17,8 @@ import kotlinx.coroutines.launch import java.util.concurrent.Executors class SearchViewModel(application: Application) : BaseViewModel(application) { - private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher() + private var searchPool = + Executors.newFixedThreadPool(context.threadCount).asCoroutineDispatcher() private var task: Coroutine<*>? = null var callBack: CallBack? = null var searchKey: String = "" diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 2a81ae398..81dfcebe9 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchBook import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.threadCount import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -18,7 +19,8 @@ import org.jetbrains.anko.debug import java.util.concurrent.Executors class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { - private var searchPool = Executors.newFixedThreadPool(16).asCoroutineDispatcher() + private var searchPool = + Executors.newFixedThreadPool(context.threadCount).asCoroutineDispatcher() var callBack: CallBack? = null val searchStateData = MutableLiveData() var name: String = "" From 7b080b9f16886e44cd53a9cf579f28027554a89b Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 23 Jan 2020 12:43:11 +0800 Subject: [PATCH 138/852] up --- .../java/io/legado/app/lib/webdav/WebDav.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index 8cf806786..32b79ce79 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -23,13 +23,20 @@ class WebDav @Throws(MalformedURLException::class) constructor(urlStr: String) { companion object { // 指定返回哪些属性 - private const val DIR = "\n" + - "\n" + - "\n" + - "\n\n\n\n\n%s" + - "\n" + - "" + private const val DIR = + """ + + + + + + + + %s + + """ } + private val url: URL = URL(null, urlStr, Handler) private val httpUrl: String? by lazy { val raw = url.toString().replace("davs://", "https://").replace("dav://", "http://") From ecaac004324e7f60dfcafc97dd12124ed092fd25 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 23 Jan 2020 20:49:17 +0800 Subject: [PATCH 139/852] up --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../java/io/legado/app/help/PrefExtensions.kt | 5 +- .../app/ui/config/OtherConfigFragment.kt | 15 ++++- .../ui/widget/number/NumberPickerDialog.kt | 66 +++++++++++++++++++ .../main/res/layout/dialog_number_picker.xml | 24 +++++++ 5 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt create mode 100644 app/src/main/res/layout/dialog_number_picker.xml diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index b869927e6..1e6600a61 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -20,4 +20,5 @@ object PreferKey { const val readBookFont = "readBookFont" const val fontFolder = "fontFolder" const val backupPath = "backupUri" + const val threadCount = "threadCount" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/PrefExtensions.kt b/app/src/main/java/io/legado/app/help/PrefExtensions.kt index b9392ef7a..9a41707a1 100644 --- a/app/src/main/java/io/legado/app/help/PrefExtensions.kt +++ b/app/src/main/java/io/legado/app/help/PrefExtensions.kt @@ -1,12 +1,13 @@ package io.legado.app.help import android.content.Context +import io.legado.app.constant.PreferKey import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefInt val Context.isShowRSS: Boolean - get() = getPrefBoolean("showRss", true) + get() = getPrefBoolean(PreferKey.showRss, true) val Context.threadCount: Int - get() = getPrefInt("threadCount", 16) \ No newline at end of file + get() = getPrefInt(PreferKey.threadCount, 16) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 4795b56bb..47e837ffe 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -17,6 +17,7 @@ import io.legado.app.help.threadCount import io.legado.app.lib.theme.ATH import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.ui.filechooser.FileChooserDialog +import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.utils.* @@ -36,7 +37,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), putPrefBoolean("process_text", isProcessTextEnabled()) addPreferencesFromResource(R.xml.pref_config_other) bindPreferenceSummaryToValue(findPreference(PreferKey.downloadPath)) - bindPreferenceSummaryToValue(findPreference("threadCount")) + bindPreferenceSummaryToValue(findPreference(PreferKey.threadCount)) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -56,6 +57,14 @@ class OtherConfigFragment : PreferenceFragmentCompat(), override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { + PreferKey.threadCount -> NumberPickerDialog(requireContext()) + .setTitle(getString(R.string.threads_num_title)) + .setMaxValue(999) + .setMinValue(1) + .setValue(requireContext().threadCount) + .show { + requireContext().putPrefInt(PreferKey.threadCount, it) + } PreferKey.downloadPath -> FileChooserDialog.show( childFragmentManager, downloadPath, @@ -92,7 +101,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), // Set the summary to reflect the new value. preference.setSummary(if (index >= 0) preference.entries[index] else null) } - preference?.key == "threadCount" -> preference.summary = + preference?.key == PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, stringValue) else -> preference?.summary = stringValue } @@ -114,7 +123,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath - "threadCount" -> requireContext().threadCount + PreferKey.threadCount -> requireContext().threadCount else -> getPrefString(key) ?: "" } } diff --git a/app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt b/app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt new file mode 100644 index 000000000..17fe9ab53 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt @@ -0,0 +1,66 @@ +package io.legado.app.ui.widget.number + +import android.content.Context +import android.widget.NumberPicker +import androidx.appcompat.app.AlertDialog +import io.legado.app.R +import io.legado.app.utils.applyTint +import io.legado.app.utils.hideSoftInput +import kotlinx.android.synthetic.main.dialog_number_picker.* + + +class NumberPickerDialog(context: Context) { + private val builder = AlertDialog.Builder(context) + private var numberPicker: NumberPicker? = null + private var maxValue: Int? = null + private var minValue: Int? = null + private var value: Int? = null + + init { + builder.setView(R.layout.dialog_number_picker) + } + + fun setTitle(title: String): NumberPickerDialog { + builder.setTitle(title) + return this + } + + fun setMaxValue(value: Int): NumberPickerDialog { + maxValue = value + return this + } + + fun setMinValue(value: Int): NumberPickerDialog { + minValue = value + return this + } + + fun setValue(value: Int): NumberPickerDialog { + this.value = value + return this + } + + fun show(callBack: ((value: Int) -> Unit)?) { + builder.setPositiveButton(R.string.ok) { _, _ -> + numberPicker?.let { + it.clearFocus() + it.hideSoftInput() + callBack?.invoke(it.value) + } + } + builder.setNegativeButton(R.string.cancel, null) + val dialog = builder.show().applyTint() + numberPicker = dialog.number_picker + numberPicker?.let { np -> + minValue?.let { + np.minValue = it + } + maxValue?.let { + np.maxValue = it + } + value?.let { + np.value = it + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_number_picker.xml b/app/src/main/res/layout/dialog_number_picker.xml new file mode 100644 index 000000000..ea6582170 --- /dev/null +++ b/app/src/main/res/layout/dialog_number_picker.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + \ No newline at end of file From 82bf797996816bc9a9a1fd6d0f5c66bf3981ef29 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 23 Jan 2020 20:52:28 +0800 Subject: [PATCH 140/852] up --- .../main/java/io/legado/app/ui/config/OtherConfigFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 47e837ffe..2898f5f17 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -63,7 +63,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), .setMinValue(1) .setValue(requireContext().threadCount) .show { - requireContext().putPrefInt(PreferKey.threadCount, it) + putPrefInt(PreferKey.threadCount, it) } PreferKey.downloadPath -> FileChooserDialog.show( childFragmentManager, From 3e86f8be10f0b5fad7a8305dcf818905ccb1d3a0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 23 Jan 2020 21:11:10 +0800 Subject: [PATCH 141/852] up --- .../main/java/io/legado/app/ui/config/OtherConfigFragment.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 2898f5f17..07a5a641d 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -63,7 +63,9 @@ class OtherConfigFragment : PreferenceFragmentCompat(), .setMinValue(1) .setValue(requireContext().threadCount) .show { - putPrefInt(PreferKey.threadCount, it) + requireContext().putPrefInt(PreferKey.threadCount, it) + findPreference(PreferKey.threadCount)?.summary = + getString(R.string.threads_num, it.toString()) } PreferKey.downloadPath -> FileChooserDialog.show( childFragmentManager, From 947e8dda38a2adfb63aa34334bfaffd6fcdf5076 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 08:03:07 +0800 Subject: [PATCH 142/852] up --- app/src/main/assets/updateLog.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 171c3d744..aa75cb7eb 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,12 +3,15 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2020/01/11 +**2020/01/24** +* 添加线程数配置 + +**2020/01/11** * RSS阅读界面添加朗读功能 * 其它一些优化 * 合并KKL369提交的代码,重写LinearLayoutManager,修复书籍目录模糊搜索后scrollToPosition在可见范围不置顶 -**2020/01/10 +**2020/01/10** * 合并KKL369提交的代码 **2020/01/08** From f66b556a437c10b543342a384ced5a9631f596e7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 11:59:25 +0800 Subject: [PATCH 143/852] up --- .../java/io/legado/app/ui/about/AboutFragment.kt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index 08a5fa6a1..e48ef9354 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -8,6 +8,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R +import io.legado.app.utils.shareText import io.legado.app.utils.toast class AboutFragment : PreferenceFragmentCompat() { @@ -29,7 +30,10 @@ class AboutFragment : PreferenceFragmentCompat() { "mail" -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com") "git" -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url)) "home_page" -> openIntent(Intent.ACTION_VIEW, getString(R.string.home_page_url)) - "share_app" -> shareText("App Share",getString(R.string.app_share_description)) + "share_app" -> activity?.shareText( + "App Share", + getString(R.string.app_share_description) + ) } return super.onPreferenceTreeClick(preference) } @@ -44,14 +48,4 @@ class AboutFragment : PreferenceFragmentCompat() { } } - private fun shareText(title: String, text: String) { - try { - val textIntent = Intent(Intent.ACTION_SEND) - textIntent.type = "text/plain" - textIntent.putExtra(Intent.EXTRA_TEXT, text) - startActivity(Intent.createChooser(textIntent, title)) - } catch (e: Exception) { - toast(R.string.can_not_share) - } - } } \ No newline at end of file From 1a6f55bc15676e0c3f1a18e0a77204fd392d9d03 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 16:13:19 +0800 Subject: [PATCH 144/852] up --- .../java/io/legado/app/constant/PreferKey.kt | 1 - .../ui/main/bookshelf/BookshelfFragment.kt | 26 +++++++++++++------ .../ui/main/bookshelf/books/BooksFragment.kt | 2 -- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 1e6600a61..bc98f163b 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -14,7 +14,6 @@ object PreferKey { const val recordLog = "recordLog" const val processText = "process_text" const val cleanCache = "cleanCache" - const val lastGroup = "lastGroup" const val saveTabPosition = "saveTabPosition" const val pageAnim = "pageAnim" const val readBookFont = "readBookFont" diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 401685b55..86a209bad 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -15,7 +15,6 @@ import io.legado.app.base.VMBaseFragment import io.legado.app.constant.AppConst import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey -import io.legado.app.constant.PreferKey.saveTabPosition import io.legado.app.data.entities.BookGroup import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH @@ -26,11 +25,11 @@ import io.legado.app.utils.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* import kotlinx.android.synthetic.main.view_title_bar.* -import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.startActivity class BookshelfFragment : VMBaseFragment(R.layout.fragment_bookshelf), + TabLayout.OnTabSelectedListener, SearchView.OnQueryTextListener, GroupManageDialog.CallBack, BookshelfAdapter.CallBack { @@ -83,12 +82,6 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b view_pager_bookshelf.adapter = BookshelfAdapter(this, this) TabLayoutMediator(tab_layout, view_pager_bookshelf) { tab, position -> tab.text = bookGroups[position].groupName - tab.view?.onLongClick { - tab.select() - putPrefInt(saveTabPosition, position) - toast("该分组<" + bookGroups[position].groupName + ">已成为默认页。") - true - } }.attach() observeEvent(Bus.UP_TABS) { tab_layout.getTabAt(it)?.select() @@ -110,6 +103,9 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b } bookGroups.addAll(it) view_pager_bookshelf.adapter?.notifyDataSetChanged() + tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select() + tab_layout.removeOnTabSelectedListener(this) + tab_layout.addOnTabSelectedListener(this) } }) } @@ -146,4 +142,18 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b activity?.recreate() } } + + override fun onTabReselected(tab: TabLayout.Tab?) { + + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + + } + + override fun onTabSelected(tab: TabLayout.Tab?) { + tab?.position?.let { + putPrefInt(PreferKey.saveTabPosition, it) + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index bff9586ff..765c06697 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -24,7 +24,6 @@ import io.legado.app.ui.main.MainViewModel import io.legado.app.utils.getPrefInt import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.observeEvent -import io.legado.app.utils.postEvent import kotlinx.android.synthetic.main.fragment_books.* import org.jetbrains.anko.startActivity @@ -57,7 +56,6 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), observeEvent(Bus.UP_BOOK) { booksAdapter.notification(it) } - postEvent(Bus.UP_TABS, getPrefInt(PreferKey.saveTabPosition, 0)) } private fun initRecyclerView() { From bd7b136e8ed5c2f09b3dcc090d5be21a71e4aab9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 16:14:25 +0800 Subject: [PATCH 145/852] up --- .../java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 86a209bad..5b946d74d 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -93,6 +93,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b bookGroupLiveData = App.db.bookGroupDao().liveDataAll() bookGroupLiveData?.observe(viewLifecycleOwner, Observer { synchronized(this) { + tab_layout.removeOnTabSelectedListener(this) bookGroups.clear() bookGroups.add(AppConst.bookGroupAll) if (AppConst.bookGroupLocalShow) { @@ -104,7 +105,6 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b bookGroups.addAll(it) view_pager_bookshelf.adapter?.notifyDataSetChanged() tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select() - tab_layout.removeOnTabSelectedListener(this) tab_layout.addOnTabSelectedListener(this) } }) From f6bfea4308ecf9faea91d60b8f887b2cf9b7f7b8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 16:17:28 +0800 Subject: [PATCH 146/852] up --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index aa75cb7eb..ce1aeddf3 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/01/24** * 添加线程数配置 +* 记住退出时的书架 **2020/01/11** * RSS阅读界面添加朗读功能 From cbfd41748b56cedb33833ac450e8cd3a70ca9ef5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 16:41:49 +0800 Subject: [PATCH 147/852] up --- .../app/lib/theme/prefs/ATEColorPreference.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEColorPreference.kt b/app/src/main/java/io/legado/app/lib/theme/prefs/ATEColorPreference.kt index 517ba8d68..02b5d2f45 100644 --- a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEColorPreference.kt +++ b/app/src/main/java/io/legado/app/lib/theme/prefs/ATEColorPreference.kt @@ -18,8 +18,8 @@ import io.legado.app.lib.theme.ATH class ATEColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), ColorPickerDialogListener { - private val SIZE_NORMAL = 0 - private val SIZE_LARGE = 1 + private val sizeNormal = 0 + private val sizeLarge = 1 private var onShowDialogListener: OnShowDialogListener? = null private var color = Color.BLACK @@ -46,20 +46,18 @@ class ATEColorPreference(context: Context, attrs: AttributeSet) : Preference(con allowCustom = a.getBoolean(R.styleable.ColorPreference_cpv_allowCustom, true) showAlphaSlider = a.getBoolean(R.styleable.ColorPreference_cpv_showAlphaSlider, false) showColorShades = a.getBoolean(R.styleable.ColorPreference_cpv_showColorShades, true) - previewSize = a.getInt(R.styleable.ColorPreference_cpv_previewSize, SIZE_NORMAL) + previewSize = a.getInt(R.styleable.ColorPreference_cpv_previewSize, sizeNormal) val presetsResId = a.getResourceId(R.styleable.ColorPreference_cpv_colorPresets, 0) dialogTitle = a.getResourceId(R.styleable.ColorPreference_cpv_dialogTitle, R.string.cpv_default_title) - if (presetsResId != 0) { - presets = context.resources.getIntArray(presetsResId) + presets = if (presetsResId != 0) { + context.resources.getIntArray(presetsResId) } else { - presets = ColorPickerDialog.MATERIAL_COLORS + ColorPickerDialog.MATERIAL_COLORS } - if (colorShape == ColorShape.CIRCLE) { - widgetLayoutResource = - if (previewSize == SIZE_LARGE) R.layout.cpv_preference_circle_large else R.layout.cpv_preference_circle + widgetLayoutResource = if (colorShape == ColorShape.CIRCLE) { + if (previewSize == sizeLarge) R.layout.cpv_preference_circle_large else R.layout.cpv_preference_circle } else { - widgetLayoutResource = - if (previewSize == SIZE_LARGE) R.layout.cpv_preference_square_large else R.layout.cpv_preference_square + if (previewSize == sizeLarge) R.layout.cpv_preference_square_large else R.layout.cpv_preference_square } a.recycle() } From 7696e36286bdec6d978c5783033c1b3397001a8c Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 19:47:20 +0800 Subject: [PATCH 148/852] up --- .../app/lib/theme/prefs/ATEListPreference.kt | 22 +++++++++++++++++++ app/src/main/res/values/arrays.xml | 4 ++-- app/src/main/res/xml/pref_config_read.xml | 8 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/io/legado/app/lib/theme/prefs/ATEListPreference.kt diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/ATEListPreference.kt b/app/src/main/java/io/legado/app/lib/theme/prefs/ATEListPreference.kt new file mode 100644 index 000000000..3e81a1d1c --- /dev/null +++ b/app/src/main/java/io/legado/app/lib/theme/prefs/ATEListPreference.kt @@ -0,0 +1,22 @@ +package io.legado.app.lib.theme.prefs + +import android.content.Context +import android.util.AttributeSet +import android.widget.TextView +import androidx.preference.ListPreference +import androidx.preference.PreferenceViewHolder +import io.legado.app.R + + +class ATEListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { + + init { + widgetLayoutResource = R.layout.item_text + } + + override fun onBindViewHolder(holder: PreferenceViewHolder?) { + super.onBindViewHolder(holder) + val textView = holder?.itemView?.findViewById(R.id.text_view) + textView?.text = entry + } +} \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 7534dcab1..67bb70836 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -78,13 +78,13 @@ 常亮 - + 0 60 120 180 -1 - + @string/screen_unspecified diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index b24a16a71..2ab931c64 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -2,6 +2,14 @@ + + Date: Fri, 24 Jan 2020 19:56:06 +0800 Subject: [PATCH 149/852] up --- app/src/main/java/io/legado/app/ui/book/read/Help.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/Help.kt b/app/src/main/java/io/legado/app/ui/book/read/Help.kt index 33294b7e4..247349a60 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/Help.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/Help.kt @@ -70,6 +70,14 @@ object Help { return false } + fun keepScreenOn(window: Window, on: Boolean) { + if (on) { + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } else { + window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + } + /** * 适配刘海 */ @@ -81,4 +89,5 @@ object Help { } } } + } \ No newline at end of file From cc6db2733acf8bb98e903e0c738953e3322e47a3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 22:45:47 +0800 Subject: [PATCH 150/852] up --- .../app/ui/book/read/ReadBookActivity.kt | 46 +++++++++++++++---- .../io/legado/app/utils/ContextExtensions.kt | 11 +++++ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 3125f70d0..8bd8c8d0c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.net.Uri import android.os.AsyncTask.execute import android.os.Bundle +import android.os.Handler import android.text.SpannableStringBuilder import android.view.KeyEvent import android.view.Menu @@ -63,20 +64,26 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ChangeSourceDialog.CallBack, ReadBook.CallBack, ColorPickerDialogListener { + private val requestCodeChapterList = 568 + private val requestCodeEditSource = 111 + private val requestCodeReplace = 31242 + override val viewModel: ReadBookViewModel get() = getViewModel(ReadBookViewModel::class.java) override val isInitFinish: Boolean get() = viewModel.isInitFinish - private val requestCodeChapterList = 568 - private val requestCodeEditSource = 111 - private val requestCodeReplace = 31242 + private val mHandler = Handler() + private val keepScreenRunnable: Runnable = Runnable { Help.keepScreenOn(window, false) } + + private var screenTimeOut: Long = 0 private var timeElectricityReceiver: TimeElectricityReceiver? = null override fun onActivityCreated(savedInstanceState: Bundle?) { Help.upLayoutInDisplayCutoutMode(window) initView() + upScreenTimeOut() ReadBook.callBack = this ReadBook.titleDate.observe(this, Observer { title_bar.title = it }) viewModel.initData(intent) @@ -179,11 +186,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo }.show().applyTint() } R.id.menu_add_bookmark -> { - val book = ReadBook.book + val book = ReadBook.book ?: return true val textChapter = ReadBook.curTextChapter alert(title = getString(R.string.bookmark_add)) { var editText: EditText? = null - message = book?.name + " • " + textChapter?.title + message = book.name + " • " + textChapter?.title customView { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { @@ -195,9 +202,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo editText?.text?.toString()?.let { editContent -> execute { val bookmark = Bookmark( - book!!.durChapterTime, - book!!.bookUrl, - book!!.name, + book.durChapterTime, + book.bookUrl, + book.name, ReadBook.durChapterIndex, ReadBook.durPageIndex, textChapter!!.title, @@ -548,4 +555,27 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } + private fun upScreenTimeOut() { + getPrefString("keep_light")?.let { + screenTimeOut = it.toLong() * 1000 + } + } + + /** + * 重置黑屏时间 + */ + fun screenOffTimerStart() { + if (screenTimeOut < 0) { + Help.keepScreenOn(window, true) + return + } + val t = screenTimeOut - getScreenOffTime() + if (t > 0) { + mHandler.removeCallbacks(keepScreenRunnable) + Help.keepScreenOn(window, true) + mHandler.postDelayed(keepScreenRunnable, screenTimeOut) + } else { + Help.keepScreenOn(window, false) + } + } } \ No newline at end of file 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 7f4be23c0..7b920dfa7 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.content.res.ColorStateList import android.graphics.Bitmap import android.graphics.drawable.Drawable +import android.provider.Settings import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat @@ -63,6 +64,16 @@ fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.g fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = ContextCompat.getColorStateList(this, id) +fun Context.getScreenOffTime(): Int { + var screenOffTime = 0 + try { + screenOffTime = Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT) + } catch (e: Exception) { + e.printStackTrace() + } + return screenOffTime +} + fun Context.getStatusBarHeight(): Int { val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") return resources.getDimensionPixelSize(resourceId) From bebce7d7a23fc73db17413034aff3152d62a0096 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 23:01:03 +0800 Subject: [PATCH 151/852] up --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 + .../java/io/legado/app/ui/book/read/ReadBookActivity.kt | 8 ++++++-- .../io/legado/app/ui/book/read/config/MoreConfigDialog.kt | 1 + .../main/java/io/legado/app/ui/book/read/page/PageView.kt | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index bc98f163b..80efd5925 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -20,4 +20,5 @@ object PreferKey { const val fontFolder = "fontFolder" const val backupPath = "backupUri" const val threadCount = "threadCount" + const val keepLight = "keep_light" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 8bd8c8d0c..d74ea4be4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -553,18 +553,22 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo observeEvent(Bus.REPLACE) { ReplaceEditDialog().show(supportFragmentManager, "replaceEditDialog") } + observeEvent(PreferKey.keepLight) { + upScreenTimeOut() + } } private fun upScreenTimeOut() { - getPrefString("keep_light")?.let { + getPrefString(PreferKey.keepLight)?.let { screenTimeOut = it.toLong() * 1000 } + screenOffTimerStart() } /** * 重置黑屏时间 */ - fun screenOffTimerStart() { + override fun screenOffTimerStart() { if (screenTimeOut < 0) { Help.keepScreenOn(window, true) return diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 899d58d63..0eac917a1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -95,6 +95,7 @@ class MoreConfigDialog : DialogFragment() { PreferKey.hideStatusBar -> postEvent(Bus.UP_CONFIG, true) PreferKey.hideNavigationBar -> postEvent(Bus.UP_CONFIG, true) PreferKey.clickAllNext -> postEvent(Bus.UP_CONFIG, true) + PreferKey.keepLight -> postEvent(PreferKey.keepLight, true) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 84dafcaa6..5a57dbdd6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -65,6 +65,7 @@ class PageView(context: Context, attrs: AttributeSet) : @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent): Boolean { + callBack?.screenOffTimerStart() return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event) } @@ -241,5 +242,7 @@ class PageView(context: Context, attrs: AttributeSet) : fun clickCenter() val isInitFinish: Boolean + + fun screenOffTimerStart() } } From 14515c52b17becbe8008da816ef9edf57c65bc0a Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 23:02:09 +0800 Subject: [PATCH 152/852] up --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index ce1aeddf3..bbb213365 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ **2020/01/24** * 添加线程数配置 * 记住退出时的书架 +* 添加屏幕超时配置 **2020/01/11** * RSS阅读界面添加朗读功能 From d40cc7691fba056f6eb850c6d1cc49010d36be0f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 24 Jan 2020 23:16:54 +0800 Subject: [PATCH 153/852] up --- app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt | 2 +- .../io/legado/app/ui/book/read/page/delegate/PageDelegate.kt | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 5a57dbdd6..02c8e409b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -119,7 +119,7 @@ class PageView(context: Context, attrs: AttributeSet) : prevPage?.scrollToBottom() } } - pageDelegate?.onPageUp() + callBack?.screenOffTimerStart() } fun moveToPrevPage(noAnim: Boolean = true) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index db1250c3d..e5ccf1b65 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -215,9 +215,6 @@ abstract class PageDelegate(protected val pageView: PageView) { open fun onScroll() {//移动contentView, slidePage } - open fun onPageUp() { - } - abstract fun onScroll( e1: MotionEvent, e2: MotionEvent, From 95e6537fefb3f0cd46c1d6dfa4987548199edf7b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 09:32:19 +0800 Subject: [PATCH 154/852] up --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 4 +++- .../main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index d74ea4be4..a8f2c484a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -479,7 +479,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo requestCodeEditSource -> viewModel.upBookSource() requestCodeChapterList -> data?.getIntExtra("index", ReadBook.durChapterIndex)?.let { index -> - viewModel.openChapter(index, data?.getIntExtra("pageIndex", ReadBook.durPageIndex)) + if (index != ReadBook.durChapterIndex) { + viewModel.openChapter(index) + } } requestCodeReplace -> ReadBook.loadContent() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 959068a8a..9b987e505 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -154,7 +154,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } - fun openChapter(index: Int, pageIndex: Int) { + fun openChapter(index: Int, pageIndex: Int = 0) { ReadBook.prevTextChapter = null ReadBook.curTextChapter = null ReadBook.nextTextChapter = null From 5bef28267eb2d42627dd50d9e2c5693798350d3a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 09:35:10 +0800 Subject: [PATCH 155/852] up --- .../main/java/io/legado/app/ui/book/read/ReadBookActivity.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index a8f2c484a..9045305b5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -502,6 +502,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } ?: super.finish() } + override fun onDestroy() { + super.onDestroy() + mHandler.removeCallbacks(keepScreenRunnable) + } + override fun observeLiveBus() { super.observeLiveBus() observeEvent(Bus.ALOUD_STATE) { From f2b5b95cc91f7986763074fd56b9a20b669e2f8f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 09:59:46 +0800 Subject: [PATCH 156/852] up --- .../legado/app/ui/book/info/BookInfoActivity.kt | 16 +++++++++++++--- .../legado/app/ui/book/read/ReadBookActivity.kt | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index c55c1812c..220328ab3 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -32,6 +32,7 @@ import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_book_info.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity +import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -41,6 +42,9 @@ class BookInfoActivity : ChapterListAdapter.CallBack, ChangeSourceDialog.CallBack { + private val requestCodeChapterList = 568 + private val requestCodeSourceEdit = 562 + override val viewModel: BookInfoViewModel get() = getViewModel(BookInfoViewModel::class.java) @@ -70,7 +74,10 @@ class BookInfoActivity : R.id.menu_edit -> { if (viewModel.inBookshelf) { viewModel.bookData.value?.let { - startActivity(Pair("bookUrl", it.bookUrl)) + startActivityForResult( + requestCodeSourceEdit, + Pair("bookUrl", it.bookUrl) + ) } } else { toast(R.string.after_add_bookshelf) @@ -284,8 +291,11 @@ class BookInfoActivity : override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) - if (resultCode == Activity.RESULT_OK) { - viewModel.initData(intent) + when (requestCode) { + requestCodeSourceEdit -> if (resultCode == Activity.RESULT_OK) { + viewModel.initData(intent) + } + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 9045305b5..7437c3cae 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -66,7 +66,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ColorPickerDialogListener { private val requestCodeChapterList = 568 private val requestCodeEditSource = 111 - private val requestCodeReplace = 31242 + private val requestCodeReplace = 312 override val viewModel: ReadBookViewModel get() = getViewModel(ReadBookViewModel::class.java) From 791ff1dff9ec2b4cef559a63cbd94474de47ed94 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 10:06:07 +0800 Subject: [PATCH 157/852] up --- .../java/io/legado/app/ui/book/info/BookInfoActivity.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 220328ab3..98128c2f2 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -221,7 +221,8 @@ class BookInfoActivity : return@onClick } viewModel.bookData.value?.let { - startActivity( + startActivityForResult( + requestCodeChapterList, Pair("bookUrl", it.bookUrl) ) } @@ -295,7 +296,11 @@ class BookInfoActivity : requestCodeSourceEdit -> if (resultCode == Activity.RESULT_OK) { viewModel.initData(intent) } - + requestCodeChapterList -> if (resultCode == Activity.RESULT_OK) { + viewModel.bookData.value?.let { + readBook(it) + } + } } } } \ No newline at end of file From 03c58f35f7643c21e59bc9e604309db10c724dba Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 10:49:58 +0800 Subject: [PATCH 158/852] up --- .../java/io/legado/app/ui/chapterlist/ChapterListFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 22092493a..2ead9c56d 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -53,6 +53,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme viewModel.bookUrl?.let { bookUrl -> App.db.bookChapterDao().observeByBook(bookUrl).observe(viewLifecycleOwner, Observer { adapter.setItems(it) + if (it.isEmpty()) return@Observer viewModel.book?.let { book -> durChapterIndex = book.durChapterIndex tv_current_chapter_info.text = it[durChapterIndex()].title From cb7bad6c0faee6136162de97c1583b4c6b5cacbb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 11:06:44 +0800 Subject: [PATCH 159/852] up --- .../java/io/legado/app/ui/book/info/BookInfoActivity.kt | 8 +++++++- .../java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 98128c2f2..e637d3eb5 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -298,7 +298,13 @@ class BookInfoActivity : } requestCodeChapterList -> if (resultCode == Activity.RESULT_OK) { viewModel.bookData.value?.let { - readBook(it) + data?.getIntExtra("index", it.durChapterIndex)?.let { index -> + if (it.durChapterIndex != index) { + it.durChapterIndex = index + it.durChapterPos = 0 + } + readBook(it) + } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index bace352ff..d7d7b0ab1 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -14,7 +14,6 @@ import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers.IO class BookInfoViewModel(application: Application) : BaseViewModel(application) { - val bookData = MutableLiveData() val chapterListData = MutableLiveData>() val isLoadingData = MutableLiveData() From c8d0109008424d1a76febd30d1fb25ebe75df265 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 11:56:03 +0800 Subject: [PATCH 160/852] up --- .../app/ui/book/info/BookInfoActivity.kt | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index e637d3eb5..117440ad7 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -217,14 +217,11 @@ class BookInfoActivity : } tv_toc.onClick { if (!viewModel.inBookshelf) { - toast(R.string.after_add_bookshelf) - return@onClick - } - viewModel.bookData.value?.let { - startActivityForResult( - requestCodeChapterList, - Pair("bookUrl", it.bookUrl) - ) + viewModel.saveBook { + openChapterList() + } + } else { + openChapterList() } } tv_group.onClick { @@ -232,6 +229,15 @@ class BookInfoActivity : } } + private fun openChapterList() { + viewModel.bookData.value?.let { + startActivityForResult( + requestCodeChapterList, + Pair("bookUrl", it.bookUrl) + ) + } + } + private fun readBook(book: Book) { if (!viewModel.inBookshelf) { viewModel.saveBook { @@ -306,6 +312,10 @@ class BookInfoActivity : readBook(it) } } + } else { + if (!viewModel.inBookshelf) { + viewModel.delBook {} + } } } } From 161eb12c32b1e723da92349ac67d33b5742270c8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 11:56:35 +0800 Subject: [PATCH 161/852] up --- .../main/java/io/legado/app/ui/book/info/BookInfoActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 117440ad7..8bec337a6 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -314,7 +314,7 @@ class BookInfoActivity : } } else { if (!viewModel.inBookshelf) { - viewModel.delBook {} + viewModel.delBook(null) } } } From c3764ed42adad41ee5c94014fb5585a3d4a9e339 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 12:07:33 +0800 Subject: [PATCH 162/852] up --- .../main/java/io/legado/app/ui/book/info/BookInfoActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 8bec337a6..b688a19d9 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -218,7 +218,9 @@ class BookInfoActivity : tv_toc.onClick { if (!viewModel.inBookshelf) { viewModel.saveBook { - openChapterList() + viewModel.saveChapterList { + openChapterList() + } } } else { openChapterList() From bd5785f1d01a5e952a31cd9dbf678f226da31bac Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 12:55:35 +0800 Subject: [PATCH 163/852] up --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index bbb213365..9738aa157 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/25** +* 修复bug +* 未加入书架可查看目录 + **2020/01/24** * 添加线程数配置 * 记住退出时的书架 From d6d558a2adfa8f182b92df3d4479f6fbc792f47d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 17:45:22 +0800 Subject: [PATCH 164/852] up --- .../main/java/io/legado/app/ui/book/info/BookInfoActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index b688a19d9..fb689519c 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -311,7 +311,7 @@ class BookInfoActivity : it.durChapterIndex = index it.durChapterPos = 0 } - readBook(it) + startReadActivity(it) } } } else { From b7023fd4f8c9c8042a25fe95f45e6433ca4847b0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 19:48:07 +0800 Subject: [PATCH 165/852] up --- .../io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 5b946d74d..54d7e71d4 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -37,6 +37,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b override val viewModel: BookshelfViewModel get() = getViewModel(BookshelfViewModel::class.java) + lateinit var bookshelfAdapter: BookshelfAdapter private var bookGroupLiveData: LiveData>? = null private val bookGroups = mutableListOf() @@ -79,7 +80,8 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b tab_layout.tabMode = TabLayout.MODE_SCROLLABLE tab_layout.setSelectedTabIndicatorColor(requireContext().accentColor) ATH.applyEdgeEffectColor(view_pager_bookshelf) - view_pager_bookshelf.adapter = BookshelfAdapter(this, this) + bookshelfAdapter = BookshelfAdapter(this, this) + view_pager_bookshelf.adapter = bookshelfAdapter TabLayoutMediator(tab_layout, view_pager_bookshelf) { tab, position -> tab.text = bookGroups[position].groupName }.attach() @@ -103,7 +105,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b bookGroups.add(AppConst.bookGroupAudio) } bookGroups.addAll(it) - view_pager_bookshelf.adapter?.notifyDataSetChanged() + bookshelfAdapter.notifyDataSetChanged() tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select() tab_layout.addOnTabSelectedListener(this) } From 0183a9f4373c05b62dd2436588dae050c312fec2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 20:15:20 +0800 Subject: [PATCH 166/852] up --- .../java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt | 2 +- .../io/legado/app/ui/main/bookshelf/books/BooksFragment.kt | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt index d3ba217a0..4caa119cd 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt @@ -15,7 +15,7 @@ class BookshelfAdapter(fragment: Fragment, val callBack: CallBack) : override fun createFragment(position: Int): Fragment { val groupId = callBack.getGroup(position).groupId - return BooksFragment.newInstance(groupId) + return BooksFragment.newInstance(position, groupId) } interface CallBack { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 765c06697..9c0e935ab 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -32,10 +32,11 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), BooksAdapter.CallBack { companion object { - fun newInstance(position: Int): BooksFragment { + fun newInstance(position: Int, groupId: Int): BooksFragment { return BooksFragment().apply { val bundle = Bundle() - bundle.putInt("groupId", position) + bundle.putInt("position", position) + bundle.putInt("groupId", groupId) arguments = bundle } } From db36dbb8a0599cdfed93b0f074215d1f7a134f79 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 20:17:49 +0800 Subject: [PATCH 167/852] up --- .../java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 9c0e935ab..0ee866fde 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -45,11 +45,13 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), private lateinit var activityViewModel: MainViewModel private lateinit var booksAdapter: BooksAdapter private var bookshelfLiveData: LiveData>? = null + private var position = 0 private var groupId = -1 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { activityViewModel = getViewModelOfActivity(MainViewModel::class.java) arguments?.let { + position = it.getInt("position", 0) groupId = it.getInt("groupId", -1) } initRecyclerView() From 3fb4c256ada39199721bc2f61619fb863f46b60e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 21:39:28 +0800 Subject: [PATCH 168/852] up --- .../main/java/io/legado/app/help/ItemTouchCallback.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt b/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt index 9cf1fccf5..5454b6e56 100644 --- a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt +++ b/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt @@ -88,16 +88,13 @@ class ItemTouchCallback : ItemTouchHelper.Callback() { srcViewHolder: RecyclerView.ViewHolder, targetViewHolder: RecyclerView.ViewHolder ): Boolean { - onItemTouchCallbackListener?.let { - return it.onMove(srcViewHolder.adapterPosition, targetViewHolder.adapterPosition) - } - return false + return onItemTouchCallbackListener + ?.onMove(srcViewHolder.adapterPosition, targetViewHolder.adapterPosition) + ?: false } override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { - onItemTouchCallbackListener?.let { - return it.onSwiped(viewHolder.adapterPosition) - } + onItemTouchCallbackListener?.onSwiped(viewHolder.adapterPosition) } override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { From c22953129d6a22278cc8c852b7cc996cbed1806c Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 25 Jan 2020 22:21:46 +0800 Subject: [PATCH 169/852] up --- app/src/main/res/layout/item_rss_article.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/layout/item_rss_article.xml b/app/src/main/res/layout/item_rss_article.xml index f67f4d694..df31c7d70 100644 --- a/app/src/main/res/layout/item_rss_article.xml +++ b/app/src/main/res/layout/item_rss_article.xml @@ -10,6 +10,8 @@ android:id="@+id/tv_title" android:layout_width="0dp" android:layout_height="0dp" + android:maxLines="2" + android:ellipsize="end" android:text="@string/app_name" android:textColor="@color/tv_text_default" android:textSize="16sp" From bbc6067a8fd27975418eb71f271fc9021ee1c2be Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 26 Jan 2020 11:28:36 +0800 Subject: [PATCH 170/852] up --- .../ui/main/bookshelf/GroupManageDialog.kt | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt index 0d432e437..1022f4ed9 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt @@ -12,10 +12,7 @@ import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.ItemTouchHelper -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.* import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -79,7 +76,10 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { ) recycler_view.adapter = adapter App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { - adapter.setItems(it) + val diffResult = + DiffUtil.calculateDiff(GroupDiffCallBack(adapter.getItems(), it)) + adapter.setItems(it, false) + diffResult.dispatchUpdatesTo(adapter) }) val itemTouchCallback = ItemTouchCallback() itemTouchCallback.onItemTouchCallbackListener = adapter @@ -145,6 +145,34 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { }.show().applyTint().requestInputMethod() } + private class GroupDiffCallBack( + private val oldItems: List, + private val newItems: List + ) : + DiffUtil.Callback() { + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + return oldItem.groupId == newItem.groupId + } + + override fun getOldListSize(): Int { + return oldItems.size + } + + override fun getNewListSize(): Int { + return newItems.size + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + return oldItem.groupName == newItem.groupName + && oldItem.order == newItem.order + } + + } + private inner class GroupAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_group_manage), ItemTouchCallback.OnItemTouchCallbackListener { From d7dba0618dc17e7cb0cf47af1cb860ca18339678 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 26 Jan 2020 11:37:15 +0800 Subject: [PATCH 171/852] up --- app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index c48bd6e6b..b06e7ac9e 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -16,6 +16,9 @@ interface BookGroupDao { @get:Query("SELECT MAX(groupId) FROM book_groups") val maxId: Int + @get:Query("SELECT MAX(`order`) FROM book_groups") + val maxOrder: Int + @Query("SELECT * FROM book_groups ORDER BY `order`") fun all(): List diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 83d3c41a5..536329915 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -10,11 +10,10 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun addGroup(groupName: String) { execute { - val maxId = App.db.bookGroupDao().maxId val bookGroup = BookGroup( - groupId = maxId.plus(1), + groupId = App.db.bookGroupDao().maxId.plus(1), groupName = groupName, - order = maxId.plus(1) + order = App.db.bookGroupDao().maxOrder.plus(1) ) App.db.bookGroupDao().insert(bookGroup) } From 3b3c3961c379ad93a1f617ceafd740967be87723 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 26 Jan 2020 11:37:44 +0800 Subject: [PATCH 172/852] up --- app/src/main/assets/updateLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 9738aa157..3302fbfff 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,7 +3,7 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2020/01/25** +**2020/01/26** * 修复bug * 未加入书架可查看目录 From 890e1b465d0815c2d00d2a45042db5f59a6d18a9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 26 Jan 2020 14:03:28 +0800 Subject: [PATCH 173/852] up --- .../java/io/legado/app/ui/rss/read/ReadRssViewModel.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 5af6841e9..03264c236 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -85,17 +85,11 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } fun clHtml(content: String): String { - return if (content.contains("$content - """ - } + $content""" } override fun onInit(status: Int) { From 94bfc9a4d32039e1681b6a141d5d04b95016862f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 26 Jan 2020 14:10:19 +0800 Subject: [PATCH 174/852] up --- .../java/io/legado/app/ui/rss/read/ReadRssViewModel.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 03264c236..36a487a6c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -86,10 +86,11 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), fun clHtml(content: String): String { return """$content""" + + $content""" } override fun onInit(status: Int) { From 23a35bb42af989d333ffbe0d657c03a0ae156e6f Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 10:56:58 +0800 Subject: [PATCH 175/852] up --- app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index a8ca32fdd..894bed7a9 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -149,7 +149,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r webView.settings.javaScriptEnabled = true webView.evaluateJavascript("document.documentElement.outerHTML") { val html = StringEscapeUtils.unescapeJson(it) - viewModel.readAloud(Jsoup.clean(html, Whitelist())) + viewModel.readAloud(Jsoup.clean(html, Whitelist.none())) } } } From 146386d78e089890bd04cb28d148216d158b80d3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 11:07:41 +0800 Subject: [PATCH 176/852] up --- app/src/main/java/io/legado/app/App.kt | 2 +- app/src/main/java/io/legado/app/constant/Theme.kt | 2 +- app/src/main/java/io/legado/app/help/PrefExtensions.kt | 5 +++++ app/src/main/java/io/legado/app/lib/theme/ATH.kt | 4 ++-- app/src/main/java/io/legado/app/ui/book/read/Help.kt | 2 +- .../main/java/io/legado/app/ui/book/read/ReadMenu.kt | 1 + .../main/java/io/legado/app/utils/ContextExtensions.kt | 10 +++++----- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index ee3e4f5f6..8565ceb9e 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -17,11 +17,11 @@ import io.legado.app.data.AppDatabase import io.legado.app.help.ActivityHelp import io.legado.app.help.CrashHandler import io.legado.app.help.ReadBookConfig +import io.legado.app.help.isNightTheme import io.legado.app.lib.theme.ThemeStore import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.utils.getCompatColor import io.legado.app.utils.getPrefInt -import io.legado.app.utils.isNightTheme @Suppress("DEPRECATION") class App : Application() { diff --git a/app/src/main/java/io/legado/app/constant/Theme.kt b/app/src/main/java/io/legado/app/constant/Theme.kt index 40467a688..975eaa802 100644 --- a/app/src/main/java/io/legado/app/constant/Theme.kt +++ b/app/src/main/java/io/legado/app/constant/Theme.kt @@ -1,7 +1,7 @@ package io.legado.app.constant import io.legado.app.App -import io.legado.app.utils.isNightTheme +import io.legado.app.help.isNightTheme enum class Theme { Dark, Light, Auto; diff --git a/app/src/main/java/io/legado/app/help/PrefExtensions.kt b/app/src/main/java/io/legado/app/help/PrefExtensions.kt index 9a41707a1..4b89939cc 100644 --- a/app/src/main/java/io/legado/app/help/PrefExtensions.kt +++ b/app/src/main/java/io/legado/app/help/PrefExtensions.kt @@ -5,6 +5,11 @@ import io.legado.app.constant.PreferKey import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefInt +val Context.isNightTheme: Boolean + get() = getPrefBoolean("isNightTheme") + +val Context.isTransparentStatusBar: Boolean + get() = getPrefBoolean("transparentStatusBar", true) val Context.isShowRSS: Boolean get() = getPrefBoolean(PreferKey.showRss, true) diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index 57c7c8403..91c7fcda2 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -16,9 +16,9 @@ import androidx.recyclerview.widget.RecyclerView import androidx.viewpager.widget.ViewPager import com.google.android.material.bottomnavigation.BottomNavigationView import io.legado.app.R +import io.legado.app.help.isNightTheme +import io.legado.app.help.isTransparentStatusBar import io.legado.app.utils.getCompatColor -import io.legado.app.utils.isNightTheme -import io.legado.app.utils.isTransparentStatusBar import kotlinx.android.synthetic.main.activity_main.view.* import org.jetbrains.anko.backgroundColor diff --git a/app/src/main/java/io/legado/app/ui/book/read/Help.kt b/app/src/main/java/io/legado/app/ui/book/read/Help.kt index 247349a60..9d1be9f0c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/Help.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/Help.kt @@ -10,10 +10,10 @@ import android.view.WindowManager import io.legado.app.App import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig +import io.legado.app.help.isTransparentStatusBar import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.isTransparentStatusBar object Help { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 19729f20b..972f89cb7 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -11,6 +11,7 @@ import androidx.core.view.isVisible import io.legado.app.App import io.legado.app.R import io.legado.app.constant.PreferKey +import io.legado.app.help.isNightTheme import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.buttonDisabledColor import io.legado.app.service.help.ReadBook 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 7b920dfa7..8d81ace88 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.content.res.ColorStateList +import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.drawable.Drawable import android.provider.Settings @@ -126,8 +127,7 @@ fun Context.shareWithQr(title: String, text: String) { } } -val Context.isNightTheme: Boolean - get() = getPrefBoolean("isNightTheme") - -val Context.isTransparentStatusBar: Boolean - get() = getPrefBoolean("transparentStatusBar", true) +fun Context.getDarkModeStatus(): Boolean { + val mode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + return mode == Configuration.UI_MODE_NIGHT_YES +} \ No newline at end of file From c88b750360680bd151abcbb11078caed95f4b1e5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 11:10:36 +0800 Subject: [PATCH 177/852] up --- app/src/main/java/io/legado/app/utils/ContextExtensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8d81ace88..d5fc85fdf 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -127,7 +127,7 @@ fun Context.shareWithQr(title: String, text: String) { } } -fun Context.getDarkModeStatus(): Boolean { +fun Context.sysIsDarkMode(): Boolean { val mode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK return mode == Configuration.UI_MODE_NIGHT_YES } \ No newline at end of file From df0b2e3ac38883da3a3fdfbd973a5255070484cb Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 11:40:31 +0800 Subject: [PATCH 178/852] up --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 1 + app/src/main/java/io/legado/app/help/PrefExtensions.kt | 5 ++++- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_config_theme.xml | 6 ++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 80efd5925..1cb5e2edc 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -21,4 +21,5 @@ object PreferKey { const val backupPath = "backupUri" const val threadCount = "threadCount" const val keepLight = "keep_light" + const val autoDarkMode = "autoDarkMode" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/PrefExtensions.kt b/app/src/main/java/io/legado/app/help/PrefExtensions.kt index 4b89939cc..4b8daf1e4 100644 --- a/app/src/main/java/io/legado/app/help/PrefExtensions.kt +++ b/app/src/main/java/io/legado/app/help/PrefExtensions.kt @@ -15,4 +15,7 @@ val Context.isShowRSS: Boolean get() = getPrefBoolean(PreferKey.showRss, true) val Context.threadCount: Int - get() = getPrefInt(PreferKey.threadCount, 16) \ No newline at end of file + get() = getPrefInt(PreferKey.threadCount, 16) + +val Context.autoDarkMode: Boolean + get() = getPrefBoolean(PreferKey.autoDarkMode, true) \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 12ceceb6d..1e352f8e4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -582,5 +582,7 @@ 文字太多,生成二维码失败 分享RSS源 分享书源 + 自动切换夜间模式 + 夜间模式跟随系统 diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index f9f3df963..853b2fb12 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -2,6 +2,12 @@ + Date: Mon, 27 Jan 2020 11:52:43 +0800 Subject: [PATCH 179/852] up --- app/src/main/java/io/legado/app/ui/README.md | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/README.md b/app/src/main/java/io/legado/app/ui/README.md index 18c04f014..a1a7a2313 100644 --- a/app/src/main/java/io/legado/app/ui/README.md +++ b/app/src/main/java/io/legado/app/ui/README.md @@ -1 +1,24 @@ -## 放置与界面有关的类 \ No newline at end of file +## 放置与界面有关的类 + +* about 关于界面 +* audio 音频播放界面 +* book\info 书籍信息查看 +* book\read 书籍阅读界面 +* book\search 搜索书籍界面 +* book\source 搜索书源界面 +* changecover 封面换源界面 +* changesource 换源界面 +* chapterlist 目录界面 +* config 配置界面 +* download 下载界面 +* explore 发现界面 +* filechooser 文件选择界面 +* importbook 书籍导入界面 +* main 主界面 +* qrcode 二维码扫描界面 +* replacerule 替换净化界面 +* rss\article 订阅条目界面 +* rss\read 订阅阅读界面 +* rss\source 订阅源界面 +* welcome 欢迎界面 +* widget 自定义插件 \ No newline at end of file From 81c6f449eb76ad1296436a13e1dceba8c4151208 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 19:32:00 +0800 Subject: [PATCH 180/852] up --- app/src/main/java/io/legado/app/App.kt | 12 +++--- .../main/java/io/legado/app/constant/Theme.kt | 5 +-- .../main/java/io/legado/app/help/AppConfig.kt | 41 +++++++++++++++++++ .../java/io/legado/app/help/PrefExtensions.kt | 21 ---------- .../java/io/legado/app/help/ReadBookConfig.kt | 14 +++---- .../main/java/io/legado/app/lib/theme/ATH.kt | 11 +++-- .../io/legado/app/service/DownloadService.kt | 4 +- .../java/io/legado/app/ui/book/read/Help.kt | 4 +- .../io/legado/app/ui/book/read/ReadMenu.kt | 6 +-- .../app/ui/book/search/SearchViewModel.kt | 4 +- .../ui/changesource/ChangeSourceViewModel.kt | 4 +- .../app/ui/config/OtherConfigFragment.kt | 6 +-- .../io/legado/app/ui/main/MainActivity.kt | 16 ++++---- 13 files changed, 83 insertions(+), 65 deletions(-) create mode 100644 app/src/main/java/io/legado/app/help/AppConfig.kt delete mode 100644 app/src/main/java/io/legado/app/help/PrefExtensions.kt diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 8565ceb9e..fed02381c 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -15,9 +15,9 @@ import io.legado.app.constant.AppConst.channelIdReadAloud import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.data.AppDatabase import io.legado.app.help.ActivityHelp +import io.legado.app.help.AppConfig import io.legado.app.help.CrashHandler import io.legado.app.help.ReadBookConfig -import io.legado.app.help.isNightTheme import io.legado.app.lib.theme.ThemeStore import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.utils.getCompatColor @@ -50,7 +50,7 @@ class App : Application() { } if (!ThemeStore.isConfigured(this, versionCode)) applyTheme() - initNightTheme() + initNightMode() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannelId() @@ -67,7 +67,7 @@ class App : Application() { * 更新主题 */ fun applyTheme() { - if (isNightTheme) { + if (AppConfig.isNightTheme) { ThemeStore.editTheme(this) .primaryColor( getPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color)) @@ -98,11 +98,11 @@ class App : Application() { fun applyDayNight() { ReadBookConfig.upBg() applyTheme() - initNightTheme() + initNightMode() } - private fun initNightTheme() { - val targetMode = if (isNightTheme) { + private fun initNightMode() { + val targetMode = if (AppConfig.isNightTheme) { AppCompatDelegate.MODE_NIGHT_YES } else { AppCompatDelegate.MODE_NIGHT_NO diff --git a/app/src/main/java/io/legado/app/constant/Theme.kt b/app/src/main/java/io/legado/app/constant/Theme.kt index 975eaa802..b8587997b 100644 --- a/app/src/main/java/io/legado/app/constant/Theme.kt +++ b/app/src/main/java/io/legado/app/constant/Theme.kt @@ -1,14 +1,13 @@ package io.legado.app.constant -import io.legado.app.App -import io.legado.app.help.isNightTheme +import io.legado.app.help.AppConfig enum class Theme { Dark, Light, Auto; companion object { fun getTheme(): Theme { - return if (App.INSTANCE.isNightTheme) { + return if (AppConfig.isNightTheme) { Dark } else Light } diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt new file mode 100644 index 000000000..8190cfd79 --- /dev/null +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -0,0 +1,41 @@ +package io.legado.app.help + +import io.legado.app.App +import io.legado.app.constant.PreferKey +import io.legado.app.utils.getPrefBoolean +import io.legado.app.utils.getPrefInt +import io.legado.app.utils.putPrefBoolean +import io.legado.app.utils.putPrefInt + +object AppConfig { + + var isNightTheme: Boolean + get() = App.INSTANCE.getPrefBoolean("isNightTheme") + set(value) { + App.INSTANCE.putPrefBoolean("isNightTheme", value) + } + + var isTransparentStatusBar: Boolean + get() = App.INSTANCE.getPrefBoolean("transparentStatusBar") + set(value) { + App.INSTANCE.putPrefBoolean("transparentStatusBar", value) + } + + var isShowRSS: Boolean + get() = App.INSTANCE.getPrefBoolean(PreferKey.showRss) + set(value) { + App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) + } + + var threadCount: Int + get() = App.INSTANCE.getPrefInt(PreferKey.threadCount) + set(value) { + App.INSTANCE.putPrefInt(PreferKey.threadCount, value) + } + + var autoDarkMode: Boolean + get() = App.INSTANCE.getPrefBoolean(PreferKey.autoDarkMode) + set(value) { + App.INSTANCE.putPrefBoolean(PreferKey.autoDarkMode, value) + } +} diff --git a/app/src/main/java/io/legado/app/help/PrefExtensions.kt b/app/src/main/java/io/legado/app/help/PrefExtensions.kt deleted file mode 100644 index 4b8daf1e4..000000000 --- a/app/src/main/java/io/legado/app/help/PrefExtensions.kt +++ /dev/null @@ -1,21 +0,0 @@ -package io.legado.app.help - -import android.content.Context -import io.legado.app.constant.PreferKey -import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getPrefInt - -val Context.isNightTheme: Boolean - get() = getPrefBoolean("isNightTheme") - -val Context.isTransparentStatusBar: Boolean - get() = getPrefBoolean("transparentStatusBar", true) - -val Context.isShowRSS: Boolean - get() = getPrefBoolean(PreferKey.showRss, true) - -val Context.threadCount: Int - get() = getPrefInt(PreferKey.threadCount, 16) - -val Context.autoDarkMode: Boolean - get() = getPrefBoolean(PreferKey.autoDarkMode, true) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 328433c3c..311093c13 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -111,7 +111,7 @@ object ReadBookConfig { var textSize: Int = 15 ) { fun setBg(bgType: Int, bg: String) { - if (App.INSTANCE.isNightTheme) { + if (AppConfig.isNightTheme) { bgTypeNight = bgType bgStrNight = bg } else { @@ -121,7 +121,7 @@ object ReadBookConfig { } fun setTextColor(color: Int) { - if (App.INSTANCE.isNightTheme) { + if (AppConfig.isNightTheme) { textColorNight = "#${color.hexString}" } else { textColor = "#${color.hexString}" @@ -129,7 +129,7 @@ object ReadBookConfig { } fun setStatusIconDark(isDark: Boolean) { - if (App.INSTANCE.isNightTheme) { + if (AppConfig.isNightTheme) { darkStatusIconNight = isDark } else { darkStatusIcon = isDark @@ -137,7 +137,7 @@ object ReadBookConfig { } fun statusIconDark(): Boolean { - return if (App.INSTANCE.isNightTheme) { + return if (AppConfig.isNightTheme) { darkStatusIconNight } else { darkStatusIcon @@ -145,17 +145,17 @@ object ReadBookConfig { } fun textColor(): Int { - return if (App.INSTANCE.isNightTheme) Color.parseColor(textColorNight) + return if (AppConfig.isNightTheme) Color.parseColor(textColorNight) else Color.parseColor(textColor) } fun bgStr(): String { - return if (App.INSTANCE.isNightTheme) bgStrNight + return if (AppConfig.isNightTheme) bgStrNight else bgStr } fun bgType(): Int { - return if (App.INSTANCE.isNightTheme) bgTypeNight + return if (AppConfig.isNightTheme) bgTypeNight else bgType } diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index 91c7fcda2..c625e1807 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -16,8 +16,7 @@ import androidx.recyclerview.widget.RecyclerView import androidx.viewpager.widget.ViewPager import com.google.android.material.bottomnavigation.BottomNavigationView import io.legado.app.R -import io.legado.app.help.isNightTheme -import io.legado.app.help.isTransparentStatusBar +import io.legado.app.help.AppConfig import io.legado.app.utils.getCompatColor import kotlinx.android.synthetic.main.activity_main.view.* import org.jetbrains.anko.backgroundColor @@ -37,7 +36,7 @@ object ATH { } fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) { - val isTransparentStatusBar = activity.isTransparentStatusBar + val isTransparentStatusBar = AppConfig.isTransparentStatusBar setStatusBarColor( activity, ThemeStore.statusBarColor(activity, isTransparentStatusBar), @@ -131,14 +130,14 @@ object ATH { fun setTint( view: View, @ColorInt color: Int, - isDark: Boolean = view.context.isNightTheme + isDark: Boolean = AppConfig.isNightTheme ) { TintHelper.setTintAuto(view, color, false, isDark) } fun setBackgroundTint( view: View, @ColorInt color: Int, - isDark: Boolean = view.context.isNightTheme + isDark: Boolean = AppConfig.isNightTheme ) { TintHelper.setTintAuto(view, color, true, isDark) } @@ -206,7 +205,7 @@ object ATH { .setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create() itemIconTintList = colorStateList itemTextColor = colorStateList - itemBackgroundResource = when(context.isNightTheme) { + itemBackgroundResource = when (AppConfig.isNightTheme) { true -> R.drawable.item_bg_dark false -> R.drawable.item_bg_light } diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 6770f7db7..9c2e7a2f3 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -9,10 +9,10 @@ import io.legado.app.base.BaseService import io.legado.app.constant.Action import io.legado.app.constant.AppConst import io.legado.app.constant.Bus +import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.IntentHelp import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.threadCount import io.legado.app.model.WebBook import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO @@ -21,7 +21,7 @@ import java.util.concurrent.Executors class DownloadService : BaseService() { private var searchPool = - Executors.newFixedThreadPool(App.INSTANCE.threadCount).asCoroutineDispatcher() + Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() private var tasks: ArrayList> = arrayListOf() private val handler = Handler() private var runnable: Runnable = Runnable { upDownload() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/Help.kt b/app/src/main/java/io/legado/app/ui/book/read/Help.kt index 9d1be9f0c..939377cb1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/Help.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/Help.kt @@ -9,8 +9,8 @@ import android.view.Window import android.view.WindowManager import io.legado.app.App import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.help.ReadBookConfig -import io.legado.app.help.isTransparentStatusBar import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.getPrefBoolean @@ -43,7 +43,7 @@ object Help { } else { ATH.setLightStatusBarAuto( activity, - ThemeStore.statusBarColor(activity, activity.isTransparentStatusBar) + ThemeStore.statusBarColor(activity, AppConfig.isTransparentStatusBar) ) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 972f89cb7..0583056cd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -11,7 +11,7 @@ import androidx.core.view.isVisible import io.legado.app.App import io.legado.app.R import io.legado.app.constant.PreferKey -import io.legado.app.help.isNightTheme +import io.legado.app.help.AppConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.buttonDisabledColor import io.legado.app.service.help.ReadBook @@ -42,7 +42,7 @@ class ReadMenu : FrameLayout { init { callBack = activity as? CallBack inflate(context, R.layout.view_read_menu, this) - if (context.isNightTheme) { + if (AppConfig.isNightTheme) { fabNightTheme.setImageResource(R.drawable.ic_daytime) } else { fabNightTheme.setImageResource(R.drawable.ic_brightness) @@ -145,7 +145,7 @@ class ReadMenu : FrameLayout { //夜间模式 fabNightTheme.onClick { - context.putPrefBoolean("isNightTheme", !context.isNightTheme) + context.putPrefBoolean("isNightTheme", !AppConfig.isNightTheme) App.INSTANCE.applyDayNight() } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 00148a7fd..125204062 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -6,8 +6,8 @@ import io.legado.app.base.BaseViewModel import io.legado.app.constant.PreferKey import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchKeyword +import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.threadCount import io.legado.app.model.WebBook import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefString @@ -18,7 +18,7 @@ import java.util.concurrent.Executors class SearchViewModel(application: Application) : BaseViewModel(application) { private var searchPool = - Executors.newFixedThreadPool(context.threadCount).asCoroutineDispatcher() + Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() private var task: Coroutine<*>? = null var callBack: CallBack? = null var searchKey: String = "" diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 81dfcebe9..3b16a4359 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -8,8 +8,8 @@ import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchBook +import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.threadCount import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -20,7 +20,7 @@ import java.util.concurrent.Executors class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { private var searchPool = - Executors.newFixedThreadPool(context.threadCount).asCoroutineDispatcher() + Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() var callBack: CallBack? = null val searchStateData = MutableLiveData() var name: String = "" diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 07a5a641d..2645002fe 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -12,8 +12,8 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp -import io.legado.app.help.threadCount import io.legado.app.lib.theme.ATH import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.ui.filechooser.FileChooserDialog @@ -61,7 +61,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), .setTitle(getString(R.string.threads_num_title)) .setMaxValue(999) .setMinValue(1) - .setValue(requireContext().threadCount) + .setValue(AppConfig.threadCount) .show { requireContext().putPrefInt(PreferKey.threadCount, it) findPreference(PreferKey.threadCount)?.summary = @@ -125,7 +125,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath - PreferKey.threadCount -> requireContext().threadCount + PreferKey.threadCount -> AppConfig.threadCount else -> getPrefString(key) ?: "" } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 0b47b24f6..bdaf72031 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -16,8 +16,8 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.isShowRSS import io.legado.app.help.storage.Backup import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService @@ -47,7 +47,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager) view_pager_main.addOnPageChangeListener(this) bottom_navigation_view.setOnNavigationItemSelectedListener(this) - bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = isShowRSS + bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS upVersion() } @@ -68,10 +68,10 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), fragmentList.add(RssFragment()) fragmentList.add(MyFragment()) } - if (isShowRSS && fragmentList.size < 4) { + if (AppConfig.isShowRSS && fragmentList.size < 4) { fragmentList.add(2, RssFragment()) } - if (!isShowRSS && fragmentList.size == 4) { + if (!AppConfig.isShowRSS && fragmentList.size == 4) { fragmentList.removeAt(2) } } @@ -89,7 +89,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), pagePosition = position when (position) { 0, 1, 3 -> bottom_navigation_view.menu.getItem(position).isChecked = true - 2 -> if (isShowRSS) { + 2 -> if (AppConfig.isShowRSS) { bottom_navigation_view.menu.getItem(position).isChecked = true } else { bottom_navigation_view.menu.getItem(3).isChecked = true @@ -147,10 +147,10 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), recreate() } observeEvent(Bus.SHOW_RSS) { - bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = isShowRSS + bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS upFragmentList() view_pager_main.adapter?.notifyDataSetChanged() - if (isShowRSS) { + if (AppConfig.isShowRSS) { view_pager_main.setCurrentItem(3, false) } } @@ -168,7 +168,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } override fun getCount(): Int { - return if (isShowRSS) 4 else 3 + return if (AppConfig.isShowRSS) 4 else 3 } } From c1d349f17633bfa321f82e462623cd54a0981477 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 19:40:44 +0800 Subject: [PATCH 181/852] up --- app/src/main/java/io/legado/app/App.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index fed02381c..2dc763432 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -22,6 +22,7 @@ import io.legado.app.lib.theme.ThemeStore import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.utils.getCompatColor import io.legado.app.utils.getPrefInt +import io.legado.app.utils.sysIsDarkMode @Suppress("DEPRECATION") class App : Application() { @@ -102,11 +103,18 @@ class App : Application() { } private fun initNightMode() { - val targetMode = if (AppConfig.isNightTheme) { - AppCompatDelegate.MODE_NIGHT_YES - } else { - AppCompatDelegate.MODE_NIGHT_NO - } + val targetMode = + if (AppConfig.autoDarkMode) { + if (sysIsDarkMode()) { + AppCompatDelegate.MODE_NIGHT_YES + } else { + AppCompatDelegate.MODE_NIGHT_NO + } + } else if (AppConfig.isNightTheme) { + AppCompatDelegate.MODE_NIGHT_YES + } else { + AppCompatDelegate.MODE_NIGHT_NO + } AppCompatDelegate.setDefaultNightMode(targetMode) } From 32d66a88a46cd991fb812120a332f14b1d72ccaa Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 19:45:52 +0800 Subject: [PATCH 182/852] up --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 3302fbfff..0aa0e4916 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/27** +* 添加根据系统主题切换夜间模式 + **2020/01/26** * 修复bug * 未加入书架可查看目录 From 7b10b267263a7600a523c8be711287dd244b2ab8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 20:29:04 +0800 Subject: [PATCH 183/852] Merge branch 'eink' of https://github.com/FadeApp/legado into FadeApp-eink # Conflicts: # app/src/main/java/io/legado/app/lib/theme/ATH.kt # app/src/main/java/io/legado/app/utils/ContextExtensions.kt --- app/build.gradle | 24 ++++++++++++------- .../main/java/io/legado/app/lib/theme/ATH.kt | 6 ++--- .../app/ui/config/ThemeConfigFragment.kt | 20 +++++++++++++++- app/src/main/res/values/strings.xml | 3 ++- app/src/main/res/xml/pref_main.xml | 6 +++++ 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7eac96051..cae1dac53 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,13 +20,15 @@ def gitCommits = Integer.parseInt('git rev-list --count HEAD'.execute([], projec android { compileSdkVersion 29 signingConfigs { - myConfig { - storeFile file(RELEASE_STORE_FILE) - storePassword RELEASE_STORE_PASSWORD - keyAlias RELEASE_KEY_ALIAS - keyPassword RELEASE_KEY_PASSWORD - v1SigningEnabled true - v2SigningEnabled true + if (project.hasProperty("RELEASE_STORE_FILE")) { + myConfig { + storeFile file(RELEASE_STORE_FILE) + storePassword RELEASE_STORE_PASSWORD + keyAlias RELEASE_KEY_ALIAS + keyPassword RELEASE_KEY_PASSWORD + v1SigningEnabled true + v2SigningEnabled true + } } } defaultConfig { @@ -49,12 +51,16 @@ android { } buildTypes { release { - signingConfig signingConfigs.myConfig + if (project.hasProperty("RELEASE_STORE_FILE")) { + signingConfig signingConfigs.myConfig + } minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debug { - signingConfig signingConfigs.myConfig + if (project.hasProperty("RELEASE_STORE_FILE")) { + signingConfig signingConfigs.myConfig + } applicationIdSuffix '.debug' versionNameSuffix 'debug' minifyEnabled false diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index c625e1807..1b17de91e 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -5,6 +5,7 @@ import android.app.Activity import android.app.ActivityManager import android.content.Context import android.graphics.Color +import android.graphics.drawable.ColorDrawable import android.os.Build import android.view.View import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR @@ -205,10 +206,7 @@ object ATH { .setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create() itemIconTintList = colorStateList itemTextColor = colorStateList - itemBackgroundResource = when (AppConfig.isNightTheme) { - true -> R.drawable.item_bg_dark - false -> R.drawable.item_bg_light - } + itemBackground = ColorDrawable(ThemeStore.primaryColor(bottomBar.context)) } } diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 6c87ff0af..477227214 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -20,7 +20,7 @@ import io.legado.app.utils.* class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener { - val items = arrayOf("极简","曜夜","经典") + val items = arrayOf("极简", "曜夜", "经典", "黑白", "A屏黑") override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config_theme) @@ -124,6 +124,24 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) putPrefBoolean("isNightTheme", false) } + 3 -> { + putPrefInt("colorPrimary", getCompatColor(R.color.white)) + putPrefInt("colorAccent", getCompatColor(R.color.black)) + putPrefInt("colorBackground", getCompatColor(R.color.white)) + putPrefBoolean("isNightTheme", false) + } + 4 -> { + putPrefInt("colorPrimaryNight", getCompatColor(R.color.black)) + putPrefInt( + "colorAccentNight", + getCompatColor(R.color.md_grey_600) + ) + putPrefInt( + "colorBackgroundNight", + getCompatColor(R.color.black) + ) + putPrefBoolean("isNightTheme", true) + } } App.INSTANCE.applyDayNight() recreateActivities() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e352f8e4..948cf5a47 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,7 +77,7 @@ 共%s个Text文件 加载中… 重试 - Web服务 + Web 服务 web编辑书源 http://%s:%d 离线下载 @@ -447,6 +447,7 @@ 切换显示样式 导入本地书籍需存储权限 夜间模式 + E-Ink 模式 本软件需要存储权限来存储备份书籍信息 再按一次退出程序 导入本地书籍需存储权限 diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml index 297298599..f59dff9f7 100644 --- a/app/src/main/res/xml/pref_main.xml +++ b/app/src/main/res/xml/pref_main.xml @@ -18,6 +18,12 @@ android:title="@string/night_theme" app:iconSpaceReserved="false" /> + + Date: Mon, 27 Jan 2020 20:35:37 +0800 Subject: [PATCH 184/852] Merge branch 'eink' of https://github.com/FadeApp/legado into FadeApp-eink # Conflicts: # app/src/main/java/io/legado/app/lib/theme/ATH.kt # app/src/main/java/io/legado/app/utils/ContextExtensions.kt --- app/src/main/java/io/legado/app/help/AppConfig.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 8190cfd79..afb9b88fd 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -38,4 +38,7 @@ object AppConfig { set(value) { App.INSTANCE.putPrefBoolean(PreferKey.autoDarkMode, value) } + + val isEInkMode: Boolean + get() = App.INSTANCE.getPrefBoolean("isEInkMode") } From f95c07cc3c0827b4c42c1a3e5c5947270e337985 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 20:39:11 +0800 Subject: [PATCH 185/852] Merge branch 'eink' of https://github.com/FadeApp/legado into FadeApp-eink # Conflicts: # app/src/main/java/io/legado/app/lib/theme/ATH.kt # app/src/main/java/io/legado/app/utils/ContextExtensions.kt --- app/src/main/res/xml/pref_config_theme.xml | 7 ------- app/src/main/res/xml/pref_main.xml | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 853b2fb12..4988e08bf 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -2,13 +2,6 @@ - - + + Date: Mon, 27 Jan 2020 20:45:31 +0800 Subject: [PATCH 186/852] =?UTF-8?q?=E8=BF=98=E6=98=AF=E6=84=9F=E8=A7=89?= =?UTF-8?q?=E5=8E=9F=E6=9D=A5=E9=A2=9C=E8=89=B2=E5=A5=BD=E7=9C=8B=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/lib/theme/ATH.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index 1b17de91e..c625e1807 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -5,7 +5,6 @@ import android.app.Activity import android.app.ActivityManager import android.content.Context import android.graphics.Color -import android.graphics.drawable.ColorDrawable import android.os.Build import android.view.View import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR @@ -206,7 +205,10 @@ object ATH { .setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create() itemIconTintList = colorStateList itemTextColor = colorStateList - itemBackground = ColorDrawable(ThemeStore.primaryColor(bottomBar.context)) + itemBackgroundResource = when (AppConfig.isNightTheme) { + true -> R.drawable.item_bg_dark + false -> R.drawable.item_bg_light + } } } From 0793f81385fee512da49bcec1fadb2343ebf0f87 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 27 Jan 2020 21:11:18 +0800 Subject: [PATCH 187/852] =?UTF-8?q?=E8=BF=98=E6=98=AF=E6=84=9F=E8=A7=89?= =?UTF-8?q?=E5=8E=9F=E6=9D=A5=E9=A2=9C=E8=89=B2=E5=A5=BD=E7=9C=8B=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/App.kt | 9 +-------- .../main/java/io/legado/app/help/AppConfig.kt | 19 +++++++++++++------ .../io/legado/app/ui/book/read/ReadMenu.kt | 2 +- .../app/ui/config/ThemeConfigFragment.kt | 13 +++++++------ .../io/legado/app/ui/main/my/MyFragment.kt | 2 +- .../io/legado/app/utils/FragmentExtensions.kt | 8 -------- app/src/main/res/values/arrays.xml | 12 ++++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_main.xml | 17 ++++++----------- 9 files changed, 42 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 2dc763432..64d6abf9d 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -22,7 +22,6 @@ import io.legado.app.lib.theme.ThemeStore import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.utils.getCompatColor import io.legado.app.utils.getPrefInt -import io.legado.app.utils.sysIsDarkMode @Suppress("DEPRECATION") class App : Application() { @@ -104,13 +103,7 @@ class App : Application() { private fun initNightMode() { val targetMode = - if (AppConfig.autoDarkMode) { - if (sysIsDarkMode()) { - AppCompatDelegate.MODE_NIGHT_YES - } else { - AppCompatDelegate.MODE_NIGHT_NO - } - } else if (AppConfig.isNightTheme) { + if (AppConfig.isNightTheme) { AppCompatDelegate.MODE_NIGHT_YES } else { AppCompatDelegate.MODE_NIGHT_NO diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index afb9b88fd..f51d7b479 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -2,17 +2,24 @@ package io.legado.app.help import io.legado.app.App import io.legado.app.constant.PreferKey -import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getPrefInt -import io.legado.app.utils.putPrefBoolean -import io.legado.app.utils.putPrefInt +import io.legado.app.utils.* object AppConfig { var isNightTheme: Boolean - get() = App.INSTANCE.getPrefBoolean("isNightTheme") + get() { + return when (App.INSTANCE.getPrefString("themeMode", "0")) { + "1" -> false + "2" -> true + else -> App.INSTANCE.sysIsDarkMode() + } + } set(value) { - App.INSTANCE.putPrefBoolean("isNightTheme", value) + if (value) { + App.INSTANCE.putPrefString("themeMode", "2") + } else { + App.INSTANCE.putPrefString("themeMode", "1") + } } var isTransparentStatusBar: Boolean diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 0583056cd..12bbb6d8b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -145,7 +145,7 @@ class ReadMenu : FrameLayout { //夜间模式 fabNightTheme.onClick { - context.putPrefBoolean("isNightTheme", !AppConfig.isNightTheme) + AppConfig.isNightTheme = !AppConfig.isNightTheme App.INSTANCE.applyDayNight() } diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 477227214..2ee2f6621 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -10,6 +10,7 @@ import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R import io.legado.app.constant.Bus +import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton @@ -110,25 +111,25 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar putPrefInt("colorPrimary", getCompatColor(R.color.md_grey_100)) putPrefInt("colorAccent", getCompatColor(R.color.lightBlue_color)) putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) - putPrefBoolean("isNightTheme", false) + AppConfig.isNightTheme = false } 1 -> { putPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color)) putPrefInt("colorAccentNight", getCompatColor(R.color.lightBlue_color)) putPrefInt("colorBackgroundNight", getCompatColor(R.color.shine_color)) - putPrefBoolean("isNightTheme", true) + AppConfig.isNightTheme = true } 2 -> { putPrefInt("colorPrimary", getCompatColor(R.color.md_light_blue_500)) putPrefInt("colorAccent", getCompatColor(R.color.md_pink_800)) putPrefInt("colorBackground", getCompatColor(R.color.md_grey_100)) - putPrefBoolean("isNightTheme", false) + AppConfig.isNightTheme = false } 3 -> { putPrefInt("colorPrimary", getCompatColor(R.color.white)) putPrefInt("colorAccent", getCompatColor(R.color.black)) putPrefInt("colorBackground", getCompatColor(R.color.white)) - putPrefBoolean("isNightTheme", false) + AppConfig.isNightTheme = false } 4 -> { putPrefInt("colorPrimaryNight", getCompatColor(R.color.black)) @@ -140,7 +141,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar "colorBackgroundNight", getCompatColor(R.color.black) ) - putPrefBoolean("isNightTheme", true) + AppConfig.isNightTheme = true } } App.INSTANCE.applyDayNight() @@ -172,7 +173,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar } private fun upTheme(isNightTheme: Boolean) { - if (this.isNightTheme == isNightTheme) { + if (AppConfig.isNightTheme == isNightTheme) { App.INSTANCE.applyTheme() recreateActivities() } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 6d79f55d4..d3ee247c7 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -200,7 +200,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { - "isNightTheme" -> App.INSTANCE.applyDayNight() + "themeMode" -> App.INSTANCE.applyDayNight() "webService" -> { if (requireContext().getPrefBoolean("webService")) { WebService.start(requireContext()) diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index f233929fb..b2379e89a 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -54,17 +54,9 @@ fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = requireContext fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id) -val Fragment.isNightTheme: Boolean - get() = getPrefBoolean("isNightTheme") - -val Fragment.isTransparentStatusBar: Boolean - get() = getPrefBoolean("transparentStatusBar") - - inline fun Fragment.startActivity(vararg params: Pair) = AnkoInternals.internalStartActivity(requireActivity(), T::class.java, params) - inline fun Fragment.startActivityForResult(requestCode: Int, vararg params: Pair) = startActivityForResult(AnkoInternals.createIntent(requireActivity(), T::class.java, params), requestCode) diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 67bb70836..b8cea9e3b 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -63,6 +63,18 @@ @string/jf_convert_f + + 跟随系统 + 亮色主题 + 暗色主题 + + + + 0 + 1 + 2 + + 自动 黑色 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 948cf5a47..43a0e6019 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -433,6 +433,7 @@ 扫描二维码 选中时点击可弹出菜单 主题 + 主题模式 默认主题 恢复主题为默认配色 加入QQ群 diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml index bd17ae2ee..29e66e13e 100644 --- a/app/src/main/res/xml/pref_main.xml +++ b/app/src/main/res/xml/pref_main.xml @@ -12,17 +12,12 @@ android:title="@string/replace_purify" app:iconSpaceReserved="false" /> - - - Date: Mon, 27 Jan 2020 21:13:34 +0800 Subject: [PATCH 188/852] =?UTF-8?q?=E8=BF=98=E6=98=AF=E6=84=9F=E8=A7=89?= =?UTF-8?q?=E5=8E=9F=E6=9D=A5=E9=A2=9C=E8=89=B2=E5=A5=BD=E7=9C=8B=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 0aa0e4916..80066583d 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/01/27** * 添加根据系统主题切换夜间模式 +* 合并Modificator提交的代码 **2020/01/26** * 修复bug From 851a5bcb31eff46629f81de902e935adc60322bd Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 11:25:28 +0800 Subject: [PATCH 189/852] =?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/utils/ZipUtils.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/ZipUtils.kt b/app/src/main/java/io/legado/app/utils/ZipUtils.kt index eab9951c7..44d547e5c 100644 --- a/app/src/main/java/io/legado/app/utils/ZipUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ZipUtils.kt @@ -57,7 +57,7 @@ object ZipUtils { } return true } finally { - if (zos != null) { + zos?.let { zos.finish() zos.close() } @@ -89,7 +89,7 @@ object ZipUtils { } return true } finally { - if (zos != null) { + zos?.let { zos.finish() zos.close() } @@ -261,7 +261,7 @@ object ZipUtils { val files = ArrayList() val zip = ZipFile(zipFile) val entries = zip.entries() - try { + zip.use { if (isSpace(keyword)) { while (entries.hasMoreElements()) { val entry = entries.nextElement() as ZipEntry @@ -285,8 +285,6 @@ object ZipUtils { } } } - } finally { - zip.close() } return files } From 660cedea6878a93101f6dcee69c65e85e7ea1552 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 11:26:28 +0800 Subject: [PATCH 190/852] =?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/utils/ViewExtensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index 81cdafe81..403f0d40c 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -24,7 +24,7 @@ private tailrec fun getCompatActivity(context: Context?): AppCompatActivity? { val View.activity: AppCompatActivity? get() = getCompatActivity(context) -inline fun View.hideSoftInput() = run { +fun View.hideSoftInput() = run { val imm = App.INSTANCE.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager imm?.let { imm.hideSoftInputFromWindow(this.windowToken, 0) From 93d4bba524f1121024d3ee06cebe1f5333e78185 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 11:30:20 +0800 Subject: [PATCH 191/852] =?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/utils/StringUtils.kt | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/StringUtils.kt b/app/src/main/java/io/legado/app/utils/StringUtils.kt index c9f80866f..6d70b244b 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -41,16 +41,18 @@ object StringUtils { //将时间转换成日期 fun dateConvert(time: Long, pattern: String): String { val date = Date(time) - @SuppressLint("SimpleDateFormat") val format = SimpleDateFormat(pattern) + @SuppressLint("SimpleDateFormat") + val format = SimpleDateFormat(pattern) return format.format(date) } //将日期转换成昨天、今天、明天 fun dateConvert(source: String, pattern: String): String { - @SuppressLint("SimpleDateFormat") val format = SimpleDateFormat(pattern) + @SuppressLint("SimpleDateFormat") + val format = SimpleDateFormat(pattern) val calendar = Calendar.getInstance() try { - val date = format.parse(source) + val date = format.parse(source) ?: return "" val curTime = calendar.timeInMillis calendar.time = date //将MISC 转换成 sec @@ -62,13 +64,18 @@ object StringUtils { //如果没有时间 if (oldHour == 0) { //比日期:昨天今天和明天 - if (difDate == 0L) { - return "今天" - } else if (difDate < DAY_OF_YESTERDAY) { - return "昨天" - } else { - @SuppressLint("SimpleDateFormat") val convertFormat = SimpleDateFormat("yyyy-MM-dd") - return convertFormat.format(date) + return when { + difDate == 0L -> { + "今天" + } + difDate < DAY_OF_YESTERDAY -> { + "昨天" + } + else -> { + @SuppressLint("SimpleDateFormat") + val convertFormat = SimpleDateFormat("yyyy-MM-dd") + convertFormat.format(date) + } } } @@ -78,7 +85,8 @@ object StringUtils { difHour < HOUR_OF_DAY -> difHour.toString() + "小时前" difDate < DAY_OF_YESTERDAY -> "昨天" else -> { - @SuppressLint("SimpleDateFormat") val convertFormat = SimpleDateFormat("yyyy-MM-dd") + @SuppressLint("SimpleDateFormat") + val convertFormat = SimpleDateFormat("yyyy-MM-dd") convertFormat.format(date) } } @@ -254,9 +262,9 @@ object StringUtils { "(?i)<(br[\\s/]*|/*p.*?|/*div.*?)>".toRegex(), "\n" )// 替换特定标签为换行符 - .replace("<[script>]*.*?>| ".toRegex(), "")// 删除script标签对和空格转义符 - .replace("\\s*\\n+\\s*".toRegex(), "\n  ")// 移除空行,并增加段前缩进2个汉字 - .replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字 - .replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行 + .replace("<[script>]*.*?>| ".toRegex(), "")// 删除script标签对和空格转义符 + .replace("\\s*\\n+\\s*".toRegex(), "\n  ")// 移除空行,并增加段前缩进2个汉字 + .replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字 + .replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行 } } From 25aba898bfef6bc75c2136587cdccb2a241fba15 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 11:39:06 +0800 Subject: [PATCH 192/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/utils/StringExtensions.kt | 63 ++++++++++--------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index 987a0fce8..19319d3ba 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -4,34 +4,41 @@ package io.legado.app.utils fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() -fun String?.isAbsUrl() = if (this.isNullOrBlank()) false else this.startsWith("http://", true) - || this.startsWith("https://", true) - -fun String?.isJson(): Boolean = this?.run { - val str = this.trim() - when { - str.startsWith("{") && str.endsWith("}") -> true - str.startsWith("[") && str.endsWith("]") -> true - else -> false - } -} ?: false - -fun String?.isJsonObject(): Boolean = this?.run { - val str = this.trim() - str.startsWith("{") && str.endsWith("}") -} ?: false - -fun String?.isJsonArray(): Boolean = this?.run { - val str = this.trim() - str.startsWith("[") && str.endsWith("]") -} ?: false - -fun String?.htmlFormat(): String = if (this.isNullOrBlank()) "" else - this.replace("(?i)<(br[\\s/]*|/*p\\b.*?|/*div\\b.*?)>".toRegex(), "\n")// 替换特定标签为换行符 - .replace("<[script>]*.*?>| ".toRegex(), "")// 删除script标签对和空格转义符 - .replace("\\s*\\n+\\s*".toRegex(), "\n  ")// 移除空行,并增加段前缩进2个汉字 - .replace("^[\\n\\s]+".toRegex(), "  ")//移除开头空行,并增加段前缩进2个汉字 - .replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行 +fun String?.isAbsUrl() = + this?.let { + it.startsWith("http://", true) + || it.startsWith("https://", true) + } ?: false + +fun String?.isJson(): Boolean = + this?.run { + val str = this.trim() + when { + str.startsWith("{") && str.endsWith("}") -> true + str.startsWith("[") && str.endsWith("]") -> true + else -> false + } + } ?: false + +fun String?.isJsonObject(): Boolean = + this?.run { + val str = this.trim() + str.startsWith("{") && str.endsWith("}") + } ?: false + +fun String?.isJsonArray(): Boolean = + this?.run { + val str = this.trim() + str.startsWith("[") && str.endsWith("]") + } ?: false + +fun String?.htmlFormat(): String = + this?.replace("(?i)<(br[\\s/]*|/*p\\b.*?|/*div\\b.*?)>".toRegex(), "\n") + ?.replace("<[script>]*.*?>| ".toRegex(), "") + ?.replace("\\s*\\n+\\s*".toRegex(), "\n  ") + ?.replace("^[\\n\\s]+".toRegex(), "  ") + ?.replace("[\\n\\s]+$".toRegex(), "") + ?: "" fun String.splitNotBlank(vararg delimiter: String): Array = run { this.split(*delimiter).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() From 722f71c93110885b4e34f46111b5408a87830aee Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 11:47:24 +0800 Subject: [PATCH 193/852] =?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/utils/ACache.kt | 10 +++++----- app/src/main/java/io/legado/app/utils/FileUtils.kt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/ACache.kt b/app/src/main/java/io/legado/app/utils/ACache.kt index 44f96631c..b173dc612 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -171,7 +171,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) * @return JSONObject数据 */ fun getAsJSONObject(key: String): JSONObject? { - val json = getAsString(key) + val json = getAsString(key) ?: return null return try { JSONObject(json) } catch (e: Exception) { @@ -311,17 +311,17 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) fun getAsObject(key: String): Any? { val data = getAsBinary(key) if (data != null) { - var bais: ByteArrayInputStream? = null + var bis: ByteArrayInputStream? = null var ois: ObjectInputStream? = null try { - bais = ByteArrayInputStream(data) - ois = ObjectInputStream(bais) + bis = ByteArrayInputStream(data) + ois = ObjectInputStream(bis) return ois.readObject() } catch (e: Exception) { e.printStackTrace() } finally { try { - bais?.close() + bis?.close() } catch (e: IOException) { e.printStackTrace() } diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index 39148fe76..23cdcabab 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -43,7 +43,7 @@ object FileUtils { val storageVolumeClazz = Class.forName("android.os.storage.StorageVolume") val getPath = storageVolumeClazz.getMethod("getPath") - val invokeVolumeList = getVolumeList.invoke(storageManager) + val invokeVolumeList = getVolumeList.invoke(storageManager) ?: return null val length = Array.getLength(invokeVolumeList) val list = ArrayList() From 8aa3e29afa1c4da04ba1e47247182a501be3afa4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 19:41:15 +0800 Subject: [PATCH 194/852] =?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/ui/config/OtherConfigFragment.kt | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 2645002fe..7a0d7fb0f 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -1,6 +1,8 @@ package io.legado.app.ui.config +import android.app.Activity.RESULT_OK import android.content.ComponentName +import android.content.Intent import android.content.SharedPreferences import android.content.pm.PackageManager import android.os.Bundle @@ -14,6 +16,8 @@ import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.theme.ATH import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.ui.filechooser.FileChooserDialog @@ -26,7 +30,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener, SharedPreferences.OnSharedPreferenceChangeListener { - private val downloadPath = 25324 + private val requestCodeDownloadPath = 25324 private val packageManager = App.INSTANCE.packageManager private val componentName = ComponentName( App.INSTANCE, @@ -67,12 +71,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), findPreference(PreferKey.threadCount)?.summary = getString(R.string.threads_num, it.toString()) } - PreferKey.downloadPath -> FileChooserDialog.show( - childFragmentManager, - downloadPath, - mode = FileChooserDialog.DIRECTORY, - initPath = getPreferenceString(PreferKey.downloadPath).toString() - ) + PreferKey.downloadPath -> selectDownloadPathSys() PreferKey.cleanCache -> { BookHelp.clearCache() toast(R.string.clear_cache_success) @@ -148,7 +147,49 @@ class OtherConfigFragment : PreferenceFragmentCompat(), } } + private fun selectDownloadPathSys() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, requestCodeDownloadPath) + } catch (e: Exception) { + selectDownloadPath() + } + } + + private fun selectDownloadPath() { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + FileChooserDialog.show( + childFragmentManager, + requestCodeDownloadPath, + mode = FileChooserDialog.DIRECTORY, + initPath = getPreferenceString(PreferKey.downloadPath).toString() + ) + } + .request() + } + override fun onFilePicked(requestCode: Int, currentPath: String) { - putPrefString(PreferKey.downloadPath, currentPath) + if (requestCode == requestCodeDownloadPath) { + putPrefString(PreferKey.downloadPath, currentPath) + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + requestCodeDownloadPath -> if (resultCode == RESULT_OK) { + data?.data?.let { uri -> + requireContext().contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + putPrefString(PreferKey.downloadPath, uri.toString()) + } + } + } } } \ No newline at end of file From 43d3b981df594f41f3469776be8dd869db875704 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 20:00:51 +0800 Subject: [PATCH 195/852] =?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/BookHelp.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index ff5ee0b7d..9225cf0ac 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -1,5 +1,6 @@ package io.legado.app.help +import android.net.Uri import io.legado.app.App import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book @@ -26,6 +27,16 @@ object BookHelp { ?: App.INSTANCE.cacheDir.absolutePath } + private val dwnloadUri get() = Uri.parse(downloadPath) + + private fun bookFolderName(book: Book): String { + return formatFolderName(book.name) + MD5Utils.md5Encode16(book.bookUrl) + } + + private fun bookChapterName(bookChapter: BookChapter): String { + return String.format("%05d-%s", bookChapter.index, MD5Utils.md5Encode(bookChapter.title)) + } + private fun getBookCachePath(): String { return "$downloadPath${File.separator}book_cache" } @@ -86,14 +97,11 @@ object BookHelp { } private fun getBookFolder(book: Book): String { - val bookFolder = formatFolderName(book.name + MD5Utils.md5Encode16(book.bookUrl)) - return "${getBookCachePath()}${File.separator}$bookFolder" + return "${getBookCachePath()}${File.separator}${bookFolderName(book)}" } private fun getChapterPath(book: Book, bookChapter: BookChapter): String { - val chapterFile = - String.format("%05d-%s", bookChapter.index, MD5Utils.md5Encode(bookChapter.title)) - return "${getBookFolder(book)}${File.separator}$chapterFile.nb" + return "${getBookFolder(book)}${File.separator}${bookChapterName(bookChapter)}.nb" } private fun formatFolderName(folderName: String): String { From 95ef2d9a0393baef7eb53b881d3ed955de7e485f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 21:47:32 +0800 Subject: [PATCH 196/852] =?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/BookHelp.kt | 43 +++++++++++-------- .../java/io/legado/app/utils/DocumentUtils.kt | 30 +++++++++++++ .../java/io/legado/app/utils/UriExtensions.kt | 3 ++ 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 9225cf0ac..fa020e466 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -1,20 +1,19 @@ package io.legado.app.help import android.net.Uri +import androidx.documentfile.provider.DocumentFile import io.legado.app.App import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.ReplaceRule -import io.legado.app.utils.MD5Utils -import io.legado.app.utils.getPrefInt -import io.legado.app.utils.getPrefString +import io.legado.app.utils.* import org.apache.commons.text.similarity.JaccardSimilarity import java.io.File import kotlin.math.min object BookHelp { - + private const val cacheFolderName = "book_cache" private var downloadPath: String = App.INSTANCE.getPrefString(PreferKey.downloadPath) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath @@ -27,7 +26,7 @@ object BookHelp { ?: App.INSTANCE.cacheDir.absolutePath } - private val dwnloadUri get() = Uri.parse(downloadPath) + private val downloadUri get() = Uri.parse(downloadPath) private fun bookFolderName(book: Book): String { return formatFolderName(book.name) + MD5Utils.md5Encode16(book.bookUrl) @@ -38,7 +37,7 @@ object BookHelp { } private fun getBookCachePath(): String { - return "$downloadPath${File.separator}book_cache" + return "$downloadPath${File.separator}$cacheFolderName" } fun clearCache() { @@ -49,15 +48,25 @@ object BookHelp { @Synchronized fun saveContent(book: Book, bookChapter: BookChapter, content: String) { if (content.isEmpty()) return - FileHelp.getFolder(getBookFolder(book)).listFiles()?.forEach { - if (it.name.startsWith(String.format("%05d", bookChapter.index))) { - it.delete() - return@forEach + if (downloadUri.isDocumentUri(App.INSTANCE)) { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + DocumentUtils.createFileIfNotExist( + it, + bookChapterName(bookChapter), + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ) } + } else { + FileHelp.getFolder(getBookFolder(book)).listFiles()?.forEach { + if (it.name.startsWith(String.format("%05d", bookChapter.index))) { + it.delete() + return@forEach + } + } + val filePath = getChapterPath(book, bookChapter) + val file = FileHelp.getFile(filePath) + file.writeText(content) } - val filePath = getChapterPath(book, bookChapter) - val file = FileHelp.getFile(filePath) - file.writeText(content) } fun getChapterCount(book: Book): Int { @@ -132,16 +141,16 @@ object BookHelp { } var newIndex = 0 - val jaccardSimilarity = JaccardSimilarity() + val jSimilarity = JaccardSimilarity() var similarity = if (chapters.size > index) { - jaccardSimilarity.apply(title, chapters[index].title) + jSimilarity.apply(title, chapters[index].title) } else 0.0 if (similarity == 1.0) { return index } else { for (i in 1..50) { if (index - i in chapters.indices) { - jaccardSimilarity.apply(title, chapters[index - i].title).let { + jSimilarity.apply(title, chapters[index - i].title).let { if (it > similarity) { similarity = it newIndex = index - i @@ -152,7 +161,7 @@ object BookHelp { } } if (index + i in chapters.indices) { - jaccardSimilarity.apply(title, chapters[index + i].title).let { + jSimilarity.apply(title, chapters[index + i].title).let { if (it > similarity) { similarity = it newIndex = index + i diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 3929874ef..99cf03f5e 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -2,9 +2,39 @@ package io.legado.app.utils import android.content.Context import android.net.Uri +import androidx.documentfile.provider.DocumentFile object DocumentUtils { + fun createFileIfNotExist( + root: DocumentFile, + fileName: String, + mimeType: String = "", + vararg subDirs: String + ): DocumentFile? { + val parent: DocumentFile? = createFileIfNotExist(root, *subDirs) + return parent?.createFile(mimeType, fileName) + } + + fun createFileIfNotExist(root: DocumentFile, vararg subDirs: String): DocumentFile? { + var parent: DocumentFile? = root + for (subDirName in subDirs) { + val subDir = parent?.findFile(subDirName) + ?: parent?.createDirectory(subDirName) + parent = subDir + } + return parent + } + + fun getDirDocument(root: DocumentFile, vararg subDirs: String): DocumentFile? { + var parent = root + for (subDirName in subDirs) { + val subDir = parent.findFile(subDirName) + parent = subDir ?: return null + } + return parent + } + @JvmStatic @Throws(Exception::class) fun writeText(context: Context, data: String, fileUri: Uri): Boolean { diff --git a/app/src/main/java/io/legado/app/utils/UriExtensions.kt b/app/src/main/java/io/legado/app/utils/UriExtensions.kt index 297a5a612..49b76b439 100644 --- a/app/src/main/java/io/legado/app/utils/UriExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/UriExtensions.kt @@ -5,6 +5,9 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import java.io.File +fun Uri.isDocumentUri(context: Context): Boolean { + return DocumentFile.isDocumentUri(context, this) +} @Throws(Exception::class) fun Uri.readBytes(context: Context): ByteArray? { From 5407cd5f3b0989f9835a9e9fc043f01e89d9c9c3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 22:33:46 +0800 Subject: [PATCH 197/852] =?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/base/BaseActivity.kt | 4 +- .../main/java/io/legado/app/help/BookHelp.kt | 10 +- .../main/java/io/legado/app/help/FileHelp.kt | 58 ---------- .../java/io/legado/app/help/storage/Backup.kt | 22 ++-- .../io/legado/app/help/storage/Restore.kt | 21 ++-- .../io/legado/app/help/storage/WebDavHelp.kt | 8 +- .../app/service/HttpReadAloudService.kt | 10 +- .../ui/book/read/config/BgTextConfigDialog.kt | 3 +- .../book/source/manage/BookSourceViewModel.kt | 3 +- .../ui/replacerule/ReplaceRuleViewModel.kt | 4 +- .../rss/source/manage/RssSourceViewModel.kt | 6 +- .../app/ui/widget/font/FontSelectDialog.kt | 15 +-- .../main/java/io/legado/app/utils/ACache.kt | 1 + .../java/io/legado/app/utils/FileUtils.kt | 106 ++++++++---------- .../main/java/io/legado/app/utils/LogUtils.kt | 5 +- .../java/io/legado/app/utils/StringUtils.kt | 2 +- 16 files changed, 101 insertions(+), 177 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/help/FileHelp.kt diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 2517cc616..048036892 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -52,8 +52,8 @@ abstract class BaseActivity( } ?: super.onCreateOptionsMenu(menu) } - override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { - menu?.applyOpenTint(this) + override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { + menu.applyOpenTint(this) return super.onMenuOpened(featureId, menu) } diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index fa020e466..bce22a823 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -41,8 +41,8 @@ object BookHelp { } fun clearCache() { - FileHelp.deleteFile(getBookCachePath()) - FileHelp.getFolder(getBookCachePath()) + FileUtils.deleteFile(getBookCachePath()) + FileUtils.getFolder(getBookCachePath()) } @Synchronized @@ -57,20 +57,20 @@ object BookHelp { ) } } else { - FileHelp.getFolder(getBookFolder(book)).listFiles()?.forEach { + FileUtils.getFolder(getBookFolder(book)).listFiles()?.forEach { if (it.name.startsWith(String.format("%05d", bookChapter.index))) { it.delete() return@forEach } } val filePath = getChapterPath(book, bookChapter) - val file = FileHelp.getFile(filePath) + val file = FileUtils.getFile(filePath) file.writeText(content) } } fun getChapterCount(book: Book): Int { - return FileHelp.getFolder(getBookFolder(book)).list()?.size ?: 0 + return FileUtils.getFolder(getBookFolder(book)).list()?.size ?: 0 } fun hasContent(book: Book, bookChapter: BookChapter): Boolean { diff --git a/app/src/main/java/io/legado/app/help/FileHelp.kt b/app/src/main/java/io/legado/app/help/FileHelp.kt deleted file mode 100644 index 5a7678563..000000000 --- a/app/src/main/java/io/legado/app/help/FileHelp.kt +++ /dev/null @@ -1,58 +0,0 @@ -package io.legado.app.help - -import io.legado.app.App -import java.io.File -import java.io.IOException - -object FileHelp { - - - //获取文件夹 - fun getFolder(filePath: String): File { - val file = File(filePath) - //如果文件夹不存在,就创建它 - if (!file.exists()) { - file.mkdirs() - } - return file - } - - //获取文件 - @Synchronized - fun getFile(filePath: String): File { - val file = File(filePath) - try { - if (!file.exists()) { - //创建父类文件夹 - getFolder(file.parent) - //创建文件 - file.createNewFile() - } - } catch (e: IOException) { - e.printStackTrace() - } - return file - } - - fun getCachePath(): String { - return App.INSTANCE.externalCacheDir?.absolutePath - ?: App.INSTANCE.cacheDir.absolutePath - } - - //递归删除文件夹下的数据 - @Synchronized - fun deleteFile(filePath: String) { - val file = File(filePath) - if (!file.exists()) return - - if (file.isDirectory) { - val files = file.listFiles() - files?.forEach { subFile -> - val path = subFile.path - deleteFile(path) - } - } - //删除文件 - file.delete() - } -} \ No newline at end of file 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 90bf3b9e2..8a635bafc 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 @@ -4,7 +4,6 @@ import android.content.Context import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.App -import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils @@ -48,37 +47,40 @@ object Backup { App.db.bookDao().allBooks.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "bookshelf.json").writeText(json) + FileUtils.getFile(backupPath + File.separator + "bookshelf.json") + .writeText(json) } } App.db.bookGroupDao().all().let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "bookGroup.json").writeText(json) + FileUtils.getFile(backupPath + File.separator + "bookGroup.json") + .writeText(json) } } App.db.bookSourceDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "bookSource.json") + FileUtils.getFile(backupPath + File.separator + "bookSource.json") .writeText(json) } } App.db.rssSourceDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "rssSource.json").writeText(json) + FileUtils.getFile(backupPath + File.separator + "rssSource.json") + .writeText(json) } } App.db.replaceRuleDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileHelp.getFile(backupPath + File.separator + "replaceRule.json") + FileUtils.getFile(backupPath + File.separator + "replaceRule.json") .writeText(json) } } GSON.toJson(ReadBookConfig.configList)?.let { - FileHelp.getFile(backupPath + File.separator + ReadBookConfig.readConfigFileName) + FileUtils.getFile(backupPath + File.separator + ReadBookConfig.readConfigFileName) .writeText(it) } Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> @@ -111,7 +113,7 @@ object Backup { doc?.let { DocumentUtils.writeText( context, - FileHelp.getFile(backupPath + File.separator + fileName).readText(), + FileUtils.getFile(backupPath + File.separator + fileName).readText(), doc.uri ) } @@ -122,8 +124,8 @@ object Backup { private fun copyBackup() { try { for (fileName in backupFileNames) { - FileHelp.getFile(backupPath + File.separator + "bookshelf.json") - .copyTo(FileHelp.getFile(legadoPath + File.separator + "bookshelf.json"), true) + FileUtils.getFile(backupPath + File.separator + "bookshelf.json") + .copyTo(FileUtils.getFile(legadoPath + File.separator + "bookshelf.json"), true) } } catch (e: Exception) { e.printStackTrace() diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 15c14051c..6741e6830 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -11,7 +11,6 @@ import com.jayway.jsonpath.ParseContext import io.legado.app.App import io.legado.app.constant.AppConst import io.legado.app.data.entities.* -import io.legado.app.help.FileHelp import io.legado.app.help.ReadBookConfig import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO @@ -38,7 +37,7 @@ object Restore { for (fileName in Backup.backupFileNames) { if (doc.name == fileName) { DocumentUtils.readText(context, doc.uri)?.let { - FileHelp.getFile(Backup.backupPath + File.separator + fileName) + FileUtils.getFile(Backup.backupPath + File.separator + fileName) .writeText(it) } } @@ -51,7 +50,7 @@ object Restore { suspend fun restore(path: String) { withContext(IO) { try { - val file = FileHelp.getFile(path + File.separator + "bookshelf.json") + val file = FileUtils.getFile(path + File.separator + "bookshelf.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.bookDao().insert(*it.toTypedArray()) @@ -60,7 +59,7 @@ object Restore { e.printStackTrace() } try { - val file = FileHelp.getFile(path + File.separator + "bookGroup.json") + val file = FileUtils.getFile(path + File.separator + "bookGroup.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.bookGroupDao().insert(*it.toTypedArray()) @@ -69,7 +68,7 @@ object Restore { e.printStackTrace() } try { - val file = FileHelp.getFile(path + File.separator + "bookSource.json") + val file = FileUtils.getFile(path + File.separator + "bookSource.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.bookSourceDao().insert(*it.toTypedArray()) @@ -78,7 +77,7 @@ object Restore { e.printStackTrace() } try { - val file = FileHelp.getFile(path + File.separator + "rssSource.json") + val file = FileUtils.getFile(path + File.separator + "rssSource.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.rssSourceDao().insert(*it.toTypedArray()) @@ -87,7 +86,7 @@ object Restore { e.printStackTrace() } try { - val file = FileHelp.getFile(path + File.separator + "replaceRule.json") + val file = FileUtils.getFile(path + File.separator + "replaceRule.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.replaceRuleDao().insert(*it.toTypedArray()) @@ -97,7 +96,7 @@ object Restore { } try { val file = - FileHelp.getFile(path + File.separator + ReadBookConfig.readConfigFileName) + FileUtils.getFile(path + File.separator + ReadBookConfig.readConfigFileName) val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + ReadBookConfig.readConfigFileName) if (file.exists()) { @@ -126,7 +125,7 @@ object Restore { GlobalScope.launch(IO) { try {// 导入书架 val shelfFile = - FileHelp.getFile(Backup.defaultPath + File.separator + "myBookShelf.json") + FileUtils.getFile(Backup.defaultPath + File.separator + "myBookShelf.json") val json = shelfFile.readText() val importCount = importOldBookshelf(json) withContext(Main) { @@ -140,7 +139,7 @@ object Restore { try {// Book source val sourceFile = - FileHelp.getFile(Backup.defaultPath + File.separator + "myBookSource.json") + FileUtils.getFile(Backup.defaultPath + File.separator + "myBookSource.json") val json = sourceFile.readText() val importCount = importOldSource(json) withContext(Main) { @@ -154,7 +153,7 @@ object Restore { try {// Replace rules val ruleFile = - FileHelp.getFile(Backup.defaultPath + File.separator + "myBookReplaceRule.json") + FileUtils.getFile(Backup.defaultPath + File.separator + "myBookReplaceRule.json") val json = ruleFile.readText() val importCount = importOldReplaceRule(json) withContext(Main) { diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 7d905299d..fb2e09a15 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -2,10 +2,10 @@ package io.legado.app.help.storage import android.content.Context import io.legado.app.App -import io.legado.app.help.FileHelp import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth +import io.legado.app.utils.FileUtils import io.legado.app.utils.ZipUtils import io.legado.app.utils.getPrefString import kotlinx.coroutines.Dispatchers.IO @@ -17,9 +17,9 @@ import java.util.* import kotlin.math.min object WebDavHelp { - private val zipFilePath = FileHelp.getCachePath() + "/backup" + ".zip" + private val zipFilePath = FileUtils.getCachePath() + "/backup" + ".zip" private val unzipFilesPath by lazy { - FileHelp.getCachePath() + FileUtils.getCachePath() } private fun getWebDavUrl(): String? { @@ -86,7 +86,7 @@ object WebDavHelp { for (i in 0 until paths.size) { paths[i] = path + File.separator + paths[i] } - FileHelp.deleteFile(zipFilePath) + FileUtils.deleteFile(zipFilePath) if (ZipUtils.zipFiles(paths, zipFilePath)) { WebDav(getWebDavUrl() + "legado").makeAsDir() val putUrl = getWebDavUrl() + "legado/backup" + diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index c2467c1eb..b12fef048 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -4,14 +4,10 @@ import android.app.PendingIntent import android.media.MediaPlayer import io.legado.app.constant.Bus import io.legado.app.data.api.IHttpPostApi -import io.legado.app.help.FileHelp import io.legado.app.help.IntentHelp import io.legado.app.help.http.HttpHelper import io.legado.app.service.help.ReadBook -import io.legado.app.utils.LogUtils -import io.legado.app.utils.getPrefInt -import io.legado.app.utils.getPrefString -import io.legado.app.utils.postEvent +import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job import kotlinx.coroutines.isActive @@ -65,7 +61,7 @@ class HttpReadAloudService : BaseReadAloudService(), private fun downloadAudio() { job = launch(IO) { - FileHelp.deleteFile(ttsFolder) + FileUtils.deleteFile(ttsFolder) for (index in 0 until contentList.size) { if (isActive) { val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com") @@ -104,7 +100,7 @@ class HttpReadAloudService : BaseReadAloudService(), } private fun getSpeakFile(index: Int = nowSpeak): File { - return FileHelp.getFile("${ttsFolder}${File.separator}${index}.mp3") + return FileUtils.getFile("${ttsFolder}${File.separator}${index}.mp3") } private fun getAudioBody(content: String): Map { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 2b4a7dc4f..460e234c0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -21,7 +21,6 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Bus -import io.legado.app.help.FileHelp import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.help.permission.Permissions @@ -174,7 +173,7 @@ class BgTextConfigDialog : DialogFragment() { var file = requireContext().getExternalFilesDir(null) ?: requireContext().filesDir file = - FileHelp.getFile(file.absolutePath + File.separator + "bg" + File.separator + doc.name) + FileUtils.getFile(file.absolutePath + File.separator + "bg" + File.separator + doc.name) DocumentUtils.readBytes(requireContext(), uri)?.let { file.writeBytes(it) ReadBookConfig.getConfig().setBg(2, file.absolutePath) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 6ae3bd977..5c75187bd 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -7,7 +7,6 @@ import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.api.IHttpGetApi import io.legado.app.data.entities.BookSource -import io.legado.app.help.FileHelp import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Backup import io.legado.app.help.storage.OldRule @@ -92,7 +91,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) }.let { val json = GSON.toJson(it) val file = - FileHelp.getFile(Backup.exportPath + File.separator + "exportBookSource.json") + FileUtils.getFile(Backup.exportPath + File.separator + "exportBookSource.json") file.writeText(json) } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index ba6bc2a61..60be30fae 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -6,9 +6,9 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.ReplaceRule -import io.legado.app.help.FileHelp import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore +import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON import io.legado.app.utils.splitNotBlank import org.jetbrains.anko.toast @@ -80,7 +80,7 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application }.let { val json = GSON.toJson(it) val file = - FileHelp.getFile(Backup.exportPath + File.separator + "exportReplaceRule.json") + FileUtils.getFile(Backup.exportPath + File.separator + "exportReplaceRule.json") file.writeText(json) } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index c47bb8c9d..22c8f62f4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -4,10 +4,10 @@ import android.app.Application import android.text.TextUtils import com.jayway.jsonpath.JsonPath import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.api.IHttpGetApi import io.legado.app.data.entities.RssSource -import io.legado.app.help.FileHelp import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore.jsonPath @@ -65,7 +65,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) App.db.rssSourceDao().getRssSources(*ids.toTypedArray()).let { val json = GSON.toJson(it) val file = - FileHelp.getFile(Backup.exportPath + File.separator + "exportRssSource.json") + FileUtils.getFile(Backup.exportPath + File.separator + "exportRssSource.json") file.writeText(json) } }.onSuccess { @@ -123,6 +123,8 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) App.db.rssSourceDao().insert(*it.toTypedArray()) } } + }.onSuccess { + finally.invoke(context.getString(R.string.success)) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 420bc9233..5e57e79fc 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -5,7 +5,6 @@ import android.app.Activity.RESULT_OK import android.content.Intent import android.net.Uri import android.os.Bundle -import android.os.Environment import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.MenuItem @@ -18,13 +17,9 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.constant.PreferKey -import io.legado.app.help.FileHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat -import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.getPrefString -import io.legado.app.utils.putPrefString -import io.legado.app.utils.toast +import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_font_select.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO @@ -127,11 +122,11 @@ class FontSelectDialog : DialogFragment(), @SuppressLint("DefaultLocale") private fun getFontFiles(uri: Uri) { launch(IO) { - FileHelp.deleteFile(fontCacheFolder) + FileUtils.deleteFile(fontCacheFolder) DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { file -> if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { - FileHelp.getFile(fontCacheFolder + file.name).writeBytes(it) + FileUtils.getFile(fontCacheFolder + file.name).writeBytes(it) } } } @@ -154,7 +149,7 @@ class FontSelectDialog : DialogFragment(), private fun getFontFilesOld() { try { val file = - File(Environment.getExternalStorageDirectory().absolutePath + File.separator + "Fonts") + File(FileUtils.getSdCardPath() + File.separator + "Fonts") file.listFiles { pathName -> pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) }?.let { @@ -167,7 +162,7 @@ class FontSelectDialog : DialogFragment(), override fun onClick(file: File) { launch(IO) { - file.copyTo(FileHelp.getFile(fontFolder + file.name), true).absolutePath.let { path -> + file.copyTo(FileUtils.getFile(fontFolder + file.name), true).absolutePath.let { path -> val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) cb?.let { if (it.curFontPath != path) { diff --git a/app/src/main/java/io/legado/app/utils/ACache.kt b/app/src/main/java/io/legado/app/utils/ACache.kt index b173dc612..03a330d6a 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -597,6 +597,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) val w = drawable.intrinsicWidth val h = drawable.intrinsicHeight // 取 drawable 的颜色格式 + @Suppress("DEPRECATION") val config = if (drawable.opacity != PixelFormat.OPAQUE) Bitmap.Config.ARGB_8888 else diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index 23cdcabab..9ebd26ea0 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -4,86 +4,76 @@ import android.content.ContentUris import android.content.Context import android.net.Uri import android.os.Environment -import android.os.storage.StorageManager import android.provider.DocumentsContract import android.provider.MediaStore -import android.util.Log -import androidx.core.content.ContextCompat +import io.legado.app.App import java.io.File import java.io.IOException -import java.lang.reflect.Array -import java.util.* object FileUtils { - fun getFileByPath(filePath: String): File? { - return if (filePath.isBlank()) null else File(filePath) + fun getCachePath(): String { + return App.INSTANCE.externalCacheDir?.absolutePath + ?: App.INSTANCE.cacheDir.absolutePath } - fun getSdCardPath(): String { - var sdCardDirectory = Environment.getExternalStorageDirectory().absolutePath - try { - sdCardDirectory = File(sdCardDirectory).canonicalPath - } catch (ioe: IOException) { - ioe.printStackTrace() + //获取文件夹 + fun getFolder(filePath: String): File { + val file = File(filePath) + //如果文件夹不存在,就创建它 + if (!file.exists()) { + file.mkdirs() } - - return sdCardDirectory + return file } - fun getStorageData(pContext: Context): ArrayList? { - - val storageManager = pContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager - + //获取文件 + @Synchronized + fun getFile(filePath: String): File { + val file = File(filePath) try { - val getVolumeList = storageManager.javaClass.getMethod("getVolumeList") - - val storageVolumeClazz = Class.forName("android.os.storage.StorageVolume") - val getPath = storageVolumeClazz.getMethod("getPath") - - val invokeVolumeList = getVolumeList.invoke(storageManager) ?: return null - val length = Array.getLength(invokeVolumeList) - - val list = ArrayList() - for (i in 0 until length) { - val storageVolume = Array.get(invokeVolumeList, i)//得到StorageVolume对象 - val path = getPath.invoke(storageVolume) as String - - list.add(path) + if (!file.exists()) { + //创建父类文件夹 + file.parent?.let { + getFolder(it) + } + //创建文件 + file.createNewFile() } - return list - } catch (e: Exception) { + } catch (e: IOException) { e.printStackTrace() } - - return null + return file } - - fun getExtSdCardPaths(con: Context): ArrayList { - val paths = ArrayList() - val files = ContextCompat.getExternalFilesDirs(con, "external") - val firstFile = files[0] - for (file in files) { - if (file != null && file != firstFile) { - val index = file.absolutePath.lastIndexOf("/Android/data") - if (index < 0) { - Log.w("", "Unexpected external file dir: " + file.absolutePath) - } else { - var path = file.absolutePath.substring(0, index) - try { - path = File(path).canonicalPath - } catch (e: IOException) { - // Keep non-canonical path. - } - - paths.add(path) - } + //递归删除文件夹下的数据 + @Synchronized + fun deleteFile(filePath: String) { + val file = File(filePath) + if (!file.exists()) return + + if (file.isDirectory) { + val files = file.listFiles() + files?.forEach { subFile -> + val path = subFile.path + deleteFile(path) } } - return paths + //删除文件 + file.delete() + } + + fun getSdCardPath(): String { + @Suppress("DEPRECATION") + var sdCardDirectory = Environment.getExternalStorageDirectory().absolutePath + try { + sdCardDirectory = File(sdCardDirectory).canonicalPath + } catch (ioe: IOException) { + ioe.printStackTrace() + } + return sdCardDirectory } fun getPath(context: Context, uri: Uri): String? { diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index 1662974a7..b6712ad4d 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -2,7 +2,6 @@ package io.legado.app.utils import android.annotation.SuppressLint import io.legado.app.App -import io.legado.app.help.FileHelp import java.io.File import java.text.SimpleDateFormat import java.util.* @@ -30,8 +29,8 @@ object LogUtils { } private val fileHandler by lazy { - val logFolder = FileHelp.getCachePath() + File.separator + "logs" - FileHelp.getFolder(logFolder) + val logFolder = FileUtils.getCachePath() + File.separator + "logs" + FileUtils.getFolder(logFolder) FileHandler( logFolder + File.separator + "app.log", 10240, diff --git a/app/src/main/java/io/legado/app/utils/StringUtils.kt b/app/src/main/java/io/legado/app/utils/StringUtils.kt index 6d70b244b..95096c087 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -250,7 +250,7 @@ object StringUtils { val m = p.matcher(data) val buf = StringBuffer(data.length) while (m.find()) { - val ch = Integer.parseInt(m.group(1), 16).toChar().toString() + val ch = Integer.parseInt(m.group(1)!!, 16).toChar().toString() m.appendReplacement(buf, Matcher.quoteReplacement(ch)) } m.appendTail(buf) From 09bbad40eda5619e8d34be2ab7d22b47f591efcb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 22:39:49 +0800 Subject: [PATCH 198/852] =?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/info/BookInfoActivity.kt | 4 ++-- .../main/java/io/legado/app/ui/book/search/SearchActivity.kt | 4 ++-- app/src/main/java/io/legado/app/utils/FileUtils.kt | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index fb689519c..57839f1c9 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -98,8 +98,8 @@ class BookInfoActivity : return super.onCompatOptionsItemSelected(item) } - override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { - menu?.findItem(R.id.menu_can_update)?.isChecked = + override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { + menu.findItem(R.id.menu_can_update)?.isChecked = viewModel.bookData.value?.canUpdate ?: true return super.onMenuOpened(featureId, menu) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index ae44ddaad..fb250fb46 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -76,7 +76,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se !getPrefBoolean(PreferKey.precisionSearch) ) precisionSearchMenuItem?.isChecked = getPrefBoolean(PreferKey.precisionSearch) - search_view.query.toString().trim()?.let { + search_view.query?.toString()?.trim()?.let { search_view.setQuery(it, true) } } @@ -88,7 +88,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } else { putPrefString("searchGroup", item.title.toString()) } - search_view.query.toString().trim()?.let { + search_view.query?.toString()?.trim()?.let { search_view.setQuery(it, true) } } diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index 9ebd26ea0..c6061acb6 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -86,6 +86,7 @@ object FileUtils { val type = split[0] if ("primary".equals(type, ignoreCase = true)) { + @Suppress("DEPRECATION") return Environment.getExternalStorageDirectory().toString() + "/" + split[1] } @@ -135,7 +136,7 @@ object FileUtils { private fun getDataColumn( context: Context, uri: Uri, selection: String?, - selectionArgs: kotlin.Array? + selectionArgs: Array? ): String? { val column = "_data" From 5e2f4ad06b97c38a354c9b6717af64ad98eecdef Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 28 Jan 2020 23:42:31 +0800 Subject: [PATCH 199/852] =?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/BookHelp.kt | 94 +++++++++++++------ .../java/io/legado/app/utils/DocumentUtils.kt | 5 + .../java/io/legado/app/utils/FileUtils.kt | 18 +++- 3 files changed, 86 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index bce22a823..2c1330b12 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -52,67 +52,101 @@ object BookHelp { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { DocumentUtils.createFileIfNotExist( it, - bookChapterName(bookChapter), + "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - ) + )?.uri?.writeText(App.INSTANCE, content) } } else { - FileUtils.getFolder(getBookFolder(book)).listFiles()?.forEach { + FileUtils.createFileIfNotExist( + File(downloadPath), + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ).listFiles()?.forEach { if (it.name.startsWith(String.format("%05d", bookChapter.index))) { it.delete() return@forEach } } - val filePath = getChapterPath(book, bookChapter) - val file = FileUtils.getFile(filePath) - file.writeText(content) + FileUtils.createFileIfNotExist( + File(downloadPath), + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ).writeText(content) } } fun getChapterCount(book: Book): Int { - return FileUtils.getFolder(getBookFolder(book)).list()?.size ?: 0 + if (downloadUri.isDocumentUri(App.INSTANCE)) { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + return DocumentUtils.createFileIfNotExist( + it, + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + )?.listFiles()?.size ?: 0 + } + } else { + return FileUtils.createFileIfNotExist( + File(downloadPath), + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ).list()?.size ?: 0 + } + return 0 } fun hasContent(book: Book, bookChapter: BookChapter): Boolean { - val filePath = getChapterPath(book, bookChapter) - runCatching { - val file = File(filePath) - if (file.exists()) { - return true + if (downloadUri.isDocumentUri(App.INSTANCE)) { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + return DocumentUtils.exists( + it, + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ) } + } else { + return FileUtils.exists( + File(downloadPath), + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ) } return false } fun getContent(book: Book, bookChapter: BookChapter): String? { - val filePath = getChapterPath(book, bookChapter) - runCatching { - val file = File(filePath) - if (file.exists()) { - return file.readText() + if (downloadUri.isDocumentUri(App.INSTANCE)) { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + return DocumentUtils.createFileIfNotExist( + it, + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + )?.uri?.readText(App.INSTANCE) } + } else { + return FileUtils.createFileIfNotExist( + File(downloadPath), + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ).readText() } return null } fun delContent(book: Book, bookChapter: BookChapter) { - val filePath = getChapterPath(book, bookChapter) - kotlin.runCatching { - val file = File(filePath) - if (file.exists()) { - file.delete() + if (downloadUri.isDocumentUri(App.INSTANCE)) { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + DocumentUtils.createFileIfNotExist( + it, + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + )?.delete() } + } else { + FileUtils.createFileIfNotExist( + File(downloadPath), + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ).delete() } } - private fun getBookFolder(book: Book): String { - return "${getBookCachePath()}${File.separator}${bookFolderName(book)}" - } - - private fun getChapterPath(book: Book, bookChapter: BookChapter): String { - return "${getBookFolder(book)}${File.separator}${bookChapterName(bookChapter)}.nb" - } - private fun formatFolderName(folderName: String): String { return folderName.replace("[\\\\/:*?\"<>|.]".toRegex(), "") } diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 99cf03f5e..3d1f53a58 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -6,6 +6,11 @@ import androidx.documentfile.provider.DocumentFile object DocumentUtils { + fun exists(root: DocumentFile, fileName: String, vararg subDirs: String): Boolean { + val parent = getDirDocument(root, *subDirs) ?: return false + return parent.findFile(fileName)?.exists() ?: false + } + fun createFileIfNotExist( root: DocumentFile, fileName: String, diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index c6061acb6..3d9923448 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -13,12 +13,28 @@ import java.io.IOException object FileUtils { + fun exists(file: File, fileName: String, vararg subDirs: String): Boolean { + val filePath = + file.absolutePath + File.separator + subDirs.joinToString(File.separator) + File.separator + fileName + return File(filePath).exists() + } + + fun createFileIfNotExist(file: File, fileName: String, vararg subDirs: String): File { + val filePath = + file.absolutePath + File.separator + subDirs.joinToString(File.separator) + File.separator + fileName + return getFile(filePath) + } + + fun createFileIfNotExist(file: File, vararg subDirs: String): File { + val filePath = file.absolutePath + File.separator + subDirs.joinToString(File.separator) + return getFolder(filePath) + } + fun getCachePath(): String { return App.INSTANCE.externalCacheDir?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath } - //获取文件夹 fun getFolder(filePath: String): File { val file = File(filePath) From de35674c439e4e29d96c198cc66af723461716d5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 08:30:55 +0800 Subject: [PATCH 200/852] =?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/BookHelp.kt | 16 +++++++++----- .../java/io/legado/app/help/storage/Backup.kt | 21 +++++++++++-------- .../io/legado/app/help/storage/Restore.kt | 21 ++++++++++--------- .../app/service/HttpReadAloudService.kt | 2 +- .../ui/book/read/config/BgTextConfigDialog.kt | 2 +- .../book/source/manage/BookSourceViewModel.kt | 2 +- .../ui/replacerule/ReplaceRuleViewModel.kt | 2 +- .../rss/source/manage/RssSourceViewModel.kt | 2 +- .../app/ui/widget/font/FontSelectDialog.kt | 5 +++-- .../java/io/legado/app/utils/FileUtils.kt | 12 +++++------ .../main/java/io/legado/app/utils/LogUtils.kt | 2 +- 11 files changed, 48 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 2c1330b12..6c65af7ed 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -41,8 +41,14 @@ object BookHelp { } fun clearCache() { - FileUtils.deleteFile(getBookCachePath()) - FileUtils.getFolder(getBookCachePath()) + if (downloadUri.isDocumentUri(App.INSTANCE)) { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri) + ?.findFile(cacheFolderName) + ?.delete() + } else { + FileUtils.deleteFile(getBookCachePath()) + FileUtils.createFolderIfNotExist(getBookCachePath()) + } } @Synchronized @@ -132,11 +138,11 @@ object BookHelp { fun delContent(book: Book, bookChapter: BookChapter) { if (downloadUri.isDocumentUri(App.INSTANCE)) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { - DocumentUtils.createFileIfNotExist( + DocumentUtils.getDirDocument( it, - "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - )?.delete() + )?.findFile("${bookChapterName(bookChapter)}.nb") + ?.delete() } } else { FileUtils.createFileIfNotExist( 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 8a635bafc..fd28eea7f 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 @@ -47,40 +47,40 @@ object Backup { App.db.bookDao().allBooks.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileUtils.getFile(backupPath + File.separator + "bookshelf.json") + FileUtils.createFileIfNotExist(backupPath + File.separator + "bookshelf.json") .writeText(json) } } App.db.bookGroupDao().all().let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileUtils.getFile(backupPath + File.separator + "bookGroup.json") + FileUtils.createFileIfNotExist(backupPath + File.separator + "bookGroup.json") .writeText(json) } } App.db.bookSourceDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileUtils.getFile(backupPath + File.separator + "bookSource.json") + FileUtils.createFileIfNotExist(backupPath + File.separator + "bookSource.json") .writeText(json) } } App.db.rssSourceDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileUtils.getFile(backupPath + File.separator + "rssSource.json") + FileUtils.createFileIfNotExist(backupPath + File.separator + "rssSource.json") .writeText(json) } } App.db.replaceRuleDao().all.let { if (it.isNotEmpty()) { val json = GSON.toJson(it) - FileUtils.getFile(backupPath + File.separator + "replaceRule.json") + FileUtils.createFileIfNotExist(backupPath + File.separator + "replaceRule.json") .writeText(json) } } GSON.toJson(ReadBookConfig.configList)?.let { - FileUtils.getFile(backupPath + File.separator + ReadBookConfig.readConfigFileName) + FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.readConfigFileName) .writeText(it) } Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> @@ -113,7 +113,7 @@ object Backup { doc?.let { DocumentUtils.writeText( context, - FileUtils.getFile(backupPath + File.separator + fileName).readText(), + FileUtils.createFileIfNotExist(backupPath + File.separator + fileName).readText(), doc.uri ) } @@ -124,8 +124,11 @@ object Backup { private fun copyBackup() { try { for (fileName in backupFileNames) { - FileUtils.getFile(backupPath + File.separator + "bookshelf.json") - .copyTo(FileUtils.getFile(legadoPath + File.separator + "bookshelf.json"), true) + FileUtils.createFileIfNotExist(backupPath + File.separator + "bookshelf.json") + .copyTo( + FileUtils.createFileIfNotExist(legadoPath + File.separator + "bookshelf.json"), + true + ) } } catch (e: Exception) { e.printStackTrace() diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 6741e6830..3f7110a54 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -37,7 +37,7 @@ object Restore { for (fileName in Backup.backupFileNames) { if (doc.name == fileName) { DocumentUtils.readText(context, doc.uri)?.let { - FileUtils.getFile(Backup.backupPath + File.separator + fileName) + FileUtils.createFileIfNotExist(Backup.backupPath + File.separator + fileName) .writeText(it) } } @@ -50,7 +50,7 @@ object Restore { suspend fun restore(path: String) { withContext(IO) { try { - val file = FileUtils.getFile(path + File.separator + "bookshelf.json") + val file = FileUtils.createFileIfNotExist(path + File.separator + "bookshelf.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.bookDao().insert(*it.toTypedArray()) @@ -59,7 +59,7 @@ object Restore { e.printStackTrace() } try { - val file = FileUtils.getFile(path + File.separator + "bookGroup.json") + val file = FileUtils.createFileIfNotExist(path + File.separator + "bookGroup.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.bookGroupDao().insert(*it.toTypedArray()) @@ -68,7 +68,7 @@ object Restore { e.printStackTrace() } try { - val file = FileUtils.getFile(path + File.separator + "bookSource.json") + val file = FileUtils.createFileIfNotExist(path + File.separator + "bookSource.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.bookSourceDao().insert(*it.toTypedArray()) @@ -77,7 +77,7 @@ object Restore { e.printStackTrace() } try { - val file = FileUtils.getFile(path + File.separator + "rssSource.json") + val file = FileUtils.createFileIfNotExist(path + File.separator + "rssSource.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.rssSourceDao().insert(*it.toTypedArray()) @@ -86,7 +86,8 @@ object Restore { e.printStackTrace() } try { - val file = FileUtils.getFile(path + File.separator + "replaceRule.json") + val file = + FileUtils.createFileIfNotExist(path + File.separator + "replaceRule.json") val json = file.readText() GSON.fromJsonArray(json)?.let { App.db.replaceRuleDao().insert(*it.toTypedArray()) @@ -96,7 +97,7 @@ object Restore { } try { val file = - FileUtils.getFile(path + File.separator + ReadBookConfig.readConfigFileName) + FileUtils.createFileIfNotExist(path + File.separator + ReadBookConfig.readConfigFileName) val configFile = File(App.INSTANCE.filesDir.absolutePath + File.separator + ReadBookConfig.readConfigFileName) if (file.exists()) { @@ -125,7 +126,7 @@ object Restore { GlobalScope.launch(IO) { try {// 导入书架 val shelfFile = - FileUtils.getFile(Backup.defaultPath + File.separator + "myBookShelf.json") + FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookShelf.json") val json = shelfFile.readText() val importCount = importOldBookshelf(json) withContext(Main) { @@ -139,7 +140,7 @@ object Restore { try {// Book source val sourceFile = - FileUtils.getFile(Backup.defaultPath + File.separator + "myBookSource.json") + FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookSource.json") val json = sourceFile.readText() val importCount = importOldSource(json) withContext(Main) { @@ -153,7 +154,7 @@ object Restore { try {// Replace rules val ruleFile = - FileUtils.getFile(Backup.defaultPath + File.separator + "myBookReplaceRule.json") + FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookReplaceRule.json") val json = ruleFile.readText() val importCount = importOldReplaceRule(json) withContext(Main) { diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index b12fef048..6f211a3c7 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -100,7 +100,7 @@ class HttpReadAloudService : BaseReadAloudService(), } private fun getSpeakFile(index: Int = nowSpeak): File { - return FileUtils.getFile("${ttsFolder}${File.separator}${index}.mp3") + return FileUtils.createFileIfNotExist("${ttsFolder}${File.separator}${index}.mp3") } private fun getAudioBody(content: String): Map { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 460e234c0..8fe683273 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -173,7 +173,7 @@ class BgTextConfigDialog : DialogFragment() { var file = requireContext().getExternalFilesDir(null) ?: requireContext().filesDir file = - FileUtils.getFile(file.absolutePath + File.separator + "bg" + File.separator + doc.name) + FileUtils.createFileIfNotExist(file.absolutePath + File.separator + "bg" + File.separator + doc.name) DocumentUtils.readBytes(requireContext(), uri)?.let { file.writeBytes(it) ReadBookConfig.getConfig().setBg(2, file.absolutePath) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 5c75187bd..06edf4033 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -91,7 +91,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) }.let { val json = GSON.toJson(it) val file = - FileUtils.getFile(Backup.exportPath + File.separator + "exportBookSource.json") + FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportBookSource.json") file.writeText(json) } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 60be30fae..00a279a33 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -80,7 +80,7 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application }.let { val json = GSON.toJson(it) val file = - FileUtils.getFile(Backup.exportPath + File.separator + "exportReplaceRule.json") + FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportReplaceRule.json") file.writeText(json) } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 22c8f62f4..bf82505d3 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -65,7 +65,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) App.db.rssSourceDao().getRssSources(*ids.toTypedArray()).let { val json = GSON.toJson(it) val file = - FileUtils.getFile(Backup.exportPath + File.separator + "exportRssSource.json") + FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportRssSource.json") file.writeText(json) } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 5e57e79fc..79d3c9512 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -126,7 +126,7 @@ class FontSelectDialog : DialogFragment(), DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { file -> if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { - FileUtils.getFile(fontCacheFolder + file.name).writeBytes(it) + FileUtils.createFileIfNotExist(fontCacheFolder + file.name).writeBytes(it) } } } @@ -162,7 +162,8 @@ class FontSelectDialog : DialogFragment(), override fun onClick(file: File) { launch(IO) { - file.copyTo(FileUtils.getFile(fontFolder + file.name), true).absolutePath.let { path -> + file.copyTo(FileUtils.createFileIfNotExist(fontFolder + file.name), true) + .absolutePath.let { path -> val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) cb?.let { if (it.curFontPath != path) { diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index 3d9923448..f8876c69d 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -22,12 +22,12 @@ object FileUtils { fun createFileIfNotExist(file: File, fileName: String, vararg subDirs: String): File { val filePath = file.absolutePath + File.separator + subDirs.joinToString(File.separator) + File.separator + fileName - return getFile(filePath) + return createFileIfNotExist(filePath) } fun createFileIfNotExist(file: File, vararg subDirs: String): File { val filePath = file.absolutePath + File.separator + subDirs.joinToString(File.separator) - return getFolder(filePath) + return createFolderIfNotExist(filePath) } fun getCachePath(): String { @@ -35,8 +35,7 @@ object FileUtils { ?: App.INSTANCE.cacheDir.absolutePath } - //获取文件夹 - fun getFolder(filePath: String): File { + fun createFolderIfNotExist(filePath: String): File { val file = File(filePath) //如果文件夹不存在,就创建它 if (!file.exists()) { @@ -45,15 +44,14 @@ object FileUtils { return file } - //获取文件 @Synchronized - fun getFile(filePath: String): File { + fun createFileIfNotExist(filePath: String): File { val file = File(filePath) try { if (!file.exists()) { //创建父类文件夹 file.parent?.let { - getFolder(it) + createFolderIfNotExist(it) } //创建文件 file.createNewFile() diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index b6712ad4d..7953259f5 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -30,7 +30,7 @@ object LogUtils { private val fileHandler by lazy { val logFolder = FileUtils.getCachePath() + File.separator + "logs" - FileUtils.getFolder(logFolder) + FileUtils.createFolderIfNotExist(logFolder) FileHandler( logFolder + File.separator + "app.log", 10240, From 15cb3feee4be0a129bd11a9204d9d35f6b5a9aa0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 08:33:24 +0800 Subject: [PATCH 201/852] =?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/BookHelp.kt | 2 +- app/src/main/java/io/legado/app/utils/DocumentUtils.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 6c65af7ed..f800800ff 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -83,7 +83,7 @@ object BookHelp { fun getChapterCount(book: Book): Int { if (downloadUri.isDocumentUri(App.INSTANCE)) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { - return DocumentUtils.createFileIfNotExist( + return DocumentUtils.createFolderIfNotExist( it, subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) )?.listFiles()?.size ?: 0 diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 3d1f53a58..8e74c63e0 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -17,11 +17,11 @@ object DocumentUtils { mimeType: String = "", vararg subDirs: String ): DocumentFile? { - val parent: DocumentFile? = createFileIfNotExist(root, *subDirs) + val parent: DocumentFile? = createFolderIfNotExist(root, *subDirs) return parent?.createFile(mimeType, fileName) } - fun createFileIfNotExist(root: DocumentFile, vararg subDirs: String): DocumentFile? { + fun createFolderIfNotExist(root: DocumentFile, vararg subDirs: String): DocumentFile? { var parent: DocumentFile? = root for (subDirName in subDirs) { val subDir = parent?.findFile(subDirName) From c5f86e0ea36a2e1c3eabe7038343ee192c05b466 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 09:12:53 +0800 Subject: [PATCH 202/852] =?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/BookHelp.kt | 12 +++--- .../java/io/legado/app/utils/FileUtils.kt | 43 +++++++++++++------ 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index f800800ff..dea6192bf 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -36,18 +36,18 @@ object BookHelp { return String.format("%05d-%s", bookChapter.index, MD5Utils.md5Encode(bookChapter.title)) } - private fun getBookCachePath(): String { - return "$downloadPath${File.separator}$cacheFolderName" - } - fun clearCache() { if (downloadUri.isDocumentUri(App.INSTANCE)) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri) ?.findFile(cacheFolderName) ?.delete() } else { - FileUtils.deleteFile(getBookCachePath()) - FileUtils.createFolderIfNotExist(getBookCachePath()) + FileUtils.deleteFile( + FileUtils.getPath( + File(downloadPath), + subDirs = *arrayOf(cacheFolderName) + ) + ) } } diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index f8876c69d..0fb054ceb 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -13,28 +13,20 @@ import java.io.IOException object FileUtils { - fun exists(file: File, fileName: String, vararg subDirs: String): Boolean { - val filePath = - file.absolutePath + File.separator + subDirs.joinToString(File.separator) + File.separator + fileName - return File(filePath).exists() + fun exists(root: File, fileName: String, vararg subDirs: String): Boolean { + return getFile(root, fileName, subDirs = *subDirs).exists() } - fun createFileIfNotExist(file: File, fileName: String, vararg subDirs: String): File { - val filePath = - file.absolutePath + File.separator + subDirs.joinToString(File.separator) + File.separator + fileName + fun createFileIfNotExist(root: File, fileName: String, vararg subDirs: String): File { + val filePath = getPath(root, fileName, *subDirs) return createFileIfNotExist(filePath) } - fun createFileIfNotExist(file: File, vararg subDirs: String): File { - val filePath = file.absolutePath + File.separator + subDirs.joinToString(File.separator) + fun createFileIfNotExist(root: File, vararg subDirs: String): File { + val filePath = root.absolutePath + File.separator + subDirs.joinToString(File.separator) return createFolderIfNotExist(filePath) } - fun getCachePath(): String { - return App.INSTANCE.externalCacheDir?.absolutePath - ?: App.INSTANCE.cacheDir.absolutePath - } - fun createFolderIfNotExist(filePath: String): File { val file = File(filePath) //如果文件夹不存在,就创建它 @@ -62,6 +54,24 @@ object FileUtils { return file } + fun getFile(file: File, fileName: String, vararg subDirs: String): File { + val filePath = getPath(file, fileName, *subDirs) + return File(filePath) + } + + fun getFile(root: File, vararg subDirs: String): File { + val filePath = getPath(root, subDirs = *subDirs) + return File(filePath) + } + + fun getPath(root: File, fileName: String? = null, vararg subDirs: String): String { + return if (fileName.isNullOrEmpty()) { + root.absolutePath + File.separator + subDirs.joinToString(File.separator) + } else { + root.absolutePath + File.separator + subDirs.joinToString(File.separator) + File.separator + fileName + } + } + //递归删除文件夹下的数据 @Synchronized fun deleteFile(filePath: String) { @@ -79,6 +89,11 @@ object FileUtils { file.delete() } + fun getCachePath(): String { + return App.INSTANCE.externalCacheDir?.absolutePath + ?: App.INSTANCE.cacheDir.absolutePath + } + fun getSdCardPath(): String { @Suppress("DEPRECATION") var sdCardDirectory = Environment.getExternalStorageDirectory().absolutePath From d5f9f153937030d57d304cb233ff33ca9458a7e9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 09:19:45 +0800 Subject: [PATCH 203/852] =?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/BookHelp.kt | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index dea6192bf..8205243cf 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -55,9 +55,18 @@ object BookHelp { fun saveContent(book: Book, bookChapter: BookChapter, content: String) { if (content.isEmpty()) return if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> + DocumentUtils.getDirDocument( + root, + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + )?.listFiles()?.forEach { + if (it.name?.startsWith(String.format("%05d", bookChapter.index)) == true) { + it.delete() + return@forEach + } + } DocumentUtils.createFileIfNotExist( - it, + root, "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) )?.uri?.writeText(App.INSTANCE, content) @@ -82,9 +91,9 @@ object BookHelp { fun getChapterCount(book: Book): Int { if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.createFolderIfNotExist( - it, + root, subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) )?.listFiles()?.size ?: 0 } @@ -99,9 +108,9 @@ object BookHelp { fun hasContent(book: Book, bookChapter: BookChapter): Boolean { if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.exists( - it, + root, "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) ) @@ -118,9 +127,9 @@ object BookHelp { fun getContent(book: Book, bookChapter: BookChapter): String? { if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.createFileIfNotExist( - it, + root, "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) )?.uri?.readText(App.INSTANCE) @@ -137,9 +146,9 @@ object BookHelp { fun delContent(book: Book, bookChapter: BookChapter) { if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> DocumentUtils.getDirDocument( - it, + root, subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) )?.findFile("${bookChapterName(bookChapter)}.nb") ?.delete() From 42b7c6d771a313526389e92a8ea3ccac84de850c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 09:42:53 +0800 Subject: [PATCH 204/852] =?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/BookHelp.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 8205243cf..73e303483 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -128,11 +128,11 @@ object BookHelp { fun getContent(book: Book, bookChapter: BookChapter): String? { if (downloadUri.isDocumentUri(App.INSTANCE)) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> - return DocumentUtils.createFileIfNotExist( + return DocumentUtils.getDirDocument( root, - "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - )?.uri?.readText(App.INSTANCE) + )?.findFile("${bookChapterName(bookChapter)}.nb") + ?.uri?.readText(App.INSTANCE) } } else { return FileUtils.createFileIfNotExist( @@ -225,9 +225,9 @@ object BookHelp { return newIndex } - var bookName: String? = null - var bookOrigin: String? = null - var replaceRules: List = arrayListOf() + private var bookName: String? = null + private var bookOrigin: String? = null + private var replaceRules: List = arrayListOf() fun disposeContent( title: String, From cf8f5e1811c39d49434e46ea227a737510f834d6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 10:17:15 +0800 Subject: [PATCH 205/852] =?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/BookHelp.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 73e303483..a93a0606f 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -135,11 +135,15 @@ object BookHelp { ?.uri?.readText(App.INSTANCE) } } else { - return FileUtils.createFileIfNotExist( + val path = FileUtils.getPath( File(downloadPath), "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - ).readText() + ) + val file = File(path) + if (file.exists()) { + return file.readText() + } } return null } From 1fff1bcb4601f53a0abb6fffb58885156ac0e7be Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 10:21:21 +0800 Subject: [PATCH 206/852] =?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/BookHelp.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index a93a0606f..7635df1f7 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -33,7 +33,7 @@ object BookHelp { } private fun bookChapterName(bookChapter: BookChapter): String { - return String.format("%05d-%s", bookChapter.index, MD5Utils.md5Encode(bookChapter.title)) + return String.format("%05d-%s", bookChapter.index, MD5Utils.md5Encode16(bookChapter.title)) } fun clearCache() { @@ -135,12 +135,11 @@ object BookHelp { ?.uri?.readText(App.INSTANCE) } } else { - val path = FileUtils.getPath( + val file = FileUtils.getFile( File(downloadPath), "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) ) - val file = File(path) if (file.exists()) { return file.readText() } From 711dff3218c700a6744f751450a2776b34a0a2a2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 11:02:00 +0800 Subject: [PATCH 207/852] =?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/utils/FileUtils.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index 0fb054ceb..13e55161d 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -59,11 +59,6 @@ object FileUtils { return File(filePath) } - fun getFile(root: File, vararg subDirs: String): File { - val filePath = getPath(root, subDirs = *subDirs) - return File(filePath) - } - fun getPath(root: File, fileName: String? = null, vararg subDirs: String): String { return if (fileName.isNullOrEmpty()) { root.absolutePath + File.separator + subDirs.joinToString(File.separator) From 1a3883823bad48b78848831891827c61247bbbc0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 12:56:59 +0800 Subject: [PATCH 208/852] =?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/res/layout/activity_import_book.xml | 45 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 2 files changed, 46 insertions(+) diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index d829e291c..ca99f8645 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -1,7 +1,52 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 43a0e6019..b72122315 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -586,5 +586,6 @@ 分享书源 自动切换夜间模式 夜间模式跟随系统 + 上级 From bc1a9f6f714431ac4461554fb6660b6dfc52ed7c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 17:55:11 +0800 Subject: [PATCH 209/852] =?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/main/bookshelf/BookshelfFragment.kt | 6 +-- .../main/res/layout/activity_import_book.xml | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 54d7e71d4..0a8318618 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -21,6 +21,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.download.DownloadActivity +import io.legado.app.ui.importbook.ImportBookActivity import io.legado.app.utils.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* @@ -37,7 +38,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b override val viewModel: BookshelfViewModel get() = getViewModel(BookshelfViewModel::class.java) - lateinit var bookshelfAdapter: BookshelfAdapter + private lateinit var bookshelfAdapter: BookshelfAdapter private var bookGroupLiveData: LiveData>? = null private val bookGroups = mutableListOf() @@ -58,8 +59,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b R.id.menu_bookshelf_layout -> selectBookshelfLayout() R.id.menu_group_manage -> GroupManageDialog() .show(childFragmentManager, "groupManageDialog") - R.id.menu_add_local -> { - } + R.id.menu_add_local -> startActivity() R.id.menu_add_url -> { } R.id.menu_arrange_bookshelf -> { diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index ca99f8645..a566d7a72 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -48,5 +48,47 @@ tools:ignore="UnusedAttribute" /> + + + + + + + + + + + \ No newline at end of file From 8af819d768a14c074d223d71215cdf34b1170436 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 19:44:25 +0800 Subject: [PATCH 210/852] =?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/res/drawable/ic_folder_open.xml | 9 +++++++++ app/src/main/res/menu/import_book.xml | 11 +++++++++++ app/src/main/res/values/strings.xml | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_folder_open.xml create mode 100644 app/src/main/res/menu/import_book.xml diff --git a/app/src/main/res/drawable/ic_folder_open.xml b/app/src/main/res/drawable/ic_folder_open.xml new file mode 100644 index 000000000..4235565f3 --- /dev/null +++ b/app/src/main/res/drawable/ic_folder_open.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/menu/import_book.xml b/app/src/main/res/menu/import_book.xml new file mode 100644 index 000000000..8ace963eb --- /dev/null +++ b/app/src/main/res/menu/import_book.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b72122315..69ea3b49e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -480,7 +480,7 @@ 二字符缩进 三字符缩进 四字符缩进 - 选择SD卡 + 选择文件夹 没有发现,可以在书源里添加。 恢复默认 自定义缓存路径需要存储权限 From c0441217c67d8664f783a9d6878172b4eed288e9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 19:53:42 +0800 Subject: [PATCH 211/852] =?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/ui/importbook/ImportBookActivity.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 8cbce52f8..81c2df2ea 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -1,19 +1,50 @@ package io.legado.app.ui.importbook +import android.app.Activity +import android.content.Intent import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.utils.getViewModel class ImportBookActivity : VMBaseActivity(R.layout.activity_import_book) { + private val requestCodeSelectFolder = 342 override val viewModel: ImportBookViewModel get() = getViewModel(ImportBookViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { + initView() + } + + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.import_book, menu) + return super.onCompatCreateOptionsMenu(menu) + } + + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_select_folder -> { + } + } + return super.onCompatOptionsItemSelected(item) + } + + private fun initView() { + + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + requestCodeSelectFolder -> if (resultCode == Activity.RESULT_OK) { + } + } } } \ No newline at end of file From 8f6efffc1fbd9b10359b56887d7d6693bdf77401 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 20:28:57 +0800 Subject: [PATCH 212/852] =?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/AppConfig.kt | 10 +++++++--- .../app/ui/importbook/ImportBookActivity.kt | 18 +++++++++++++++++- .../main/res/layout/activity_import_book.xml | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index f51d7b479..02f84a838 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -40,10 +40,14 @@ object AppConfig { App.INSTANCE.putPrefInt(PreferKey.threadCount, value) } - var autoDarkMode: Boolean - get() = App.INSTANCE.getPrefBoolean(PreferKey.autoDarkMode) + var importBookPath: String? + get() = App.INSTANCE.getPrefString("importBookPath") set(value) { - App.INSTANCE.putPrefBoolean(PreferKey.autoDarkMode, value) + if (value == null) { + App.INSTANCE.removePref("importBookPath") + } else { + App.INSTANCE.putPrefString("importBookPath", value) + } } val isEInkMode: Boolean diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 81c2df2ea..697c57d14 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -2,23 +2,30 @@ package io.legado.app.ui.importbook import android.app.Activity import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem +import androidx.documentfile.provider.DocumentFile +import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.help.AppConfig import io.legado.app.utils.getViewModel +import kotlinx.android.synthetic.main.activity_import_book.* class ImportBookActivity : VMBaseActivity(R.layout.activity_import_book) { private val requestCodeSelectFolder = 342 + private var rootDoc: DocumentFile? = null + private val subDirs = arrayListOf() override val viewModel: ImportBookViewModel get() = getViewModel(ImportBookViewModel::class.java) - override fun onActivityCreated(savedInstanceState: Bundle?) { initView() + upPath() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -35,14 +42,23 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } private fun initView() { + recycler_view.layoutManager = LinearLayoutManager(this) + } + private fun upPath() { + AppConfig.importBookPath?.let { + val rootUri = Uri.parse(it) + rootDoc = DocumentFile.fromTreeUri(this, rootUri) + } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { requestCodeSelectFolder -> if (resultCode == Activity.RESULT_OK) { + data?.data?.let { + } } } } diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index a566d7a72..abccf0f01 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -49,7 +49,7 @@ From 81eda56ea9d92d14cb647ebc617989daac824cd6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 20:38:39 +0800 Subject: [PATCH 213/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/importbook/ImportBookActivity.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 697c57d14..42ffb491f 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -35,8 +35,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_select_folder -> { - } + R.id.menu_select_folder -> selectImportFolder() } return super.onCompatOptionsItemSelected(item) } @@ -52,6 +51,16 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } } + private fun selectImportFolder() { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, requestCodeSelectFolder) + } catch (e: Exception) { + e.printStackTrace() + } + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) when (requestCode) { From 985a53f86217afe784124267c52ba07b270f2e37 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 21:26:28 +0800 Subject: [PATCH 214/852] =?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 +- .../legado/app/ui/importbook/ImportBookActivity.kt | 13 +++++++++++++ app/src/main/res/layout/activity_import_book.xml | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cae1dac53..f5886b609 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -117,7 +117,7 @@ dependencies { implementation 'com.google.android:flexbox:1.1.0' //lifecycle - def lifecycle_version = '2.1.0' + def lifecycle_version = '2.2.0' implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 42ffb491f..4dcd75776 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -13,12 +13,14 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.help.AppConfig import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_import_book.* +import java.io.File class ImportBookActivity : VMBaseActivity(R.layout.activity_import_book) { private val requestCodeSelectFolder = 342 private var rootDoc: DocumentFile? = null private val subDirs = arrayListOf() + private lateinit var importBookAdapter: ImportBookAdapter override val viewModel: ImportBookViewModel get() = getViewModel(ImportBookViewModel::class.java) @@ -42,15 +44,26 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private fun initView() { recycler_view.layoutManager = LinearLayoutManager(this) + importBookAdapter = ImportBookAdapter(this) + recycler_view.adapter = importBookAdapter } private fun upPath() { AppConfig.importBookPath?.let { val rootUri = Uri.parse(it) rootDoc = DocumentFile.fromTreeUri(this, rootUri) + subDirs.clear() + tv_path.text = getPath() } } + private fun getPath(): String { + rootDoc?.let { + return it.name + File.separator + subDirs.joinToString(File.separator) + } + return "" + } + private fun selectImportFolder() { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index abccf0f01..e3fd0cef3 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -21,7 +21,7 @@ android:orientation="horizontal"> Date: Wed, 29 Jan 2020 21:30:06 +0800 Subject: [PATCH 215/852] =?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/importbook/ImportBookActivity.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 4dcd75776..191dbc10a 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -79,7 +79,12 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity when (requestCode) { requestCodeSelectFolder -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { - + contentResolver.takePersistableUriPermission( + it, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + AppConfig.importBookPath = it.toString() + upPath() } } } From 02d3b2ae06d9a8cb59816bb67b91284699519ff5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 29 Jan 2020 21:37:28 +0800 Subject: [PATCH 216/852] =?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/res/layout/activity_import_book.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index e3fd0cef3..d6882abb9 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -86,6 +86,7 @@ android:layout_width="70dp" android:layout_height="35dp" android:layout_centerVertical="true" + android:layout_marginLeft="10dp" android:gravity="center" android:layout_toLeftOf="@id/file_system_btn_add_book" android:text="@string/delete" /> From 4e21a1ce19f360cb607906f8853d9fced3196771 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 11:12:43 +0800 Subject: [PATCH 217/852] =?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/res/layout/activity_import_book.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index d6882abb9..820fef31d 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -15,9 +15,11 @@ From 361b5ae800902a9bc622e4195c02af1432c3da2a Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 11:18:38 +0800 Subject: [PATCH 218/852] =?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/importbook/ImportBookActivity.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 191dbc10a..16ea5ded3 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -59,7 +59,11 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private fun getPath(): String { rootDoc?.let { - return it.name + File.separator + subDirs.joinToString(File.separator) + var path = it.name + File.separator + subDirs.joinToString(File.separator) + if (!path.endsWith(File.separator)) { + path += File.separator + } + return path } return "" } From a9a14ce8b109323b3542d5019249855032c85ddd Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 12:32:52 +0800 Subject: [PATCH 219/852] =?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/ui/importbook/ImportBookActivity.kt | 29 +++++-- .../app/ui/importbook/ImportBookAdapter.kt | 28 +++++- app/src/main/res/layout/item_import_book.xml | 86 ++++++++++++++++++- 3 files changed, 131 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 16ea5ded3..286549dda 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -16,7 +16,8 @@ import kotlinx.android.synthetic.main.activity_import_book.* import java.io.File -class ImportBookActivity : VMBaseActivity(R.layout.activity_import_book) { +class ImportBookActivity : VMBaseActivity(R.layout.activity_import_book), + ImportBookAdapter.CallBack { private val requestCodeSelectFolder = 342 private var rootDoc: DocumentFile? = null private val subDirs = arrayListOf() @@ -27,7 +28,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity override fun onActivityCreated(savedInstanceState: Bundle?) { initView() - upPath() + upRootDoc() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -44,28 +45,34 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private fun initView() { recycler_view.layoutManager = LinearLayoutManager(this) - importBookAdapter = ImportBookAdapter(this) + importBookAdapter = ImportBookAdapter(this, this) recycler_view.adapter = importBookAdapter } - private fun upPath() { + private fun upRootDoc() { AppConfig.importBookPath?.let { val rootUri = Uri.parse(it) rootDoc = DocumentFile.fromTreeUri(this, rootUri) subDirs.clear() - tv_path.text = getPath() + upPath() } } - private fun getPath(): String { + private fun upPath() { rootDoc?.let { var path = it.name + File.separator + subDirs.joinToString(File.separator) if (!path.endsWith(File.separator)) { path += File.separator } - return path + tv_path.text = path + var doc = rootDoc + for (dirName in subDirs) { + doc = rootDoc?.findFile(dirName) + } + doc?.listFiles()?.let { + importBookAdapter.setItems(it.toList()) + } } - return "" } private fun selectImportFolder() { @@ -88,10 +95,14 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.importBookPath = it.toString() - upPath() + upRootDoc() } } } } + override fun findFolder(dirName: String) { + subDirs.add(dirName) + upPath() + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 29ac7e579..124071266 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -5,14 +5,40 @@ import androidx.documentfile.provider.DocumentFile import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.utils.invisible +import io.legado.app.utils.visible +import kotlinx.android.synthetic.main.item_import_book.view.* +import org.jetbrains.anko.sdk27.listeners.onClick -class ImportBookAdapter(context: Context) : +class ImportBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_import_book) { override fun convert(holder: ItemViewHolder, item: DocumentFile, payloads: MutableList) { + holder.itemView.apply { + if (item.isDirectory) { + iv_icon.visible() + cb_select.invisible() + } else { + iv_icon.invisible() + cb_select.visible() + } + tv_name.text = item.name + onClick { + item.name?.let { name -> + if (item.isDirectory) { + callBack.findFolder(name) + } else { + } + } + } + } + } + + interface CallBack { + fun findFolder(dirName: String) } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_import_book.xml b/app/src/main/res/layout/item_import_book.xml index f14841ad0..abd638413 100644 --- a/app/src/main/res/layout/item_import_book.xml +++ b/app/src/main/res/layout/item_import_book.xml @@ -1,8 +1,90 @@ + android:layout_height="60dp" + android:background="@drawable/selector_common_bg" + android:orientation="horizontal" + android:baselineAligned="false"> + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 7ee45823039e99fc29cb45677515a2884fb0f3c9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 12:44:44 +0800 Subject: [PATCH 220/852] =?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/ui/importbook/ImportBookActivity.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 286549dda..1d83fcbe0 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.importbook +import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.net.Uri @@ -58,16 +59,16 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } } + @SuppressLint("SetTextI18n") private fun upPath() { - rootDoc?.let { - var path = it.name + File.separator + subDirs.joinToString(File.separator) - if (!path.endsWith(File.separator)) { - path += File.separator - } - tv_path.text = path - var doc = rootDoc + rootDoc?.let { rootDoc -> + tv_path.text = rootDoc.name.toString() + File.separator + var doc: DocumentFile? = rootDoc for (dirName in subDirs) { - doc = rootDoc?.findFile(dirName) + doc = doc?.findFile(dirName) + doc?.let { + tv_path.text = tv_path.text.toString() + it.name + File.separator + } } doc?.listFiles()?.let { importBookAdapter.setItems(it.toList()) From c1f51e3bd40e66f9b8aa0446310ad7995844f848 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 12:53:49 +0800 Subject: [PATCH 221/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/importbook/ImportBookActivity.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 1d83fcbe0..e1586bda4 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -106,4 +106,13 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity subDirs.add(dirName) upPath() } + + override fun onBackPressed() { + if (subDirs.isNotEmpty()) { + subDirs.removeAt(subDirs.lastIndex) + upPath() + } else { + super.onBackPressed() + } + } } \ No newline at end of file From 5b7c6bcaabbe12faf86cbae8c28236eee6d7042a Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 13:02:46 +0800 Subject: [PATCH 222/852] =?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/base/BaseActivity.kt | 9 ++++++--- .../java/io/legado/app/ui/book/info/BookInfoActivity.kt | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 048036892..e0d4713d7 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -52,9 +52,12 @@ abstract class BaseActivity( } ?: super.onCreateOptionsMenu(menu) } - override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { - menu.applyOpenTint(this) - return super.onMenuOpened(featureId, menu) + override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { + menu?.let { + menu.applyOpenTint(this) + return super.onMenuOpened(featureId, menu) + } + return true } open fun onCompatCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 57839f1c9..fb689519c 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -98,8 +98,8 @@ class BookInfoActivity : return super.onCompatOptionsItemSelected(item) } - override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { - menu.findItem(R.id.menu_can_update)?.isChecked = + override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { + menu?.findItem(R.id.menu_can_update)?.isChecked = viewModel.bookData.value?.canUpdate ?: true return super.onMenuOpened(featureId, menu) } From 616611db6afa6474829c3391772120214e1fe051 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 13:57:37 +0800 Subject: [PATCH 223/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/http/HttpHelper.kt | 14 +++++++++--- .../book/source/manage/BookSourceViewModel.kt | 22 ++++++++----------- .../ui/replacerule/ReplaceRuleViewModel.kt | 10 ++++++++- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index da70b17a7..3e6d6c3ab 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -1,5 +1,7 @@ package io.legado.app.help.http +import io.legado.app.data.api.IHttpGetApi +import io.legado.app.utils.NetworkUtils import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.* import retrofit2.Retrofit @@ -35,11 +37,17 @@ object HttpHelper { builder.build() } - inline fun getApiService(baseUrl: String): T { - return getRetrofit(baseUrl).create(T::class.java) + fun simpleGet(url: String, encode: String? = null): String? { + NetworkUtils.getBaseUrl(url)?.let { baseUrl -> + val response = getApiService(baseUrl, encode) + .get(url, mapOf()) + .execute() + return response.body() + } + return null } - inline fun getApiService(baseUrl: String, encode: String): T { + inline fun getApiService(baseUrl: String, encode: String? = null): T { return getRetrofit(baseUrl, encode).create(T::class.java) } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 06edf4033..554ae4165 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -5,7 +5,6 @@ import android.text.TextUtils import com.jayway.jsonpath.JsonPath import io.legado.app.App import io.legado.app.base.BaseViewModel -import io.legado.app.data.api.IHttpGetApi import io.legado.app.data.entities.BookSource import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Backup @@ -202,20 +201,17 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) } private fun importSourceUrl(url: String): Int { - NetworkUtils.getBaseUrl(url)?.let { - val response = HttpHelper.getApiService(it).get(url, mapOf()).execute() - response.body()?.let { body -> - val bookSources = mutableListOf() - val items: List> = jsonPath.parse(body).read("$") - for (item in items) { - val jsonItem = jsonPath.parse(item) - OldRule.jsonToBookSource(jsonItem.jsonString())?.let { source -> - bookSources.add(source) - } + HttpHelper.simpleGet(url)?.let { body -> + val bookSources = mutableListOf() + val items: List> = jsonPath.parse(body).read("$") + for (item in items) { + val jsonItem = jsonPath.parse(item) + OldRule.jsonToBookSource(jsonItem.jsonString())?.let { source -> + bookSources.add(source) } - App.db.bookSourceDao().insert(*bookSources.toTypedArray()) - return bookSources.size } + App.db.bookSourceDao().insert(*bookSources.toTypedArray()) + return bookSources.size } return 0 } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 00a279a33..f8c9dda24 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -6,10 +6,12 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.ReplaceRule +import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON +import io.legado.app.utils.isAbsUrl import io.legado.app.utils.splitNotBlank import org.jetbrains.anko.toast import java.io.File @@ -18,7 +20,13 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application fun importSource(text: String, showMsg: (msg: String) -> Unit) { execute { - Restore.importOldReplaceRule(text) + if (text.isAbsUrl()) { + HttpHelper.simpleGet(text)?.let { + Restore.importOldReplaceRule(it) + } + } else { + Restore.importOldReplaceRule(text) + } }.onError { showMsg(it.localizedMessage ?: "ERROR") }.onSuccess { From fb5d88a05454b499d2a8826ee994bc1fe98a8329 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 14:05:16 +0800 Subject: [PATCH 224/852] =?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/assets/updateLog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 80066583d..a7f4ef2cd 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,11 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/30** +* 优化缓存文件夹选择,不再需要存储权限 +* 修复替换净化导入报错的bug +* 正在写本地导入,还没写完 + **2020/01/27** * 添加根据系统主题切换夜间模式 * 合并Modificator提交的代码 From 8d52168468091facabadeda227c8d9a5cb6ff309 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 15:15:08 +0800 Subject: [PATCH 225/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rss/source/manage/RssSourceViewModel.kt | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index bf82505d3..bed9a6e62 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -6,7 +6,6 @@ import com.jayway.jsonpath.JsonPath import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseViewModel -import io.legado.app.data.api.IHttpGetApi import io.legado.app.data.entities.RssSource import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Backup @@ -174,20 +173,18 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) } private fun importSourceUrl(url: String): Int { - NetworkUtils.getBaseUrl(url)?.let { - val response = HttpHelper.getApiService(it).get(url, mapOf()).execute() - response.body()?.let { body -> - val sources = mutableListOf() - val items: List> = jsonPath.parse(body).read("$") - for (item in items) { - val jsonItem = jsonPath.parse(item) - GSON.fromJsonObject(jsonItem.jsonString())?.let { source -> - sources.add(source) - } + HttpHelper.simpleGet(url)?.let { body -> + val sources = mutableListOf() + val items: List> = jsonPath.parse(body).read("$") + for (item in items) { + val jsonItem = jsonPath.parse(item) + GSON.fromJsonObject(jsonItem.jsonString())?.let { source -> + sources.add(source) } - App.db.rssSourceDao().insert(*sources.toTypedArray()) - return sources.size } + App.db.rssSourceDao().insert(*sources.toTypedArray()) + return sources.size + } return 0 } From bee89db3ddc9ffb0921925d1f2854775a60df2df Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 15:23:40 +0800 Subject: [PATCH 226/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainViewModel.kt | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 27b37fe1a..960f860c1 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -4,13 +4,11 @@ import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.constant.Bus -import io.legado.app.data.api.IHttpGetApi import io.legado.app.data.entities.RssSource import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Restore import io.legado.app.model.WebBook import io.legado.app.utils.GSON -import io.legado.app.utils.NetworkUtils import io.legado.app.utils.fromJsonObject import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO @@ -58,20 +56,16 @@ class MainViewModel(application: Application) : BaseViewModel(application) { fun initRss() { execute { val url = "https://gitee.com/alanskycn/yuedu/raw/master/JS/RSS/rssSource" - NetworkUtils.getBaseUrl(url)?.let { - val response = - HttpHelper.getApiService(it).getAsync(url, mapOf()).await() - response.body()?.let { body -> - val sources = mutableListOf() - val items: List> = Restore.jsonPath.parse(body).read("$") - for (item in items) { - val jsonItem = Restore.jsonPath.parse(item) - GSON.fromJsonObject(jsonItem.jsonString())?.let { source -> - sources.add(source) - } + HttpHelper.simpleGet(url)?.let { body -> + val sources = mutableListOf() + val items: List> = Restore.jsonPath.parse(body).read("$") + for (item in items) { + val jsonItem = Restore.jsonPath.parse(item) + GSON.fromJsonObject(jsonItem.jsonString())?.let { source -> + sources.add(source) } - App.db.rssSourceDao().insert(*sources.toTypedArray()) } + App.db.rssSourceDao().insert(*sources.toTypedArray()) } } } From 943186974c28ae5ec91779ebfe15db11bd823eaf Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 16:46:59 +0800 Subject: [PATCH 227/852] =?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/ui/importbook/ImportBookActivity.kt | 17 +++++++++++++++++ .../main/res/layout/activity_import_book.xml | 8 ++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index e1586bda4..b2b5cdca9 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -14,6 +14,7 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.help.AppConfig import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_import_book.* +import org.jetbrains.anko.sdk27.listeners.onClick import java.io.File @@ -29,6 +30,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity override fun onActivityCreated(savedInstanceState: Bundle?) { initView() + initEvent() upRootDoc() } @@ -50,6 +52,21 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity recycler_view.adapter = importBookAdapter } + private fun initEvent() { + tv_go_back.onClick { + if (subDirs.isNotEmpty()) { + subDirs.removeAt(subDirs.lastIndex) + upPath() + } + } + btn_add_book.onClick { + + } + btn_delete.onClick { + + } + } + private fun upRootDoc() { AppConfig.importBookPath?.let { val rootUri = Uri.parse(it) diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index 820fef31d..4167ab86f 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -68,7 +68,7 @@ tools:ignore="RtlHardcoded,RtlSymmetry"> From 4f65b80efcf95c272ffc60df7c3439daa2651217 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 16:58:07 +0800 Subject: [PATCH 228/852] =?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/ui/importbook/ImportBookAdapter.kt | 2 +- app/src/main/res/layout/item_import_book.xml | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 124071266..fde0fba88 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -30,7 +30,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : if (item.isDirectory) { callBack.findFolder(name) } else { - + cb_select.isChecked = !cb_select.isChecked } } } diff --git a/app/src/main/res/layout/item_import_book.xml b/app/src/main/res/layout/item_import_book.xml index abd638413..4beb7b6a0 100644 --- a/app/src/main/res/layout/item_import_book.xml +++ b/app/src/main/res/layout/item_import_book.xml @@ -11,6 +11,15 @@ + + - - Date: Thu, 30 Jan 2020 20:33:59 +0800 Subject: [PATCH 229/852] =?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/ui/importbook/ImportBookAdapter.kt | 13 +++++++++++++ .../main/java/io/legado/app/utils/StringUtils.kt | 16 ++++++++++++++++ app/src/main/res/layout/item_import_book.xml | 3 +++ 3 files changed, 32 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index fde0fba88..d872dd169 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -5,10 +5,14 @@ import androidx.documentfile.provider.DocumentFile import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.constant.AppConst +import io.legado.app.utils.StringUtils +import io.legado.app.utils.gone import io.legado.app.utils.invisible import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_import_book.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import java.util.* class ImportBookAdapter(context: Context, val callBack: CallBack) : @@ -20,9 +24,18 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : if (item.isDirectory) { iv_icon.visible() cb_select.invisible() + ll_brief.gone() + tv_sub_count.visible() + tv_sub_count.text = + context.getString(R.string.nb_file_sub_count, item.listFiles().size) } else { iv_icon.invisible() cb_select.visible() + ll_brief.visible() + tv_sub_count.gone() + tv_tag.text = item.name?.substringAfterLast(".") + tv_size.text = StringUtils.toSize(item.length()) + tv_date.text = AppConst.DATE_FORMAT.format(Date(item.lastModified())) } tv_name.text = item.name onClick { diff --git a/app/src/main/java/io/legado/app/utils/StringUtils.kt b/app/src/main/java/io/legado/app/utils/StringUtils.kt index 95096c087..46053cad8 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -2,12 +2,15 @@ package io.legado.app.utils import android.annotation.SuppressLint import android.text.TextUtils.isEmpty +import java.text.DecimalFormat import java.text.ParseException import java.text.SimpleDateFormat import java.util.* import java.util.regex.Matcher import java.util.regex.Pattern import kotlin.math.abs +import kotlin.math.log10 +import kotlin.math.pow object StringUtils { private const val HOUR_OF_DAY = 24 @@ -97,6 +100,19 @@ object StringUtils { return "" } + fun toSize(length: Long): String { + if (length <= 0) return "0" + val units = arrayOf("b", "kb", "M", "G", "T") + //计算单位的,原理是利用lg,公式是 lg(1024^n) = nlg(1024),最后 nlg(1024)/lg(1024) = n。 + //计算单位的,原理是利用lg,公式是 lg(1024^n) = nlg(1024),最后 nlg(1024)/lg(1024) = n。 + val digitGroups = + (log10(length.toDouble()) / log10(1024.0)).toInt() + //计算原理是,size/单位值。单位值指的是:比如说b = 1024,KB = 1024^2 + //计算原理是,size/单位值。单位值指的是:比如说b = 1024,KB = 1024^2 + return DecimalFormat("#,##0.##") + .format(length / 1024.0.pow(digitGroups.toDouble())) + " " + units[digitGroups] + } + @SuppressLint("DefaultLocale") fun toFirstCapital(str: String): String { return str.substring(0, 1).toUpperCase() + str.substring(1) diff --git a/app/src/main/res/layout/item_import_book.xml b/app/src/main/res/layout/item_import_book.xml index 4beb7b6a0..882274b2d 100644 --- a/app/src/main/res/layout/item_import_book.xml +++ b/app/src/main/res/layout/item_import_book.xml @@ -62,6 +62,9 @@ android:paddingStart="5dp" android:paddingEnd="5dp" android:text="TXT" + android:maxLines="1" + android:maxWidth="50dp" + app:abt_radius="2dp" tools:ignore="HardcodedText,RtlHardcoded" /> Date: Thu, 30 Jan 2020 20:49:31 +0800 Subject: [PATCH 230/852] =?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/utils/ViewModelKt.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/ViewModelKt.kt b/app/src/main/java/io/legado/app/utils/ViewModelKt.kt index b777c8bbf..0b76009cf 100644 --- a/app/src/main/java/io/legado/app/utils/ViewModelKt.kt +++ b/app/src/main/java/io/legado/app/utils/ViewModelKt.kt @@ -3,14 +3,15 @@ package io.legado.app.utils import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProviders +import androidx.lifecycle.ViewModelProvider -fun AppCompatActivity.getViewModel(clazz: Class) = ViewModelProviders.of(this).get(clazz) +fun AppCompatActivity.getViewModel(clazz: Class) = + ViewModelProvider(this).get(clazz) -fun Fragment.getViewModel(clazz: Class) = ViewModelProviders.of(this).get(clazz) +fun Fragment.getViewModel(clazz: Class) = ViewModelProvider(this).get(clazz) /** * 与activity数据同步 */ fun Fragment.getViewModelOfActivity(clazz: Class) = - ViewModelProviders.of(requireActivity()).get(clazz) \ No newline at end of file + ViewModelProvider(requireActivity()).get(clazz) \ No newline at end of file From 427eac43137e33cdfe8eafaea37269fd8f33f1d4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 20:51:44 +0800 Subject: [PATCH 231/852] =?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/utils/ViewModelKt.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/utils/ViewModelKt.kt b/app/src/main/java/io/legado/app/utils/ViewModelKt.kt index 0b76009cf..9e1f74f24 100644 --- a/app/src/main/java/io/legado/app/utils/ViewModelKt.kt +++ b/app/src/main/java/io/legado/app/utils/ViewModelKt.kt @@ -8,7 +8,8 @@ import androidx.lifecycle.ViewModelProvider fun AppCompatActivity.getViewModel(clazz: Class) = ViewModelProvider(this).get(clazz) -fun Fragment.getViewModel(clazz: Class) = ViewModelProvider(this).get(clazz) +fun Fragment.getViewModel(clazz: Class) = + ViewModelProvider(this).get(clazz) /** * 与activity数据同步 From 0aafde21e4f7b8f04dfb406be59697a346efdf0b Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 21:04:29 +0800 Subject: [PATCH 232/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/importbook/ImportBookActivity.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index b2b5cdca9..cbd7863eb 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -87,9 +87,13 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity tv_path.text = tv_path.text.toString() + it.name + File.separator } } - doc?.listFiles()?.let { - importBookAdapter.setItems(it.toList()) + val docList = arrayListOf() + doc?.listFiles()?.forEach { + if (it.isDirectory || it.name?.endsWith(".txt", true) == true) { + docList.add(it) + } } + importBookAdapter.setItems(docList) } } From bee2a59594e8abc2e68063e34e66ff88d79e995b Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 21:37:37 +0800 Subject: [PATCH 233/852] =?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/ui/importbook/ImportBookActivity.kt | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index cbd7863eb..cf8843600 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -14,6 +14,10 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.help.AppConfig import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_import_book.* +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.jetbrains.anko.sdk27.listeners.onClick import java.io.File @@ -79,21 +83,27 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity @SuppressLint("SetTextI18n") private fun upPath() { rootDoc?.let { rootDoc -> - tv_path.text = rootDoc.name.toString() + File.separator - var doc: DocumentFile? = rootDoc - for (dirName in subDirs) { - doc = doc?.findFile(dirName) - doc?.let { - tv_path.text = tv_path.text.toString() + it.name + File.separator + launch(IO) { + var path = rootDoc.name.toString() + File.separator + var doc: DocumentFile? = rootDoc + for (dirName in subDirs) { + doc = doc?.findFile(dirName) + doc?.let { + path = path + it.name + File.separator + } } - } - val docList = arrayListOf() - doc?.listFiles()?.forEach { - if (it.isDirectory || it.name?.endsWith(".txt", true) == true) { - docList.add(it) + val docList = arrayListOf() + doc?.listFiles()?.forEach { + if (it.isDirectory || it.name?.endsWith(".txt", true) == true) { + docList.add(it) + } + } + docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) + withContext(Main) { + tv_path.text = path + importBookAdapter.setItems(docList) } } - importBookAdapter.setItems(docList) } } From ee66194c155f6741bbbad616e5d1ac2eb24ab65c Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 21:58:42 +0800 Subject: [PATCH 234/852] =?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/ui/importbook/ImportBookActivity.kt | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index cf8843600..f56429d5f 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -14,10 +14,6 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.help.AppConfig import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_import_book.* -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.jetbrains.anko.sdk27.listeners.onClick import java.io.File @@ -58,10 +54,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private fun initEvent() { tv_go_back.onClick { - if (subDirs.isNotEmpty()) { - subDirs.removeAt(subDirs.lastIndex) - upPath() - } + goBackDir() } btn_add_book.onClick { @@ -81,29 +74,26 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } @SuppressLint("SetTextI18n") + @Synchronized private fun upPath() { rootDoc?.let { rootDoc -> - launch(IO) { - var path = rootDoc.name.toString() + File.separator - var doc: DocumentFile? = rootDoc - for (dirName in subDirs) { - doc = doc?.findFile(dirName) - doc?.let { - path = path + it.name + File.separator - } - } - val docList = arrayListOf() - doc?.listFiles()?.forEach { - if (it.isDirectory || it.name?.endsWith(".txt", true) == true) { - docList.add(it) - } + var path = rootDoc.name.toString() + File.separator + var doc: DocumentFile? = rootDoc + for (dirName in subDirs) { + doc = doc?.findFile(dirName) + doc?.let { + path = path + it.name + File.separator } - docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) - withContext(Main) { - tv_path.text = path - importBookAdapter.setItems(docList) + } + val docList = arrayListOf() + doc?.listFiles()?.forEach { + if (it.isDirectory || it.name?.endsWith(".txt", true) == true) { + docList.add(it) } } + docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) + tv_path.text = path + importBookAdapter.setItems(docList) } } @@ -133,16 +123,25 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } } + @Synchronized override fun findFolder(dirName: String) { subDirs.add(dirName) upPath() } - override fun onBackPressed() { - if (subDirs.isNotEmpty()) { + @Synchronized + private fun goBackDir(): Boolean { + return if (subDirs.isNotEmpty()) { subDirs.removeAt(subDirs.lastIndex) upPath() + true } else { + false + } + } + + override fun onBackPressed() { + if (!goBackDir()) { super.onBackPressed() } } From 563f989703df274e7aecff2c279ab72c1dd35b73 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 30 Jan 2020 22:35:11 +0800 Subject: [PATCH 235/852] =?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/importbook/ImportBookActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index f56429d5f..24de12ebd 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -87,7 +87,9 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } val docList = arrayListOf() doc?.listFiles()?.forEach { - if (it.isDirectory || it.name?.endsWith(".txt", true) == true) { + if (it.isDirectory && it.name?.startsWith(".") == false) { + docList.add(it) + } else if (it.name?.endsWith(".txt", true) == true) { docList.add(it) } } From f7e731ce405b3f996ffca585ee306d887eab8ca7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 10:43:18 +0800 Subject: [PATCH 236/852] =?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/ui/importbook/ImportBookAdapter.kt | 4 --- app/src/main/res/layout/item_import_book.xml | 25 ++++++++----------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index d872dd169..a5eb9251c 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -25,14 +25,10 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : iv_icon.visible() cb_select.invisible() ll_brief.gone() - tv_sub_count.visible() - tv_sub_count.text = - context.getString(R.string.nb_file_sub_count, item.listFiles().size) } else { iv_icon.invisible() cb_select.visible() ll_brief.visible() - tv_sub_count.gone() tv_tag.text = item.name?.substringAfterLast(".") tv_size.text = StringUtils.toSize(item.length()) tv_date.text = AppConst.DATE_FORMAT.format(Date(item.lastModified())) diff --git a/app/src/main/res/layout/item_import_book.xml b/app/src/main/res/layout/item_import_book.xml index 882274b2d..e467aab97 100644 --- a/app/src/main/res/layout/item_import_book.xml +++ b/app/src/main/res/layout/item_import_book.xml @@ -31,26 +31,28 @@ app:tint="@color/tv_text_default" /> - + android:orientation="vertical"> + android:textSize="16sp" + android:gravity="center_vertical" + tools:ignore="NestedWeights" /> @@ -82,12 +84,5 @@ tools:text="2017-05-22" /> - - + \ No newline at end of file From aa496ea3826fd0bd03dd5f6c5eb29d9bca99bf96 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 11:11:04 +0800 Subject: [PATCH 237/852] =?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/data/dao/BookDao.kt | 3 +++ .../app/ui/importbook/ImportBookActivity.kt | 13 +++++++++++++ .../app/ui/importbook/ImportBookAdapter.kt | 18 ++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 68de17a66..303be7d5c 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -17,6 +17,9 @@ interface BookDao { @Query("SELECT * FROM books WHERE origin = '${BookType.local}' order by durChapterTime desc") fun observeLocal(): LiveData> + @Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}' order by durChapterTime desc") + fun observeLocalUri(): LiveData> + @Query("SELECT * FROM books WHERE origin <> '${BookType.local}' and type = 0 order by durChapterTime desc") fun observeDownload(): LiveData> diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 24de12ebd..58c8aec0f 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -8,7 +8,10 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import androidx.documentfile.provider.DocumentFile +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.help.AppConfig @@ -24,6 +27,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private var rootDoc: DocumentFile? = null private val subDirs = arrayListOf() private lateinit var importBookAdapter: ImportBookAdapter + private var localUriLiveData: LiveData>? = null override val viewModel: ImportBookViewModel get() = getViewModel(ImportBookViewModel::class.java) @@ -31,6 +35,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity override fun onActivityCreated(savedInstanceState: Bundle?) { initView() initEvent() + initData() upRootDoc() } @@ -64,6 +69,14 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } } + private fun initData() { + localUriLiveData?.removeObservers(this) + localUriLiveData = App.db.bookDao().observeLocalUri() + localUriLiveData?.observe(this, Observer { + importBookAdapter.upBookHas(it) + }) + } + private fun upRootDoc() { AppConfig.importBookPath?.let { val rootUri = Uri.parse(it) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index a5eb9251c..40cc5b8b5 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -18,16 +18,30 @@ import java.util.* class ImportBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_import_book) { + private var localUri = arrayListOf() + + fun upBookHas(uriList: List) { + localUri.clear() + localUri.addAll(uriList) + notifyDataSetChanged() + } override fun convert(holder: ItemViewHolder, item: DocumentFile, payloads: MutableList) { holder.itemView.apply { if (item.isDirectory) { + iv_icon.setImageResource(R.drawable.ic_folder) iv_icon.visible() cb_select.invisible() ll_brief.gone() } else { - iv_icon.invisible() - cb_select.visible() + if (localUri.contains(item.uri.toString())) { + iv_icon.setImageResource(R.drawable.ic_book_has) + iv_icon.visible() + cb_select.invisible() + } else { + iv_icon.invisible() + cb_select.visible() + } ll_brief.visible() tv_tag.text = item.name?.substringAfterLast(".") tv_size.text = StringUtils.toSize(item.length()) From 46abd120cd8f8eade54b7b21a5bac7ebc9a0c544 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 11:20:38 +0800 Subject: [PATCH 238/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/importbook/ImportBookActivity.kt | 1 + .../java/io/legado/app/ui/importbook/ImportBookAdapter.kt | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 58c8aec0f..297715822 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -108,6 +108,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) tv_path.text = path + importBookAdapter.selectedUris.clear() importBookAdapter.setItems(docList) } } diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 40cc5b8b5..5c80057d4 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -17,7 +17,7 @@ import java.util.* class ImportBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_import_book) { - + var selectedUris = linkedSetOf() private var localUri = arrayListOf() fun upBookHas(uriList: List) { @@ -48,12 +48,18 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : tv_date.text = AppConst.DATE_FORMAT.format(Date(item.lastModified())) } tv_name.text = item.name + cb_select.isChecked = selectedUris.contains(item.uri.toString()) onClick { item.name?.let { name -> if (item.isDirectory) { callBack.findFolder(name) } else { cb_select.isChecked = !cb_select.isChecked + if (cb_select.isChecked) { + selectedUris.add(item.uri.toString()) + } else { + selectedUris.remove(item.uri.toString()) + } } } } From 2fe5dd57e86aaaf9bc787d308037ba54deefd041 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 11:23:27 +0800 Subject: [PATCH 239/852] =?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/res/layout/item_import_book.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/res/layout/item_import_book.xml b/app/src/main/res/layout/item_import_book.xml index e467aab97..67ac3aeda 100644 --- a/app/src/main/res/layout/item_import_book.xml +++ b/app/src/main/res/layout/item_import_book.xml @@ -35,6 +35,8 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" + android:paddingTop="5dp" + android:paddingBottom="5dp" android:orientation="vertical"> Date: Fri, 31 Jan 2020 12:08:56 +0800 Subject: [PATCH 240/852] =?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/ui/importbook/ImportBookActivity.kt | 22 +++++++++++++++++++ .../app/ui/importbook/ImportBookAdapter.kt | 1 + 2 files changed, 23 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 297715822..5d3fb2810 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -161,4 +161,26 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity super.onBackPressed() } } + + override fun upCountView() { + if (importBookAdapter.selectedUris.isEmpty()) { + btn_add_book.setText(R.string.nb_file_add_shelf) + //设置某些按钮的是否可点击 + setMenuClickable(false) + } else { + btn_add_book.text = + getString(R.string.nb_file_add_shelves, importBookAdapter.selectedUris.size) + //设置某些按钮的是否可点击 + setMenuClickable(true) + } + } + + private fun setMenuClickable(isClickable: Boolean) { + //设置是否可删除 + btn_delete.isEnabled = isClickable + btn_delete.isClickable = isClickable + //设置是否可添加书籍 + btn_add_book.isEnabled = isClickable + btn_add_book.isClickable = isClickable + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 5c80057d4..02645acc3 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -68,6 +68,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : interface CallBack { fun findFolder(dirName: String) + fun upCountView() } } \ No newline at end of file From 5ccf4b8e2cd853e0b33bbda82cbcee4d80332071 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 12:15:38 +0800 Subject: [PATCH 241/852] =?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/ui/importbook/ImportBookActivity.kt | 24 +++++++++---------- .../app/ui/importbook/ImportBookAdapter.kt | 18 +++++++------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 5d3fb2810..ad6b67419 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -25,7 +25,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity ImportBookAdapter.CallBack { private val requestCodeSelectFolder = 342 private var rootDoc: DocumentFile? = null - private val subDirs = arrayListOf() + private val subDocs = arrayListOf() private lateinit var importBookAdapter: ImportBookAdapter private var localUriLiveData: LiveData>? = null @@ -81,7 +81,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity AppConfig.importBookPath?.let { val rootUri = Uri.parse(it) rootDoc = DocumentFile.fromTreeUri(this, rootUri) - subDirs.clear() + subDocs.clear() upPath() } } @@ -91,15 +91,13 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private fun upPath() { rootDoc?.let { rootDoc -> var path = rootDoc.name.toString() + File.separator - var doc: DocumentFile? = rootDoc - for (dirName in subDirs) { - doc = doc?.findFile(dirName) - doc?.let { - path = path + it.name + File.separator - } + var lastDoc = rootDoc + for (doc in subDocs) { + lastDoc = doc + path = path + doc.name + File.separator } val docList = arrayListOf() - doc?.listFiles()?.forEach { + lastDoc.listFiles().forEach { if (it.isDirectory && it.name?.startsWith(".") == false) { docList.add(it) } else if (it.name?.endsWith(".txt", true) == true) { @@ -140,15 +138,15 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } @Synchronized - override fun findFolder(dirName: String) { - subDirs.add(dirName) + override fun nextDoc(doc: DocumentFile) { + subDocs.add(doc) upPath() } @Synchronized private fun goBackDir(): Boolean { - return if (subDirs.isNotEmpty()) { - subDirs.removeAt(subDirs.lastIndex) + return if (subDocs.isNotEmpty()) { + subDocs.removeAt(subDocs.lastIndex) upPath() true } else { diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 02645acc3..34ebd4e36 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -50,16 +50,14 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : tv_name.text = item.name cb_select.isChecked = selectedUris.contains(item.uri.toString()) onClick { - item.name?.let { name -> - if (item.isDirectory) { - callBack.findFolder(name) + if (item.isDirectory) { + callBack.nextDoc(item) + } else { + cb_select.isChecked = !cb_select.isChecked + if (cb_select.isChecked) { + selectedUris.add(item.uri.toString()) } else { - cb_select.isChecked = !cb_select.isChecked - if (cb_select.isChecked) { - selectedUris.add(item.uri.toString()) - } else { - selectedUris.remove(item.uri.toString()) - } + selectedUris.remove(item.uri.toString()) } } } @@ -67,7 +65,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : } interface CallBack { - fun findFolder(dirName: String) + fun nextDoc(doc: DocumentFile) fun upCountView() } From 3c9d0cf03e353d8b8c6d292c0494a685630882fb Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 13:11:59 +0800 Subject: [PATCH 242/852] =?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/importbook/ImportBookActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index ad6b67419..43cfd95a5 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -96,6 +96,9 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity lastDoc = doc path = path + doc.name + File.separator } + tv_path.text = path + importBookAdapter.selectedUris.clear() + val docList = arrayListOf() lastDoc.listFiles().forEach { if (it.isDirectory && it.name?.startsWith(".") == false) { @@ -105,8 +108,6 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } } docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) - tv_path.text = path - importBookAdapter.selectedUris.clear() importBookAdapter.setItems(docList) } } From 064f872cdb503790bd5f416f9eaf4c8debece294 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 13:33:00 +0800 Subject: [PATCH 243/852] =?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/ui/importbook/ImportBookActivity.kt | 30 +++++++++++++------ .../main/res/layout/activity_import_book.xml | 18 +++++++++-- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 43cfd95a5..1352268aa 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -15,8 +15,13 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.help.AppConfig +import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_import_book.* +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.jetbrains.anko.sdk27.listeners.onClick import java.io.File @@ -55,6 +60,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity recycler_view.layoutManager = LinearLayoutManager(this) importBookAdapter = ImportBookAdapter(this, this) recycler_view.adapter = importBookAdapter + rotate_loading.loadingColor = accentColor } private fun initEvent() { @@ -98,17 +104,23 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } tv_path.text = path importBookAdapter.selectedUris.clear() - - val docList = arrayListOf() - lastDoc.listFiles().forEach { - if (it.isDirectory && it.name?.startsWith(".") == false) { - docList.add(it) - } else if (it.name?.endsWith(".txt", true) == true) { - docList.add(it) + importBookAdapter.clearItems() + rotate_loading.show() + launch(IO) { + val docList = arrayListOf() + lastDoc.listFiles().forEach { + if (it.isDirectory && it.name?.startsWith(".") == false) { + docList.add(it) + } else if (it.name?.endsWith(".txt", true) == true) { + docList.add(it) + } + } + docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) + withContext(Main) { + rotate_loading.hide() + importBookAdapter.setItems(docList) } } - docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) - importBookAdapter.setItems(docList) } } diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index 4167ab86f..1d322fcfc 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -50,11 +50,23 @@ tools:ignore="UnusedAttribute" /> - + android:layout_weight="1"> + + + + + + Date: Fri, 31 Jan 2020 15:21:42 +0800 Subject: [PATCH 244/852] =?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/ui/importbook/ImportBookActivity.kt | 13 ++--- .../app/ui/importbook/ImportBookAdapter.kt | 22 +++----- .../java/io/legado/app/utils/DocumentUtils.kt | 56 +++++++++++++++++++ 3 files changed, 69 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 1352268aa..7fe292b31 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -16,6 +16,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.help.AppConfig import io.legado.app.lib.theme.accentColor +import io.legado.app.utils.DocumentUtils import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_import_book.* import kotlinx.coroutines.Dispatchers.IO @@ -107,15 +108,8 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity importBookAdapter.clearItems() rotate_loading.show() launch(IO) { - val docList = arrayListOf() - lastDoc.listFiles().forEach { - if (it.isDirectory && it.name?.startsWith(".") == false) { - docList.add(it) - } else if (it.name?.endsWith(".txt", true) == true) { - docList.add(it) - } - } - docList.sortWith(compareBy({ !it.isDirectory }, { it.name })) + val docList = DocumentUtils.listFiles(this@ImportBookActivity, lastDoc.uri) + docList.sortWith(compareBy({ !it.isDir }, { it.name })) withContext(Main) { rotate_loading.hide() importBookAdapter.setItems(docList) @@ -194,4 +188,5 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity btn_add_book.isEnabled = isClickable btn_add_book.isClickable = isClickable } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 34ebd4e36..14fe2d5a5 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -6,17 +6,13 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.AppConst -import io.legado.app.utils.StringUtils -import io.legado.app.utils.gone -import io.legado.app.utils.invisible -import io.legado.app.utils.visible +import io.legado.app.utils.* import kotlinx.android.synthetic.main.item_import_book.view.* import org.jetbrains.anko.sdk27.listeners.onClick -import java.util.* class ImportBookAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context, R.layout.item_import_book) { + SimpleRecyclerAdapter(context, R.layout.item_import_book) { var selectedUris = linkedSetOf() private var localUri = arrayListOf() @@ -26,9 +22,9 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : notifyDataSetChanged() } - override fun convert(holder: ItemViewHolder, item: DocumentFile, payloads: MutableList) { + override fun convert(holder: ItemViewHolder, item: DocItem, payloads: MutableList) { holder.itemView.apply { - if (item.isDirectory) { + if (item.isDir) { iv_icon.setImageResource(R.drawable.ic_folder) iv_icon.visible() cb_select.invisible() @@ -43,15 +39,15 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : cb_select.visible() } ll_brief.visible() - tv_tag.text = item.name?.substringAfterLast(".") - tv_size.text = StringUtils.toSize(item.length()) - tv_date.text = AppConst.DATE_FORMAT.format(Date(item.lastModified())) + tv_tag.text = item.name.substringAfterLast(".") + tv_size.text = StringUtils.toSize(item.size) + tv_date.text = AppConst.DATE_FORMAT.format(item.date) } tv_name.text = item.name cb_select.isChecked = selectedUris.contains(item.uri.toString()) onClick { - if (item.isDirectory) { - callBack.nextDoc(item) + if (item.isDir) { + callBack.nextDoc(DocumentFile.fromTreeUri(context, item.uri)!!) } else { cb_select.isChecked = !cb_select.isChecked if (cb_select.isChecked) { diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 8e74c63e0..15b1a7754 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -1,8 +1,11 @@ package io.legado.app.utils import android.content.Context +import android.database.Cursor import android.net.Uri +import android.provider.DocumentsContract import androidx.documentfile.provider.DocumentFile +import java.util.* object DocumentUtils { @@ -79,5 +82,58 @@ object DocumentUtils { return null } + fun listFiles(context: Context, uri: Uri): ArrayList { + val docList = arrayListOf() + val childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree( + uri, + DocumentsContract.getDocumentId(uri) + ) + var c: Cursor? = null + try { + c = context.contentResolver.query( + childrenUri, arrayOf( + DocumentsContract.Document.COLUMN_DOCUMENT_ID, + DocumentsContract.Document.COLUMN_DISPLAY_NAME, + DocumentsContract.Document.COLUMN_LAST_MODIFIED, + DocumentsContract.Document.COLUMN_SIZE, + DocumentsContract.Document.COLUMN_MIME_TYPE + ), null, null, null + ) + c?.let { + val ici = c.getColumnIndex(DocumentsContract.Document.COLUMN_DOCUMENT_ID) + val nci = c.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME) + val sci = c.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE) + val mci = c.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE) + val dci = c.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED) + c.moveToFirst() + do { + val item = DocItem( + name = c.getString(nci), + attr = c.getString(mci), + size = c.getLong(sci), + date = Date(c.getLong(dci)), + uri = DocumentsContract.buildDocumentUriUsingTree(uri, c.getString(ici)) + ) + docList.add(item) + } while (c.moveToNext()) + } + } catch (e: java.lang.Exception) { + } finally { + c?.close() + } + return docList + } +} + +data class DocItem( + val name: String, + val attr: String, + val size: Long, + val date: Date, + val uri: Uri +) { + val isDir: Boolean by lazy { + DocumentsContract.Document.MIME_TYPE_DIR == attr + } } \ No newline at end of file From 7e7655a7e1f50682d580d03be05778b80a695f5b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 15:48:04 +0800 Subject: [PATCH 245/852] =?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/AppConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 02f84a838..f8eb4f62e 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -35,7 +35,7 @@ object AppConfig { } var threadCount: Int - get() = App.INSTANCE.getPrefInt(PreferKey.threadCount) + get() = App.INSTANCE.getPrefInt(PreferKey.threadCount, 16) set(value) { App.INSTANCE.putPrefInt(PreferKey.threadCount, value) } From 4233f34b19872d0ab149e01f445603e8ea93a687 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 15:49:20 +0800 Subject: [PATCH 246/852] =?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/assets/updateLog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index a7f4ef2cd..605e0a482 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,10 +3,13 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/31** +* 正在写本地导入,还没写完 +* 修复搜索闪退,因为默认线程为0了 + **2020/01/30** * 优化缓存文件夹选择,不再需要存储权限 * 修复替换净化导入报错的bug -* 正在写本地导入,还没写完 **2020/01/27** * 添加根据系统主题切换夜间模式 From 6685e37f968ca20f1008d1d6f4085cae833054ae Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 17:03:10 +0800 Subject: [PATCH 247/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/importbook/ImportBookActivity.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 7fe292b31..c8f63b7e5 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -108,7 +108,18 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity importBookAdapter.clearItems() rotate_loading.show() launch(IO) { - val docList = DocumentUtils.listFiles(this@ImportBookActivity, lastDoc.uri) + val docList = DocumentUtils.listFiles( + this@ImportBookActivity, + lastDoc.uri + ) + for (i in docList.lastIndex downTo 0) { + val item = docList[i] + if (item.name.startsWith(".")) { + docList.removeAt(i) + } else if (!item.isDir && !item.name.endsWith(".txt", true)) { + docList.removeAt(i) + } + } docList.sortWith(compareBy({ !it.isDir }, { it.name })) withContext(Main) { rotate_loading.hide() From ec4f4c33a1dd5d2e8a70019874d4db49884882ea Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 17:11:58 +0800 Subject: [PATCH 248/852] =?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/main/my/MyFragment.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index d3ee247c7..e8b061144 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -69,6 +69,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { if (doc?.canWrite() == true) { launch { Backup.backup(requireContext(), uri) + toast(R.string.backup_success) } } else { selectBackupFolder() @@ -90,6 +91,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { .onGranted { launch { Backup.backup(requireContext(), null) + toast(R.string.backup_success) } } .request() @@ -147,6 +149,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { putPrefString(PreferKey.backupPath, uri.toString()) launch { Backup.backup(requireContext(), uri) + toast(R.string.backup_success) } } } From d940849decffcc07d7f3fa766c414f67f6703973 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 17:20:54 +0800 Subject: [PATCH 249/852] =?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/importbook/ImportBookAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 14fe2d5a5..5a028a8be 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -47,7 +47,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : cb_select.isChecked = selectedUris.contains(item.uri.toString()) onClick { if (item.isDir) { - callBack.nextDoc(DocumentFile.fromTreeUri(context, item.uri)!!) + callBack.nextDoc(DocumentFile.fromSingleUri(context, item.uri)!!) } else { cb_select.isChecked = !cb_select.isChecked if (cb_select.isChecked) { From e9d8cbf87bdfd9ad24d6837d1e4b81a289803369 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 17:55:42 +0800 Subject: [PATCH 250/852] =?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/ui/importbook/ImportBookActivity.kt | 34 ++++++++++---- .../app/ui/importbook/ImportBookAdapter.kt | 47 ++++++++++++++++--- 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index c8f63b7e5..6eb1c59eb 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -32,7 +32,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private val requestCodeSelectFolder = 342 private var rootDoc: DocumentFile? = null private val subDocs = arrayListOf() - private lateinit var importBookAdapter: ImportBookAdapter + private lateinit var adapter: ImportBookAdapter private var localUriLiveData: LiveData>? = null override val viewModel: ImportBookViewModel @@ -59,8 +59,8 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity private fun initView() { recycler_view.layoutManager = LinearLayoutManager(this) - importBookAdapter = ImportBookAdapter(this, this) - recycler_view.adapter = importBookAdapter + adapter = ImportBookAdapter(this, this) + recycler_view.adapter = adapter rotate_loading.loadingColor = accentColor } @@ -74,13 +74,16 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity btn_delete.onClick { } + cb_selected_all.onClick { + adapter.selectAll(cb_selected_all.isChecked) + } } private fun initData() { localUriLiveData?.removeObservers(this) localUriLiveData = App.db.bookDao().observeLocalUri() localUriLiveData?.observe(this, Observer { - importBookAdapter.upBookHas(it) + adapter.upBookHas(it) }) } @@ -104,8 +107,8 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity path = path + doc.name + File.separator } tv_path.text = path - importBookAdapter.selectedUris.clear() - importBookAdapter.clearItems() + adapter.selectedUris.clear() + adapter.clearItems() rotate_loading.show() launch(IO) { val docList = DocumentUtils.listFiles( @@ -123,7 +126,7 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity docList.sortWith(compareBy({ !it.isDir }, { it.name })) withContext(Main) { rotate_loading.hide() - importBookAdapter.setItems(docList) + adapter.setData(docList) } } } @@ -179,16 +182,29 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } override fun upCountView() { - if (importBookAdapter.selectedUris.isEmpty()) { + if (adapter.selectedUris.isEmpty()) { btn_add_book.setText(R.string.nb_file_add_shelf) //设置某些按钮的是否可点击 setMenuClickable(false) } else { btn_add_book.text = - getString(R.string.nb_file_add_shelves, importBookAdapter.selectedUris.size) + getString(R.string.nb_file_add_shelves, adapter.selectedUris.size) //设置某些按钮的是否可点击 setMenuClickable(true) } + + if (adapter.checkableCount == 0) { + cb_selected_all.isChecked = false + } else { + cb_selected_all.isChecked = adapter.selectedUris.size >= adapter.checkableCount + } + + //重置全选的文字 + if (cb_selected_all.isChecked) { + cb_selected_all.setText(R.string.cancel) + } else { + cb_selected_all.setText(R.string.select_all) + } } private fun setMenuClickable(isClickable: Boolean) { diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt index 5a028a8be..94deb2b7e 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt @@ -14,12 +14,45 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ImportBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_import_book) { var selectedUris = linkedSetOf() - private var localUri = arrayListOf() + var checkableCount = 0 + private var bookshelf = arrayListOf() fun upBookHas(uriList: List) { - localUri.clear() - localUri.addAll(uriList) + bookshelf.clear() + bookshelf.addAll(uriList) notifyDataSetChanged() + upCheckableCount() + } + + fun setData(data: List) { + setItems(data) + upCheckableCount() + } + + private fun upCheckableCount() { + checkableCount = 0 + getItems().forEach { + if (!it.isDir && !bookshelf.contains(it.uri.toString())) { + checkableCount++ + } + } + callBack.upCountView() + } + + fun selectAll(selectAll: Boolean) { + if (selectAll) { + getItems().forEach { + if (!it.isDir && !bookshelf.contains(it.uri.toString())) { + selectedUris.add(it.uri.toString()) + } + } + notifyDataSetChanged() + callBack.upCountView() + } else { + selectedUris.clear() + notifyDataSetChanged() + callBack.upCountView() + } } override fun convert(holder: ItemViewHolder, item: DocItem, payloads: MutableList) { @@ -29,8 +62,9 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : iv_icon.visible() cb_select.invisible() ll_brief.gone() + cb_select.isChecked = false } else { - if (localUri.contains(item.uri.toString())) { + if (bookshelf.contains(item.uri.toString())) { iv_icon.setImageResource(R.drawable.ic_book_has) iv_icon.visible() cb_select.invisible() @@ -42,19 +76,20 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : tv_tag.text = item.name.substringAfterLast(".") tv_size.text = StringUtils.toSize(item.size) tv_date.text = AppConst.DATE_FORMAT.format(item.date) + cb_select.isChecked = selectedUris.contains(item.uri.toString()) } tv_name.text = item.name - cb_select.isChecked = selectedUris.contains(item.uri.toString()) onClick { if (item.isDir) { callBack.nextDoc(DocumentFile.fromSingleUri(context, item.uri)!!) - } else { + } else if (!bookshelf.contains(item.uri.toString())) { cb_select.isChecked = !cb_select.isChecked if (cb_select.isChecked) { selectedUris.add(item.uri.toString()) } else { selectedUris.remove(item.uri.toString()) } + callBack.upCountView() } } } From 46e4916bfe309886d536716318d0bfcab5015fdb Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 17:59:02 +0800 Subject: [PATCH 251/852] =?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/importbook/ImportBookActivity.kt | 4 ++-- .../io/legado/app/ui/importbook/ImportBookViewModel.kt | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 6eb1c59eb..1b78fa963 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -69,10 +69,10 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity goBackDir() } btn_add_book.onClick { - + viewModel.addToBookshelf(adapter.selectedUris) } btn_delete.onClick { - + viewModel.deleteDoc(adapter.selectedUris) } cb_selected_all.onClick { adapter.selectAll(cb_selected_all.isChecked) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt index 1865f1be8..6fdcd8034 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt @@ -6,5 +6,12 @@ import io.legado.app.base.BaseViewModel class ImportBookViewModel(application: Application) : BaseViewModel(application) { + fun addToBookshelf(uriList: HashSet) { + + } + + fun deleteDoc(uriList: HashSet) { + + } } \ No newline at end of file From 7487b2a4ca93a2dc10045fcc2b2fede2b0ff72c4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 18:03:30 +0800 Subject: [PATCH 252/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/importbook/ImportBookActivity.kt | 8 ++++++-- .../app/ui/importbook/ImportBookViewModel.kt | 14 +++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 1b78fa963..2f67e8f90 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -69,10 +69,14 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity goBackDir() } btn_add_book.onClick { - viewModel.addToBookshelf(adapter.selectedUris) + viewModel.addToBookshelf(adapter.selectedUris) { + upPath() + } } btn_delete.onClick { - viewModel.deleteDoc(adapter.selectedUris) + viewModel.deleteDoc(adapter.selectedUris) { + upPath() + } } cb_selected_all.onClick { adapter.selectAll(cb_selected_all.isChecked) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt index 6fdcd8034..a8bd64ea8 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt @@ -1,17 +1,25 @@ package io.legado.app.ui.importbook import android.app.Application +import android.net.Uri +import androidx.documentfile.provider.DocumentFile import io.legado.app.base.BaseViewModel class ImportBookViewModel(application: Application) : BaseViewModel(application) { - fun addToBookshelf(uriList: HashSet) { + fun addToBookshelf(uriList: HashSet, finally: () -> Unit) { } - fun deleteDoc(uriList: HashSet) { - + fun deleteDoc(uriList: HashSet, finally: () -> Unit) { + execute { + uriList.forEach { + DocumentFile.fromSingleUri(context, Uri.parse(it))?.delete() + } + }.onFinally { + finally.invoke() + } } } \ No newline at end of file From 0daf05c814fe314017626677fe0652033b4d64a9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 18:50:02 +0800 Subject: [PATCH 253/852] =?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/ui/importbook/ImportBookViewModel.kt | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt index a8bd64ea8..b81167bd9 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt @@ -3,13 +3,34 @@ package io.legado.app.ui.importbook import android.app.Application import android.net.Uri import androidx.documentfile.provider.DocumentFile +import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.Book class ImportBookViewModel(application: Application) : BaseViewModel(application) { fun addToBookshelf(uriList: HashSet, finally: () -> Unit) { - + execute { + uriList.forEach { uriStr -> + DocumentFile.fromSingleUri(context, Uri.parse(uriStr))?.let { doc -> + doc.name?.let { fileName -> + val str = fileName.substringBeforeLast(".") + var name = str.substringBefore("作者") + val author = str.substringAfter("作者") + val smhStart = name.indexOf("《") + val smhEnd = name.indexOf("》") + if (smhStart != -1 && smhEnd != -1) { + name = (name.substring(smhStart + 1, smhEnd)) + } + val book = Book(bookUrl = uriStr, name = name, author = author) + App.db.bookDao().insert(book) + } + } + } + }.onFinally { + finally.invoke() + } } fun deleteDoc(uriList: HashSet, finally: () -> Unit) { From a388f9eb9b086c929b5e60f36bcfd9767491871a Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 19:09:21 +0800 Subject: [PATCH 254/852] =?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/data/entities/Book.kt | 4 ++++ .../main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 1 + 2 files changed, 5 insertions(+) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index d98f79603..f01d95bce 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -48,6 +48,10 @@ data class Book( var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息) ) : Parcelable, BaseBook { + fun isLocalBook(): Boolean { + return origin == BookType.local + } + @Ignore @IgnoredOnParcel override var variableMap: HashMap? = null diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index d7d7b0ab1..8179c058a 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -55,6 +55,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { book: Book, changeDruChapterIndex: ((chapters: List) -> Unit)? = null ) { + if (book.isLocalBook()) return execute { isLoadingData.postValue(true) App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> From a64bf9174974207a28164ffe2985fcc5d8212414 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 20:20:48 +0800 Subject: [PATCH 255/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/http/EncodeConverter.kt | 1 + .../app/model/localbook/AnalyzeTxtFile.kt | 21 +++++++++++++++++++ .../{help/http => utils}/EncodingDetect.java | 18 ++++++++-------- 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/io/legado/app/model/localbook/AnalyzeTxtFile.kt rename app/src/main/java/io/legado/app/{help/http => utils}/EncodingDetect.java (99%) diff --git a/app/src/main/java/io/legado/app/help/http/EncodeConverter.kt b/app/src/main/java/io/legado/app/help/http/EncodeConverter.kt index 9e0b5ff1f..b27d0a210 100644 --- a/app/src/main/java/io/legado/app/help/http/EncodeConverter.kt +++ b/app/src/main/java/io/legado/app/help/http/EncodeConverter.kt @@ -1,5 +1,6 @@ package io.legado.app.help.http +import io.legado.app.utils.EncodingDetect import io.legado.app.utils.UTF8BOMFighter import okhttp3.ResponseBody import retrofit2.Converter diff --git a/app/src/main/java/io/legado/app/model/localbook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localbook/AnalyzeTxtFile.kt new file mode 100644 index 000000000..a3df30783 --- /dev/null +++ b/app/src/main/java/io/legado/app/model/localbook/AnalyzeTxtFile.kt @@ -0,0 +1,21 @@ +package io.legado.app.model.localbook + +import android.content.Context +import android.net.Uri +import io.legado.app.data.entities.Book +import io.legado.app.utils.EncodingDetect + +object AnalyzeTxtFile { + + + fun analyze(context: Context, book: Book) { + context.contentResolver.openInputStream(Uri.parse(book.bookUrl))?.use { stream -> + val rawByteArray = ByteArray(2000) + stream.read(rawByteArray) + book.charset = EncodingDetect.getJavaEncode(rawByteArray) + + + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/http/EncodingDetect.java b/app/src/main/java/io/legado/app/utils/EncodingDetect.java similarity index 99% rename from app/src/main/java/io/legado/app/help/http/EncodingDetect.java rename to app/src/main/java/io/legado/app/utils/EncodingDetect.java index 2659e0cb4..9f1aad37b 100644 --- a/app/src/main/java/io/legado/app/help/http/EncodingDetect.java +++ b/app/src/main/java/io/legado/app/utils/EncodingDetect.java @@ -1,6 +1,7 @@ -package io.legado.app.help.http; +package io.legado.app.utils; import androidx.annotation.NonNull; + import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -119,19 +120,19 @@ public class EncodingDetect { class BytesEncodingDetect extends Encoding { // Frequency tables to hold the GB, Big5, and EUC-TW character // frequencies - int GBFreq[][]; + int[][] GBFreq; - int GBKFreq[][]; + int[][] GBKFreq; - int Big5Freq[][]; + int[][] Big5Freq; - int Big5PFreq[][]; + int[][] Big5PFreq; - int EUC_TWFreq[][]; + int[][] EUC_TWFreq; - int KRFreq[][]; + int[][] KRFreq; - int JPFreq[][]; + int[][] JPFreq; // int UnicodeFreq[94][128]; // public static String[] nicename; @@ -170,7 +171,6 @@ class BytesEncodingDetect extends Encoding { rawtext.length - byteoffset)) > 0) { byteoffset += bytesread; } - ; chinesestream.close(); guess = detectEncoding(rawtext); } catch (Exception e) { From 394771e46b1b74a3566c3fe6392e1aff29125746 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 20:39:51 +0800 Subject: [PATCH 256/852] =?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/model/README.md | 6 +++++- app/src/main/java/io/legado/app/model/WebBook.kt | 8 ++++---- .../app/model/{localbook => localBook}/AnalyzeTxtFile.kt | 2 +- .../app/model/{webbook => webBook}/BookChapterList.kt | 2 +- .../legado/app/model/{webbook => webBook}/BookContent.kt | 2 +- .../io/legado/app/model/{webbook => webBook}/BookInfo.kt | 2 +- .../io/legado/app/model/{webbook => webBook}/BookList.kt | 2 +- .../legado/app/model/{webbook => webBook}/ChapterData.kt | 2 +- .../legado/app/model/{webbook => webBook}/ContentData.kt | 2 +- 9 files changed, 16 insertions(+), 12 deletions(-) rename app/src/main/java/io/legado/app/model/{localbook => localBook}/AnalyzeTxtFile.kt (92%) rename app/src/main/java/io/legado/app/model/{webbook => webBook}/BookChapterList.kt (99%) rename app/src/main/java/io/legado/app/model/{webbook => webBook}/BookContent.kt (99%) rename app/src/main/java/io/legado/app/model/{webbook => webBook}/BookInfo.kt (98%) rename app/src/main/java/io/legado/app/model/{webbook => webBook}/BookList.kt (99%) rename app/src/main/java/io/legado/app/model/{webbook => webBook}/ChapterData.kt (79%) rename app/src/main/java/io/legado/app/model/{webbook => webBook}/ContentData.kt (67%) diff --git a/app/src/main/java/io/legado/app/model/README.md b/app/src/main/java/io/legado/app/model/README.md index 0b9c08ba9..d791c861e 100644 --- a/app/src/main/java/io/legado/app/model/README.md +++ b/app/src/main/java/io/legado/app/model/README.md @@ -1,2 +1,6 @@ ## 放置一些模块类 -* 书源解析 +* analyzeRule 书源规则解析 +* localBook 本地书籍解析 +* rss 订阅规则解析 +* webBook 获取网络书籍 + diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index e28c09519..4cc2544f5 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -6,10 +6,10 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.analyzeRule.AnalyzeUrl -import io.legado.app.model.webbook.BookChapterList -import io.legado.app.model.webbook.BookContent -import io.legado.app.model.webbook.BookInfo -import io.legado.app.model.webbook.BookList +import io.legado.app.model.webBook.BookChapterList +import io.legado.app.model.webBook.BookContent +import io.legado.app.model.webBook.BookInfo +import io.legado.app.model.webBook.BookList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlin.coroutines.CoroutineContext diff --git a/app/src/main/java/io/legado/app/model/localbook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt similarity index 92% rename from app/src/main/java/io/legado/app/model/localbook/AnalyzeTxtFile.kt rename to app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index a3df30783..6eb5d4a18 100644 --- a/app/src/main/java/io/legado/app/model/localbook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -1,4 +1,4 @@ -package io.legado.app.model.localbook +package io.legado.app.model.localBook import android.content.Context import android.net.Uri diff --git a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt similarity index 99% rename from app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt rename to app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index c8fd7c9f8..82f06e54a 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -1,4 +1,4 @@ -package io.legado.app.model.webbook +package io.legado.app.model.webBook import android.text.TextUtils import io.legado.app.App diff --git a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt similarity index 99% rename from app/src/main/java/io/legado/app/model/webbook/BookContent.kt rename to app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 43e90c4cb..b9455e6ff 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -1,4 +1,4 @@ -package io.legado.app.model.webbook +package io.legado.app.model.webBook import io.legado.app.App import io.legado.app.R diff --git a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt similarity index 98% rename from app/src/main/java/io/legado/app/model/webbook/BookInfo.kt rename to app/src/main/java/io/legado/app/model/webBook/BookInfo.kt index e56c25347..75d5f94ba 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt @@ -1,4 +1,4 @@ -package io.legado.app.model.webbook +package io.legado.app.model.webBook import io.legado.app.App import io.legado.app.R diff --git a/app/src/main/java/io/legado/app/model/webbook/BookList.kt b/app/src/main/java/io/legado/app/model/webBook/BookList.kt similarity index 99% rename from app/src/main/java/io/legado/app/model/webbook/BookList.kt rename to app/src/main/java/io/legado/app/model/webBook/BookList.kt index ed440b9f2..56f511815 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookList.kt @@ -1,4 +1,4 @@ -package io.legado.app.model.webbook +package io.legado.app.model.webBook import io.legado.app.App import io.legado.app.R diff --git a/app/src/main/java/io/legado/app/model/webbook/ChapterData.kt b/app/src/main/java/io/legado/app/model/webBook/ChapterData.kt similarity index 79% rename from app/src/main/java/io/legado/app/model/webbook/ChapterData.kt rename to app/src/main/java/io/legado/app/model/webBook/ChapterData.kt index bbbf6060b..6b06eb508 100644 --- a/app/src/main/java/io/legado/app/model/webbook/ChapterData.kt +++ b/app/src/main/java/io/legado/app/model/webBook/ChapterData.kt @@ -1,4 +1,4 @@ -package io.legado.app.model.webbook +package io.legado.app.model.webBook import io.legado.app.data.entities.BookChapter diff --git a/app/src/main/java/io/legado/app/model/webbook/ContentData.kt b/app/src/main/java/io/legado/app/model/webBook/ContentData.kt similarity index 67% rename from app/src/main/java/io/legado/app/model/webbook/ContentData.kt rename to app/src/main/java/io/legado/app/model/webBook/ContentData.kt index 195778ce8..65185d806 100644 --- a/app/src/main/java/io/legado/app/model/webbook/ContentData.kt +++ b/app/src/main/java/io/legado/app/model/webBook/ContentData.kt @@ -1,4 +1,4 @@ -package io.legado.app.model.webbook +package io.legado.app.model.webBook data class ContentData( var content: String = "", From 28d79000edc8b23e5bece04757375f7e763d30ac Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 20:43:20 +0800 Subject: [PATCH 257/852] =?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/lib/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/lib/README.md b/app/src/main/java/io/legado/app/lib/README.md index 8b248561d..1089be064 100644 --- a/app/src/main/java/io/legado/app/lib/README.md +++ b/app/src/main/java/io/legado/app/lib/README.md @@ -1 +1,4 @@ -## 放置一些copy过来的库 \ No newline at end of file +## 放置一些copy过来的库 +* dialogs 弹出框 +* theme 主题 +* webDav 网络存储 \ No newline at end of file From 680cf6d5a9329b3581e79c1d51a1fadf972dbbd2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 20:59:37 +0800 Subject: [PATCH 258/852] =?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/model/webBook/BookInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt index 75d5f94ba..b2a9083fd 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt @@ -68,7 +68,7 @@ object BookInfo { } Debug.log(bookSource.bookSourceUrl, "└${book.coverUrl}") Debug.log(bookSource.bookSourceUrl, "┌获取目录链接") - book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true) ?: baseUrl + book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true) if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl if (book.tocUrl == baseUrl) { book.tocHtml = body From f4109a0c4b2484222cfb92d04f0109deb478db43 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 21:18:11 +0800 Subject: [PATCH 259/852] =?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/http/SSLHelper.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/SSLHelper.kt b/app/src/main/java/io/legado/app/help/http/SSLHelper.kt index ef70ac1b5..1d95aae58 100644 --- a/app/src/main/java/io/legado/app/help/http/SSLHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/SSLHelper.kt @@ -14,11 +14,9 @@ import javax.net.ssl.* object SSLHelper { - val sslSocketFactory: SSLParams? - get() = getSslSocketFactoryBase(null, null, null) - /** - * 为了解决客户端不信任服务器数字证书的问题,网络上大部分的解决方案都是让客户端不对证书做任何检查, + * 为了解决客户端不信任服务器数字证书的问题, + * 网络上大部分的解决方案都是让客户端不对证书做任何检查, * 这是一种有很大安全漏洞的办法 */ val unsafeTrustManager: X509TrustManager = object : X509TrustManager { From 886ca32715ebf550b33641110d527bb9b7ece2df Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 31 Jan 2020 21:25:38 +0800 Subject: [PATCH 260/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/http/HttpHelper.kt | 4 ++-- .../http/api/HttpGetApi.kt} | 4 ++-- .../http/api/HttpPostApi.kt} | 4 ++-- .../app/model/analyzeRule/AnalyzeUrl.kt | 20 +++++++++---------- .../app/service/HttpReadAloudService.kt | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) rename app/src/main/java/io/legado/app/{data/api/IHttpGetApi.kt => help/http/api/HttpGetApi.kt} (93%) rename app/src/main/java/io/legado/app/{data/api/IHttpPostApi.kt => help/http/api/HttpPostApi.kt} (95%) diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 3e6d6c3ab..7ba5c4058 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -1,6 +1,6 @@ package io.legado.app.help.http -import io.legado.app.data.api.IHttpGetApi +import io.legado.app.help.http.api.HttpGetApi import io.legado.app.utils.NetworkUtils import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.* @@ -39,7 +39,7 @@ object HttpHelper { fun simpleGet(url: String, encode: String? = null): String? { NetworkUtils.getBaseUrl(url)?.let { baseUrl -> - val response = getApiService(baseUrl, encode) + val response = getApiService(baseUrl, encode) .get(url, mapOf()) .execute() return response.body() diff --git a/app/src/main/java/io/legado/app/data/api/IHttpGetApi.kt b/app/src/main/java/io/legado/app/help/http/api/HttpGetApi.kt similarity index 93% rename from app/src/main/java/io/legado/app/data/api/IHttpGetApi.kt rename to app/src/main/java/io/legado/app/help/http/api/HttpGetApi.kt index e4180fa59..46346d091 100644 --- a/app/src/main/java/io/legado/app/data/api/IHttpGetApi.kt +++ b/app/src/main/java/io/legado/app/help/http/api/HttpGetApi.kt @@ -1,4 +1,4 @@ -package io.legado.app.data.api +package io.legado.app.help.http.api import kotlinx.coroutines.Deferred import retrofit2.Call @@ -13,7 +13,7 @@ import retrofit2.http.Url * get web content */ -interface IHttpGetApi { +interface HttpGetApi { @GET fun getAsync( @Url url: String, diff --git a/app/src/main/java/io/legado/app/data/api/IHttpPostApi.kt b/app/src/main/java/io/legado/app/help/http/api/HttpPostApi.kt similarity index 95% rename from app/src/main/java/io/legado/app/data/api/IHttpPostApi.kt rename to app/src/main/java/io/legado/app/help/http/api/HttpPostApi.kt index 17bf16ee8..8dab48762 100644 --- a/app/src/main/java/io/legado/app/data/api/IHttpPostApi.kt +++ b/app/src/main/java/io/legado/app/help/http/api/HttpPostApi.kt @@ -1,4 +1,4 @@ -package io.legado.app.data.api +package io.legado.app.help.http.api import kotlinx.coroutines.Deferred import okhttp3.RequestBody @@ -11,7 +11,7 @@ import retrofit2.http.* * post */ -interface IHttpPostApi { +interface HttpPostApi { @FormUrlEncoded @POST diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index b5343cf7f..4c278e7f9 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -6,14 +6,14 @@ import androidx.annotation.Keep import io.legado.app.constant.AppConst.SCRIPT_ENGINE import io.legado.app.constant.Pattern.EXP_PATTERN import io.legado.app.constant.Pattern.JS_PATTERN -import io.legado.app.data.api.IHttpGetApi -import io.legado.app.data.api.IHttpPostApi import io.legado.app.data.entities.BaseBook import io.legado.app.help.JsExtensions import io.legado.app.help.http.AjaxWebView import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.RequestMethod import io.legado.app.help.http.Res +import io.legado.app.help.http.api.HttpGetApi +import io.legado.app.help.http.api.HttpPostApi import io.legado.app.utils.* import okhttp3.FormBody import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -248,19 +248,19 @@ class AnalyzeUrl( method == RequestMethod.POST -> { if (fieldMap.isNotEmpty()) { HttpHelper - .getApiService(baseUrl) + .getApiService(baseUrl) .postMap(url, fieldMap, headerMap) } else { HttpHelper - .getApiService(baseUrl) + .getApiService(baseUrl) .postBody(url, body!!, headerMap) } } fieldMap.isEmpty() -> HttpHelper - .getApiService(baseUrl) + .getApiService(baseUrl) .get(url, headerMap) else -> HttpHelper - .getApiService(baseUrl) + .getApiService(baseUrl) .getMap(url, fieldMap, headerMap) } } @@ -284,22 +284,22 @@ class AnalyzeUrl( method == RequestMethod.POST -> { if (fieldMap.isNotEmpty()) { HttpHelper - .getApiService(baseUrl) + .getApiService(baseUrl) .postMapAsync(url, fieldMap, headerMap) .await() } else { HttpHelper - .getApiService(baseUrl) + .getApiService(baseUrl) .postBodyAsync(url, body!!, headerMap) .await() } } fieldMap.isEmpty() -> HttpHelper - .getApiService(baseUrl) + .getApiService(baseUrl) .getAsync(url, headerMap) .await() else -> HttpHelper - .getApiService(baseUrl) + .getApiService(baseUrl) .getMapAsync(url, fieldMap, headerMap) .await() } diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 6f211a3c7..9e1fe70cd 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -3,9 +3,9 @@ package io.legado.app.service import android.app.PendingIntent import android.media.MediaPlayer import io.legado.app.constant.Bus -import io.legado.app.data.api.IHttpPostApi import io.legado.app.help.IntentHelp import io.legado.app.help.http.HttpHelper +import io.legado.app.help.http.api.HttpPostApi import io.legado.app.service.help.ReadBook import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO @@ -65,7 +65,7 @@ class HttpReadAloudService : BaseReadAloudService(), for (index in 0 until contentList.size) { if (isActive) { val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com") - .create(IHttpPostApi::class.java) + .create(HttpPostApi::class.java) .postMapByteAsync( "http://tts.baidu.com/text2audio", getAudioBody(contentList[index]), mapOf() From 7f79735d50820b6ffc6dae76a36306c4cc8fa285 Mon Sep 17 00:00:00 2001 From: M17764017422 <31874069+M17764017422@users.noreply.github.com> Date: Sat, 1 Feb 2020 19:46:14 +0800 Subject: [PATCH 261/852] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E4=B9=B1=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复BaseURL模式下部分图片无法加载 --- .../main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 894bed7a9..d0311370c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -73,9 +73,9 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r val url = NetworkUtils.getAbsoluteURL(it.origin, it.link) val html = viewModel.clHtml(content) if (viewModel.rssSource?.loadWithBaseUrl == true) { - webView.loadDataWithBaseURL(url, html, "text/html", "utf-8", url) + webView.loadDataWithBaseURL(null, html, "text/html", "utf-8", url)//Referer会导致一些有反盗链的图片无法加载,暂时先用null应该还有更好的办法 } else { - webView.loadData(html, "text/html", "utf-8") + webView.loadData(html, "text/html;charset=utf-8", "utf-8")//经测试可以解决中文乱码 } } }) @@ -154,4 +154,4 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } } -} \ No newline at end of file +} From dce2be9f6744ddddab3300f53434f5568fe33517 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 1 Feb 2020 19:55:48 +0800 Subject: [PATCH 262/852] =?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/main/bookshelf/BookshelfFragment.kt | 25 ++++++++++++++++--- .../ui/main/bookshelf/BookshelfViewModel.kt | 4 +++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 0a8318618..d58e6fd48 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -16,13 +16,15 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.Bus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup -import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.lib.theme.view.ATEAutoCompleteTextView import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.download.DownloadActivity import io.legado.app.ui.importbook.ImportBookActivity import io.legado.app.utils.* +import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* import kotlinx.android.synthetic.main.view_title_bar.* @@ -60,8 +62,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b R.id.menu_group_manage -> GroupManageDialog() .show(childFragmentManager, "groupManageDialog") R.id.menu_add_local -> startActivity() - R.id.menu_add_url -> { - } + R.id.menu_add_url -> addBookByUrl() R.id.menu_arrange_bookshelf -> { } R.id.menu_download -> startActivity() @@ -145,6 +146,24 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b } } + private fun addBookByUrl() { + requireContext() + .alert(titleResource = R.string.add_book_url) { + var editText: ATEAutoCompleteTextView? = null + customView { + layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { + editText = edit_view + } + } + okButton { + editText?.text?.toString()?.let { + viewModel.addBookByUrl(it) + } + } + noButton { } + }.show().applyTint() + } + override fun onTabReselected(tab: TabLayout.Tab?) { } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 536329915..50e77a765 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -31,4 +31,8 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } + fun addBookByUrl(bookUrl: String) { + + } + } From 0e84934b5b602b3a56e71d158b9050e17e3dbf48 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 1 Feb 2020 20:12:54 +0800 Subject: [PATCH 263/852] =?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/assets/updateLog.md | 5 ++++- .../io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 605e0a482..00f7293df 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,8 +3,11 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2020/01/31** +**2020/02/01** +* merged commit e584606, rss修复BaseURL模式下部分图片无法加载, 修复可能出现的乱码 * 正在写本地导入,还没写完 + +**2020/01/31** * 修复搜索闪退,因为默认线程为0了 **2020/01/30** diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index d58e6fd48..237e73567 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.main.bookshelf +import android.annotation.SuppressLint import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -146,6 +147,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b } } + @SuppressLint("InflateParams") private fun addBookByUrl() { requireContext() .alert(titleResource = R.string.add_book_url) { From 9011b95a32d0f4fbea739ad40cb3d7afd2dd72e3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 1 Feb 2020 21:21:16 +0800 Subject: [PATCH 264/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookSourceDao.kt | 3 ++ .../ui/main/bookshelf/BookshelfViewModel.kt | 44 ++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index f76ed3d13..159622898 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -53,6 +53,9 @@ interface BookSourceDao { @Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'") fun getEnabledByGroup(group: String): List + @get:Query("select * from book_sources where bookUrlPattern is not null || bookUrlPattern <> ''") + val hasBookUrlPattern: List + @get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''") val noGroup: List diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 50e77a765..b41031484 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -2,8 +2,14 @@ package io.legado.app.ui.main.bookshelf import android.app.Application import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup +import io.legado.app.data.entities.BookSource +import io.legado.app.model.WebBook +import io.legado.app.utils.NetworkUtils +import kotlinx.coroutines.Dispatchers.IO class BookshelfViewModel(application: Application) : BaseViewModel(application) { @@ -31,8 +37,42 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } - fun addBookByUrl(bookUrl: String) { - + fun addBookByUrl(bookUrls: String) { + execute { + var hasBookUrlPattern: List? = null + val urls = bookUrls.split("\n") + for (url in urls) { + val bookUrl = url.trim() + if (bookUrl.isEmpty()) continue + App.db.bookDao().getBook(bookUrl) ?: continue + val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue + var source = App.db.bookSourceDao().getBookSource(baseUrl) + if (source == null) { + if (hasBookUrlPattern == null) { + hasBookUrlPattern = App.db.bookSourceDao().hasBookUrlPattern + } + hasBookUrlPattern.forEach { bookSource -> + if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) { + source = bookSource + return@forEach + } + } + } + source?.let { bookSource -> + val book = Book(bookUrl = bookUrl) + WebBook(bookSource).getBookInfo(book, this) + .onSuccess(IO) { + it?.let { book -> + App.db.bookDao().insert(book) + } + } + } + } + }.onSuccess { + toast(R.string.success) + }.onError { + toast(it.localizedMessage ?: "ERROR") + } } } From 207d18340fe6212ff20a3ee82b6fc2ec5f883fe3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 1 Feb 2020 21:25:07 +0800 Subject: [PATCH 265/852] =?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/assets/updateLog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 00f7293df..737637c45 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,7 +5,8 @@ **2020/02/01** * merged commit e584606, rss修复BaseURL模式下部分图片无法加载, 修复可能出现的乱码 -* 正在写本地导入,还没写完 +* 菜单添加网址功能完成 +* 添加本地书籍完成,还差解析txt文件,目前添加了不能看 **2020/01/31** * 修复搜索闪退,因为默认线程为0了 From 08ce86ba408d73a7975f3f73f9a15a6b241d4e74 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 08:08:19 +0800 Subject: [PATCH 266/852] =?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/main/bookshelf/BookshelfViewModel.kt | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index b41031484..0c4033587 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -38,6 +38,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } fun addBookByUrl(bookUrls: String) { + var successCount = 0 execute { var hasBookUrlPattern: List? = null val urls = bookUrls.split("\n") @@ -59,17 +60,30 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } source?.let { bookSource -> - val book = Book(bookUrl = bookUrl) - WebBook(bookSource).getBookInfo(book, this) - .onSuccess(IO) { - it?.let { book -> - App.db.bookDao().insert(book) + val book = Book( + bookUrl = bookUrl, + origin = bookSource.bookSourceUrl, + originName = bookSource.bookSourceName + ) + suspend { + WebBook(bookSource).getBookInfo(book, this) + .onSuccess(IO) { + it?.let { book -> + App.db.bookDao().insert(book) + successCount++ + } + }.onError { + throw Exception(it.localizedMessage) } - } + } } } }.onSuccess { - toast(R.string.success) + if (successCount > 0) { + toast(R.string.success) + } else { + toast("ERROR") + } }.onError { toast(it.localizedMessage ?: "ERROR") } From 7f9defbb098b1873f65ad055c19758ec8a0fa114 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 08:16:04 +0800 Subject: [PATCH 267/852] =?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/main/bookshelf/BookshelfViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 0c4033587..71e2001a6 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -45,7 +45,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) for (url in urls) { val bookUrl = url.trim() if (bookUrl.isEmpty()) continue - App.db.bookDao().getBook(bookUrl) ?: continue + if (App.db.bookDao().getBook(bookUrl) != null) continue val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue var source = App.db.bookSourceDao().getBookSource(baseUrl) if (source == null) { From 969356d4ba368e9d781d4a4992e326723382485e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 08:21:33 +0800 Subject: [PATCH 268/852] =?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/main/bookshelf/BookshelfViewModel.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 71e2001a6..74c963763 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -65,17 +65,15 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) origin = bookSource.bookSourceUrl, originName = bookSource.bookSourceName ) - suspend { - WebBook(bookSource).getBookInfo(book, this) - .onSuccess(IO) { - it?.let { book -> - App.db.bookDao().insert(book) - successCount++ - } - }.onError { - throw Exception(it.localizedMessage) + WebBook(bookSource).getBookInfo(book, this) + .onSuccess(IO) { + it?.let { book -> + App.db.bookDao().insert(book) + successCount++ } - } + }.onError { + throw Exception(it.localizedMessage) + } } } }.onSuccess { From 4c31435812a0ac11da9dc88efb70b4217e3d0d1a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 08:22:51 +0800 Subject: [PATCH 269/852] =?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/assets/updateLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 737637c45..8828a731b 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,7 +3,7 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2020/02/01** +**2020/02/02** * merged commit e584606, rss修复BaseURL模式下部分图片无法加载, 修复可能出现的乱码 * 菜单添加网址功能完成 * 添加本地书籍完成,还差解析txt文件,目前添加了不能看 From 9e8eed355cffb38373621d1af6454102dda6f9d4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 10:15:17 +0800 Subject: [PATCH 270/852] =?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/data/entities/Book.kt | 2 +- .../app/model/localBook/AnalyzeTxtFile.kt | 27 ++++++++++++++----- .../app/ui/importbook/ImportBookViewModel.kt | 7 ++++- .../io/legado/app/utils/EncodingDetect.java | 8 +++--- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index f01d95bce..17198cdda 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -19,7 +19,7 @@ data class Book( var bookUrl: String = "", // 详情页Url(本地书源存储完整文件路径) var tocUrl: String = "", // 目录页Url (toc=table of Contents) var origin: String = BookType.local, // 书源URL(默认BookType.local) - var originName: String = "", //书源名称 + var originName: String = "", //书源名称 or 本地书籍文件名 var name: String = "", // 书籍名称(书源获取) var author: String = "", // 作者名称(书源获取) override var kind: String? = null, // 分类信息(书源获取) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 6eb5d4a18..148c5c8f6 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -2,20 +2,33 @@ package io.legado.app.model.localBook import android.content.Context import android.net.Uri +import io.legado.app.App import io.legado.app.data.entities.Book +import io.legado.app.utils.DocumentUtils import io.legado.app.utils.EncodingDetect +import io.legado.app.utils.FileUtils +import java.io.File object AnalyzeTxtFile { - + private const val folderName = "bookTxt" + private val cacheFolder: File by lazy { + val rootFile = App.INSTANCE.getExternalFilesDir(null) + ?: App.INSTANCE.externalCacheDir + ?: App.INSTANCE.cacheDir + FileUtils.createFileIfNotExist(rootFile, subDirs = *arrayOf(folderName)) + } fun analyze(context: Context, book: Book) { - context.contentResolver.openInputStream(Uri.parse(book.bookUrl))?.use { stream -> - val rawByteArray = ByteArray(2000) - stream.read(rawByteArray) - book.charset = EncodingDetect.getJavaEncode(rawByteArray) - - + val uri = Uri.parse(book.bookUrl) + val bookFile = FileUtils.getFile(cacheFolder, book.originName, subDirs = *arrayOf()) + if (!bookFile.exists()) { + bookFile.createNewFile() + DocumentUtils.readBytes(context, uri)?.let { + bookFile.writeBytes(it) + } } + book.charset = EncodingDetect.getEncode(bookFile) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt index b81167bd9..75d2fc5e0 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt @@ -23,7 +23,12 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application) if (smhStart != -1 && smhEnd != -1) { name = (name.substring(smhStart + 1, smhEnd)) } - val book = Book(bookUrl = uriStr, name = name, author = author) + val book = Book( + bookUrl = uriStr, + name = name, + author = author, + originName = fileName + ) App.db.bookDao().insert(book) } } diff --git a/app/src/main/java/io/legado/app/utils/EncodingDetect.java b/app/src/main/java/io/legado/app/utils/EncodingDetect.java index 9f1aad37b..08b43b228 100644 --- a/app/src/main/java/io/legado/app/utils/EncodingDetect.java +++ b/app/src/main/java/io/legado/app/utils/EncodingDetect.java @@ -62,10 +62,10 @@ public class EncodingDetect { } } catch (Exception ignored) { } - return getJavaEncode(bytes); + return getEncode(bytes); } - public static String getJavaEncode(@NonNull byte[] bytes) { + public static String getEncode(@NonNull byte[] bytes) { int len = bytes.length > 2000 ? 2000 : bytes.length; byte[] cBytes = new byte[len]; System.arraycopy(bytes, 0, cBytes, 0, len); @@ -83,7 +83,7 @@ public class EncodingDetect { /** * 得到文件的编码 */ - public static String getJavaEncode(@NonNull String filePath) { + public static String getEncode(@NonNull String filePath) { BytesEncodingDetect s = new BytesEncodingDetect(); String fileCode = BytesEncodingDetect.javaname[s .detectEncoding(new File(filePath))]; @@ -102,7 +102,7 @@ public class EncodingDetect { /** * 得到文件的编码 */ - public static String getJavaEncode(@NonNull File file) { + public static String getEncode(@NonNull File file) { BytesEncodingDetect s = new BytesEncodingDetect(); String fileCode = BytesEncodingDetect.javaname[s.detectEncoding(file)]; // UTF-16LE 特殊处理 From d47ddef4d7b728cb71591dee3298b50fc3d06031 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 10:57:58 +0800 Subject: [PATCH 271/852] =?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/constant/PreferKey.kt | 4 ++-- app/src/main/java/io/legado/app/help/AppConfig.kt | 6 +++--- .../io/legado/app/model/localBook/AnalyzeTxtFile.kt | 4 ++++ .../main/java/io/legado/app/ui/main/my/MyFragment.kt | 12 ++++++------ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 1cb5e2edc..3c6046bde 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -1,7 +1,7 @@ package io.legado.app.constant object PreferKey { - + const val themeMode = "themeMode" const val downloadPath = "downloadPath" const val hideStatusBar = "hideStatusBar" const val clickAllNext = "clickAllNext" @@ -21,5 +21,5 @@ object PreferKey { const val backupPath = "backupUri" const val threadCount = "threadCount" const val keepLight = "keep_light" - const val autoDarkMode = "autoDarkMode" + const val webService = "webService" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index f8eb4f62e..31107ad5f 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -8,7 +8,7 @@ object AppConfig { var isNightTheme: Boolean get() { - return when (App.INSTANCE.getPrefString("themeMode", "0")) { + return when (App.INSTANCE.getPrefString(PreferKey.themeMode, "0")) { "1" -> false "2" -> true else -> App.INSTANCE.sysIsDarkMode() @@ -16,9 +16,9 @@ object AppConfig { } set(value) { if (value) { - App.INSTANCE.putPrefString("themeMode", "2") + App.INSTANCE.putPrefString(PreferKey.themeMode, "2") } else { - App.INSTANCE.putPrefString("themeMode", "1") + App.INSTANCE.putPrefString(PreferKey.themeMode, "1") } } diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 148c5c8f6..96a44e1c5 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -8,6 +8,7 @@ import io.legado.app.utils.DocumentUtils import io.legado.app.utils.EncodingDetect import io.legado.app.utils.FileUtils import java.io.File +import java.io.RandomAccessFile object AnalyzeTxtFile { private const val folderName = "bookTxt" @@ -29,6 +30,9 @@ object AnalyzeTxtFile { } book.charset = EncodingDetect.getEncode(bookFile) + //获取文件流 + val bookStream = RandomAccessFile(bookFile, "r") + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index e8b061144..7e95c1c34 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -174,13 +174,13 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { if (WebService.isRun) { - putPrefBoolean("webService", true) + putPrefBoolean(PreferKey.webService, true) } else { - putPrefBoolean("webService", false) + putPrefBoolean(PreferKey.webService, false) } addPreferencesFromResource(R.xml.pref_main) observeEvent(Bus.WEB_SERVICE_STOP) { - findPreference("webService")?.let { + findPreference(PreferKey.webService)?.let { it.isChecked = false } } @@ -203,8 +203,8 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { - "themeMode" -> App.INSTANCE.applyDayNight() - "webService" -> { + PreferKey.themeMode -> App.INSTANCE.applyDayNight() + PreferKey.webService -> { if (requireContext().getPrefBoolean("webService")) { WebService.start(requireContext()) toast("正在启动服务\n具体信息查看通知栏") @@ -213,8 +213,8 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { toast("服务已停止") } } + PreferKey.downloadPath -> BookHelp.upDownloadPath() "recordLog" -> LogUtils.upLevel() - "downloadPath" -> BookHelp.upDownloadPath() } } From 0ed336ed8d1b2446b3fb63228ae7e8d27baec6c9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 11:19:41 +0800 Subject: [PATCH 272/852] =?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/main/my/MyFragment.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 7e95c1c34..fdae803bf 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -11,7 +11,6 @@ import android.view.View import androidx.documentfile.provider.DocumentFile import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import androidx.preference.SwitchPreference import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment @@ -24,6 +23,7 @@ import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.theme.ATH +import io.legado.app.lib.theme.prefs.ATESwitchPreference import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity import io.legado.app.ui.about.DonateActivity @@ -179,10 +179,9 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { putPrefBoolean(PreferKey.webService, false) } addPreferencesFromResource(R.xml.pref_main) + val webServicePre = findPreference(PreferKey.webService) observeEvent(Bus.WEB_SERVICE_STOP) { - findPreference(PreferKey.webService)?.let { - it.isChecked = false - } + webServicePre?.isChecked = false } } From 864b61ccba0a860755067ab6c805052a0c8353c4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 12:19:33 +0800 Subject: [PATCH 273/852] =?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/data/AppDatabase.kt | 3 ++- .../io/legado/app/data/dao/TxtTocRuleDao.kt | 24 +++++++++++++++++++ .../io/legado/app/data/entities/TxtTocRule.kt | 14 +++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt create mode 100644 app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index eb44e9381..b5ace94ba 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -16,7 +16,7 @@ import kotlinx.coroutines.launch @Database( entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, - RssSource::class, Bookmark::class, RssArticle::class, RssStar::class], + RssSource::class, Bookmark::class, RssArticle::class, RssStar::class, TxtTocRule::class], version = 6, exportSchema = true ) @@ -50,4 +50,5 @@ abstract class AppDatabase : RoomDatabase() { abstract fun rssArticleDao(): RssArticleDao abstract fun rssStarDao(): RssStarDao abstract fun cookieDao(): CookieDao + abstract fun txtTocRule(): TxtTocRuleDao } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt new file mode 100644 index 000000000..d0ae20207 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt @@ -0,0 +1,24 @@ +package io.legado.app.data.dao + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import io.legado.app.data.entities.TxtTocRule +import retrofit2.http.DELETE + +@Dao +interface TxtTocRuleDao { + + @get:Query("select * from txtTocRules order by serialNumber") + val all: List + + @get:Query("select * from txtTocRules where enable = 1 order by serialNumber") + val enabled: List + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(vararg rule: TxtTocRule) + + @DELETE + fun delete(vararg rule: TxtTocRule) +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt new file mode 100644 index 000000000..c9cd51d4d --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt @@ -0,0 +1,14 @@ +package io.legado.app.data.entities + +import androidx.room.Entity +import androidx.room.PrimaryKey + + +@Entity(tableName = "txtTocRules") +data class TxtTocRule( + @PrimaryKey + var name: String = "", + var rule: String = "", + var serialNumber: Int, + var enable: Boolean = true +) \ No newline at end of file From d867dc34354f74b7a98a6674f6097b317eef1e41 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 12:34:47 +0800 Subject: [PATCH 274/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{txtChapterRule.json => txtTocRule.json} | 0 .../app/model/localBook/AnalyzeTxtFile.kt | 20 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) rename app/src/main/assets/{txtChapterRule.json => txtTocRule.json} (100%) diff --git a/app/src/main/assets/txtChapterRule.json b/app/src/main/assets/txtTocRule.json similarity index 100% rename from app/src/main/assets/txtChapterRule.json rename to app/src/main/assets/txtTocRule.json diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 96a44e1c5..9d6777057 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -4,9 +4,8 @@ import android.content.Context import android.net.Uri import io.legado.app.App import io.legado.app.data.entities.Book -import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.EncodingDetect -import io.legado.app.utils.FileUtils +import io.legado.app.data.entities.TxtTocRule +import io.legado.app.utils.* import java.io.File import java.io.RandomAccessFile @@ -29,10 +28,23 @@ object AnalyzeTxtFile { } } book.charset = EncodingDetect.getEncode(bookFile) - + val tocRules = getTocRules() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") } + + private fun getTocRules(): List { + val rules = App.db.txtTocRule().all + if (rules.isEmpty()) { + App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> + GSON.fromJsonArray(String(byteArray))?.let { + App.db.txtTocRule().insert(*it.toTypedArray()) + return it + } + } + } + return rules + } } \ No newline at end of file From 90d10a907da548b94c3cf0d911ec44103a5208d0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 13:06:46 +0800 Subject: [PATCH 275/852] =?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/model/localBook/AnalyzeTxtFile.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 9d6777057..61693d8f6 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -4,6 +4,7 @@ import android.content.Context import android.net.Uri import io.legado.app.App import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.TxtTocRule import io.legado.app.utils.* import java.io.File @@ -28,13 +29,27 @@ object AnalyzeTxtFile { } } book.charset = EncodingDetect.getEncode(bookFile) - val tocRules = getTocRules() + val toc = arrayListOf() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") + val tocRule = getTocRule(bookStream) + } + private fun getTocRule(bookStream: RandomAccessFile): String? { + val tocRules = getTocRules() + var tocRule: String? = null + //首先获取128k的数据 + val buffer = ByteArray(10240) + val length = bookStream.read(buffer, 0, buffer.size) + for (str in tocRules) { + + } + return tocRule + } + private fun getTocRules(): List { val rules = App.db.txtTocRule().all if (rules.isEmpty()) { From 8c22b09cc24b09bac586f6296e15ed47e79c414f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 14:37:00 +0800 Subject: [PATCH 276/852] =?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/model/localBook/AnalyzeTxtFile.kt | 177 +++++++++++++++++- 1 file changed, 168 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 61693d8f6..85c83c514 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -9,9 +9,17 @@ import io.legado.app.data.entities.TxtTocRule import io.legado.app.utils.* import java.io.File import java.io.RandomAccessFile +import java.nio.charset.Charset +import java.util.regex.Matcher +import java.util.regex.Pattern object AnalyzeTxtFile { private const val folderName = "bookTxt" + private const val BLANK: Byte = 0x0a + //默认从文件中获取数据的长度 + private const val BUFFER_SIZE = 512 * 1024 + //没有标题的时候,每个章节的最大长度 + private const val MAX_LENGTH_WITH_NO_CHAPTER = 10 * 1024 private val cacheFolder: File by lazy { val rootFile = App.INSTANCE.getExternalFilesDir(null) ?: App.INSTANCE.externalCacheDir @@ -19,7 +27,7 @@ object AnalyzeTxtFile { FileUtils.createFileIfNotExist(rootFile, subDirs = *arrayOf(folderName)) } - fun analyze(context: Context, book: Book) { + fun analyze(context: Context, book: Book): ArrayList { val uri = Uri.parse(book.bookUrl) val bookFile = FileUtils.getFile(cacheFolder, book.originName, subDirs = *arrayOf()) if (!bookFile.exists()) { @@ -28,26 +36,177 @@ object AnalyzeTxtFile { bookFile.writeBytes(it) } } - book.charset = EncodingDetect.getEncode(bookFile) + val charset = charset(EncodingDetect.getEncode(bookFile)) + book.charset = charset.name() val toc = arrayListOf() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") - val tocRule = getTocRule(bookStream) + val rulePattern = getTocRule(bookStream, charset) + //加载章节 + val buffer = ByteArray(BUFFER_SIZE) + //获取到的块起始点,在文件中的位置 + var curOffset: Long = 0 + //block的个数 + var blockPos = 0 + //读取的长度 + var length: Int + var allLength = 0 + //获取文件中的数据到buffer,直到没有数据为止 + while (bookStream.read(buffer, 0, buffer.size).also { length = it } > 0) { + ++blockPos + //如果存在Chapter + if (rulePattern != null) { //将数据转换成String + var blockContent = String(buffer, 0, length, charset) + val lastN = blockContent.lastIndexOf("\n") + if (lastN != 0) { + blockContent = blockContent.substring(0, lastN) + length = blockContent.toByteArray(charset).size + allLength += length + bookStream.seek(allLength.toLong()) + } + //当前Block下使过的String的指针 + var seekPos = 0 + //进行正则匹配 + val matcher: Matcher = rulePattern.matcher(blockContent) + //如果存在相应章节 + while (matcher.find()) { //获取匹配到的字符在字符串中的起始位置 + val chapterStart = matcher.start() + //如果 seekPos == 0 && nextChapterPos != 0 表示当前block处前面有一段内容 + //第一种情况一定是序章 第二种情况可能是上一个章节的内容 + if (seekPos == 0 && chapterStart != 0) { //获取当前章节的内容 + val chapterContent = blockContent.substring(seekPos, chapterStart) + //设置指针偏移 + seekPos += chapterContent.length + if (toc.size == 0) { //如果当前没有章节,那么就是序章 + //加入简介 + book.intro = chapterContent + //创建当前章节 + val curChapter = BookChapter() + curChapter.title = matcher.group() + curChapter.start = chapterContent.toByteArray(charset).size.toLong() + toc.add(curChapter) + } else { //否则就block分割之后,上一个章节的剩余内容 + //获取上一章节 + val lastChapter = toc.last() + //将当前段落添加上一章去 + lastChapter.end = + lastChapter.end!! + chapterContent.toByteArray(charset).size + //创建当前章节 + val curChapter = BookChapter() + curChapter.title = matcher.group() + curChapter.start = lastChapter.end + toc.add(curChapter) + } + } else { //是否存在章节 + if (toc.size != 0) { //获取章节内容 + val chapterContent = blockContent.substring(seekPos, matcher.start()) + seekPos += chapterContent.length + //获取上一章节 + val lastChapter = toc.last() + lastChapter.end = + lastChapter.start!! + chapterContent.toByteArray(charset).size + //创建当前章节 + val curChapter = BookChapter() + curChapter.title = matcher.group() + curChapter.start = lastChapter.end + toc.add(curChapter) + } else { //如果章节不存在则创建章节 + val curChapter = BookChapter() + curChapter.title = matcher.group() + curChapter.start = 0L + curChapter.end = 0L + toc.add(curChapter) + } + } + } + } else { //进行本地虚拟分章 + //章节在buffer的偏移量 + var chapterOffset = 0 + //当前剩余可分配的长度 + var strLength = length + //分章的位置 + var chapterPos = 0 + while (strLength > 0) { + ++chapterPos + //是否长度超过一章 + if (strLength > MAX_LENGTH_WITH_NO_CHAPTER) { //在buffer中一章的终止点 + var end = length + //寻找换行符作为终止点 + for (i in chapterOffset + MAX_LENGTH_WITH_NO_CHAPTER until length) { + if (buffer[i] == BLANK) { + end = i + break + } + } + val chapter = BookChapter() + chapter.title = "第${blockPos}章($chapterPos)" + chapter.start = curOffset + chapterOffset + 1 + chapter.end = curOffset + end + toc.add(chapter) + //减去已经被分配的长度 + strLength -= (end - chapterOffset) + //设置偏移的位置 + chapterOffset = end + } else { + val chapter = BookChapter() + chapter.title = "第" + blockPos + "章" + "(" + chapterPos + ")" + chapter.start = curOffset + chapterOffset + 1 + chapter.end = curOffset + length + toc.add(chapter) + strLength = 0 + } + } + } + + //block的偏移点 + curOffset += length.toLong() + + if (rulePattern != null) { //设置上一章的结尾 + val lastChapter = toc.last() + lastChapter.end = curOffset + } + + //当添加的block太多的时候,执行GC + //当添加的block太多的时候,执行GC + if (blockPos % 15 == 0) { + System.gc() + System.runFinalization() + } + } + + for (i in toc.indices) { + val bean = toc[i] + bean.index = i + bean.bookUrl = book.bookUrl + bean.url = (MD5Utils.md5Encode16(book.originName + i + bean.title) ?: "") + } + bookStream.close() + + System.gc() + System.runFinalization() + return toc } - private fun getTocRule(bookStream: RandomAccessFile): String? { + private fun getTocRule(bookStream: RandomAccessFile, charset: Charset): Pattern? { val tocRules = getTocRules() - var tocRule: String? = null + var rulePattern: Pattern? = null //首先获取128k的数据 - val buffer = ByteArray(10240) + val buffer = ByteArray(BUFFER_SIZE / 4) val length = bookStream.read(buffer, 0, buffer.size) - for (str in tocRules) { - + val content = String(buffer, 0, length, charset) + for (tocRule in tocRules) { + val pattern = Pattern.compile(tocRule.rule, Pattern.MULTILINE) + val matcher = pattern.matcher(content) + if (matcher.find()) { + rulePattern = pattern + break + } } - return tocRule + bookStream.seek(0) + return rulePattern } private fun getTocRules(): List { From 325228aab6883b3804a966a453087d807b4e859b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 18:31:25 +0800 Subject: [PATCH 277/852] =?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/rss/read/ReadRssActivity.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index d0311370c..018be1339 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -73,7 +73,13 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r val url = NetworkUtils.getAbsoluteURL(it.origin, it.link) val html = viewModel.clHtml(content) if (viewModel.rssSource?.loadWithBaseUrl == true) { - webView.loadDataWithBaseURL(null, html, "text/html", "utf-8", url)//Referer会导致一些有反盗链的图片无法加载,暂时先用null应该还有更好的办法 + webView.loadDataWithBaseURL( + url, + html, + "text/html", + "utf-8", + url + )//不想用baseUrl进下一个吧 } else { webView.loadData(html, "text/html;charset=utf-8", "utf-8")//经测试可以解决中文乱码 } From 2639db7b6c59b0b19748c9dff7962b1f44a2ac9f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 18:49:28 +0800 Subject: [PATCH 278/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 2 +- .../io/legado/app/ui/rss/read/ReadRssViewModel.kt | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 018be1339..7bbf4e741 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -79,7 +79,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r "text/html", "utf-8", url - )//不想用baseUrl进下一个吧 + )//不想用baseUrl进else } else { webView.loadData(html, "text/html;charset=utf-8", "utf-8")//经测试可以解决中文乱码 } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 36a487a6c..a81655c27 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -85,12 +85,18 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } fun clHtml(content: String): String { - return """ - $content""" + $content + """.trimIndent() + } } override fun onInit(status: Int) { From 2aa0be91ea7fbe9625c3b34a04bf587742846148 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 20:10:16 +0800 Subject: [PATCH 279/852] =?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/data/entities/Book.kt | 5 ++ .../main/java/io/legado/app/help/BookHelp.kt | 5 +- .../app/model/localBook/AnalyzeTxtFile.kt | 31 ++++++++---- .../io/legado/app/service/help/ReadBook.kt | 1 + .../app/ui/book/read/ReadBookViewModel.kt | 47 ++++++++++++------- 5 files changed, 63 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 17198cdda..0d853d2cf 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -10,6 +10,7 @@ import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.Parcelize +import java.nio.charset.Charset import kotlin.math.max @Parcelize @@ -81,6 +82,10 @@ data class Book( variable = GSON.toJson(variableMap) } + fun getCharset(): Charset { + return charset(charset ?: "UTF-8") + } + fun toSearchBook(): SearchBook { return SearchBook( name = name, diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 7635df1f7..018b99605 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -7,6 +7,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.ReplaceRule +import io.legado.app.model.localBook.AnalyzeTxtFile import io.legado.app.utils.* import org.apache.commons.text.similarity.JaccardSimilarity import java.io.File @@ -126,7 +127,9 @@ object BookHelp { } fun getContent(book: Book, bookChapter: BookChapter): String? { - if (downloadUri.isDocumentUri(App.INSTANCE)) { + if (book.isLocalBook()) { + AnalyzeTxtFile.getContent(book, bookChapter) + } else if (downloadUri.isDocumentUri(App.INSTANCE)) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.getDirDocument( root, diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 85c83c514..35c394251 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -28,14 +28,7 @@ object AnalyzeTxtFile { } fun analyze(context: Context, book: Book): ArrayList { - val uri = Uri.parse(book.bookUrl) - val bookFile = FileUtils.getFile(cacheFolder, book.originName, subDirs = *arrayOf()) - if (!bookFile.exists()) { - bookFile.createNewFile() - DocumentUtils.readBytes(context, uri)?.let { - bookFile.writeBytes(it) - } - } + val bookFile = getBookFile(context, book) val charset = charset(EncodingDetect.getEncode(bookFile)) book.charset = charset.name() val toc = arrayListOf() @@ -189,6 +182,28 @@ object AnalyzeTxtFile { return toc } + fun getContent(book: Book, bookChapter: BookChapter): String { + val bookFile = getBookFile(App.INSTANCE, book) + //获取文件流 + val bookStream = RandomAccessFile(bookFile, "r") + bookStream.seek(bookChapter.start ?: 0) + val extent = (bookChapter.end!! - bookChapter.start!!).toInt() + val content = ByteArray(extent) + bookStream.read(content, 0, extent) + return String(content, book.getCharset()) + } + + private fun getBookFile(context: Context, book: Book): File { + val uri = Uri.parse(book.bookUrl) + val bookFile = FileUtils.getFile(cacheFolder, book.originName, subDirs = *arrayOf()) + if (!bookFile.exists()) { + bookFile.createNewFile() + DocumentUtils.readBytes(context, uri)?.let { + bookFile.writeBytes(it) + } + } + return bookFile + } private fun getTocRule(bookStream: RandomAccessFile, charset: Charset): Pattern? { val tocRules = getTocRules() diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 451883b55..770b21e18 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -197,6 +197,7 @@ object ReadBook { private fun download(index: Int) { book?.let { book -> + if (book.isLocalBook()) return if (addLoading(index)) { Coroutine.async { App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 9b987e505..646aa3702 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -10,6 +10,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp import io.legado.app.help.IntentDataHelp import io.legado.app.model.WebBook +import io.legado.app.model.localBook.AnalyzeTxtFile import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook @@ -79,10 +80,14 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { changeDruChapterIndex: ((chapters: List) -> Unit)? = null ) { execute { - ReadBook.webBook?.getBookInfo(book, this) - ?.onSuccess { - loadChapterList(book, changeDruChapterIndex) - } + if (book.isLocalBook()) { + loadChapterList(book, changeDruChapterIndex) + } else { + ReadBook.webBook?.getBookInfo(book, this) + ?.onSuccess { + loadChapterList(book, changeDruChapterIndex) + } + } } } @@ -91,22 +96,30 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { changeDruChapterIndex: ((chapters: List) -> Unit)? = null ) { execute { - ReadBook.webBook?.getChapterList(book, this) - ?.onSuccess(IO) { cList -> - if (!cList.isNullOrEmpty()) { - if (changeDruChapterIndex == null) { - App.db.bookChapterDao().insert(*cList.toTypedArray()) - ReadBook.chapterSize = cList.size - ReadBook.loadContent() + if (book.isLocalBook()) { + AnalyzeTxtFile.analyze(context, book).let { + App.db.bookChapterDao().insert(*it.toTypedArray()) + ReadBook.chapterSize = it.size + ReadBook.loadContent() + } + } else { + ReadBook.webBook?.getChapterList(book, this) + ?.onSuccess(IO) { cList -> + if (!cList.isNullOrEmpty()) { + if (changeDruChapterIndex == null) { + App.db.bookChapterDao().insert(*cList.toTypedArray()) + ReadBook.chapterSize = cList.size + ReadBook.loadContent() + } else { + changeDruChapterIndex(cList) + } } else { - changeDruChapterIndex(cList) + toast(R.string.error_load_toc) } - } else { + }?.onError { toast(R.string.error_load_toc) - } - }?.onError { - toast(R.string.error_load_toc) - } ?: autoChangeSource() + } ?: autoChangeSource() + } } } From 9070f610ecfdf45e254ba2c56f554e5084376f91 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 20:11:20 +0800 Subject: [PATCH 280/852] =?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/model/localBook/AnalyzeTxtFile.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 35c394251..2a21a0e5f 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -29,8 +29,8 @@ object AnalyzeTxtFile { fun analyze(context: Context, book: Book): ArrayList { val bookFile = getBookFile(context, book) - val charset = charset(EncodingDetect.getEncode(bookFile)) - book.charset = charset.name() + book.charset = EncodingDetect.getEncode(bookFile) + val charset = book.getCharset() val toc = arrayListOf() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") From f370e83a3d79a947d8de1913d24cf34f80fa56cc Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 20:13:31 +0800 Subject: [PATCH 281/852] =?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/data/entities/Book.kt | 2 +- .../main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 0d853d2cf..27f9baec8 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -82,7 +82,7 @@ data class Book( variable = GSON.toJson(variableMap) } - fun getCharset(): Charset { + fun fileCharset(): Charset { return charset(charset ?: "UTF-8") } diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 2a21a0e5f..145558a07 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -30,7 +30,7 @@ object AnalyzeTxtFile { fun analyze(context: Context, book: Book): ArrayList { val bookFile = getBookFile(context, book) book.charset = EncodingDetect.getEncode(bookFile) - val charset = book.getCharset() + val charset = book.fileCharset() val toc = arrayListOf() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") @@ -190,7 +190,7 @@ object AnalyzeTxtFile { val extent = (bookChapter.end!! - bookChapter.start!!).toInt() val content = ByteArray(extent) bookStream.read(content, 0, extent) - return String(content, book.getCharset()) + return String(content, book.fileCharset()) } private fun getBookFile(context: Context, book: Book): File { From da0db2b6c0fc7808b422af1bc9b8ebd7f3f3536e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 20:15:13 +0800 Subject: [PATCH 282/852] =?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/data/dao/TxtTocRuleDao.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt index d0ae20207..119daa651 100644 --- a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt @@ -1,11 +1,7 @@ package io.legado.app.data.dao -import androidx.room.Dao -import androidx.room.Insert -import androidx.room.OnConflictStrategy -import androidx.room.Query +import androidx.room.* import io.legado.app.data.entities.TxtTocRule -import retrofit2.http.DELETE @Dao interface TxtTocRuleDao { @@ -19,6 +15,6 @@ interface TxtTocRuleDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg rule: TxtTocRule) - @DELETE + @Delete fun delete(vararg rule: TxtTocRule) } \ No newline at end of file From 2f3e74c66f3dbe6979acbca4a01866df0f82b8a1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 20:18:14 +0800 Subject: [PATCH 283/852] =?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/data/AppDatabase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index b5ace94ba..b817927d0 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -17,7 +17,7 @@ import kotlinx.coroutines.launch entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, RssSource::class, Bookmark::class, RssArticle::class, RssStar::class, TxtTocRule::class], - version = 6, + version = 7, exportSchema = true ) abstract class AppDatabase : RoomDatabase() { From 46d9acbf03c9629064709a455ecdcbcb4e3ca66f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 20:41:42 +0800 Subject: [PATCH 284/852] =?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/ui/book/info/BookInfoViewModel.kt | 97 +++++++++++-------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 8179c058a..0a54aaeac 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -11,6 +11,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookGroup import io.legado.app.help.BookHelp import io.legado.app.model.WebBook +import io.legado.app.model.localBook.AnalyzeTxtFile import kotlinx.coroutines.Dispatchers.IO class BookInfoViewModel(application: Application) : BaseViewModel(application) { @@ -55,26 +56,29 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { book: Book, changeDruChapterIndex: ((chapters: List) -> Unit)? = null ) { - if (book.isLocalBook()) return execute { - isLoadingData.postValue(true) - App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> - WebBook(bookSource).getBookInfo(book, this) - .onSuccess(IO) { - it?.let { - bookData.postValue(book) - if (inBookshelf) { - App.db.bookDao().update(book) + if (book.isLocalBook()) { + loadChapter(book, changeDruChapterIndex) + } else { + isLoadingData.postValue(true) + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> + WebBook(bookSource).getBookInfo(book, this) + .onSuccess(IO) { + it?.let { + bookData.postValue(book) + if (inBookshelf) { + App.db.bookDao().update(book) + } + loadChapter(it, changeDruChapterIndex) } - loadChapter(it, changeDruChapterIndex) + }.onError { + isLoadingData.postValue(false) + toast(R.string.error_get_book_info) } - }.onError { - isLoadingData.postValue(false) - toast(R.string.error_get_book_info) - } - } ?: let { - isLoadingData.postValue(false) - toast(R.string.error_no_source) + } ?: let { + isLoadingData.postValue(false) + toast(R.string.error_no_source) + } } } } @@ -85,33 +89,46 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { ) { execute { isLoadingData.postValue(true) - App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> - WebBook(bookSource).getChapterList(book, this) - .onSuccess(IO) { - it?.let { - if (it.isNotEmpty()) { - if (inBookshelf) { - App.db.bookDao().update(book) - App.db.bookChapterDao().insert(*it.toTypedArray()) - } - if (changeDruChapterIndex == null) { - chapterListData.postValue(it) - isLoadingData.postValue(false) + if (book.isLocalBook()) { + AnalyzeTxtFile.analyze(context, book).let { + App.db.bookDao().update(book) + App.db.bookChapterDao().insert(*it.toTypedArray()) + if (changeDruChapterIndex == null) { + chapterListData.postValue(it) + isLoadingData.postValue(false) + } else { + changeDruChapterIndex(it) + } + } + } else { + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> + WebBook(bookSource).getChapterList(book, this) + .onSuccess(IO) { + it?.let { + if (it.isNotEmpty()) { + if (inBookshelf) { + App.db.bookDao().update(book) + App.db.bookChapterDao().insert(*it.toTypedArray()) + } + if (changeDruChapterIndex == null) { + chapterListData.postValue(it) + isLoadingData.postValue(false) + } else { + changeDruChapterIndex(it) + } } else { - changeDruChapterIndex(it) + isLoadingData.postValue(false) + toast(R.string.chapter_list_empty) } - } else { - isLoadingData.postValue(false) - toast(R.string.chapter_list_empty) } + }.onError { + isLoadingData.postValue(false) + toast(R.string.error_get_chapter_list) } - }.onError { - isLoadingData.postValue(false) - toast(R.string.error_get_chapter_list) - } - } ?: let { - isLoadingData.postValue(false) - toast(R.string.error_no_source) + } ?: let { + isLoadingData.postValue(false) + toast(R.string.error_no_source) + } } } } From a2a0c03d53527a67b99b8abc0673f2ebadecdbb6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 21:18:07 +0800 Subject: [PATCH 285/852] =?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/BookHelp.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 018b99605..2f916adbe 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -128,7 +128,7 @@ object BookHelp { fun getContent(book: Book, bookChapter: BookChapter): String? { if (book.isLocalBook()) { - AnalyzeTxtFile.getContent(book, bookChapter) + return AnalyzeTxtFile.getContent(book, bookChapter) } else if (downloadUri.isDocumentUri(App.INSTANCE)) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.getDirDocument( From c9cc9a617874c188deb8253f928c6efc57187c6d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 21:19:13 +0800 Subject: [PATCH 286/852] =?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/BookHelp.kt | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 2f916adbe..0cdb7e1e8 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -108,20 +108,26 @@ object BookHelp { } fun hasContent(book: Book, bookChapter: BookChapter): Boolean { - if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> - return DocumentUtils.exists( - root, + when { + book.isLocalBook() -> { + return true + } + downloadUri.isDocumentUri(App.INSTANCE) -> { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> + return DocumentUtils.exists( + root, + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ) + } + } + else -> { + return FileUtils.exists( + File(downloadPath), "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) ) } - } else { - return FileUtils.exists( - File(downloadPath), - "${bookChapterName(bookChapter)}.nb", - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - ) } return false } From c043b16fa6fd49b2e9e2f58342ae87c1d818bd7a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 21:21:05 +0800 Subject: [PATCH 287/852] =?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/BookHelp.kt | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 0cdb7e1e8..7071579ea 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -133,44 +133,52 @@ object BookHelp { } fun getContent(book: Book, bookChapter: BookChapter): String? { - if (book.isLocalBook()) { - return AnalyzeTxtFile.getContent(book, bookChapter) - } else if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> - return DocumentUtils.getDirDocument( - root, - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - )?.findFile("${bookChapterName(bookChapter)}.nb") - ?.uri?.readText(App.INSTANCE) + when { + book.isLocalBook() -> { + return AnalyzeTxtFile.getContent(book, bookChapter) } - } else { - val file = FileUtils.getFile( - File(downloadPath), - "${bookChapterName(bookChapter)}.nb", - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - ) - if (file.exists()) { - return file.readText() + downloadUri.isDocumentUri(App.INSTANCE) -> { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> + return DocumentUtils.getDirDocument( + root, + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + )?.findFile("${bookChapterName(bookChapter)}.nb") + ?.uri?.readText(App.INSTANCE) + } + } + else -> { + val file = FileUtils.getFile( + File(downloadPath), + "${bookChapterName(bookChapter)}.nb", + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + ) + if (file.exists()) { + return file.readText() + } } } return null } fun delContent(book: Book, bookChapter: BookChapter) { - if (downloadUri.isDocumentUri(App.INSTANCE)) { - DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> - DocumentUtils.getDirDocument( - root, + when { + book.isLocalBook() -> return + downloadUri.isDocumentUri(App.INSTANCE) -> { + DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> + DocumentUtils.getDirDocument( + root, + subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) + )?.findFile("${bookChapterName(bookChapter)}.nb") + ?.delete() + } + } + else -> { + FileUtils.createFileIfNotExist( + File(downloadPath), + "${bookChapterName(bookChapter)}.nb", subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - )?.findFile("${bookChapterName(bookChapter)}.nb") - ?.delete() + ).delete() } - } else { - FileUtils.createFileIfNotExist( - File(downloadPath), - "${bookChapterName(bookChapter)}.nb", - subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - ).delete() } } From 23e0d446679043ce85eeacb4a99c80dc0f3c80cf Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 21:25:10 +0800 Subject: [PATCH 288/852] =?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/model/localBook/AnalyzeTxtFile.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 145558a07..30f172615 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -168,14 +168,14 @@ object AnalyzeTxtFile { System.runFinalization() } } - + bookStream.close() for (i in toc.indices) { val bean = toc[i] bean.index = i bean.bookUrl = book.bookUrl bean.url = (MD5Utils.md5Encode16(book.originName + i + bean.title) ?: "") } - bookStream.close() + book.latestChapterTitle = toc.last().title System.gc() System.runFinalization() From d261d25330235037fea62d934e833a1425be3fbb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 21:31:07 +0800 Subject: [PATCH 289/852] =?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/ReadBookActivity.kt | 3 +++ .../main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt | 2 +- app/src/main/res/menu/read_book.xml | 4 ++-- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 7437c3cae..f11f3c835 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -219,6 +219,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo R.id.menu_copy_text -> { } + R.id.menu_update_toc -> ReadBook.book?.let { + viewModel.loadChapterList(it) + } } return super.onCompatOptionsItemSelected(item) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 646aa3702..553ab5ede 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -91,7 +91,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } - private fun loadChapterList( + fun loadChapterList( book: Book, changeDruChapterIndex: ((chapters: List) -> Unit)? = null ) { diff --git a/app/src/main/res/menu/read_book.xml b/app/src/main/res/menu/read_book.xml index 2994a6dbe..18d024862 100644 --- a/app/src/main/res/menu/read_book.xml +++ b/app/src/main/res/menu/read_book.xml @@ -80,9 +80,9 @@ app:showAsAction="never" /> 常见问题 显示所有发现 关闭则只显示勾选源的发现 - 更新目录 + 更新目录 txt目录正则 设置编码 倒序-顺序 From f6daceb5c3c0bf0283a7c7a07f22872f44f14121 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 21:32:53 +0800 Subject: [PATCH 290/852] =?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/ReadBookViewModel.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 553ab5ede..bb4ef95f0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -99,6 +99,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { if (book.isLocalBook()) { AnalyzeTxtFile.analyze(context, book).let { App.db.bookChapterDao().insert(*it.toTypedArray()) + App.db.bookDao().update(book) ReadBook.chapterSize = it.size ReadBook.loadContent() } @@ -108,6 +109,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { if (!cList.isNullOrEmpty()) { if (changeDruChapterIndex == null) { App.db.bookChapterDao().insert(*cList.toTypedArray()) + App.db.bookDao().update(book) ReadBook.chapterSize = cList.size ReadBook.loadContent() } else { From 4dde81e9e906633b0aa3dd6897577d191cb26681 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 2 Feb 2020 21:36:53 +0800 Subject: [PATCH 291/852] =?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/assets/updateLog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 8828a731b..b56be4258 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,10 +3,12 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/03** +* 添加本地书籍完成,解析txt文件完成,本地txt可以看了 + **2020/02/02** * merged commit e584606, rss修复BaseURL模式下部分图片无法加载, 修复可能出现的乱码 * 菜单添加网址功能完成 -* 添加本地书籍完成,还差解析txt文件,目前添加了不能看 **2020/01/31** * 修复搜索闪退,因为默认线程为0了 From 1ab80749fbd4c1ef5b715af4edfabf62e8f13546 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 08:42:04 +0800 Subject: [PATCH 292/852] =?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/main/MainActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index bdaf72031..f3a1a4a05 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -86,6 +86,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } override fun onPageSelected(position: Int) { + view_pager_main.hideSoftInput() pagePosition = position when (position) { 0, 1, 3 -> bottom_navigation_view.menu.getItem(position).isChecked = true From 15955676f2c7fc80e386977bad4d585b2896f304 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 08:43:09 +0800 Subject: [PATCH 293/852] =?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/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index b56be4258..ab1238f8a 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,6 +4,7 @@ * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 **2020/02/03** +* 主界面切换时自动隐藏键盘 * 添加本地书籍完成,解析txt文件完成,本地txt可以看了 **2020/02/02** From a964823df80a31cfd0123b42b1c6b66b7768692c Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 09:21:16 +0800 Subject: [PATCH 294/852] =?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/constant/PreferKey.kt | 1 + app/src/main/java/io/legado/app/help/storage/Restore.kt | 2 ++ app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 3c6046bde..ef572f1f3 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -1,6 +1,7 @@ package io.legado.app.constant object PreferKey { + const val versionCode = "versionCode" const val themeMode = "themeMode" const val downloadPath = "downloadPath" const val hideStatusBar = "hideStatusBar" diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 3f7110a54..4385d6282 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -10,6 +10,7 @@ import com.jayway.jsonpath.Option import com.jayway.jsonpath.ParseContext import io.legado.app.App import io.legado.app.constant.AppConst +import io.legado.app.constant.PreferKey import io.legado.app.data.entities.* import io.legado.app.help.ReadBookConfig import io.legado.app.utils.* @@ -117,6 +118,7 @@ object Restore { is String -> edit.putString(it.key, value) else -> Unit } + edit.putInt(PreferKey.versionCode, App.INSTANCE.versionCode) edit.commit() } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index f3a1a4a05..5d9fee452 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -77,8 +77,8 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } private fun upVersion() { - if (getPrefInt("versionCode") != App.INSTANCE.versionCode) { - putPrefInt("versionCode", App.INSTANCE.versionCode) + if (getPrefInt(PreferKey.versionCode) != App.INSTANCE.versionCode) { + putPrefInt(PreferKey.versionCode, App.INSTANCE.versionCode) if (!BuildConfig.DEBUG) { UpdateLog().show(supportFragmentManager, "updateLog") } From ce738b3ff6f3a1292be59c4da909e7959bd815d2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 09:53:54 +0800 Subject: [PATCH 295/852] =?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/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/README.md b/app/src/main/java/io/legado/app/ui/README.md index a1a7a2313..9809241ec 100644 --- a/app/src/main/java/io/legado/app/ui/README.md +++ b/app/src/main/java/io/legado/app/ui/README.md @@ -6,17 +6,17 @@ * book\read 书籍阅读界面 * book\search 搜索书籍界面 * book\source 搜索书源界面 -* changecover 封面换源界面 -* changesource 换源界面 -* chapterlist 目录界面 +* changeCover 封面换源界面 +* changeSource 换源界面 +* chapterList 目录界面 * config 配置界面 * download 下载界面 * explore 发现界面 -* filechooser 文件选择界面 -* importbook 书籍导入界面 +* fileChooser 文件选择界面 +* importBook 书籍导入界面 * main 主界面 -* qrcode 二维码扫描界面 -* replacerule 替换净化界面 +* qrCode 二维码扫描界面 +* replaceRule 替换净化界面 * rss\article 订阅条目界面 * rss\read 订阅阅读界面 * rss\source 订阅源界面 From 71903c290f658ec5288bf8ecef78caad997f2bb9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 10:00:38 +0800 Subject: [PATCH 296/852] =?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/service/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/README.md b/app/src/main/java/io/legado/app/service/README.md index 0b66f70aa..64c4ca44c 100644 --- a/app/src/main/java/io/legado/app/service/README.md +++ b/app/src/main/java/io/legado/app/service/README.md @@ -1 +1,7 @@ -## android服务 \ No newline at end of file +## android服务 +* AudioPlayService 音频播放服务 +* CheckSourceService 书源检测服务 +* DownloadService 缓存服务 +* HttpReadAloudService 在线朗读服务 +* TTSReadAloudService tts朗读服务 +* WebService web服务 \ No newline at end of file From a9b5d52b4c1290e265c0684e460e43c9620fb28d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 10:02:07 +0800 Subject: [PATCH 297/852] =?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/data/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/README.md b/app/src/main/java/io/legado/app/data/README.md index 18061b12d..ec1ddefbe 100644 --- a/app/src/main/java/io/legado/app/data/README.md +++ b/app/src/main/java/io/legado/app/data/README.md @@ -1 +1,3 @@ -## 存储数据用 \ No newline at end of file +## 存储数据用 +* dao 数据操作 +* entities 数据模型 \ No newline at end of file From bf2f12d7adc8d00cf214bca6455a555d94b273e1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 10:09:37 +0800 Subject: [PATCH 298/852] =?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/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/src/main/java/io/legado/app/README.md diff --git a/app/src/main/java/io/legado/app/README.md b/app/src/main/java/io/legado/app/README.md new file mode 100644 index 000000000..b23d4196d --- /dev/null +++ b/app/src/main/java/io/legado/app/README.md @@ -0,0 +1,12 @@ +## 文件结构介绍 + +* base 基类 +* constant 常量 +* data 数据 +* help 帮助 +* lib 库 +* model 解析 +* receiver 广播侦听 +* service 服务 +* ui 界面 +* web web服务 \ No newline at end of file From 37c7a4fdad41bbb6f084c804905d627c9aaae4a1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 10:14:46 +0800 Subject: [PATCH 299/852] =?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/web/ReadMe.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/web/ReadMe.md b/app/src/main/java/io/legado/app/web/ReadMe.md index cd5544c3e..aee2e2dc6 100644 --- a/app/src/main/java/io/legado/app/web/ReadMe.md +++ b/app/src/main/java/io/legado/app/web/ReadMe.md @@ -1 +1,5 @@ -# web服务 \ No newline at end of file +# web服务 + +* controller 数据操作 +* HttpServer http服务 +* WebSocketServer 持续通讯服务 \ No newline at end of file From 8ffa73f269f04843291f1141f6092b7343d12b92 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 10:19:05 +0800 Subject: [PATCH 300/852] =?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/model/localBook/AnalyzeTxtFile.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 30f172615..82ec88179 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -34,7 +34,7 @@ object AnalyzeTxtFile { val toc = arrayListOf() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") - val rulePattern = getTocRule(bookStream, charset) + val rulePattern = getTocRule(book, bookStream, charset) //加载章节 val buffer = ByteArray(BUFFER_SIZE) @@ -205,7 +205,7 @@ object AnalyzeTxtFile { return bookFile } - private fun getTocRule(bookStream: RandomAccessFile, charset: Charset): Pattern? { + private fun getTocRule(book: Book, bookStream: RandomAccessFile, charset: Charset): Pattern? { val tocRules = getTocRules() var rulePattern: Pattern? = null //首先获取128k的数据 @@ -216,6 +216,7 @@ object AnalyzeTxtFile { val pattern = Pattern.compile(tocRule.rule, Pattern.MULTILINE) val matcher = pattern.matcher(content) if (matcher.find()) { + book.tocUrl = tocRule.rule rulePattern = pattern break } From 1e569347055a41db36e6031c119691828e7f93ea Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 11:10:37 +0800 Subject: [PATCH 301/852] =?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/read/config/MoreConfigDialog.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 0eac917a1..3251cfc94 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -94,7 +94,6 @@ class MoreConfigDialog : DialogFragment() { when (key) { PreferKey.hideStatusBar -> postEvent(Bus.UP_CONFIG, true) PreferKey.hideNavigationBar -> postEvent(Bus.UP_CONFIG, true) - PreferKey.clickAllNext -> postEvent(Bus.UP_CONFIG, true) PreferKey.keepLight -> postEvent(PreferKey.keepLight, true) } } From d42e687ba322a47e93131b4a9619a25b23769e36 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 11:19:59 +0800 Subject: [PATCH 302/852] =?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/AppConfig.kt | 2 ++ .../legado/app/ui/book/read/page/delegate/PageDelegate.kt | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 31107ad5f..002fee5ff 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -52,4 +52,6 @@ object AppConfig { val isEInkMode: Boolean get() = App.INSTANCE.getPrefBoolean("isEInkMode") + + val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index e5ccf1b65..e4cbf9560 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -9,10 +9,9 @@ import android.widget.Scroller import androidx.annotation.CallSuper import androidx.interpolator.view.animation.FastOutLinearInInterpolator import com.google.android.material.snackbar.Snackbar -import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.ui.book.read.page.ContentView import io.legado.app.ui.book.read.page.PageView -import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.screenshot import io.legado.app.utils.snackbar import kotlin.math.abs @@ -256,7 +255,8 @@ abstract class PageDelegate(protected val pageView: PageView) { setTouchPoint(x, y) } else { bitmap = if (x > viewWidth / 2 || - pageView.context.getPrefBoolean(PreferKey.clickAllNext, false)) { + AppConfig.clickAllNext + ) { //设置动画方向 if (!hasNext()) { return true From 1d3bcac3d78b18b1e366002c7f49ee0a10d799ce Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 11:24:52 +0800 Subject: [PATCH 303/852] =?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/res/menu/read_book.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/menu/read_book.xml b/app/src/main/res/menu/read_book.xml index 18d024862..a67fd0fb6 100644 --- a/app/src/main/res/menu/read_book.xml +++ b/app/src/main/res/menu/read_book.xml @@ -41,7 +41,7 @@ Date: Mon, 3 Feb 2020 11:42:00 +0800 Subject: [PATCH 304/852] =?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/ui/book/read/ReadBookActivity.kt | 21 +++++++++++++++++-- .../ui/book/read/config/ReadAloudDialog.kt | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index f11f3c835..ee387edb8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -67,6 +67,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo private val requestCodeChapterList = 568 private val requestCodeEditSource = 111 private val requestCodeReplace = 312 + private var replaceUseMenu: MenuItem? = null override val viewModel: ReadBookViewModel get() = getViewModel(ReadBookViewModel::class.java) @@ -85,7 +86,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo initView() upScreenTimeOut() ReadBook.callBack = this - ReadBook.titleDate.observe(this, Observer { title_bar.title = it }) + ReadBook.titleDate.observe(this, Observer { + title_bar.title = it + upMenu() + }) viewModel.initData(intent) } @@ -143,9 +147,18 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.read_book, menu) + replaceUseMenu = menu.findItem(R.id.menu_enable_replace) + upMenu() return super.onCompatCreateOptionsMenu(menu) } + private fun upMenu() { + ReadBook.book?.let { + replaceUseMenu?.isChecked = it.useReplaceRule + } + + } + /** * 菜单 */ @@ -222,6 +235,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo R.id.menu_update_toc -> ReadBook.book?.let { viewModel.loadChapterList(it) } + R.id.menu_enable_replace -> ReadBook.book?.let { + it.useReplaceRule = !it.useReplaceRule + replaceUseMenu?.isChecked = it.useReplaceRule + } } return super.onCompatOptionsItemSelected(item) } @@ -378,7 +395,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo seek_read_page.progress = ReadBook.durPageIndex } - override fun showMenu() { + override fun showMenuBar() { read_menu.runMenuIn() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index a20ac2efe..f464d99b2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -101,7 +101,7 @@ class ReadAloudDialog : DialogFragment() { } private fun initOnClick() { - iv_menu.onClick { callBack?.showMenu(); dismiss() } + iv_menu.onClick { callBack?.showMenuBar(); dismiss() } iv_other_config.onClick { ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") } @@ -135,7 +135,7 @@ class ReadAloudDialog : DialogFragment() { } interface CallBack { - fun showMenu() + fun showMenuBar() fun openChapterList() fun onClickReadAloud() fun finish() From 7824d938551ae4a87aac0c0335ab68a2e8f29867 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 12:25:07 +0800 Subject: [PATCH 305/852] =?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/data/entities/Book.kt | 4 ++ .../io/legado/app/service/help/ReadBook.kt | 1 + .../app/ui/book/read/ReadBookActivity.kt | 37 +++++++++++++++---- app/src/main/res/menu/read_book.xml | 2 +- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 27f9baec8..0c43860f0 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -53,6 +53,10 @@ data class Book( return origin == BookType.local } + fun isTxt(): Boolean { + return isLocalBook() && originName.endsWith(".txt", true) + } + @Ignore @IgnoredOnParcel override var variableMap: HashMap? = null diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 770b21e18..f5227f731 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -39,6 +39,7 @@ object ReadBook { durChapterIndex = book.durChapterIndex durPageIndex = book.durChapterPos isLocalBook = book.origin == BookType.local + webBook = null App.db.bookSourceDao().getBookSource(book.origin)?.let { webBook = WebBook(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index ee387edb8..60057a622 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -13,7 +13,9 @@ import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.EditText +import androidx.core.view.get import androidx.core.view.isVisible +import androidx.core.view.size import androidx.lifecycle.Observer import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import io.legado.app.App @@ -67,7 +69,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo private val requestCodeChapterList = 568 private val requestCodeEditSource = 111 private val requestCodeReplace = 312 - private var replaceUseMenu: MenuItem? = null + private var menu: Menu? = null override val viewModel: ReadBookViewModel get() = getViewModel(ReadBookViewModel::class.java) @@ -147,16 +149,34 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.read_book, menu) - replaceUseMenu = menu.findItem(R.id.menu_enable_replace) - upMenu() return super.onCompatCreateOptionsMenu(menu) } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + this.menu = menu + upMenu() + return super.onPrepareOptionsMenu(menu) + } + private fun upMenu() { - ReadBook.book?.let { - replaceUseMenu?.isChecked = it.useReplaceRule + menu?.let { menu -> + ReadBook.book?.let { book -> + val onLine = !book.isLocalBook() + for (i in 0 until menu.size) { + val item = menu[i] + when (item.groupId) { + R.id.menu_group_on_line -> item.isVisible = onLine + R.id.menu_group_local -> item.isVisible = !onLine + R.id.menu_group_text -> item.isVisible = book.isTxt() + R.id.menu_group_login -> + item.isVisible = !ReadBook.webBook?.bookSource?.loginUrl.isNullOrEmpty() + else -> if (item.itemId == R.id.menu_enable_replace) { + item.isChecked = book.useReplaceRule + } + } + } + } } - } /** @@ -221,7 +241,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ReadBook.durChapterIndex, ReadBook.durPageIndex, textChapter!!.title, - editContent) + editContent + ) App.db.bookmarkDao().insert(bookmark) } } @@ -237,7 +258,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } R.id.menu_enable_replace -> ReadBook.book?.let { it.useReplaceRule = !it.useReplaceRule - replaceUseMenu?.isChecked = it.useReplaceRule + menu?.findItem(R.id.menu_enable_replace)?.isChecked = it.useReplaceRule } } return super.onCompatOptionsItemSelected(item) diff --git a/app/src/main/res/menu/read_book.xml b/app/src/main/res/menu/read_book.xml index a67fd0fb6..b27cd41ff 100644 --- a/app/src/main/res/menu/read_book.xml +++ b/app/src/main/res/menu/read_book.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" tools:context=".ui.main.MainActivity"> - + Date: Mon, 3 Feb 2020 13:07:16 +0800 Subject: [PATCH 306/852] =?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/OtherConfigFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 7a0d7fb0f..c865aeae6 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -188,6 +188,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.downloadPath, uri.toString()) + BookHelp.upDownloadPath() } } } From 1503fadbee1079f74d38e31f10524d4de1357ec0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 13:52:45 +0800 Subject: [PATCH 307/852] =?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/config/BackupConfigFragment.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index d403324fe..10c787bac 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -47,10 +47,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(), fun bindPreferenceSummaryToValue(preference: Preference?) { preference?.apply { onPreferenceChangeListener = this@BackupConfigFragment - onPreferenceChange( - this, - context.getPrefString(key) - ) + onPreferenceChange(this, context.getPrefString(key)) } } addPreferencesFromResource(R.xml.pref_config_backup) From 6c92f21a2682f1db8c73f0d1a7002c227eeb8eb8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 15:22:02 +0800 Subject: [PATCH 308/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/changecover/ChangeCoverDialog.kt | 4 ++-- .../legado/app/ui/changecover/ChangeCoverViewModel.kt | 11 +++++++++++ .../java/io/legado/app/ui/changecover/CoverAdapter.kt | 3 +++ .../legado/app/ui/changesource/ChangeSourceDialog.kt | 6 +----- .../app/ui/changesource/ChangeSourceViewModel.kt | 4 ++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index f566cbbbb..0eb939fe4 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -13,7 +13,7 @@ import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.dialog_change_source.* -class ChangeCoverDialog : DialogFragment() { +class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { companion object { const val tag = "changeCoverDialog" @@ -32,7 +32,7 @@ class ChangeCoverDialog : DialogFragment() { private var callBack: CallBack? = null private lateinit var viewModel: ChangeCoverViewModel - private lateinit var adapter: CoverAdapter + override lateinit var adapter: CoverAdapter override fun onStart() { super.onStart() diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index 5f12c56b2..b38ced035 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.changecover import android.app.Application +import io.legado.app.App import io.legado.app.base.BaseViewModel class ChangeCoverViewModel(application: Application) : BaseViewModel(application) { @@ -8,5 +9,15 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application var name: String = "" var author: String = "" + fun initData() { + execute { + App.db.searchBookDao().getByNameAuthorEnable(name, author).let { + } + } + } + + interface CallBack { + var adapter: CoverAdapter + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index 408acbeb4..0290d7749 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -22,4 +22,7 @@ class CoverAdapter(context: Context) : } } + interface CallBack { + fun changeTo() + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index edf3057a3..1097a936c 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -40,7 +40,7 @@ class ChangeSourceDialog : DialogFragment(), private var callBack: CallBack? = null private lateinit var viewModel: ChangeSourceViewModel - private lateinit var changeSourceAdapter: ChangeSourceAdapter + override lateinit var changeSourceAdapter: ChangeSourceAdapter override fun onStart() { super.onStart() @@ -139,10 +139,6 @@ class ChangeSourceDialog : DialogFragment(), override val bookUrl: String? get() = callBack?.oldBook?.bookUrl - override fun adapter(): ChangeSourceAdapter { - return changeSourceAdapter - } - interface CallBack { val oldBook: Book? fun changeTo(book: Book) diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 3b16a4359..cccdd0e71 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -40,7 +40,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio private fun upAdapter() { execute { - callBack?.adapter()?.let { + callBack?.changeSourceAdapter?.let { val books = searchBooks.toList() books.sorted() val diffResult = DiffUtil.calculateDiff(DiffCallBack(it.getItems(), books)) @@ -131,7 +131,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } interface CallBack { - fun adapter(): ChangeSourceAdapter + var changeSourceAdapter: ChangeSourceAdapter } override fun onCleared() { From 24359939167395e3f3695c45191abbba0380d032 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 15:25:29 +0800 Subject: [PATCH 309/852] =?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/changecover/ChangeCoverDialog.kt | 1 + .../java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt | 2 +- .../java/io/legado/app/ui/changesource/ChangeSourceDialog.kt | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 0eb939fe4..4d3176695 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -47,6 +47,7 @@ class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { savedInstanceState: Bundle? ): View? { viewModel = getViewModel(ChangeCoverViewModel::class.java) + viewModel.callBack = this return inflater.inflate(R.layout.dialog_change_source, container) } diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index b38ced035..4e59d4d00 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -5,7 +5,7 @@ import io.legado.app.App import io.legado.app.base.BaseViewModel class ChangeCoverViewModel(application: Application) : BaseViewModel(application) { - + var callBack: CallBack? = null var name: String = "" var author: String = "" diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index 1097a936c..be039e6d0 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -55,6 +55,7 @@ class ChangeSourceDialog : DialogFragment(), savedInstanceState: Bundle? ): View? { viewModel = getViewModel(ChangeSourceViewModel::class.java) + viewModel.callBack = this return inflater.inflate(R.layout.dialog_change_source, container) } @@ -92,7 +93,6 @@ class ChangeSourceDialog : DialogFragment(), DividerItemDecoration(requireContext(), LinearLayout.VERTICAL) ) recycler_view.adapter = changeSourceAdapter - viewModel.callBack = this } private fun initSearchView() { From 5e754a31301bef89e9fa3dc9348343f5e8cc1aff Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 18:50:45 +0800 Subject: [PATCH 310/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/SearchBookDao.kt | 8 ++++++++ .../app/ui/changecover/ChangeCoverDialog.kt | 1 + .../app/ui/changecover/ChangeCoverViewModel.kt | 18 ++++++++++++++++-- .../ui/changesource/ChangeSourceViewModel.kt | 10 +++++----- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt index 7e623bfcc..fd3f69951 100644 --- a/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/SearchBookDao.kt @@ -28,6 +28,14 @@ interface SearchBookDao { @Query("select * from searchBooks where name = :name and author = :author and origin in (select bookSourceUrl from book_sources where enabled = 1) order by originOrder") fun getByNameAuthorEnable(name: String, author: String): List + @Query( + """select * from searchBooks + where name = :name and author = :author and origin in (select bookSourceUrl from book_sources where enabled = 1) + and coverUrl is not null and coverUrl <> '' + order by originOrder""" + ) + fun getEnableHasCover(name: String, author: String): List + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg searchBook: SearchBook): List diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 4d3176695..cc8554a7f 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -66,6 +66,7 @@ class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) adapter = CoverAdapter(requireContext()) recycler_view.adapter = adapter + viewModel.initData() } interface CallBack { diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index 4e59d4d00..6c5fb759b 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -3,20 +3,34 @@ package io.legado.app.ui.changecover import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.help.AppConfig +import kotlinx.coroutines.asCoroutineDispatcher +import java.util.concurrent.Executors class ChangeCoverViewModel(application: Application) : BaseViewModel(application) { + private var searchPool = + Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() var callBack: CallBack? = null var name: String = "" var author: String = "" fun initData() { execute { - App.db.searchBookDao().getByNameAuthorEnable(name, author).let { - + App.db.searchBookDao().getEnableHasCover(name, author).let { + callBack?.adapter?.setItems(it) } } } + fun search() { + + } + + override fun onCleared() { + super.onCleared() + searchPool.close() + } + interface CallBack { var adapter: CoverAdapter } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index cccdd0e71..1b6a4e679 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -42,7 +42,6 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio execute { callBack?.changeSourceAdapter?.let { val books = searchBooks.toList() - books.sorted() val diffResult = DiffUtil.calculateDiff(DiffCallBack(it.getItems(), books)) withContext(Main) { synchronized(this) { @@ -130,12 +129,13 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } } - interface CallBack { - var changeSourceAdapter: ChangeSourceAdapter - } - override fun onCleared() { super.onCleared() searchPool.close() } + + interface CallBack { + var changeSourceAdapter: ChangeSourceAdapter + } + } \ No newline at end of file From 3c3654f2781a52b14fae92c78ecd090067fd1154 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 18:54:27 +0800 Subject: [PATCH 311/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/info/BookInfoActivity.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index fb689519c..0c1713246 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -24,6 +24,7 @@ import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.ui.book.info.edit.BookInfoEditActivity import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity +import io.legado.app.ui.changecover.ChangeCoverDialog import io.legado.app.ui.changesource.ChangeSourceDialog import io.legado.app.ui.chapterlist.ChapterListActivity import io.legado.app.utils.getViewModel @@ -40,7 +41,8 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_book_info, theme = Theme.Dark), GroupSelectDialog.CallBack, ChapterListAdapter.CallBack, - ChangeSourceDialog.CallBack { + ChangeSourceDialog.CallBack, + ChangeCoverDialog.CallBack { private val requestCodeChapterList = 568 private val requestCodeSourceEdit = 562 @@ -184,6 +186,9 @@ class BookInfoActivity : } private fun initOnClick() { + iv_cover.onClick { + + } tv_read.onClick { viewModel.bookData.value?.let { readBook(it) @@ -276,6 +281,13 @@ class BookInfoActivity : viewModel.changeTo(book) } + override fun coverChangeTo(coverUrl: String) { + viewModel.bookData.value?.let { + it.coverUrl = coverUrl + viewModel.saveBook() + } + } + override fun openChapter(chapter: BookChapter) { if (chapter.index != viewModel.durChapterIndex) { viewModel.bookData.value?.let { From 3c2e0f53de61ce0f4b4f00fc77f4afe3c5764af1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 18:56:51 +0800 Subject: [PATCH 312/852] =?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/ui/book/info/BookInfoActivity.kt | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 0c1713246..9a829baa8 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -112,23 +112,13 @@ class BookInfoActivity : } private fun showBook(book: Book) { + showCover(book) tv_name.text = book.name tv_author.text = getString(R.string.author_show, book.author) tv_origin.text = getString(R.string.origin_show, book.originName) tv_lasted.text = getString(R.string.lasted_show, book.latestChapterTitle) tv_toc.text = getString(R.string.toc_s, book.latestChapterTitle) tv_intro.text = book.getDisplayIntro() - book.getDisplayCover()?.let { - ImageLoader.load(this, it) - .centerCrop() - .into(iv_cover) - ImageLoader.load(this, it) - .transition(DrawableTransitionOptions.withCrossFade(1500)) - .thumbnail(defaultCover()) - .centerCrop() - .apply(bitmapTransform(BlurTransformation(this, 25))) - .into(bg_book) //模糊、渐变、缩小效果 - } val kinds = book.getKindList() if (kinds.isEmpty()) { ll_kind.gone() @@ -161,6 +151,20 @@ class BookInfoActivity : } } + private fun showCover(book: Book) { + book.getDisplayCover()?.let { + ImageLoader.load(this, it) + .centerCrop() + .into(iv_cover) + ImageLoader.load(this, it) + .transition(DrawableTransitionOptions.withCrossFade(1500)) + .thumbnail(defaultCover()) + .centerCrop() + .apply(bitmapTransform(BlurTransformation(this, 25))) + .into(bg_book) //模糊、渐变、缩小效果 + } + } + private fun showChapter(chapterList: List) { viewModel.bookData.value?.let { if (it.durChapterIndex < chapterList.size) { @@ -285,6 +289,7 @@ class BookInfoActivity : viewModel.bookData.value?.let { it.coverUrl = coverUrl viewModel.saveBook() + showCover(it) } } From f09dda0e8a00297ad082d7d362030818c8f4dbeb Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 19:39:35 +0800 Subject: [PATCH 313/852] =?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/info/BookInfoActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 9a829baa8..6f5c23d67 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -191,7 +191,9 @@ class BookInfoActivity : private fun initOnClick() { iv_cover.onClick { - + viewModel.bookData.value?.let { + ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) + } } tv_read.onClick { viewModel.bookData.value?.let { From d1d91d95d76ffa9efe8df0b807ba56ba444765b2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 19:59:37 +0800 Subject: [PATCH 314/852] =?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/ui/changecover/ChangeCoverDialog.kt | 6 +++- .../ui/changecover/ChangeCoverViewModel.kt | 31 +++++++++++++++++++ .../legado/app/ui/changecover/CoverAdapter.kt | 4 +++ .../app/ui/changesource/ChangeSourceDialog.kt | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index cc8554a7f..24ecbd7f0 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -7,6 +7,7 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Observer import androidx.recyclerview.widget.GridLayoutManager import io.legado.app.R import io.legado.app.utils.getViewModel @@ -46,6 +47,7 @@ class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { container: ViewGroup?, savedInstanceState: Bundle? ): View? { + callBack = activity as? CallBack viewModel = getViewModel(ChangeCoverViewModel::class.java) viewModel.callBack = this return inflater.inflate(R.layout.dialog_change_source, container) @@ -53,7 +55,9 @@ class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - callBack = activity as? CallBack + viewModel.searchStateData.observe(this, Observer { + refresh_progress_bar.isAutoLoading = it + }) tool_bar.setTitle(R.string.change_cover_source) arguments?.let { bundle -> bundle.getString("name")?.let { diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index 6c5fb759b..066fdf99c 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -1,9 +1,13 @@ package io.legado.app.ui.changecover import android.app.Application +import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.help.AppConfig +import io.legado.app.help.coroutine.Coroutine +import io.legado.app.model.WebBook +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors @@ -13,17 +17,44 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application var callBack: CallBack? = null var name: String = "" var author: String = "" + private var task: Coroutine<*>? = null + val searchStateData = MutableLiveData() fun initData() { execute { App.db.searchBookDao().getEnableHasCover(name, author).let { callBack?.adapter?.setItems(it) + search() } } } fun search() { + task = execute { + searchStateData.postValue(true) + val bookSourceList = App.db.bookSourceDao().allEnabled + for (item in bookSourceList) { + //task取消时自动取消 by (scope = this@execute) + WebBook(item).searchBook(name, scope = this@execute, context = searchPool) + .timeout(30000L) + .onSuccess(Dispatchers.IO) { + if (it != null && it.isNotEmpty()) { + val searchBook = it[0] + if (searchBook.name == name && searchBook.author == author) { + callBack?.adapter?.let { adapter -> + if (!adapter.getItems().contains(searchBook)) { + adapter.addItem(searchBook) + } + } + } + } + } + } + } + task?.invokeOnCompletion { + searchStateData.postValue(false) + } } override fun onCleared() { diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index 0290d7749..ba250a8a2 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -7,6 +7,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchBook import io.legado.app.help.ImageLoader import kotlinx.android.synthetic.main.item_cover.view.* +import org.jetbrains.anko.sdk27.listeners.onClick class CoverAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_cover) { @@ -19,6 +20,9 @@ class CoverAdapter(context: Context) : .into(iv_cover) } tv_source.text = item.originName + onClick { + + } } } diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index be039e6d0..c05e171b1 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -54,6 +54,7 @@ class ChangeSourceDialog : DialogFragment(), container: ViewGroup?, savedInstanceState: Bundle? ): View? { + callBack = activity as? CallBack viewModel = getViewModel(ChangeSourceViewModel::class.java) viewModel.callBack = this return inflater.inflate(R.layout.dialog_change_source, container) @@ -61,7 +62,6 @@ class ChangeSourceDialog : DialogFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - callBack = activity as? CallBack viewModel.searchStateData.observe(viewLifecycleOwner, Observer { refresh_progress_bar.isAutoLoading = it }) From 85dfd302749ef965c8664442f4d4f8ad754382f9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 20:14:32 +0800 Subject: [PATCH 315/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/changecover/ChangeCoverViewModel.kt | 7 +++++-- .../main/java/io/legado/app/ui/changecover/CoverAdapter.kt | 1 + app/src/main/res/layout/item_cover.xml | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index 066fdf99c..f2b351c68 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -22,10 +22,13 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application fun initData() { execute { - App.db.searchBookDao().getEnableHasCover(name, author).let { + App.db.searchBookDao().getEnableHasCover(name, author) + }.onSuccess { + it?.let { callBack?.adapter?.setItems(it) - search() } + }.onFinally { + search() } } diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index ba250a8a2..f952a8b20 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -16,6 +16,7 @@ class CoverAdapter(context: Context) : with(holder.itemView) { item.coverUrl?.let { ImageLoader.load(context, it) + .error(R.drawable.image_cover_default) .centerCrop() .into(iv_cover) } diff --git a/app/src/main/res/layout/item_cover.xml b/app/src/main/res/layout/item_cover.xml index 018b5f2f8..b80cf9b6c 100644 --- a/app/src/main/res/layout/item_cover.xml +++ b/app/src/main/res/layout/item_cover.xml @@ -15,7 +15,6 @@ android:layout_height="100dp" android:contentDescription="@string/img_cover" android:scaleType="centerCrop" - android:src="@drawable/image_cover_default" android:transitionName="img_cover" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" From bed1bc8f7ab5e9179b8a74e750c72f1246442bba Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 20:26:07 +0800 Subject: [PATCH 316/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/changecover/ChangeCoverViewModel.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index f2b351c68..5469717bd 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -8,7 +8,9 @@ import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.withContext import java.util.concurrent.Executors class ChangeCoverViewModel(application: Application) : BaseViewModel(application) { @@ -44,9 +46,12 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application if (it != null && it.isNotEmpty()) { val searchBook = it[0] if (searchBook.name == name && searchBook.author == author) { + App.db.searchBookDao().insert(searchBook) callBack?.adapter?.let { adapter -> if (!adapter.getItems().contains(searchBook)) { - adapter.addItem(searchBook) + withContext(Main) { + adapter.addItem(searchBook) + } } } } From 0ff380e183b1e756729b369a0a013f534c83c4ca Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 20:32:03 +0800 Subject: [PATCH 317/852] =?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/changecover/ChangeCoverViewModel.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index 5469717bd..27899a44c 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -8,7 +8,6 @@ import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.withContext import java.util.concurrent.Executors @@ -49,7 +48,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application App.db.searchBookDao().insert(searchBook) callBack?.adapter?.let { adapter -> if (!adapter.getItems().contains(searchBook)) { - withContext(Main) { + withContext(Dispatchers.Main) { adapter.addItem(searchBook) } } From 682712cc842b73e82c39054f50cd2e2a6bf9fe91 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 20:43:09 +0800 Subject: [PATCH 318/852] =?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/res/layout/item_cover.xml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/app/src/main/res/layout/item_cover.xml b/app/src/main/res/layout/item_cover.xml index b80cf9b6c..9956e4bd1 100644 --- a/app/src/main/res/layout/item_cover.xml +++ b/app/src/main/res/layout/item_cover.xml @@ -1,13 +1,12 @@ - + android:orientation="vertical"> - \ No newline at end of file + \ No newline at end of file From 7f2ba54d9d38facc36799485ee96a9bfbf3f9d0f Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 20:47:33 +0800 Subject: [PATCH 319/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/changecover/ChangeCoverDialog.kt | 10 ++++++++-- .../legado/app/ui/changecover/ChangeCoverViewModel.kt | 4 +++- .../java/io/legado/app/ui/changecover/CoverAdapter.kt | 6 +++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 24ecbd7f0..73486159d 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -14,7 +14,9 @@ import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.dialog_change_source.* -class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { +class ChangeCoverDialog : DialogFragment(), + ChangeCoverViewModel.CallBack, + CoverAdapter.CallBack { companion object { const val tag = "changeCoverDialog" @@ -68,11 +70,15 @@ class ChangeCoverDialog : DialogFragment(), ChangeCoverViewModel.CallBack { } } recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) - adapter = CoverAdapter(requireContext()) + adapter = CoverAdapter(requireContext(), this) recycler_view.adapter = adapter viewModel.initData() } + override fun changeTo(coverUrl: String) { + callBack?.coverChangeTo(coverUrl) + } + interface CallBack { fun coverChangeTo(coverUrl: String) } diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt index 27899a44c..d8ed01d9f 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverViewModel.kt @@ -44,7 +44,9 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application .onSuccess(Dispatchers.IO) { if (it != null && it.isNotEmpty()) { val searchBook = it[0] - if (searchBook.name == name && searchBook.author == author) { + if (searchBook.name == name && searchBook.author == author + && !searchBook.coverUrl.isNullOrEmpty() + ) { App.db.searchBookDao().insert(searchBook) callBack?.adapter?.let { adapter -> if (!adapter.getItems().contains(searchBook)) { diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index f952a8b20..884e4adff 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -9,7 +9,7 @@ import io.legado.app.help.ImageLoader import kotlinx.android.synthetic.main.item_cover.view.* import org.jetbrains.anko.sdk27.listeners.onClick -class CoverAdapter(context: Context) : +class CoverAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_cover) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { @@ -22,12 +22,12 @@ class CoverAdapter(context: Context) : } tv_source.text = item.originName onClick { - + callBack.changeTo(item.coverUrl!!) } } } interface CallBack { - fun changeTo() + fun changeTo(coverUrl: String) } } \ No newline at end of file From 303d234ece494daad06cf5d7c67bbb24483e8833 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 21:18:02 +0800 Subject: [PATCH 320/852] =?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/ui/widget/image/CoverImageView.kt | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 289790a1a..2db34ef74 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -4,18 +4,31 @@ import android.annotation.SuppressLint import android.content.Context import android.graphics.Canvas import android.graphics.Path +import android.text.TextPaint import android.util.AttributeSet +import io.legado.app.utils.dp class CoverImageView : androidx.appcompat.widget.AppCompatImageView { internal var width: Float = 0.toFloat() internal var height: Float = 0.toFloat() + private val textPaint = TextPaint() + private var name: String? = null + constructor(context: Context) : super(context) constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( + context, + attrs, + defStyleAttr + ) + + init { + textPaint.textSize = 13.dp.toFloat() + } override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { super.onLayout(changed, left, top, right, bottom) @@ -26,7 +39,10 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) val measuredHeight = measuredWidth * 7 / 5 - super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(measuredHeight, MeasureSpec.EXACTLY)) + super.onMeasure( + widthMeasureSpec, + MeasureSpec.makeMeasureSpec(measuredHeight, MeasureSpec.EXACTLY) + ) } override fun onDraw(canvas: Canvas) { @@ -47,6 +63,14 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { canvas.clipPath(path) } super.onDraw(canvas) + name?.let { + canvas.drawText(it, width / 3, height * 2 / 3, textPaint) + } + } + + fun setName(name: String) { + this.name = name + invalidate() } fun setHeight(height: Int) { From da891e122732f767eca8761a6fff9a45da7656ab Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 21:55:41 +0800 Subject: [PATCH 321/852] =?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/ui/book/info/BookInfoActivity.kt | 28 ++++----- .../main/bookshelf/books/BooksAdapterGrid.kt | 9 +-- .../main/bookshelf/books/BooksAdapterList.kt | 9 +-- .../app/ui/widget/image/CoverImageView.kt | 59 +++++++++++++++---- 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 6f5c23d67..37d8c6d3f 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -106,11 +106,6 @@ class BookInfoActivity : return super.onMenuOpened(featureId, menu) } - private fun defaultCover(): RequestBuilder { - return ImageLoader.load(this, R.drawable.image_cover_default) - .apply(bitmapTransform(BlurTransformation(this, 25))) - } - private fun showBook(book: Book) { showCover(book) tv_name.text = book.name @@ -152,17 +147,18 @@ class BookInfoActivity : } private fun showCover(book: Book) { - book.getDisplayCover()?.let { - ImageLoader.load(this, it) - .centerCrop() - .into(iv_cover) - ImageLoader.load(this, it) - .transition(DrawableTransitionOptions.withCrossFade(1500)) - .thumbnail(defaultCover()) - .centerCrop() - .apply(bitmapTransform(BlurTransformation(this, 25))) - .into(bg_book) //模糊、渐变、缩小效果 - } + iv_cover.load(book.getDisplayCover(), book.name) + ImageLoader.load(this, book.getDisplayCover()) + .transition(DrawableTransitionOptions.withCrossFade(1500)) + .thumbnail(defaultCover()) + .centerCrop() + .apply(bitmapTransform(BlurTransformation(this, 25))) + .into(bg_book) //模糊、渐变、缩小效果 + } + + private fun defaultCover(): RequestBuilder { + return ImageLoader.load(this, R.drawable.image_cover_default) + .apply(bitmapTransform(BlurTransformation(this, 25))) } private fun showChapter(chapterList: List) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt index f6761ce78..5cc19d9fc 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt @@ -5,7 +5,6 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.constant.BookType import io.legado.app.data.entities.Book -import io.legado.app.help.ImageLoader import io.legado.app.lib.theme.ATH import io.legado.app.utils.invisible import kotlinx.android.synthetic.main.item_bookshelf_grid.view.* @@ -21,13 +20,7 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) : ATH.applyBackgroundTint(this) tv_name.text = item.name bv_author.text = item.author - item.getDisplayCover()?.let { - ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.image_cover_default) - .error(R.drawable.image_cover_default) - .centerCrop() - .into(iv_cover) - } + iv_cover.load(item.getDisplayCover(), item.name) onClick { callBack.open(item) } onLongClick { callBack.openBookInfo(item) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt index 133f865d9..948b9128e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt @@ -5,7 +5,6 @@ import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.constant.BookType import io.legado.app.data.entities.Book -import io.legado.app.help.ImageLoader import io.legado.app.lib.theme.ATH import io.legado.app.utils.invisible import kotlinx.android.synthetic.main.item_bookshelf_list.view.* @@ -23,13 +22,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : tv_author.text = item.author tv_read.text = item.durChapterTitle tv_last.text = item.latestChapterTitle - item.getDisplayCover()?.let { - ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.image_cover_default) - .error(R.drawable.image_cover_default) - .centerCrop() - .into(iv_cover) - } + iv_cover.load(item.getDisplayCover(), item.name) onClick { callBack.open(item) } onLongClick { callBack.openBookInfo(item) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 2db34ef74..8e520d222 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -4,9 +4,15 @@ import android.annotation.SuppressLint import android.content.Context import android.graphics.Canvas import android.graphics.Path +import android.graphics.drawable.Drawable import android.text.TextPaint import android.util.AttributeSet -import io.legado.app.utils.dp +import com.bumptech.glide.load.DataSource +import com.bumptech.glide.load.engine.GlideException +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +import io.legado.app.R +import io.legado.app.help.ImageLoader class CoverImageView : androidx.appcompat.widget.AppCompatImageView { @@ -26,16 +32,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { defStyleAttr ) - init { - textPaint.textSize = 13.dp.toFloat() - } - - override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { - super.onLayout(changed, left, top, right, bottom) - width = getWidth().toFloat() - height = getHeight().toFloat() - } - override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) val measuredHeight = measuredWidth * 7 / 5 @@ -45,6 +41,13 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { ) } + override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { + super.onLayout(changed, left, top, right, bottom) + width = getWidth().toFloat() + height = getHeight().toFloat() + textPaint.textSize = width / 9 + } + override fun onDraw(canvas: Canvas) { if (width >= 10 && height > 10) { @SuppressLint("DrawAllocation") @@ -77,4 +80,38 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { val width = height * 5 / 7 minimumWidth = width } + + fun load(path: String?, name: String) { + if (path.isNullOrEmpty()) { + setName(name) + } else { + ImageLoader.load(context, path)//Glide自动识别http://和file:// + .placeholder(R.drawable.image_cover_default) + .error(R.drawable.image_cover_default) + .listener(object : RequestListener { + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target?, + isFirstResource: Boolean + ): Boolean { + setName(name) + return false + } + + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { + return false + } + + }) + .centerCrop() + .into(this) + } + } } From 150d1b15bc71ead3b397dc6b434f9c78b88524d6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 21:59:34 +0800 Subject: [PATCH 322/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/info/edit/BookInfoEditActivity.kt | 7 ++----- .../java/io/legado/app/ui/book/search/SearchAdapter.kt | 8 +------- .../java/io/legado/app/ui/widget/image/CoverImageView.kt | 5 +++-- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index a4e420af1..9f7b387f2 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -8,7 +8,6 @@ import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book -import io.legado.app.help.ImageLoader import io.legado.app.ui.changecover.ChangeCoverDialog import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_book_info_edit.* @@ -59,10 +58,8 @@ class BookInfoEditActivity : } private fun upCover() { - viewModel.book?.getDisplayCover()?.let { - ImageLoader.load(this, it) - .centerCrop() - .into(iv_cover) + viewModel.book.let { + iv_cover.load(it?.getDisplayCover(), it?.name) } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 04d2e46f8..49127927f 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -67,13 +67,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } } } - searchBook.coverUrl.let { - ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.image_cover_default) - .error(R.drawable.image_cover_default) - .centerCrop() - .into(iv_cover) - } + iv_cover.load(searchBook.coverUrl, searchBook.name) onClick { callBack.showBookInfo(searchBook.name, searchBook.author) } diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 8e520d222..33cb24b43 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -71,7 +71,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } } - fun setName(name: String) { + fun setName(name: String?) { this.name = name invalidate() } @@ -81,7 +81,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { minimumWidth = width } - fun load(path: String?, name: String) { + fun load(path: String?, name: String?) { if (path.isNullOrEmpty()) { setName(name) } else { @@ -106,6 +106,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { dataSource: DataSource?, isFirstResource: Boolean ): Boolean { + setName(null) return false } From 5feebce678c9e375180c0bc21876635031076357 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 22:01:26 +0800 Subject: [PATCH 323/852] =?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/explore/ExploreShowAdapter.kt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt index d25e7f255..9afad2422 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt @@ -6,7 +6,6 @@ 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.SearchBook -import io.legado.app.help.ImageLoader import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_bookshelf_list.view.iv_cover @@ -58,13 +57,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : } } } - item.coverUrl.let { - ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.image_cover_default) - .error(R.drawable.image_cover_default) - .centerCrop() - .into(iv_cover) - } + iv_cover.load(item.coverUrl, item.name) onClick { callBack.showBookInfo(item.toBook()) } From 88482d25d7cec430fde3f7ae5442c32ad2254842 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 22:02:16 +0800 Subject: [PATCH 324/852] =?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/changecover/CoverAdapter.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index 884e4adff..e6934675d 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -5,7 +5,6 @@ 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.SearchBook -import io.legado.app.help.ImageLoader import kotlinx.android.synthetic.main.item_cover.view.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -14,12 +13,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) : override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { with(holder.itemView) { - item.coverUrl?.let { - ImageLoader.load(context, it) - .error(R.drawable.image_cover_default) - .centerCrop() - .into(iv_cover) - } + iv_cover.load(item.coverUrl, item.name) tv_source.text = item.originName onClick { callBack.changeTo(item.coverUrl!!) From 12f49e3df3754115daa37280d0fbe370170cba39 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 22:12:28 +0800 Subject: [PATCH 325/852] =?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/widget/image/CoverImageView.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 33cb24b43..eb82ad0d5 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.content.Context import android.graphics.Canvas import android.graphics.Path +import android.graphics.Typeface import android.graphics.drawable.Drawable import android.text.TextPaint import android.util.AttributeSet @@ -46,6 +47,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { width = getWidth().toFloat() height = getHeight().toFloat() textPaint.textSize = width / 9 + textPaint.typeface = Typeface.DEFAULT_BOLD } override fun onDraw(canvas: Canvas) { From c8a47f789150f683d4219db6eb00274dccae195d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 3 Feb 2020 22:38:37 +0800 Subject: [PATCH 326/852] =?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/ui/widget/image/CoverImageView.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index eb82ad0d5..06cefd274 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -2,9 +2,7 @@ package io.legado.app.ui.widget.image import android.annotation.SuppressLint import android.content.Context -import android.graphics.Canvas -import android.graphics.Path -import android.graphics.Typeface +import android.graphics.* import android.graphics.drawable.Drawable import android.text.TextPaint import android.util.AttributeSet @@ -33,6 +31,11 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { defStyleAttr ) + init { + textPaint.typeface = Typeface.DEFAULT_BOLD + textPaint.isAntiAlias = true + } + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) val measuredHeight = measuredWidth * 7 / 5 @@ -46,8 +49,8 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { super.onLayout(changed, left, top, right, bottom) width = getWidth().toFloat() height = getHeight().toFloat() - textPaint.textSize = width / 9 - textPaint.typeface = Typeface.DEFAULT_BOLD + textPaint.textSize = width / 8 + textPaint.strokeWidth = textPaint.textSize / 10 } override fun onDraw(canvas: Canvas) { @@ -69,7 +72,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } super.onDraw(canvas) name?.let { - canvas.drawText(it, width / 3, height * 2 / 3, textPaint) + textPaint.color = Color.WHITE + textPaint.style = Paint.Style.STROKE + canvas.drawText(it, width / 6, height * 2 / 3, textPaint) + textPaint.color = Color.BLACK + textPaint.style = Paint.Style.FILL + canvas.drawText(it, width / 6, height * 2 / 3, textPaint) } } From 9acd86f556d4ca830fb3c18bee5f414b88ac9c80 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 08:40:56 +0800 Subject: [PATCH 327/852] =?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/ui/book/info/BookInfoActivity.kt | 2 +- .../ui/book/info/edit/BookInfoEditActivity.kt | 2 +- .../app/ui/book/search/SearchAdapter.kt | 2 +- .../legado/app/ui/changecover/CoverAdapter.kt | 2 +- .../app/ui/explore/ExploreShowAdapter.kt | 2 +- .../main/bookshelf/books/BooksAdapterGrid.kt | 2 +- .../main/bookshelf/books/BooksAdapterList.kt | 2 +- .../app/ui/widget/image/CoverImageView.kt | 66 +++++++++---------- 8 files changed, 39 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 37d8c6d3f..6b0e5433f 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -147,7 +147,7 @@ class BookInfoActivity : } private fun showCover(book: Book) { - iv_cover.load(book.getDisplayCover(), book.name) + iv_cover.load(book.getDisplayCover(), book.name, book.author) ImageLoader.load(this, book.getDisplayCover()) .transition(DrawableTransitionOptions.withCrossFade(1500)) .thumbnail(defaultCover()) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 9f7b387f2..6bcae9257 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -59,7 +59,7 @@ class BookInfoEditActivity : private fun upCover() { viewModel.book.let { - iv_cover.load(it?.getDisplayCover(), it?.name) + iv_cover.load(it?.getDisplayCover(), it?.name, it?.author) } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 49127927f..4a725e854 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -67,7 +67,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } } } - iv_cover.load(searchBook.coverUrl, searchBook.name) + iv_cover.load(searchBook.coverUrl, searchBook.name, searchBook.author) onClick { callBack.showBookInfo(searchBook.name, searchBook.author) } diff --git a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt index e6934675d..a26c21f57 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/CoverAdapter.kt @@ -13,7 +13,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) : override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { with(holder.itemView) { - iv_cover.load(item.coverUrl, item.name) + iv_cover.load(item.coverUrl, item.name, item.author) tv_source.text = item.originName onClick { callBack.changeTo(item.coverUrl!!) diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt index 9afad2422..8e2fcf5e8 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt @@ -57,7 +57,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : } } } - iv_cover.load(item.coverUrl, item.name) + iv_cover.load(item.coverUrl, item.name, item.author) onClick { callBack.showBookInfo(item.toBook()) } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt index 5cc19d9fc..ffb608f4f 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt @@ -20,7 +20,7 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) : ATH.applyBackgroundTint(this) tv_name.text = item.name bv_author.text = item.author - iv_cover.load(item.getDisplayCover(), item.name) + iv_cover.load(item.getDisplayCover(), item.name, item.author) onClick { callBack.open(item) } onLongClick { callBack.openBookInfo(item) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt index 948b9128e..71b70f0c2 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt @@ -22,7 +22,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : tv_author.text = item.author tv_read.text = item.durChapterTitle tv_last.text = item.latestChapterTitle - iv_cover.load(item.getDisplayCover(), item.name) + iv_cover.load(item.getDisplayCover(), item.name, item.author) onClick { callBack.open(item) } onLongClick { callBack.openBookInfo(item) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 06cefd274..2f7bfb74e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -20,6 +20,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { private val textPaint = TextPaint() private var name: String? = null + private var author: String? = null constructor(context: Context) : super(context) @@ -81,8 +82,9 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } } - fun setName(name: String?) { + fun setName(name: String?, author: String?) { this.name = name + this.author = author invalidate() } @@ -91,38 +93,34 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { minimumWidth = width } - fun load(path: String?, name: String?) { - if (path.isNullOrEmpty()) { - setName(name) - } else { - ImageLoader.load(context, path)//Glide自动识别http://和file:// - .placeholder(R.drawable.image_cover_default) - .error(R.drawable.image_cover_default) - .listener(object : RequestListener { - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: Target?, - isFirstResource: Boolean - ): Boolean { - setName(name) - return false - } - - override fun onResourceReady( - resource: Drawable?, - model: Any?, - target: Target?, - dataSource: DataSource?, - isFirstResource: Boolean - ): Boolean { - setName(null) - return false - } - - }) - .centerCrop() - .into(this) - } + fun load(path: String?, name: String?, author: String?) { + ImageLoader.load(context, path)//Glide自动识别http://和file:// + .placeholder(R.drawable.image_cover_default) + .error(R.drawable.image_cover_default) + .listener(object : RequestListener { + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target?, + isFirstResource: Boolean + ): Boolean { + setName(name, author) + return false + } + + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { + setName(null, null) + return false + } + + }) + .centerCrop() + .into(this) } } From a34697b5404da7415cd9a448dd0421ca6dc04824 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 09:05:02 +0800 Subject: [PATCH 328/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/widget/image/CoverImageView.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 2f7bfb74e..a494f9ca9 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -35,6 +35,8 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { init { textPaint.typeface = Typeface.DEFAULT_BOLD textPaint.isAntiAlias = true + textPaint.textAlign = Paint.Align.CENTER + textPaint.textSkewX = -0.2f } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { @@ -50,7 +52,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { super.onLayout(changed, left, top, right, bottom) width = getWidth().toFloat() height = getHeight().toFloat() - textPaint.textSize = width / 8 + textPaint.textSize = width / 6 textPaint.strokeWidth = textPaint.textSize / 10 } @@ -75,15 +77,20 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { name?.let { textPaint.color = Color.WHITE textPaint.style = Paint.Style.STROKE - canvas.drawText(it, width / 6, height * 2 / 3, textPaint) + canvas.drawText(it, width / 2, height * 3 / 5, textPaint) textPaint.color = Color.BLACK textPaint.style = Paint.Style.FILL - canvas.drawText(it, width / 6, height * 2 / 3, textPaint) + canvas.drawText(it, width / 2, height * 3 / 5, textPaint) } } fun setName(name: String?, author: String?) { - this.name = name + this.name = + when { + name == null -> null + name.length > 5 -> name.substring(0, 4) + "…" + else -> name + } this.author = author invalidate() } From d6367e716fb88246ba3f393d6089c67b5367688e Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 09:30:33 +0800 Subject: [PATCH 329/852] =?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/ui/widget/image/CoverImageView.kt | 53 +++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index a494f9ca9..014280a7a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -17,8 +17,10 @@ import io.legado.app.help.ImageLoader class CoverImageView : androidx.appcompat.widget.AppCompatImageView { internal var width: Float = 0.toFloat() internal var height: Float = 0.toFloat() - - private val textPaint = TextPaint() + private var nameHeight = 0f + private var authorHeight = 0f + private val namePaint = TextPaint() + private val authorPaint = TextPaint() private var name: String? = null private var author: String? = null @@ -33,10 +35,14 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { ) init { - textPaint.typeface = Typeface.DEFAULT_BOLD - textPaint.isAntiAlias = true - textPaint.textAlign = Paint.Align.CENTER - textPaint.textSkewX = -0.2f + namePaint.typeface = Typeface.DEFAULT_BOLD + namePaint.isAntiAlias = true + namePaint.textAlign = Paint.Align.CENTER + namePaint.textSkewX = -0.2f + authorPaint.typeface = Typeface.DEFAULT + authorPaint.isAntiAlias = true + authorPaint.textAlign = Paint.Align.CENTER + authorPaint.textSkewX = -0.1f } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { @@ -52,8 +58,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { super.onLayout(changed, left, top, right, bottom) width = getWidth().toFloat() height = getHeight().toFloat() - textPaint.textSize = width / 6 - textPaint.strokeWidth = textPaint.textSize / 10 + namePaint.textSize = width / 6 + namePaint.strokeWidth = namePaint.textSize / 10 + authorPaint.textSize = width / 9 + authorPaint.strokeWidth = authorPaint.textSize / 10 + nameHeight = height * 3 / 5 + authorHeight = nameHeight + authorPaint.fontSpacing } override fun onDraw(canvas: Canvas) { @@ -75,12 +85,20 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } super.onDraw(canvas) name?.let { - textPaint.color = Color.WHITE - textPaint.style = Paint.Style.STROKE - canvas.drawText(it, width / 2, height * 3 / 5, textPaint) - textPaint.color = Color.BLACK - textPaint.style = Paint.Style.FILL - canvas.drawText(it, width / 2, height * 3 / 5, textPaint) + namePaint.color = Color.WHITE + namePaint.style = Paint.Style.STROKE + canvas.drawText(it, width / 2, nameHeight, namePaint) + namePaint.color = Color.BLACK + namePaint.style = Paint.Style.FILL + canvas.drawText(it, width / 2, nameHeight, namePaint) + } + author?.let { + authorPaint.color = Color.WHITE + authorPaint.style = Paint.Style.STROKE + canvas.drawText(it, width / 2, authorHeight, authorPaint) + authorPaint.color = Color.BLACK + authorPaint.style = Paint.Style.FILL + canvas.drawText(it, width / 2, authorHeight, authorPaint) } } @@ -91,7 +109,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { name.length > 5 -> name.substring(0, 4) + "…" else -> name } - this.author = author + this.author = + when { + author == null -> null + author.length > 8 -> author.substring(0, 7) + "…" + else -> author + } invalidate() } From e5bd78d50118484545a57c5deed8b5cccef95068 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 09:52:28 +0800 Subject: [PATCH 330/852] =?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/ui/widget/image/CoverImageView.kt | 6 +++--- .../main/res/drawable/image_cover_default.jpg | Bin 6927 -> 11323 bytes 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 014280a7a..64e61508b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -62,7 +62,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { namePaint.strokeWidth = namePaint.textSize / 10 authorPaint.textSize = width / 9 authorPaint.strokeWidth = authorPaint.textSize / 10 - nameHeight = height * 3 / 5 + nameHeight = height / 2 authorHeight = nameHeight + authorPaint.fontSpacing } @@ -88,7 +88,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { namePaint.color = Color.WHITE namePaint.style = Paint.Style.STROKE canvas.drawText(it, width / 2, nameHeight, namePaint) - namePaint.color = Color.BLACK + namePaint.color = Color.RED namePaint.style = Paint.Style.FILL canvas.drawText(it, width / 2, nameHeight, namePaint) } @@ -96,7 +96,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { authorPaint.color = Color.WHITE authorPaint.style = Paint.Style.STROKE canvas.drawText(it, width / 2, authorHeight, authorPaint) - authorPaint.color = Color.BLACK + authorPaint.color = Color.RED authorPaint.style = Paint.Style.FILL canvas.drawText(it, width / 2, authorHeight, authorPaint) } diff --git a/app/src/main/res/drawable/image_cover_default.jpg b/app/src/main/res/drawable/image_cover_default.jpg index 6504a4e7e8857ff417e2564aec97897265ef3289..0b502033cdc6c48b811d9880eaadf55438cb965b 100644 GIT binary patch literal 11323 zcmb8VcTm$$)IRzN3B5`aloB9Fkq%O&wo!Ob)ea_6z?Cv?wo~wzg1%LsmgU|s$AOHYe7vO3d z&;+O{Darr0Qc_-b{|D5R)YLT8*Nv8e<^~-t9StKpBmXT^Sm3Wx`hXh1UL2Z2$m+ z{s+MS0}u%qLP|z{J*db4fWX%vfslg1q}LMx5XlW504&Ll$a+~)&6~t zS!0n5wa+JQ;~mBVlga-d;{Rp+|1kf*#3DBU5)u;7H8C0Z|JuD~2J=Wl7>(7RG4Xm; zkuoP<(}phYUrhlt*M_f0Zvd*mh5Bq?yMssG6hZW^Fw#+@hTWQ)M6>?qfVo&tj)R9x zT+*&+-NGYqCF?&gm2Qjy-9RnF_KeEVDUGaBfSfqI(qV;UZ_=fRgk0cs zihx~KxWnJ!E(j#?If@Pr3NZrrT}E3bY)?mDuW;!h_|hMkax>0gDOWmnVFR$&AbeQir|TsjHhZ7SH{mpvcRD)$F=Qzw zyy=!(s)i6H?V|)GPt4Vutk|jdJ)8ZlB)k0>aS9(!DYXpsHHIP}yAPE!c2RLA^9eJP zS}Ej8v>EOPW;YFu4C0&(%k;nGs#t_g!NtyuQS;$9dY&h{iEu8Skxx++s6?b0zY7_1 zE3r~b@RS@{)qJNbzZ1|c2&LIuZ>BrBeWuO6pTooqJl?)9?V-8Eb>Hxh;3fB5YOor| zIABWhaRit`Jlm}$4c!`{X>k&mf(Cyc(5b#11(oTOxXnVXZ7@6UO*U|90%50_K2~vg z(vTIsy%zOCg<`==W0=8IOwCo zZp%J?DYr?sAYprgqjw2oYS`#I;dWSHz-?`?d%!GgD)F~pO*Dr^(@{+AMNL|fZ#-~} z_dYaO++*)Z<1NO=(N@iBt4dAvIBuOob)v)b{b3Lz}n=vXN3y~Pg{rC2p&xVACYY*HxC+*&sL&(P9U zc=ffVVtFpD3#!7In(8Kx2#D@>U_(X4hl0zxFaLrZCQ;iTjPS#`1@4D`v+RGPX}gHB zJLNoZxLJyjH>3Ddp<8MajBMQHFZE&5N1Cf7 zy_wok>3m0@!Y$97Jbd1GA$Ys>`})8woataU(An;AHvBh|No->8ENAd-q$g-4YYF46 zgh3~G!MQuRo)p=24{0Qb$a?y+5mu)jkB|-Yo5;^*h3_8ZdYs1sj^IkJ$1av8YfpoY zVqb-sH}H9Cg>=d8uM9OAF-YBS+ItSO&~K{W;a$A~{^fzpQeQs*nBpQ}MG%^tjbl*q zcwBcvv*0x#66q*H&;Dk(PE@k^=zbH2iTgKA8Nb|{k)kstdtOeaBZEpI4f1Q4`h6tKc>uu>-F3q@0(cdH7GAw$Vem zpt_+A@r;sxA{E1^&KNl6udd|dWc&*f^@=BxGuO9FEZj}lcqADHCQ7WZDG9H9wY)cjSw%+X5%-ykb zFsnaZ@+sxLcIRW7a=RHLSoz}VP~F{;CG*~eYIyp{2(kTzU@`yA=f{Hh_7|dUxk|ue z67-we2laGwT5#s}AkmJ8@vik|_oqhzkeiW__GI!H^!X+V z5a8(;ln3ZkGsZc?8*LuvFyA=vooRI2O!hcHi;K>THJ&vnM;I#wTmiJa=%~mmAf4gC zYEKv_bSeX*<|}gBW~fFLPsJrGr_Qs4-=N&ZH+(V9Qal!w5r;%(2~iuVi_+b5b&ps0u-btTwwWw)IP4po?*Iz)D>WM5KJF1%2 z1_+2a&Wrix-kCsEKrposA`&1Kt_hDF5qnU|S5x}*!1W5yP&-Oz zpZM&)wKK%reSMN~Xs)phx~C5gKml_FJjKZ`e}czZhi=UOY8?H{q~*Obgv zUnpZpZnz0Kf%=TUExrxNUrixVu_s1QTyJdX?FQ!$^u!a(FU++s(G`b+p9ymmyh{w_ zFlS@F|H{A7SO5H&oimKpDS(q6Lmiw_i~XZ*e%dt*@6J^{`{`#-2^BC$JX77F3o!hx z{X+b`{_nPuV^pFWh_Wv3*ljXP`$sZEpy8^v+``KH2;q#$xhEXx%$v>^f(8Y6ci%gX z)2Fc<+;j@lwUYRS%HzCcx*pDN^)keU1kts3d^_?XCj>91meX7TV|U(wR|PC5=6z}S zg1OArzpw+C)*`vi9Mhq%2dTrGdBoPo zC`t3xY`)|rR=&$R4k_0dcb^iovUujkkGv16{A(%4z0KEUJ7#e@t7>d(q1NaIzYB*D zyVWFF^r*a%Pq?(FF9bIg-HDWz|C;b$AE8I0>%!Q8Qg;x1#)Zp%)8AUxsG_y}^rpx8 z@8Zk+zMrlZ+N~*WtZFaOR;9g<(9teSaGHow8NXAE^;rNI^U3tyZxT7W8(QmaohNt z%Va2h)5S0AZ>Qe-u$&)>m%h7N44@8fn!VW~a1(><4k&V4$Jb`N`o=E2wS1+TReCDj z3g-u8`(Xu*Zp`2v0SRXM9bd*P!0Oj>WxVD#ifx7`Tdi$`rXxH%WB^pqtxng`ec1nF z#;PK<q!mYTNkxh z$~Iji;PG|d8z=-~)C2zPF9{~>+sZwbId`j?Fn_#ko7%0E&%KXtEO3{zIITCjZsNel z%gkpgi=S_)59QR#l5n@aEAiwZgTq#}p^-GZoSRJuTJd%n2c_`(;a7R#3Y{ulIb4E9 z_tCc14}uR2t8P>Yc;1ycA2Mn8=Gc;bcKICM<_l#H^mgLHsBR9#+EIi;Y9(}89LReN<=wN#-&GC~nmsfx(g^D@TTjG4UDSupI zR`1c&`>FTiqc5d4R%baskf-k1y)4=g%|B7AbDM6o1`*N2g{q>6ZBmthM?wAg?a*?B z4v|PP_SkZa1JZr?K7gj>!2Nb>rb7xc-a=si&f56XFpy=Y)bKrtNf*Ae&t4ivuTznz zl_m@b4Wzj)RZt#_ckx{`;iJ#%@&=mj=fur7e)q}WRBw4dMz24jB`OT{*Q~S|dsMpl zf*7tY00|0Cek7#JfBr#txP5%Nhi-CtCm1a^gAV7~waBQZ^!)RLoF2=zK2`MF>qJJe zmfP6GnU)ytC>5ek!|`V&o7=6l`0oHov(U0z%v|W^iw@dqlg(!$T-NZx1DCcL>_R0z z&#A>y2iWcZPLGdv&1r_Uw7-k8AvJmB6pYA&EKtUDn=3IP$#$gt3JJo@ARuZ-8_s|C z)Q*;4EF9M0jWTKLO*+DgxCbcA+=HIoOp>s5AL|JJrU~#x`ajNQ164v+?g5lZkr3~J zoI7FGiG$v=zY??8TYPgdotV`g=`IR+xWgOtzQqQ=U5zSkI#TJO7HiHU$MpZoSnfEW z)F9F~#O5u%|AVA@n!k;c@8*lGSE8esY^hOr`{0kYgjbzD3NG^Z3SiP=BY8UiXAOsO z!dw9l9?GpRjJO;AR4CEVggf_5sHd$mTYW!M8%} z0zqSX)ijx--Mgs*Dnd=ZV$&o&E})RU$&3*HlyX6hu`(WE;|VEsRsRn({O7Ok^^IG7 zyy;Q!DI-+*VN=X$;-66(R6g~aD?m2$c32}{(jw=>omyqxN1ojHe1;fn^Imud)!i{W z2$2%00f2aD7_ndpCl}$#vPq7$Rr-`yBq%ipBXV0Ni`HW%NXr8Kk8*1)1X}<3iI}Li?Gqb=_#?T#FM)?@$eso)@p41dgICQX5`-@ zPt(YcP~sSfKO9RbK$5|*oBB4bUPel$UHW{jx`Fu@%D8CSESH0PjOxX4&+fx_&j31( z7NPik(K)$&<9HB1l|zK2XAxhTQjm-8^599BdVf-vg&0pAxP2)RJ>y`b)LR0+QJp$L za@z%naKFcTVfluC4{E>c(x7yN$N!o4m9*$*X$<#3ltXa9CjG zh%^(Z-k}%t%Th6;3Bfl2CF8Q|Zzv<}j}bG?XA6@W)*~LXd^C#)W+4yLp`UwQ@Cc&t zj$YHZ-TKdTE$J659}RlY@b6(>cq8XIP1C+<@5fU}=#(69DNT>xOw%p09y;*O^CJ}ay$U`a1XaOfsX-k3>>O_dhb)=|CYL#a zGRp6QRzdD#(9Z_s0?ER3s7G=jiEH6u2FYof44k9!5`smoL9A&En?|15-;+*_O?0(q zbz-BFM5rshC5tmCr#PSgi zq)I)a1J1woSUth4?$a;yE1yWxxBWG$*FkPc=;}lN|vu1r`>Llc+fNdcNrf@oonJ$9VkJ`F?qWCc)dn3T0()OhgzZA!-KJvcO zkwIBr-&ZVJ>EMNIF3R1t#Avt4)9r_q%U6KNkvK|^tuKV6m~tHJXD#68buN>z=-Upk z@prNk%ld(?9-gBYC<+|tmRXODXScSdcBMP8bXO{SJt)I4&@5(L3{OYK8Lw|l$38~Q zNa3co#PxciFEhEGm>G#X1J>SYP^rVmV3Dcs=q+>kd6Fu@zFcc>p)I+~#wZ)cub$e1 z7HJQM3E`W)Y2xC%)lUbEpeZY~Jlb#c=;lHcC!?*&GbxuaJ)=#jo`Z51zfd9{)KBdy zq0I8wGj0Wz;y@(@_yo86nb}>vr3c-V^zv*a^`6*79~FwndUh`CTL*mq6||&9p;yls zzn`MAEkV2>cc1WwnQUG$zJW)Cm84AhXfQ-ob)d)&O!n{2yUZ7B0aS@K+YEE_L;D8o z?>aFOeCc2eOUYWRS!t=ck24HHHqtY?-s6Awd0lJ_cg(FAgO}tu`eqio=I#v|wLYfa zBxyrq?C^@tdh3RMMl=))$??afl1|`l&cgiGio-%D>yi>&253Fj$n032(_&16bY}*f zQ|UOXR0j_kspSJ>9Q((f(cbm004z!& z(62b_f#+8v%wn7az8vFeN=^bxT^a8WJ8z8~04YJM6~?4GDU;66Oq?WuUZwag-vSD# zq^BC)&PjTz1Am{Q2^hA3KO3VUG=(hnWNEQFPHvE=q7WjNPkNX~i#)eLV91}7Jgv%h z92)p*8gZX-nzehKdHD_N{(ym1X9IckvWrLBg6APzKz?M${H6`r%1G}R6HFcgP}827 zka`9f40~Q|z~H3W0rkbz8W^OS1Elg?SDNm<%o4AKmW;Hz_^C1Job`>*3OUS~_sK9b z3^Y`rcz|Y5t@Ehx_2QaERn~wI7|J<#KOIJ4E9QAA2)1Y9%C!T4?FUjgJuTc0^hGnT zHO3cUwR!f7{+K?Br*T_@R#?x4KT1Hl%^^Rjy6FmFGd7~&8r?EXen7HZ8)eKUzmWPhnzB*P4SZe$y zT}s@bg2y2sH2esDVZD$gE0uA!g~<^{c4B7ORHYnOL z=814lG}9=BO=&9J4k~s;{7nV0%PjJwQHpR-)``fVlFFfyLdP2f=#P@g?X0|yx9r}g zzonOk5?1sOrOzagb_!-}?z>U})+P>U>m8jHt|cN@Bw~W8k@U^k!}}e<2U={MZSBqw z)2xZiRCWk%SJfqCJ9uG-yY_Z#Wr-k9Luwyy!jyp!6Sv_>N$_QGGNf&I$(oC+aEy6p zuMO{MKUefXMY&^8mn3qx9-z-%BeFO(jFe@DM%}1lfii7|gW@UQ&L0sbZ1ezKDMV8D zmm*iH0yGd=Vy6RHC;}$Q*>^Q-YPt*2{SpO(&?Z(T_<(FQQ{ucsE>mJ1<@pnvSPO90 z31?9rLa!2&**?@V#<&p(^MMTZc#a~yBe6&G7L6z|vvB@B&?+i1$( zr=N<(+|n6kO9!0(`4M#M7C##LBgVr!!eL|!nx5@IvwjSWR=^I|C$vW&G)u{HVRWk zmGUbJ5X$kMW**F9$I$4Dqrw?!kFMJRVUI)hksqla$lArL-L`crQpBLiqx!uJxSg`~ zO#XIo(;J!N_7FCmnyjfGlCA*Mq1@KX3$A?qh=Ulbq-4^#lGE3khIwZXLyA-s_UUrU zbUT9CY61@}^rtsvN4?N}$@wD)$}z1}avs9ZzLy27XXuK%OUf@-1Amv)WTZxn!N}}O zMjnxB?h9zVAfpglZ9n>F*x`-P6-j^eEY8AvI~AymO20=FKwD5O_|a(C zTEZ3kUvhwB`x<^{T6%YPD&ge*nGvfGW{93oGJzkk85Dxm*h04r zXcXw_pfQf5Z+_k*9QIkZcqe+%EjnA`7PkNRNO)Wf_@wqaIzqxUxAgS2wnpD7R{v3r zezM83uNqTUuJ^g3shG+nxh#1`c7zOatsq!&D!y%?M2aPxMK^@8B^+BCvrTh36fQL@ zpQ*B*bTt(jUMsV~3zRV0n}&nxz}qhoy83?ThZJLM80O?M#Ea_(Ny+S%Dp3RZif6i3 zZ;SKc+aQhIgIMjnSKK-FX2}}Ki+ZvnI8`P+IgH)EdHUZKfx=h7z(z`G!6s{R#g`v4 zA_Sa;i-R#^_?%|gobNa5eAMgnFPrsVax(n0vD75X;CtVyeOHA(m1>@P?_7@YJ2D z*pY~g=XIv*+QZlyoZjXL{4BkyLEb}jTQ}bExBf!+z$I5CC<7h})nd5s^@N*t^TT0~ z+_zTO$F1(GXE#x4AhRC?Z09?gp5NhC!&C6x)r?qda_)=~oT>q3rbSvrM#YzYOCMeH zqX(n1%`6E@0Jzqtvgbow)WSGOsIeRj-^?$UUaJUPJRWuW{V$j(Wb%@gv^JTjbsJCP z|1Oj8_GtU53X^zVq&li5T3qDv`9VUQkI+eiW!wuGsX_Rg;B}7t?d@npgHZbbLhzj{wMwYNh z(EuSK*>oYp2mrrcK!n|0|J0JGtlfW8F*r+hV0DIf!kQat)QyBsM@m`YfORgnbzAh?g-*6&G=sHjZz7!p$*~k%KFX$-F z0!%^_z*XC7$VzXk+03MegoXmidVN9RGV05kW?rHEI4p-M(tL>&q$ z4wA*Vgs-VVnIxWSW8+9kh zc6c+_RZj9CgG-XPch#0#-z}EXRhRz?<{Y*9t@!)sQ*iq56;O=cAHkwQgd_}b=QG2H zgpg~cdppEr&m*)cIjd zD)*bk~TnPY#>G0b|pod%Wrra8%UQ%$1txHh|DjF+Z zO)i>?jeoBfdjsEzNKWOJ1@@z(&E-hDpex+?&WIay|J~=htCjL^gaE+=!5B1fU*JQw z+!-cVpnOHZ01KKC>W^IZr|?uihe<_BlTYDTO4t6G<>1T7&1rJmHjy|u^a_yAB{Swh zLJ9nt%#nB09AAXXfX$LJ1J)b!u^=rn2xmOhRWMg5^cz(|irb?bFA@As$l(aa4{&38 zqBwDo(($~c%}cz+dRVEmTXWFx#rc3!FKF_JD-d1KW?RW8s^7*weY%T$T7&m>7bKPL z50fXY{?GC0{_~)F9V0$=C8c|9(Imk|Wca!m$fgT;nSV zQ7?n&s`plXiuC(qKN04tycd3a==?~SrGouI{L`jw*KSQ4Dmb~d^R#-OJN`f2$NSX( zRb&rC&XpF|5~UR#r9s!b@7SlFC!7uF+xUE2v3brtop+D zzh&UNY_5xEKZhnaK801}v04c=j?FeZOf~a%5&0D(vqo6T3bdt1o;14+nPs@N%NAqjD#wyj z^ryHW?HVGo9{t@q-y9%hbuQ!#`~G*L+u7F;Qf}BM!s+~(P$cM_{Q71f)$-=`KUr$f zE%#!o0L*QynMUgr8^|KLIidLb`F&O4zQSKVK0ilYHr;YTR z$5bV4Q;>E$A=MLSA?!v;j(6hrt@sdmcvCSx{>u*W18ja{H#v#;NHL)QV=ez6CH-z% z#kDx|$7Wl<(B;=wAXnR;JwY7Ym-lIALb=A5Q8$-bS5Y-Zx8e{H!Ow3k^;8q)ilvx} zM=W5`B9`j%{v4L$xYt(tb3_-D>4pqNa3cb4B#Dujm{lku9fl$4(mewpV z_XYR2htP?43T@llNIThuBaXAt+y%ef8#W7XGg^c?&OqGn&D?FTfDeO39#=puwYCn9 z`er0lDyN=B2+6QWsi7{WfnwxX>3m3gK1LxqeNd!cO!3HpM~wiWdVuP&^EfeP!f(_Q z!i+uh(T&(2sT;9GloQkqaI2esl=Jf?>$dPu15tiocYfaST*Rk*1JV2mIp7NLj>jrg ztgKq4aH}I3n<9kZ*V(OtpkjYUpG^f(<87li$^0G;4qdN_(8)TVD3o2H2_i73aNR7! z31NxFhShmv0TbJ)Qem)jC|J3Kl?ZlASn@@S9~SFmBt3S(q>}EbbGEHj*SpLTAUr&R z0kMv-=B|>ZxKteCUUB=;`KDZny__ke{sqk4@NKdDr5zPV)e*6EB-xqo?)$a7KR5w4 zDUO?1+pZVM)Q(mkG}2`v5vlexk`<+C+yf=_iz?&YdXD+@rp^wV75rLVot$?K+AVxq zkFpBt#4O@spb9RF8Oil8UC<1Ndxft8Zj3h5#j eZ=!NlHa_?N{!N1qJsmX_%f_P5B4T_s`F{YUB+ah? literal 6927 zcmb7{cTm&8xAwnuh*AwrLX#i~0aTiyHz^4{ARR@iK|#6#(gg*P5}I_7gx;itB3)WU zqy#}AAkwP^L7K?r_r7=L-hc1eo!Omv&VJ4_yR$p9XJ5`105-G^N(Z2#q5|~J8*nxY zXaV%Jbo6wz^z?M}3=H&)AT|()i3tQ|VZF%44d&tD26J&;<`)&b%qIfj;u4Y&61ge{ z7l-o-N?wB2_ph@V;35sxxn~-7Kn?gz+9DN@4rCz~0md!W=M%cz zlSG+~Q-hB+>0rCOMWNy9M3yFD4<$k*{@5Mkm@h@bSGUX>!$Gy{(rX+oM*(@CM>lB=zphD^ol`*ptYrOeo zg+C!axVOT7=cYoUg2FVrdAG~?W4^iRKbda1!7d^@2tBq{*Av_^29~nMeh(>=&}NUNK6dt= zI!xT|ahdi;1eQcn62>TLOCW)Jr_DlaO8*c-{sU0uUq}R|DSdE8I`FS$W*OF z8-_A{&x5`VhpC(a-)awCgX|E>Zuz$Ce=pyf*7}crgzSRL_9% zy*NeaPosY}p>FdJ^FKMwKtKA}!8{o^v`l*-7~UD2&TboI;hPnI{V#LdKZS`El{@_n z_SGhieaAJLVm-4DS*_x-!a--)&_d771b z5VK6gMUf;?-4x2{X}Q(Ry zSvY06)AW+;$gi{_B{nN+bv0UJeJVUA_@RyUaTs+h5n1 z35~+~HlPbe%)JC4(zhp&XRT>5ITkr4?g7FCl;Sy55){B*GU~5ATDJ5Q3-WTZ#^dv8 z#K7i8ZZTzEDD$z_kcyCEj+H)>X3^TTOj^YTHe+pp;FGVXup)iWh4>>A%8d+4%HEsDC3>i|7k7 z#Y>`0u+b=aQ~w`jXy=ZN(@Mz+=>@EJ=^$eKyM;YCW|6?>Zpt>*gvcdRzuR~jI^$~WS>Jw)~{%>@I zUOKPCv*r7lFdvmIb7!eudzx+Ro8Qd~WSNvVB9`vR%SQdDlPm3pL`)Ld3SpBr$`Z;d zmLQ&Z!PM|G3n|Rx#?>L`gfHILkA6cr#eAp-*YX&dsB8V7)=0j(fTcqk)&zplD z_58R_F_Ke83NH;4CRgkg{yPosrc+*j^2<`SRK*5;vrB@mEbDn=d% zWhWLLJ&5UF9r6_4)5)tJS^~d+!q}K#FVHY`?Q~HoJ=q#CLNIG@qhz*JE?X7Vc*j3_ z-uT4HBDVz{!1aad5KF^Jlk)4UZK{B6miZ$yY0eQx&d za~qUyNhQQKk&~1=vsE;|$B=OO<=n^bTi;4fOEc@feE;Q4SS@JThf+Z#YfT6>!f>H~ zi_*F?#8+~v_KE6ML*wz7?paO*6$nnJnge=dKV#Kp&= zTFYivC2AL@?T9wEhOLUD_>zq-I=Z{fu4O0WR#|Ijo?z6eDx<&cXSWFF``Y79(QmJd zg8KCf1JNdL^Ds$Xic8cvBu}f1C(OP6%Zf4YU9{eRu;!tI3pM~gz7yk~)AHF1sfnvx ze7}=oC^H~jw6o9&&5o{!3fz>L0qWqAr8;U8QNA9F;METyK2dQOoz3bQ)YK85csOts z?H9P&w`e1a*S0O}e_GartJ%0GtOY4zDCr2w`EBuB_k{qg80kUWz8tuV$3=6z$??DA zMeyUlk?7v1(W10|%xW?cr(j;|_4)T{-0cc&_bTY$*zujJ*VV}TCBYxCKDFjygofyg z+YCA0aa;Vk`?j{MeReLk&W);zE5thU@A}Rns;Q+vH9pNBmX0Jo6&JI76ZHI>oWSyt zIr-!+sdm<{jnGG)RH!k;9*k~x?FA0`<0W~zx{(+RqiPxib^;pp9HI|NG;U2B@pm`K z6u(1G&)RH^yzbMUt1xm<1hH9On_P=A66)~$H-F(GvhsaA<;ma|vLllbY5gx-%p4WM~1YOI>9>v;>?nuBG&#A$ARxJx8?7zWN}BOeJ?CaC{gFps5g zDnv!_O3CwCVTJYd0O*4Ez-o?YXB=Lhv%jBC&NnLm;rNkg(j`8G-|}kq>GkgjzYPJu z&+o3kxic`6Nru)H1_g(vK0Oxu+~1exo&H0(ZEL>B3aN8 zp23xO9Up-4^8IqUm97BBFLn%!ZThtYw6#20si8n$+Naphyip6Puln;P(76~7TLCe+ zccNP%ej`W4Hxn8C{0`qaS{G^JX23jwIQ;fqXExRf`UVA?Cv_efNfLQnJ@N0wa|7O~ z+=xby0+b02F)2CE3VD(1GT(JV#e)sk|7=^5xMk<1eot)Qj73F~EM5>y1g(-BP(R!TJw+c}`@0C$3HDq4U_j zo^f^)p9VuQt8XMC`|_7LLCY%R+i^09oR5yemcv|$U5(NWT@KRZI0PJBmy?GN>qD1- zXdrRx+rNq_xkI&j{a!HdF1#UiC>@|oW`q9H?#BYit|Ab9WW}#rkhR4KpfCYm-^LzC z+mEsL$e+sDuiP@(vc2`7qO$x6NQa7%PF=9MJa!m4&F3(B%=xYy5*?80^GtS#DX$@C zNtsPU8Nsv8qTB8^Y0v9GY|Xegi+PTDl|8XIS#TrXDQB;ACg{?L!nhr@w4V5ZgT_sL zb^=r))(iX4(!&4JeCoAZYL!QcPe1ZhgsAI#+d^~M*JsMKu=mALqv09QC#i>R((`cj zq(UwyrzB?ivYY`y8Svtm^bG#SN>O9gI*y1r-Gqrh3DMUc4>cfCl6Q^+ZmqIidXCcr zL7kRP77KWOQ9q2`eAb`;+Xb3rt%WaTpK5aFcxx);FMs|On2`=UL7bNRIPWqOUc_~x zTrP|h1$;~cbfg*h>tKbZcgV;8I6p1yVar@DKc*cJM%(0xTG8L~z5~#diGfYlu@9#%NtM}DwR##f6ol82v%|%{#=UN&RGTeV$w*wA&C~?7 zO{Goz0UWc$pH0!p^jQxX77iLZHUI1xaY#I>Q6+f@uTZb^Y%?>G1lk-}B7}foP>Ms4 zHUiE#Pq;!?>^H!*$uT5uv6|eDTH*Oc-}{R0M! zJ{*DgsL76121(sqX$hH{v3P&Q?;yRj3Vx7J)dEPA^}I<=N@;@l#+!X*y!lnma9r~{ zHxrx3(0i(Zi2?#=DYWKo7wyvgOTKR``FL_d*%MR5}V<`7!2PW~6I$i}JFC%*I ztdb4M+g@YI_HBmbkwMRZi6(i?iE%HVO6ZQlCz<>>ZVfx`S=|?kxb5bA-8Xp>B>3)E zvn}QwwdM*J`GaA-!>FKasx@mzz3R;#$4mPwwYJXaPhNUE-J7uW+a#l(Z_H;g{661G zP|v`30=5tN?iV%$)v7D+FR-CxL&9n#9_KQi5G_(?{cb8T(*3}K+(j+U1=4|0881(T{UQhL%3-)4nB)J2pcyUg65`f^D$bts5sxR$h?!x<=X_IR!MI*Q?@;V=oLis3=&Om-P1EE)mpE;;eh+;y)RREf z4bQN_+*R433tdpSK9D1z=<-%yzNVEz<~Z`6uuT8H=>|nkrgH=caXJW7;uBDVG&MmL za*+#JO`A%+*;)S*E$%*>)?!hty26KGGX7z$0`Q}{IPd-A^OsvQ@9z*_y1~*NQ=Az; z`;a(}A$UT=Qxm$vg6OB{?jL#i_I>5es_XJblP7Wb)=gtPF)hqA%)gYDHC$Z(u>2jP z#qbT+cxsvo?}>&yk{+Wv&62E@Wp}fUu=t!ylZIfitV`x!0&uyn^957Z_-ChgYF9$u zDq1-1^tns3XVO9hj8w)^YbD^=M5oRO3l(%O;^N%$>}NuWmhH!GEurSM>@%RW(yv=A zYJ|G1L$$kU`g^Mu+Dcf4j>FFEgGc3V6GR^?rT|?Ca}Tf_=J?uMS+H}WjeSw{Z*!y| zfP$CJ|H*k;&R~sdxpM}*zh@akU;l9VhP;#BupY-_?b#MIfTw8|P_Zum zsK)S-C%!Lgk%gGZn|l7h`cj)bO9-dx0uP&SF!=Vk-tjO*O&t&a;gWA2U-N3nEBMQ9 zF&moLI3tVCRVzuVP_~>gb6)QXY%!U!Y_YdYkjBP-bo`e8+#-xs$S~2>=hpM9$h3D? zjOJG0Jm@F<3}U}cJ4BxtV}DWaaD>dP`NlO@1~NDCxllaC#U_|YBZqjt4)vdBKu@rI zTnAr+ZQA4tRNnTXkr!OjwLF}EaB166W3G*c{MZ`j^r_9AuIj*Iw>t@!`vICmou5Td zAi-UJJ~E!EVX8op`GtPb6UL?f1f9X|~ zUbDh#S;SX|0os%OlgD(O;aMj=J8D%mm2)*d)rM&2)Y=FEbxlkvPKRD`MK`OusEhw{ zM(VBc$TJIZ1@ zVk@HsP@Jz}X)v6Rp^WwzUjRrl-mf&mz_p&LyNFniaeA(2VWyWc=vTszP$2b}HdiPd zKnz^y7RDy}faz+gyOvsMXuY73M`402{xH5T52 zIm9{lz542;7%yIwLzE~@WhZ9pR{b945pXv!<6>b$R&V;6!ltotP;Wb&#sPS=b=hm? z?R*a5R-7Z)kd;1JT~y&V%+wGRGtQeJB-zIl0a{o9=huTXb%q03+iW4RVY z*h$!C9zpg~N-pCroO7S^O1+#Z0}$nshVl{3%U0uY;*hk1=x@WMSR8P2EWWId|5m z$CGl78CA3;I};Sg6HYrVU1f=1$)gSa2%5(>LDP#3k->rBe34X`BlzJN;9ea8VSzCf zI0(Qw_hi}nw~!>+5Bdfzxg>@wFQv2bPRAMg(`izAq4OW?OvSuDczI7nB^*_{`?q{C z6NooyJVL`M9Dzp_Z*Hs{x|UQArBk%aDKmCStW4J5Zj*BG6zjOs?~lCsUWPmK(m*d+ zb=V)?jK?<{<@zXI z{Rw^;BW!T2O6BzZl&HZBrqOz%z-UMJlt$YSE#4zALBeMayq@`U9ga`4aOuZ!KFfM# zHjOM!d+p?hY3$a20Mb)RL~`nL9G~9<8$X8@Ir7Bmx=+YprP~&rxX^xyM}?3{e;ddl zps=6<3AxPUQN`NU*lNKQ0#|GBuYUTa1g>eiaqb@K$g5-D5WUuS>yWkgNh)y{gaSBn z4pv{UpQ_Gh5f#`or3TRyDNkP--gQ85wcP5ai}h1}wkf3B8lmRnc0Rg(!u0omsjWDY z`Vy*i!HlXQ!PbI7rM&foz{2Khc`4iU!5e|S88L0|I>4GoGttrd*@+WTR8qhU?;3e2 z$$iF!&1Etuzn%GhK!gs+#arZ=Ha_3SPDh^m0QDf3^xaF9j(MHMOyL!eubjts*Md{WcQ{mOO zzw`f`r&vDkmikXE7r*+7Qea!qq$F1Pvi23JGr%i=GGrvfZ|r$zoP$Zou?GB4DbCgn z6T<{7eHRDk{Yj{7cD%?=dfKEFGZmHPleX6G<_n@5Yl;J?YqAXWm$CqjzSSh_0t0QG z6ok;Idh%xIo-A{&y}HnL=v!k3EmUfh$QkhU0RMc;k}`4aqo4B`5F=RXcR Date: Tue, 4 Feb 2020 10:05:53 +0800 Subject: [PATCH 331/852] =?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/assets/updateLog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index ab1238f8a..cc98be492 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,9 +3,11 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2020/02/03** +**2020/02/04** * 主界面切换时自动隐藏键盘 * 添加本地书籍完成,解析txt文件完成,本地txt可以看了 +* 封面换源,书籍信息界面点击封面弹出封面换源界面 +* 默认封面绘制书名和作者 **2020/02/02** * merged commit e584606, rss修复BaseURL模式下部分图片无法加载, 修复可能出现的乱码 From c1cb5fb0d74bf29704cc7d2c9ea16bed48e900f7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 10:34:08 +0800 Subject: [PATCH 332/852] =?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/constant/PreferKey.kt | 3 +++ .../java/io/legado/app/service/BaseReadAloudService.kt | 7 ++----- .../java/io/legado/app/service/HttpReadAloudService.kt | 3 ++- .../main/java/io/legado/app/service/help/ReadAloud.kt | 3 ++- .../app/ui/book/read/config/ReadAloudConfigDialog.kt | 9 +++++---- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index ef572f1f3..1bfd5b634 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -8,6 +8,9 @@ object PreferKey { const val clickAllNext = "clickAllNext" const val hideNavigationBar = "hideNavigationBar" const val precisionSearch = "precisionSearch" + const val readAloudOnLine = "readAloudOnLine" + const val readAloudByPage = "readAloudByPage" + const val ttsSpeechPer = "ttsSpeechPer" const val prevKey = "prevKeyCode" const val nextKey = "nextKeyCode" const val showRss = "showRss" diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index c657f621e..45915fd1d 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -16,10 +16,7 @@ import androidx.core.app.NotificationCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.Action -import io.legado.app.constant.AppConst -import io.legado.app.constant.Bus -import io.legado.app.constant.Status +import io.legado.app.constant.* import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentHelp import io.legado.app.help.MediaHelp @@ -111,7 +108,7 @@ abstract class BaseReadAloudService : BaseService(), nowSpeak = 0 readAloudNumber = textChapter.getReadLength(pageIndex) contentList.clear() - if (getPrefBoolean("readAloudByPage")) { + if (getPrefBoolean(PreferKey.readAloudByPage)) { for (index in pageIndex..textChapter.lastIndex()) { textChapter.page(index)?.text?.split("\n")?.let { contentList.addAll(it) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 9e1fe70cd..8dc5c3927 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -3,6 +3,7 @@ package io.legado.app.service import android.app.PendingIntent import android.media.MediaPlayer import io.legado.app.constant.Bus +import io.legado.app.constant.PreferKey import io.legado.app.help.IntentHelp import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.api.HttpPostApi @@ -107,7 +108,7 @@ class HttpReadAloudService : BaseReadAloudService(), return mapOf( Pair("tex", encodeTwo(content)), Pair("spd", ((getPrefInt("ttsSpeechRate", 25) + 5) / 5).toString()), - Pair("per", getPrefString("ttsSpeechPer") ?: "0"), + Pair("per", getPrefString(PreferKey.ttsSpeechPer) ?: "0"), Pair("cuid", "baidu_speech_demo"), Pair("idx", "1"), Pair("cod", "2"), diff --git a/app/src/main/java/io/legado/app/service/help/ReadAloud.kt b/app/src/main/java/io/legado/app/service/help/ReadAloud.kt index d2a789a5a..49285eeff 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadAloud.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadAloud.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import io.legado.app.App import io.legado.app.constant.Action +import io.legado.app.constant.PreferKey import io.legado.app.service.BaseReadAloudService import io.legado.app.service.HttpReadAloudService import io.legado.app.service.TTSReadAloudService @@ -13,7 +14,7 @@ object ReadAloud { var aloudClass: Class<*> = getReadAloudClass() fun getReadAloudClass(): Class<*> { - return if (App.INSTANCE.getPrefBoolean("readAloudOnLine")) { + return if (App.INSTANCE.getPrefBoolean(PreferKey.readAloudOnLine)) { HttpReadAloudService::class.java } else { TTSReadAloudService::class.java diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 0d066dd54..6dcd2b341 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -13,6 +13,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.Bus +import io.legado.app.constant.PreferKey import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud @@ -68,7 +69,7 @@ class ReadAloudConfigDialog : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ATH.applyEdgeEffectColor(listView) - bindPreferenceSummaryToValue(findPreference("ttsSpeechPer")) + bindPreferenceSummaryToValue(findPreference(PreferKey.ttsSpeechPer)) } override fun onResume() { @@ -86,18 +87,18 @@ class ReadAloudConfigDialog : DialogFragment() { key: String? ) { when (key) { - "readAloudByPage" -> { + PreferKey.readAloudByPage -> { if (BaseReadAloudService.isRun) { postEvent(Bus.MEDIA_BUTTON, false) } } - "readAloudOnLine" -> { + PreferKey.readAloudOnLine -> { if (BaseReadAloudService.isRun) { ReadAloud.stop(requireContext()) ReadAloud.aloudClass = ReadAloud.getReadAloudClass() } } - "ttsSpeechPer" -> ReadAloud.upTtsSpeechRate(requireContext()) + PreferKey.ttsSpeechPer -> ReadAloud.upTtsSpeechRate(requireContext()) } } From 6422bd511c7f61327637345b87e5adfb1bd1213e Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 10:38:37 +0800 Subject: [PATCH 333/852] =?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/ui/book/read/config/ReadAloudConfigDialog.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 6dcd2b341..14f5c0b9b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -93,10 +93,8 @@ class ReadAloudConfigDialog : DialogFragment() { } } PreferKey.readAloudOnLine -> { - if (BaseReadAloudService.isRun) { - ReadAloud.stop(requireContext()) - ReadAloud.aloudClass = ReadAloud.getReadAloudClass() - } + ReadAloud.stop(requireContext()) + ReadAloud.aloudClass = ReadAloud.getReadAloudClass() } PreferKey.ttsSpeechPer -> ReadAloud.upTtsSpeechRate(requireContext()) } @@ -113,7 +111,7 @@ class ReadAloudConfigDialog : DialogFragment() { // For all other preferences, set the summary to the value's preference?.summary = stringValue } - return true + return false } private fun bindPreferenceSummaryToValue(preference: Preference?) { From 662b7df35b97561e47e3b3b9a12984fd7c50f7a2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 10:55:44 +0800 Subject: [PATCH 334/852] =?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/ImageLoader.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ImageLoader.kt b/app/src/main/java/io/legado/app/help/ImageLoader.kt index 26a9063d6..3d4272e9e 100644 --- a/app/src/main/java/io/legado/app/help/ImageLoader.kt +++ b/app/src/main/java/io/legado/app/help/ImageLoader.kt @@ -12,13 +12,15 @@ import java.io.File object ImageLoader { fun load(context: Context, path: String?): RequestBuilder { - if (path?.startsWith("http", true) == true) { - return Glide.with(context).load(path) + return when { + path.isNullOrEmpty() -> Glide.with(context).load(path) + path.startsWith("http", true) -> Glide.with(context).load(path) + else -> try { + Glide.with(context).load(File(path)) + } catch (e: Exception) { + Glide.with(context).load(path) + } } - kotlin.runCatching { - return Glide.with(context).load(File(path)) - } - return Glide.with(context).load(path) } fun load(context: Context, @DrawableRes resId: Int?): RequestBuilder { From 07aac1e0a999e74fb0955d795c981bec99726cf0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 11:05:04 +0800 Subject: [PATCH 335/852] =?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/changecover/ChangeCoverDialog.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt index 73486159d..d1c081f76 100644 --- a/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changecover/ChangeCoverDialog.kt @@ -77,6 +77,7 @@ class ChangeCoverDialog : DialogFragment(), override fun changeTo(coverUrl: String) { callBack?.coverChangeTo(coverUrl) + dismiss() } interface CallBack { From 101dcbde839757940db393d8a0845665c2e0811a Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 11:35:24 +0800 Subject: [PATCH 336/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/service/BaseReadAloudService.kt | 2 +- .../legado/app/service/HttpReadAloudService.kt | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 45915fd1d..74a5980f9 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -40,7 +40,7 @@ abstract class BaseReadAloudService : BaseService(), } } - private val handler = Handler() + val handler = Handler() private lateinit var audioManager: AudioManager private var mFocusRequest: AudioFocusRequest? = null private var broadcastReceiver: BroadcastReceiver? = null diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 8dc5c3927..7cbfb0b50 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -8,7 +8,10 @@ import io.legado.app.help.IntentHelp import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.api.HttpPostApi import io.legado.app.service.help.ReadBook -import io.legado.app.utils.* +import io.legado.app.utils.FileUtils +import io.legado.app.utils.getPrefInt +import io.legado.app.utils.getPrefString +import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job import kotlinx.coroutines.isActive @@ -94,6 +97,7 @@ class HttpReadAloudService : BaseReadAloudService(), mediaPlayer.reset() mediaPlayer.setDataSource(fd) mediaPlayer.prepareAsync() + postEvent(Bus.TTS_START, readAloudNumber + 1) } catch (e: Exception) { e.printStackTrace() } @@ -182,11 +186,19 @@ class HttpReadAloudService : BaseReadAloudService(), } override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { + handler.postDelayed({ + readAloudNumber += contentList[nowSpeak].length + 1 + if (nowSpeak < contentList.lastIndex) { + nowSpeak++ + play() + } else { + nextChapter() + } + }, 1000) return true } override fun onCompletion(mp: MediaPlayer?) { - LogUtils.d("播放完成", contentList[nowSpeak]) readAloudNumber += contentList[nowSpeak].length + 1 if (nowSpeak < contentList.lastIndex) { nowSpeak++ From 20134f757e0f577b1169107ce0e256e3a4d0e853 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 11:50:08 +0800 Subject: [PATCH 337/852] =?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/service/HttpReadAloudService.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 7cbfb0b50..cb8ed973b 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -41,6 +41,7 @@ class HttpReadAloudService : BaseReadAloudService(), override fun onDestroy() { super.onDestroy() + job?.cancel() mediaPlayer.release() } @@ -48,6 +49,7 @@ class HttpReadAloudService : BaseReadAloudService(), mediaPlayer.reset() job?.cancel() playingIndex = -1 + nowSpeak = 0 super.newReadAloud(dataKey, play) } From 5522533bc1578d7ee64bf62667f10ebb40463bbd Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 11:58:05 +0800 Subject: [PATCH 338/852] =?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/service/HttpReadAloudService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index cb8ed973b..34e74859e 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -80,7 +80,7 @@ class HttpReadAloudService : BaseReadAloudService(), if (bytes != null && isActive) { val file = getSpeakFile(index) file.writeBytes(bytes) - if (index == nowSpeak) { + if (index == nowSpeak && !pause) { playAudio(FileInputStream(file).fd) } } From 1dd1ad163bff976b71be477230bc13f4ebc686f6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 11:58:32 +0800 Subject: [PATCH 339/852] =?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/service/HttpReadAloudService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 34e74859e..cb8ed973b 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -80,7 +80,7 @@ class HttpReadAloudService : BaseReadAloudService(), if (bytes != null && isActive) { val file = getSpeakFile(index) file.writeBytes(bytes) - if (index == nowSpeak && !pause) { + if (index == nowSpeak) { playAudio(FileInputStream(file).fd) } } From b705edc5c8116b5b0be50fc8d01f0f352ac01436 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 12:16:43 +0800 Subject: [PATCH 340/852] =?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/service/HttpReadAloudService.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index cb8ed973b..33d05fd11 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -49,7 +49,6 @@ class HttpReadAloudService : BaseReadAloudService(), mediaPlayer.reset() job?.cancel() playingIndex = -1 - nowSpeak = 0 super.newReadAloud(dataKey, play) } From 096bccd4d850c28522df80a757f4b12f2bd140d7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 12:27:01 +0800 Subject: [PATCH 341/852] =?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/service/HttpReadAloudService.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 33d05fd11..f8048af54 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -141,7 +141,11 @@ class HttpReadAloudService : BaseReadAloudService(), override fun resumeReadAloud() { super.resumeReadAloud() - mediaPlayer.start() + if (playingIndex == -1) { + play() + } else { + mediaPlayer.start() + } } override fun upSpeechRate(reset: Boolean) { From 8b5864fd32c97ca99dbc205d58395eb3c99f5566 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 12:29:30 +0800 Subject: [PATCH 342/852] =?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/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index cc98be492..aafd1d243 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -8,6 +8,7 @@ * 添加本地书籍完成,解析txt文件完成,本地txt可以看了 * 封面换源,书籍信息界面点击封面弹出封面换源界面 * 默认封面绘制书名和作者 +* 修复在线朗读遇到单独标点,停止朗读的问题 **2020/02/02** * merged commit e584606, rss修复BaseURL模式下部分图片无法加载, 修复可能出现的乱码 From abc1f597a6325337a45e750d522bc74498d77b6e Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 13:06:26 +0800 Subject: [PATCH 343/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/BaseReadAloudService.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 74a5980f9..5603da72c 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -40,18 +40,18 @@ abstract class BaseReadAloudService : BaseService(), } } - val handler = Handler() + internal val handler = Handler() private lateinit var audioManager: AudioManager private var mFocusRequest: AudioFocusRequest? = null private var broadcastReceiver: BroadcastReceiver? = null private var mediaSessionCompat: MediaSessionCompat? = null private var title: String = "" private var subtitle: String = "" - val contentList = arrayListOf() - var nowSpeak: Int = 0 - var readAloudNumber: Int = 0 - var textChapter: TextChapter? = null - var pageIndex = 0 + internal val contentList = arrayListOf() + internal var nowSpeak: Int = 0 + internal var readAloudNumber: Int = 0 + internal var textChapter: TextChapter? = null + internal var pageIndex = 0 private val dsRunnable: Runnable = Runnable { doDs() } override fun onCreate() { From 228289b6756e22339075ab81367cc387b3ccccfd Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 13:14:30 +0800 Subject: [PATCH 344/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/model/localBook/LocalBook.kt | 30 +++++++++++++++++++ .../app/ui/importbook/ImportBookViewModel.kt | 21 ++----------- 2 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/io/legado/app/model/localBook/LocalBook.kt diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt new file mode 100644 index 000000000..e17c08603 --- /dev/null +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -0,0 +1,30 @@ +package io.legado.app.model.localBook + +import androidx.documentfile.provider.DocumentFile +import io.legado.app.App +import io.legado.app.data.entities.Book + + +object LocalBook { + + fun importFile(doc: DocumentFile) { + doc.name?.let { fileName -> + val str = fileName.substringBeforeLast(".") + var name = str.substringBefore("作者") + val author = str.substringAfter("作者") + val smhStart = name.indexOf("《") + val smhEnd = name.indexOf("》") + if (smhStart != -1 && smhEnd != -1) { + name = (name.substring(smhStart + 1, smhEnd)) + } + val book = Book( + bookUrl = doc.uri.toString(), + name = name, + author = author, + originName = fileName + ) + App.db.bookDao().insert(book) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt index 75d2fc5e0..1250da682 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt @@ -3,9 +3,8 @@ package io.legado.app.ui.importbook import android.app.Application import android.net.Uri import androidx.documentfile.provider.DocumentFile -import io.legado.app.App import io.legado.app.base.BaseViewModel -import io.legado.app.data.entities.Book +import io.legado.app.model.localBook.LocalBook class ImportBookViewModel(application: Application) : BaseViewModel(application) { @@ -14,23 +13,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application) execute { uriList.forEach { uriStr -> DocumentFile.fromSingleUri(context, Uri.parse(uriStr))?.let { doc -> - doc.name?.let { fileName -> - val str = fileName.substringBeforeLast(".") - var name = str.substringBefore("作者") - val author = str.substringAfter("作者") - val smhStart = name.indexOf("《") - val smhEnd = name.indexOf("》") - if (smhStart != -1 && smhEnd != -1) { - name = (name.substring(smhStart + 1, smhEnd)) - } - val book = Book( - bookUrl = uriStr, - name = name, - author = author, - originName = fileName - ) - App.db.bookDao().insert(book) - } + LocalBook.importFile(doc) } } }.onFinally { From 40a8c6f17411928b00f9e64d785a34e8f36e948f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 13:16:17 +0800 Subject: [PATCH 345/852] =?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/model/localBook/LocalBook.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index e17c08603..44ee337b2 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -11,7 +11,7 @@ object LocalBook { doc.name?.let { fileName -> val str = fileName.substringBeforeLast(".") var name = str.substringBefore("作者") - val author = str.substringAfter("作者") + val author = str.substringAfter("作者", "") val smhStart = name.indexOf("《") val smhEnd = name.indexOf("》") if (smhStart != -1 && smhEnd != -1) { From 501a9273dce32b943829856b9422b0395f191bb9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 14:08:25 +0800 Subject: [PATCH 346/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/widget/image/CoverImageView.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 64e61508b..3d5d65d02 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -23,6 +23,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { private val authorPaint = TextPaint() private var name: String? = null private var author: String? = null + private var loadField = false constructor(context: Context) : super(context) @@ -84,6 +85,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { canvas.clipPath(path) } super.onDraw(canvas) + if (!loadField) return name?.let { namePaint.color = Color.WHITE namePaint.style = Paint.Style.STROKE @@ -102,7 +104,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } } - fun setName(name: String?, author: String?) { + fun setText(name: String?, author: String?) { this.name = when { name == null -> null @@ -115,7 +117,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { author.length > 8 -> author.substring(0, 7) + "…" else -> author } - invalidate() } fun setHeight(height: Int) { @@ -124,6 +125,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } fun load(path: String?, name: String?, author: String?) { + setText(name, author) ImageLoader.load(context, path)//Glide自动识别http://和file:// .placeholder(R.drawable.image_cover_default) .error(R.drawable.image_cover_default) @@ -134,7 +136,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { target: Target?, isFirstResource: Boolean ): Boolean { - setName(name, author) + loadField = true return false } @@ -145,7 +147,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { dataSource: DataSource?, isFirstResource: Boolean ): Boolean { - setName(null, null) + loadField = false return false } From b9f37c2601e13d4136ca5e8fe5a97dc43cfbd231 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 14:11:37 +0800 Subject: [PATCH 347/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bookshelf/books/{BooksAdapter.kt => BaseBooksAdapter.kt} | 2 +- .../io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt | 2 +- .../io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt | 2 +- .../legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt | 1 + .../io/legado/app/ui/main/bookshelf/books/BooksFragment.kt | 4 ++-- 5 files changed, 6 insertions(+), 5 deletions(-) rename app/src/main/java/io/legado/app/ui/main/bookshelf/books/{BooksAdapter.kt => BaseBooksAdapter.kt} (90%) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt similarity index 90% rename from app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapter.kt rename to app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt index c8f085b74..9103d3c3c 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt @@ -4,7 +4,7 @@ import android.content.Context import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book -abstract class BooksAdapter(context: Context, layoutId: Int) : +abstract class BaseBooksAdapter(context: Context, layoutId: Int) : SimpleRecyclerAdapter(context, layoutId) { fun notification(bookUrl: String) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt index ffb608f4f..92a47d790 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt @@ -12,7 +12,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick class BooksAdapterGrid(context: Context, private val callBack: CallBack) : - BooksAdapter(context, R.layout.item_bookshelf_grid) { + BaseBooksAdapter(context, R.layout.item_bookshelf_grid) { override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt index 71b70f0c2..b35d6fd21 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt @@ -12,7 +12,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick class BooksAdapterList(context: Context, private val callBack: CallBack) : - BooksAdapter(context, R.layout.item_bookshelf_list) { + BaseBooksAdapter(context, R.layout.item_bookshelf_list) { override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt index 45ad277f2..fc4358f5e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt @@ -23,6 +23,7 @@ class BooksDiffCallBack(private val oldItems: List, private val newItems: val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] return oldItem.name == newItem.name + && oldItem.author == newItem.author && oldItem.durChapterTitle == newItem.durChapterTitle && oldItem.latestChapterTitle == newItem.latestChapterTitle && oldItem.getDisplayCover() == newItem.getDisplayCover() diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 0ee866fde..2b92d361b 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -29,7 +29,7 @@ import org.jetbrains.anko.startActivity class BooksFragment : BaseFragment(R.layout.fragment_books), - BooksAdapter.CallBack { + BaseBooksAdapter.CallBack { companion object { fun newInstance(position: Int, groupId: Int): BooksFragment { @@ -43,7 +43,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), } private lateinit var activityViewModel: MainViewModel - private lateinit var booksAdapter: BooksAdapter + private lateinit var booksAdapter: BaseBooksAdapter private var bookshelfLiveData: LiveData>? = null private var position = 0 private var groupId = -1 From 5987b2c2e20d9d8cf0e313705e7b3a0f93429b71 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 14:21:37 +0800 Subject: [PATCH 348/852] =?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/ui/widget/image/CoverImageView.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index 3d5d65d02..f20ace6ce 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -23,7 +23,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { private val authorPaint = TextPaint() private var name: String? = null private var author: String? = null - private var loadField = false + private var loadFailed = false constructor(context: Context) : super(context) @@ -85,7 +85,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { canvas.clipPath(path) } super.onDraw(canvas) - if (!loadField) return + if (!loadFailed) return name?.let { namePaint.color = Color.WHITE namePaint.style = Paint.Style.STROKE @@ -104,7 +104,12 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } } - fun setText(name: String?, author: String?) { + fun setHeight(height: Int) { + val width = height * 5 / 7 + minimumWidth = width + } + + private fun setText(name: String?, author: String?) { this.name = when { name == null -> null @@ -119,11 +124,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { } } - fun setHeight(height: Int) { - val width = height * 5 / 7 - minimumWidth = width - } - fun load(path: String?, name: String?, author: String?) { setText(name, author) ImageLoader.load(context, path)//Glide自动识别http://和file:// @@ -136,7 +136,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { target: Target?, isFirstResource: Boolean ): Boolean { - loadField = true + loadFailed = true return false } @@ -147,7 +147,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { dataSource: DataSource?, isFirstResource: Boolean ): Boolean { - loadField = false + loadFailed = false return false } From c2fd24836ce049eeb70b6ae2ebc6307886956a97 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 20:15:25 +0800 Subject: [PATCH 349/852] =?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/config/BackupConfigFragment.kt | 4 +++- .../main/java/io/legado/app/ui/config/OtherConfigFragment.kt | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 10c787bac..39c711974 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -108,7 +108,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(), } else -> preference?.summary = newValue?.toString() } - return true + return false } override fun onPreferenceTreeClick(preference: Preference?): Boolean { @@ -305,6 +305,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.backupPath, uri.toString()) + findPreference(PreferKey.backupPath)?.summary = uri.toString() launch { Backup.backup(requireContext(), uri) } @@ -317,6 +318,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.backupPath, uri.toString()) + findPreference(PreferKey.backupPath)?.summary = uri.toString() launch { Restore.restore(requireContext(), uri) toast(R.string.restore_success) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index c865aeae6..ccfc88116 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -106,7 +106,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), getString(R.string.threads_num, stringValue) else -> preference?.summary = stringValue } - return true + return false } private fun bindPreferenceSummaryToValue(preference: Preference?) { @@ -188,6 +188,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.downloadPath, uri.toString()) + findPreference(PreferKey.downloadPath)?.summary = uri.toString() BookHelp.upDownloadPath() } } From 2469983166a01b123d8789af24778cfba9a6e3c8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 20:46:12 +0800 Subject: [PATCH 350/852] =?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/BookHelp.kt | 12 ++++++------ .../java/io/legado/app/utils/StringExtensions.kt | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 7071579ea..b9bf8d11c 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -38,7 +38,7 @@ object BookHelp { } fun clearCache() { - if (downloadUri.isDocumentUri(App.INSTANCE)) { + if (downloadPath.isContentPath()) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri) ?.findFile(cacheFolderName) ?.delete() @@ -55,7 +55,7 @@ object BookHelp { @Synchronized fun saveContent(book: Book, bookChapter: BookChapter, content: String) { if (content.isEmpty()) return - if (downloadUri.isDocumentUri(App.INSTANCE)) { + if (downloadPath.isContentPath()) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> DocumentUtils.getDirDocument( root, @@ -91,7 +91,7 @@ object BookHelp { } fun getChapterCount(book: Book): Int { - if (downloadUri.isDocumentUri(App.INSTANCE)) { + if (downloadPath.isContentPath()) { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.createFolderIfNotExist( root, @@ -112,7 +112,7 @@ object BookHelp { book.isLocalBook() -> { return true } - downloadUri.isDocumentUri(App.INSTANCE) -> { + downloadPath.isContentPath() -> { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.exists( root, @@ -137,7 +137,7 @@ object BookHelp { book.isLocalBook() -> { return AnalyzeTxtFile.getContent(book, bookChapter) } - downloadUri.isDocumentUri(App.INSTANCE) -> { + downloadPath.isContentPath() -> { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> return DocumentUtils.getDirDocument( root, @@ -163,7 +163,7 @@ object BookHelp { fun delContent(book: Book, bookChapter: BookChapter) { when { book.isLocalBook() -> return - downloadUri.isDocumentUri(App.INSTANCE) -> { + downloadPath.isContentPath() -> { DocumentFile.fromTreeUri(App.INSTANCE, downloadUri)?.let { root -> DocumentUtils.getDirDocument( root, diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index 19319d3ba..02faf53c3 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -4,6 +4,8 @@ package io.legado.app.utils fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() +fun String?.isContentPath(): Boolean = this?.startsWith("content://") == true + fun String?.isAbsUrl() = this?.let { it.startsWith("http://", true) @@ -48,7 +50,4 @@ fun String.splitNotBlank(regex: Regex, limit: Int = 0): Array = run { this.split(regex, limit).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() } -fun String.startWithIgnoreCase(start: String): Boolean { - return if (this.isBlank()) false else startsWith(start, true) -} From 2d2adfc8efe8b061bfd19efe377f0d7c2b5010cb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 20:57:57 +0800 Subject: [PATCH 351/852] =?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/BookHelp.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index b9bf8d11c..fa6b63c39 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -60,10 +60,12 @@ object BookHelp { DocumentUtils.getDirDocument( root, subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) - )?.listFiles()?.forEach { - if (it.name?.startsWith(String.format("%05d", bookChapter.index)) == true) { - it.delete() - return@forEach + )?.uri?.let { uri -> + DocumentUtils.listFiles(App.INSTANCE, uri).forEach { + if (it.name.startsWith(String.format("%05d", bookChapter.index))) { + DocumentFile.fromSingleUri(App.INSTANCE, it.uri)?.delete() + return@forEach + } } } DocumentUtils.createFileIfNotExist( From 2ee88e1bea366b8ccc7483a362acc5b7dc488d96 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 21:00:40 +0800 Subject: [PATCH 352/852] =?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/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index aafd1d243..1f7f9e874 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/05** +* 修复bug + **2020/02/04** * 主界面切换时自动隐藏键盘 * 添加本地书籍完成,解析txt文件完成,本地txt可以看了 From 7269ca40a91ce8c3be77a5ec8b96d2be2e21f7c4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 21:02:37 +0800 Subject: [PATCH 353/852] =?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/utils/UriExtensions.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/UriExtensions.kt b/app/src/main/java/io/legado/app/utils/UriExtensions.kt index 49b76b439..4062c74df 100644 --- a/app/src/main/java/io/legado/app/utils/UriExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/UriExtensions.kt @@ -5,10 +5,6 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import java.io.File -fun Uri.isDocumentUri(context: Context): Boolean { - return DocumentFile.isDocumentUri(context, this) -} - @Throws(Exception::class) fun Uri.readBytes(context: Context): ByteArray? { if (DocumentFile.isDocumentUri(context, this)) { From 6c9a63fb097a589b8a99985241f662b4a71c93bd Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 21:12:42 +0800 Subject: [PATCH 354/852] =?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/AndroidManifest.xml | 1 + .../app/ui/rss/favorites/RssFavoritesActivity.kt | 16 ++++++++++++++++ .../main/res/layout/activity_rss_favorites.xml | 7 +++++++ 3 files changed, 24 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt create mode 100644 app/src/main/res/layout/activity_rss_favorites.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 23f5edd36..4be71d133 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -103,6 +103,7 @@ + + + + \ No newline at end of file From e6ea59aaff500a2e89d8bc2f9a0af4ea037e6acc Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 21:19:42 +0800 Subject: [PATCH 355/852] =?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/main/rss/RssFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 0ec49f315..b0ad73f2e 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -13,6 +13,7 @@ import io.legado.app.data.entities.RssSource import io.legado.app.lib.theme.ATH import io.legado.app.ui.main.MainViewModel import io.legado.app.ui.rss.article.RssArticlesActivity +import io.legado.app.ui.rss.favorites.RssFavoritesActivity import io.legado.app.ui.rss.source.manage.RssSourceActivity import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.startActivity @@ -38,8 +39,7 @@ class RssFragment : BaseFragment(R.layout.fragment_rss), super.onCompatOptionsItemSelected(item) when (item.itemId) { R.id.menu_rss_config -> startActivity() - R.id.menu_rss_star -> { - } + R.id.menu_rss_star -> startActivity() } } From cd4f3fe161f01c06988569f880e85eff62913eaa Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 21:25:29 +0800 Subject: [PATCH 356/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/rss/read/ReadRssActivity.kt | 4 +-- .../res/layout/activity_rss_favorites.xml | 30 ++++++++++++++++--- app/src/main/res/menu/main_rss.xml | 2 +- app/src/main/res/menu/rss_read.xml | 2 +- app/src/main/res/values/strings.xml | 7 +++-- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 7bbf4e741..ffb5c4994 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -101,10 +101,10 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r override fun upStarMenu() { if (viewModel.star) { starMenuItem?.setIcon(R.drawable.ic_star) - starMenuItem?.setTitle(R.string.y_store_up) + starMenuItem?.setTitle(R.string.in_favorites) } else { starMenuItem?.setIcon(R.drawable.ic_star_border) - starMenuItem?.setTitle(R.string.w_store_up) + starMenuItem?.setTitle(R.string.out_favorites) } DrawableUtils.setTint(starMenuItem?.icon, primaryTextColor) } diff --git a/app/src/main/res/layout/activity_rss_favorites.xml b/app/src/main/res/layout/activity_rss_favorites.xml index d829e291c..5b80c0714 100644 --- a/app/src/main/res/layout/activity_rss_favorites.xml +++ b/app/src/main/res/layout/activity_rss_favorites.xml @@ -1,7 +1,29 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> - \ No newline at end of file + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/main_rss.xml b/app/src/main/res/menu/main_rss.xml index 4403621bd..97343e877 100644 --- a/app/src/main/res/menu/main_rss.xml +++ b/app/src/main/res/menu/main_rss.xml @@ -5,7 +5,7 @@ diff --git a/app/src/main/res/menu/rss_read.xml b/app/src/main/res/menu/rss_read.xml index f32d01d2e..7afb7f128 100644 --- a/app/src/main/res/menu/rss_read.xml +++ b/app/src/main/res/menu/rss_read.xml @@ -4,7 +4,7 @@ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b5d27918a..8b283bb42 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -33,9 +33,10 @@ 启用 替换净化-搜索 书架 - 收藏 - 已收藏 - 未收藏 + 收藏夹 + 收藏 + 已收藏 + 未收藏 订阅 全部 最近阅读 From 83c2be867d218854b4f3c49690de59d34c387094 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 21:38:19 +0800 Subject: [PATCH 357/852] =?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/rss/favorites/RssFavoritesActivity.kt | 44 ++++++++++++- .../ui/rss/favorites/RssFavoritesAdapter.kt | 64 +++++++++++++++++++ .../res/layout/activity_rss_favorites.xml | 16 ++--- 3 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt index 96bc3f99a..0188fe104 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt @@ -1,16 +1,58 @@ package io.legado.app.ui.rss.favorites import android.os.Bundle +import androidx.core.content.ContextCompat +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseActivity +import io.legado.app.data.entities.RssStar +import io.legado.app.lib.theme.ATH +import io.legado.app.ui.rss.read.ReadRssActivity +import kotlinx.android.synthetic.main.view_refresh_recycler.* +import org.jetbrains.anko.startActivity -class RssFavoritesActivity : BaseActivity(R.layout.activity_rss_favorites) { +class RssFavoritesActivity : BaseActivity(R.layout.activity_rss_favorites), + RssFavoritesAdapter.CallBack { + private var liveData: LiveData>? = null + private lateinit var adapter: RssFavoritesAdapter override fun onActivityCreated(savedInstanceState: Bundle?) { + initView() + initData() + } + private fun initView() { + ATH.applyEdgeEffectColor(recycler_view) + recycler_view.layoutManager = LinearLayoutManager(this) + recycler_view.addItemDecoration( + DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { + ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { + this.setDrawable(it) + } + }) + adapter = RssFavoritesAdapter(this, this) + recycler_view.adapter = adapter } + private fun initData() { + liveData?.removeObservers(this) + liveData = App.db.rssStarDao().liveAll() + liveData?.observe(this, Observer { + adapter.setItems(it) + }) + } + override fun readRss(rssStar: RssStar) { + startActivity( + Pair("title", rssStar.title), + Pair("origin", rssStar.origin), + Pair("link", rssStar.link) + ) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt new file mode 100644 index 000000000..2cb607df5 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt @@ -0,0 +1,64 @@ +package io.legado.app.ui.rss.favorites + +import android.content.Context +import android.graphics.drawable.Drawable +import com.bumptech.glide.load.DataSource +import com.bumptech.glide.load.engine.GlideException +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.target.Target +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.RssStar +import io.legado.app.help.ImageLoader +import io.legado.app.utils.gone +import io.legado.app.utils.visible +import kotlinx.android.synthetic.main.item_rss_article.view.* +import org.jetbrains.anko.sdk27.listeners.onClick + +class RssFavoritesAdapter(context: Context, val callBack: CallBack) : + SimpleRecyclerAdapter(context, R.layout.item_rss_article) { + + override fun convert(holder: ItemViewHolder, item: RssStar, payloads: MutableList) { + with(holder.itemView) { + tv_title.text = item.title + tv_pub_date.text = item.pubDate + onClick { + callBack.readRss(item) + } + if (item.image.isNullOrBlank()) { + image_view.gone() + } else { + ImageLoader.load(context, item.image) + .addListener(object : RequestListener { + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target?, + isFirstResource: Boolean + ): Boolean { + image_view.gone() + return false + } + + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { + image_view.visible() + return false + } + + }) + .into(image_view) + } + } + } + + interface CallBack { + fun readRss(rssStar: RssStar) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_rss_favorites.xml b/app/src/main/res/layout/activity_rss_favorites.xml index 5b80c0714..7740c1981 100644 --- a/app/src/main/res/layout/activity_rss_favorites.xml +++ b/app/src/main/res/layout/activity_rss_favorites.xml @@ -1,6 +1,7 @@ @@ -12,18 +13,13 @@ app:title="@string/favorites" app:layout_constraintTop_toTopOf="parent" /> - - - - - + app:layout_constraintTop_toBottomOf="@id/title_bar" + app:layout_constraintVertical_bias="0.0" + tools:layout_editor_absoluteX="0dp" /> \ No newline at end of file From f408209565ab8eee7fbcde764bace6df1e0cee3c Mon Sep 17 00:00:00 2001 From: M17764017422 <31874069+M17764017422@users.noreply.github.com> Date: Tue, 4 Feb 2020 21:42:13 +0800 Subject: [PATCH 358/852] =?UTF-8?q?=E6=B8=85=E7=90=86=E6=9C=97=E8=AF=BB?= =?UTF-8?q?=E6=9D=82=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index ffb5c4994..d497ccb06 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -155,7 +155,9 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r webView.settings.javaScriptEnabled = true webView.evaluateJavascript("document.documentElement.outerHTML") { val html = StringEscapeUtils.unescapeJson(it) - viewModel.readAloud(Jsoup.clean(html, Whitelist.none())) + val 需读内容 = Jsoup.clean(html, Whitelist.none()).replace(Regex("""&\w+;"""),"").trim()//朗读过程中总是听到一些杂音,清理一下 + //longToast(需读内容)调试一下 + viewModel.readAloud(需读内容) } } } From 8892da54689ed5ed75c9b5e4ed52e6c58911b286 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 21:57:05 +0800 Subject: [PATCH 359/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 12 ++++++++---- .../io/legado/app/ui/rss/read/ReadRssViewModel.kt | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index ffb5c4994..af113b5c0 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -40,15 +40,19 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.rss_read, menu) - starMenuItem = menu.findItem(R.id.menu_rss_star) - ttsMenuItem = menu.findItem(R.id.menu_aloud) - upStarMenu() return super.onCompatCreateOptionsMenu(menu) } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + starMenuItem = menu?.findItem(R.id.menu_rss_star) + ttsMenuItem = menu?.findItem(R.id.menu_aloud) + upStarMenu() + return super.onPrepareOptionsMenu(menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_rss_star -> viewModel.star() + R.id.menu_rss_star -> viewModel.favorite() R.id.menu_share_it -> viewModel.rssArticle?.let { shareText("链接分享", it.link) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index a81655c27..0ace44358 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -70,7 +70,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } } - fun star() { + fun favorite() { execute { rssArticle?.let { if (star) { @@ -78,6 +78,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } else { App.db.rssStarDao().insert(it.toStar()) } + star = !star } }.onSuccess { callBack?.upStarMenu() From 29bebf4995f2fd328c5d53f15d62c909ee384530 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 22:18:43 +0800 Subject: [PATCH 360/852] =?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/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1f7f9e874..c703795e9 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/02/05** * 修复bug +* Rss收藏功能完成 **2020/02/04** * 主界面切换时自动隐藏键盘 From 3d1a8eb281de7f511af5ccb0ccfd5a70f53e8289 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 10:42:45 +0800 Subject: [PATCH 361/852] =?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/data/AppDatabase.kt | 5 +++-- .../main/java/io/legado/app/data/dao/RssArticleDao.kt | 10 +++++++++- .../java/io/legado/app/data/entities/RssReadRecord.kt | 7 +++++++ .../legado/app/ui/rss/article/RssArticlesViewModel.kt | 4 ++-- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/entities/RssReadRecord.kt diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index b817927d0..e548f4584 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -16,8 +16,9 @@ import kotlinx.coroutines.launch @Database( entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, - RssSource::class, Bookmark::class, RssArticle::class, RssStar::class, TxtTocRule::class], - version = 7, + RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, + RssStar::class, TxtTocRule::class], + version = 8, exportSchema = true ) abstract class AppDatabase : RoomDatabase() { diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index 247a5be6e..ea5bb1ad8 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -3,6 +3,7 @@ package io.legado.app.data.dao import androidx.lifecycle.LiveData import androidx.room.* import io.legado.app.data.entities.RssArticle +import io.legado.app.data.entities.RssReadRecord @Dao interface RssArticleDao { @@ -10,7 +11,11 @@ interface RssArticleDao { @Query("select * from rssArticles where origin = :origin and link = :link") fun get(origin: String, link: String): RssArticle? - @Query("select * from rssArticles where origin = :origin order by `order` desc") + @Query( + """select t1.link, t1.origin, t1.`order`, t1.title, t1.content, t1.description, t1.image, t1.pubDate, ifNull(t2.read, 0) as read + from rssArticles as t1 left join rssReadRecords as t2 + on t1.link = t2.record where origin = :origin order by `order` desc""" + ) fun liveByOrigin(origin: String): LiveData> @Insert(onConflict = OnConflictStrategy.REPLACE) @@ -24,4 +29,7 @@ interface RssArticleDao { @Query("delete from rssArticles where origin = :origin") fun delete(origin: String) + + @Insert(onConflict = OnConflictStrategy.IGNORE) + fun insertRecord(vararg rssReadRecord: RssReadRecord) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/RssReadRecord.kt b/app/src/main/java/io/legado/app/data/entities/RssReadRecord.kt new file mode 100644 index 000000000..edbb4c15d --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/RssReadRecord.kt @@ -0,0 +1,7 @@ +package io.legado.app.data.entities + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "rssReadRecords") +data class RssReadRecord(@PrimaryKey val record: String, val read: Boolean = true) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 8a93301b9..42bc5c2d4 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssArticle +import io.legado.app.data.entities.RssReadRecord import io.legado.app.data.entities.RssSource import io.legado.app.model.Rss import kotlinx.coroutines.Dispatchers.IO @@ -101,8 +102,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application fun read(rssArticle: RssArticle) { execute { - rssArticle.read = true - App.db.rssArticleDao().update(rssArticle) + App.db.rssArticleDao().insertRecord(RssReadRecord(rssArticle.link)) } } From 8501b6a35f2bb465912402080efbf6469c4925f3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 10:43:38 +0800 Subject: [PATCH 362/852] =?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/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index c703795e9..50ee128dc 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ **2020/02/05** * 修复bug * Rss收藏功能完成 +* Rss已读标记不会再丢失 **2020/02/04** * 主界面切换时自动隐藏键盘 From 8db7c3943f3cd171d5217bbfce0eab168d0b12ac Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 12:18:45 +0800 Subject: [PATCH 363/852] =?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/data/dao/BookDao.kt | 2 +- .../io/legado/app/data/dao/BookGroupDao.kt | 4 +- .../io/legado/app/data/dao/RssArticleDao.kt | 2 + .../java/io/legado/app/data/dao/RssStarDao.kt | 3 ++ .../java/io/legado/app/help/storage/Backup.kt | 50 ++++++------------- .../app/web/controller/BookshelfController.kt | 2 +- 6 files changed, 24 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 303be7d5c..cbd0f61ce 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -45,7 +45,7 @@ interface BookDao { val hasUpdateBooks: List @get:Query("SELECT * FROM books") - val allBooks: List + val all: List @get:Query("SELECT * FROM books where type = 0 ORDER BY durChapterTime DESC limit 1") val lastReadBook: Book? diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index b06e7ac9e..af15188bb 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -19,8 +19,8 @@ interface BookGroupDao { @get:Query("SELECT MAX(`order`) FROM book_groups") val maxOrder: Int - @Query("SELECT * FROM book_groups ORDER BY `order`") - fun all(): List + @get:Query("SELECT * FROM book_groups ORDER BY `order`") + val all: List @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookGroup: BookGroup) diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index ea5bb1ad8..fbf3c3611 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -32,4 +32,6 @@ interface RssArticleDao { @Insert(onConflict = OnConflictStrategy.IGNORE) fun insertRecord(vararg rssReadRecord: RssReadRecord) + + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt b/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt index 87e527f75..faaf85b9f 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssStarDao.kt @@ -7,6 +7,9 @@ import io.legado.app.data.entities.RssStar @Dao interface RssStarDao { + @get:Query("select * from rssStars order by starTime desc") + val all: List + @Query("select * from rssStars where origin = :origin and link = :link") fun get(origin: String, link: String): RssStar? 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 fd28eea7f..d8fc7e4a3 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 @@ -36,6 +36,7 @@ object Backup { "bookGroup.json", "bookSource.json", "rssSource.json", + "rssStar.json", "replaceRule.json", ReadBookConfig.readConfigFileName, "config.xml" @@ -44,41 +45,13 @@ object Backup { suspend fun backup(context: Context, uri: Uri?) { withContext(IO) { - App.db.bookDao().allBooks.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "bookshelf.json") - .writeText(json) - } - } - App.db.bookGroupDao().all().let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "bookGroup.json") - .writeText(json) - } - } - App.db.bookSourceDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "bookSource.json") - .writeText(json) - } - } - App.db.rssSourceDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "rssSource.json") - .writeText(json) - } - } - App.db.replaceRuleDao().all.let { - if (it.isNotEmpty()) { - val json = GSON.toJson(it) - FileUtils.createFileIfNotExist(backupPath + File.separator + "replaceRule.json") - .writeText(json) - } - } + writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) + writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath) + writeListToJson(App.db.bookSourceDao().all, "bookSource.json", backupPath) + writeListToJson(App.db.rssSourceDao().all, "rssSource.json", backupPath) + writeListToJson(App.db.rssStarDao().all, "rssStar.json", backupPath) + writeListToJson(App.db.replaceRuleDao().all, "replaceRule.json", backupPath) + GSON.toJson(ReadBookConfig.configList)?.let { FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.readConfigFileName) .writeText(it) @@ -106,6 +79,13 @@ object Backup { } } + private fun writeListToJson(list: List, fileName: String, path: String) { + if (list.isNotEmpty()) { + val json = GSON.toJson(list) + FileUtils.createFileIfNotExist(path + File.separator + fileName).writeText(json) + } + } + private fun copyBackup(context: Context, uri: Uri) { DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> for (fileName in backupFileNames) { diff --git a/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt b/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt index 87bcb3e1c..961407998 100644 --- a/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt +++ b/app/src/main/java/io/legado/app/web/controller/BookshelfController.kt @@ -13,7 +13,7 @@ class BookshelfController { val bookshelf: ReturnData get() { - val books = App.db.bookDao().allBooks + val books = App.db.bookDao().all val returnData = ReturnData() return if (books.isEmpty()) { returnData.setErrorMsg("还没有添加小说") From 72bf906bd6ade0c7ed9466537f753adb2d007c16 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 12:53:29 +0800 Subject: [PATCH 364/852] =?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/help/storage/Backup.kt | 1 - .../io/legado/app/help/storage/OldBook.kt | 55 +++++++++ .../io/legado/app/help/storage/Restore.kt | 110 +++++------------- 3 files changed, 84 insertions(+), 82 deletions(-) create mode 100644 app/src/main/java/io/legado/app/help/storage/OldBook.kt 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 d8fc7e4a3..30e77eab6 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 @@ -51,7 +51,6 @@ object Backup { writeListToJson(App.db.rssSourceDao().all, "rssSource.json", backupPath) writeListToJson(App.db.rssStarDao().all, "rssStar.json", backupPath) writeListToJson(App.db.replaceRuleDao().all, "replaceRule.json", backupPath) - GSON.toJson(ReadBookConfig.configList)?.let { FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.readConfigFileName) .writeText(it) diff --git a/app/src/main/java/io/legado/app/help/storage/OldBook.kt b/app/src/main/java/io/legado/app/help/storage/OldBook.kt new file mode 100644 index 000000000..f8321973c --- /dev/null +++ b/app/src/main/java/io/legado/app/help/storage/OldBook.kt @@ -0,0 +1,55 @@ +package io.legado.app.help.storage + +import android.util.Log +import io.legado.app.App +import io.legado.app.constant.AppConst +import io.legado.app.data.entities.Book +import io.legado.app.utils.readBool +import io.legado.app.utils.readInt +import io.legado.app.utils.readLong +import io.legado.app.utils.readString + +object OldBook { + + fun toNewBook(json: String): List { + val books = mutableListOf() + val items: List> = Restore.jsonPath.parse(json).read("$") + val existingBooks = App.db.bookDao().allBookUrls.toSet() + for (item in items) { + val jsonItem = Restore.jsonPath.parse(item) + val book = Book() + book.bookUrl = jsonItem.readString("$.noteUrl") ?: "" + if (book.bookUrl.isBlank()) continue + book.name = jsonItem.readString("$.bookInfoBean.name") ?: "" + if (book.bookUrl in existingBooks) { + Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}") + continue + } + book.origin = jsonItem.readString("$.tag") ?: "" + book.originName = jsonItem.readString("$.bookInfoBean.origin") ?: "" + book.author = jsonItem.readString("$.bookInfoBean.author") ?: "" + book.type = + if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0 + book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl + book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl") + book.customCoverUrl = jsonItem.readString("$.customCoverPath") + book.lastCheckTime = jsonItem.readLong("$.bookInfoBean.finalRefreshData") ?: 0 + book.canUpdate = jsonItem.readBool("$.allowUpdate") == true + book.totalChapterNum = jsonItem.readInt("$.chapterListSize") ?: 0 + book.durChapterIndex = jsonItem.readInt("$.durChapter") ?: 0 + book.durChapterTitle = jsonItem.readString("$.durChapterName") + book.durChapterPos = jsonItem.readInt("$.durChapterPage") ?: 0 + book.durChapterTime = jsonItem.readLong("$.finalDate") ?: 0 + book.group = jsonItem.readInt("$.group") ?: 0 + book.intro = jsonItem.readString("$.bookInfoBean.introduce") + book.latestChapterTitle = jsonItem.readString("$.lastChapterName") + book.lastCheckCount = jsonItem.readInt("$.newChapters") ?: 0 + book.order = jsonItem.readInt("$.serialNumber") ?: 0 + book.useReplaceRule = jsonItem.readBool("$.useReplaceRule") == true + book.variable = jsonItem.readString("$.variable") + books.add(book) + } + return books + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 4385d6282..ee58fffbd 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -2,18 +2,19 @@ package io.legado.app.help.storage import android.content.Context import android.net.Uri -import android.util.Log import androidx.documentfile.provider.DocumentFile import com.jayway.jsonpath.Configuration import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.Option import com.jayway.jsonpath.ParseContext import io.legado.app.App -import io.legado.app.constant.AppConst import io.legado.app.constant.PreferKey import io.legado.app.data.entities.* import io.legado.app.help.ReadBookConfig -import io.legado.app.utils.* +import io.legado.app.utils.DocumentUtils +import io.legado.app.utils.FileUtils +import io.legado.app.utils.GSON +import io.legado.app.utils.fromJsonArray import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.GlobalScope @@ -50,51 +51,23 @@ object Restore { suspend fun restore(path: String) { withContext(IO) { - try { - val file = FileUtils.createFileIfNotExist(path + File.separator + "bookshelf.json") - val json = file.readText() - GSON.fromJsonArray(json)?.let { - App.db.bookDao().insert(*it.toTypedArray()) - } - } catch (e: Exception) { - e.printStackTrace() + fileToListT(path, "bookshelf.json")?.let { + App.db.bookDao().insert(*it.toTypedArray()) } - try { - val file = FileUtils.createFileIfNotExist(path + File.separator + "bookGroup.json") - val json = file.readText() - GSON.fromJsonArray(json)?.let { - App.db.bookGroupDao().insert(*it.toTypedArray()) - } - } catch (e: Exception) { - e.printStackTrace() + fileToListT(path, "bookGroup.json")?.let { + App.db.bookGroupDao().insert(*it.toTypedArray()) } - try { - val file = FileUtils.createFileIfNotExist(path + File.separator + "bookSource.json") - val json = file.readText() - GSON.fromJsonArray(json)?.let { - App.db.bookSourceDao().insert(*it.toTypedArray()) - } - } catch (e: Exception) { - e.printStackTrace() + fileToListT(path, "bookSource.json")?.let { + App.db.bookSourceDao().insert(*it.toTypedArray()) } - try { - val file = FileUtils.createFileIfNotExist(path + File.separator + "rssSource.json") - val json = file.readText() - GSON.fromJsonArray(json)?.let { - App.db.rssSourceDao().insert(*it.toTypedArray()) - } - } catch (e: Exception) { - e.printStackTrace() + fileToListT(path, "rssSource.json")?.let { + App.db.rssSourceDao().insert(*it.toTypedArray()) } - try { - val file = - FileUtils.createFileIfNotExist(path + File.separator + "replaceRule.json") - val json = file.readText() - GSON.fromJsonArray(json)?.let { - App.db.replaceRuleDao().insert(*it.toTypedArray()) - } - } catch (e: Exception) { - e.printStackTrace() + fileToListT(path, "rssStar.json")?.let { + App.db.rssStarDao().insert(*it.toTypedArray()) + } + fileToListT(path, "replaceRule.json")?.let { + App.db.replaceRuleDao().insert(*it.toTypedArray()) } try { val file = @@ -124,6 +97,17 @@ object Restore { } } + private inline fun fileToListT(path: String, fileName: String): List? { + try { + val file = FileUtils.createFileIfNotExist(path + File.separator + fileName) + val json = file.readText() + return GSON.fromJsonArray(json) + } catch (e: Exception) { + e.printStackTrace() + } + return null + } + fun importYueDuData(context: Context) { GlobalScope.launch(IO) { try {// 导入书架 @@ -171,43 +155,7 @@ object Restore { } fun importOldBookshelf(json: String): Int { - val books = mutableListOf() - val items: List> = jsonPath.parse(json).read("$") - val existingBooks = App.db.bookDao().allBookUrls.toSet() - for (item in items) { - val jsonItem = jsonPath.parse(item) - val book = Book() - book.bookUrl = jsonItem.readString("$.noteUrl") ?: "" - if (book.bookUrl.isBlank()) continue - book.name = jsonItem.readString("$.bookInfoBean.name") ?: "" - if (book.bookUrl in existingBooks) { - Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}") - continue - } - book.origin = jsonItem.readString("$.tag") ?: "" - book.originName = jsonItem.readString("$.bookInfoBean.origin") ?: "" - book.author = jsonItem.readString("$.bookInfoBean.author") ?: "" - book.type = - if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0 - book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl - book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl") - book.customCoverUrl = jsonItem.readString("$.customCoverPath") - book.lastCheckTime = jsonItem.readLong("$.bookInfoBean.finalRefreshData") ?: 0 - book.canUpdate = jsonItem.readBool("$.allowUpdate") == true - book.totalChapterNum = jsonItem.readInt("$.chapterListSize") ?: 0 - book.durChapterIndex = jsonItem.readInt("$.durChapter") ?: 0 - book.durChapterTitle = jsonItem.readString("$.durChapterName") - book.durChapterPos = jsonItem.readInt("$.durChapterPage") ?: 0 - book.durChapterTime = jsonItem.readLong("$.finalDate") ?: 0 - book.group = jsonItem.readInt("$.group") ?: 0 - book.intro = jsonItem.readString("$.bookInfoBean.introduce") - book.latestChapterTitle = jsonItem.readString("$.lastChapterName") - book.lastCheckCount = jsonItem.readInt("$.newChapters") ?: 0 - book.order = jsonItem.readInt("$.serialNumber") ?: 0 - book.useReplaceRule = jsonItem.readBool("$.useReplaceRule") == true - book.variable = jsonItem.readString("$.variable") - books.add(book) - } + val books = OldBook.toNewBook(json) App.db.bookDao().insert(*books.toTypedArray()) return books.size } From f37c24e550a88788d6aa25ac738d8d0ddf73612b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 13:10:02 +0800 Subject: [PATCH 365/852] =?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/WebDavHelp.kt | 8 +++++--- .../java/io/legado/app/ui/config/BackupConfigFragment.kt | 4 +++- app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index fb2e09a15..abd7a8a8a 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -54,12 +54,12 @@ object WebDavHelp { return names } - suspend fun showRestoreDialog(context: Context): Boolean { + suspend fun showRestoreDialog(context: Context, restoreSuccess: () -> Unit): Boolean { val names = withContext(IO) { getWebDavFileNames() } return if (names.isNotEmpty()) { context.selector(title = "选择恢复文件", items = names) { _, index -> if (index in 0 until names.size) { - restoreWebDav(names[index]) + restoreWebDav(names[index], restoreSuccess) } } true @@ -68,7 +68,7 @@ object WebDavHelp { } } - private fun restoreWebDav(name: String) { + private fun restoreWebDav(name: String, success: () -> Unit) { Coroutine.async { getWebDavUrl()?.let { val file = WebDav(it + "legado/" + name) @@ -77,6 +77,8 @@ object WebDavHelp { ZipUtils.unzipFile(zipFilePath, unzipFilesPath) Restore.restore(unzipFilesPath) } + }.onSuccess { + success.invoke() } } diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 39c711974..2f153da3f 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -158,7 +158,9 @@ class BackupConfigFragment : PreferenceFragmentCompat(), fun restore() { launch { - if (!WebDavHelp.showRestoreDialog(requireContext())) { + if (!WebDavHelp.showRestoreDialog(requireContext()) { + toast(R.string.restore_success) + }) { val backupPath = getPrefString(PreferKey.backupPath) if (backupPath?.isNotEmpty() == true) { val uri = Uri.parse(backupPath) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index fdae803bf..2c515dbb7 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -100,7 +100,9 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { fun restore() { launch { - if (!WebDavHelp.showRestoreDialog(requireContext())) { + if (!WebDavHelp.showRestoreDialog(requireContext()) { + toast(R.string.restore_success) + }) { val backupPath = getPrefString(PreferKey.backupPath) if (backupPath?.isNotEmpty() == true) { val uri = Uri.parse(backupPath) From 5a20999017bf45c823be5344010d2a26ba91d6d6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 13:28:45 +0800 Subject: [PATCH 366/852] =?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/rss/read/ReadRssActivity.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 494ea37bb..86d6e9ee8 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -159,9 +159,10 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r webView.settings.javaScriptEnabled = true webView.evaluateJavascript("document.documentElement.outerHTML") { val html = StringEscapeUtils.unescapeJson(it) - val 需读内容 = Jsoup.clean(html, Whitelist.none()).replace(Regex("""&\w+;"""),"").trim()//朗读过程中总是听到一些杂音,清理一下 + val text = Jsoup.clean(html, Whitelist.none()).replace(Regex("""&\w+;"""), "") + .trim()//朗读过程中总是听到一些杂音,清理一下 //longToast(需读内容)调试一下 - viewModel.readAloud(需读内容) + viewModel.readAloud(text) } } } From 7c48e5b5016ed029e9c639a970b4a824828d57e2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 13:29:30 +0800 Subject: [PATCH 367/852] =?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/rss/read/ReadRssActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 86d6e9ee8..d5d9b9b66 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -159,7 +159,8 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r webView.settings.javaScriptEnabled = true webView.evaluateJavascript("document.documentElement.outerHTML") { val html = StringEscapeUtils.unescapeJson(it) - val text = Jsoup.clean(html, Whitelist.none()).replace(Regex("""&\w+;"""), "") + val text = Jsoup.clean(html, Whitelist.none()) + .replace(Regex("""&\w+;"""), "") .trim()//朗读过程中总是听到一些杂音,清理一下 //longToast(需读内容)调试一下 viewModel.readAloud(text) From e8c105cddc6ffa2e33f302be1ebf38bf896d6aa8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 13:41:49 +0800 Subject: [PATCH 368/852] =?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/model/webBook/BookChapterList.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 82f06e54a..8c92ae7ed 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -100,6 +100,11 @@ object BookChapterList { item.index = index } book.latestChapterTitle = chapterList.last().title + if (book.durChapterIndex < chapterList.size) { + book.durChapterTitle = chapterList[book.durChapterIndex].title + } else { + book.durChapterTitle = book.latestChapterTitle + } if (book.totalChapterNum < chapterList.size) { book.lastCheckCount = chapterList.size - book.totalChapterNum } From a6df28d421ca50e87cf6366bf195551412572b43 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 15:31:17 +0800 Subject: [PATCH 369/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/CheckSourceService.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 5fa36c1ba..ba36d1e8b 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -7,23 +7,34 @@ import io.legado.app.base.BaseService import io.legado.app.constant.Action import io.legado.app.constant.AppConst import io.legado.app.data.entities.BookSource +import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.ui.book.source.manage.BookSourceActivity +import kotlinx.coroutines.asCoroutineDispatcher +import java.util.concurrent.Executors class CheckSourceService : BaseService() { - + private var searchPool = + Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() private var sourceList: List? = null override fun onCreate() { super.onCreate() + updateNotification(0, getString(R.string.start)) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + when (intent?.action) { + Action.start -> { + } + else -> stopSelf() + } return super.onStartCommand(intent, flags, startId) } override fun onDestroy() { super.onDestroy() + searchPool.close() } /** From 4ea7526edfa24e2d3f8bd6eafb8e58ec1ab06ead Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 15:57:05 +0800 Subject: [PATCH 370/852] =?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/res/anim/moprogress_bottom_in.xml | 8 -------- app/src/main/res/anim/moprogress_bottom_out.xml | 9 --------- app/src/main/res/anim/moprogress_in.xml | 17 ----------------- .../res/anim/moprogress_in_bottom_right.xml | 17 ----------------- .../main/res/anim/moprogress_in_top_right.xml | 17 ----------------- app/src/main/res/anim/moprogress_out.xml | 17 ----------------- .../res/anim/moprogress_out_bottom_right.xml | 17 ----------------- .../main/res/anim/moprogress_out_top_right.xml | 17 ----------------- 8 files changed, 119 deletions(-) delete mode 100644 app/src/main/res/anim/moprogress_bottom_in.xml delete mode 100644 app/src/main/res/anim/moprogress_bottom_out.xml delete mode 100644 app/src/main/res/anim/moprogress_in.xml delete mode 100644 app/src/main/res/anim/moprogress_in_bottom_right.xml delete mode 100644 app/src/main/res/anim/moprogress_in_top_right.xml delete mode 100644 app/src/main/res/anim/moprogress_out.xml delete mode 100644 app/src/main/res/anim/moprogress_out_bottom_right.xml delete mode 100644 app/src/main/res/anim/moprogress_out_top_right.xml diff --git a/app/src/main/res/anim/moprogress_bottom_in.xml b/app/src/main/res/anim/moprogress_bottom_in.xml deleted file mode 100644 index 59904f594..000000000 --- a/app/src/main/res/anim/moprogress_bottom_in.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_bottom_out.xml b/app/src/main/res/anim/moprogress_bottom_out.xml deleted file mode 100644 index 2348594fc..000000000 --- a/app/src/main/res/anim/moprogress_bottom_out.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_in.xml b/app/src/main/res/anim/moprogress_in.xml deleted file mode 100644 index 8e922153b..000000000 --- a/app/src/main/res/anim/moprogress_in.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_in_bottom_right.xml b/app/src/main/res/anim/moprogress_in_bottom_right.xml deleted file mode 100644 index 93348f5a8..000000000 --- a/app/src/main/res/anim/moprogress_in_bottom_right.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_in_top_right.xml b/app/src/main/res/anim/moprogress_in_top_right.xml deleted file mode 100644 index 81bb2e919..000000000 --- a/app/src/main/res/anim/moprogress_in_top_right.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_out.xml b/app/src/main/res/anim/moprogress_out.xml deleted file mode 100644 index 546619cc2..000000000 --- a/app/src/main/res/anim/moprogress_out.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_out_bottom_right.xml b/app/src/main/res/anim/moprogress_out_bottom_right.xml deleted file mode 100644 index d0d1eaffa..000000000 --- a/app/src/main/res/anim/moprogress_out_bottom_right.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/anim/moprogress_out_top_right.xml b/app/src/main/res/anim/moprogress_out_top_right.xml deleted file mode 100644 index 310b29d7e..000000000 --- a/app/src/main/res/anim/moprogress_out_top_right.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file From d87f85754b3067ee2d4c39d1996e1cdd9c4da51b Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 16:12:57 +0800 Subject: [PATCH 371/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/config/BgTextConfigDialog.kt | 4 ++-- .../io/legado/app/ui/book/read/config/MoreConfigDialog.kt | 4 ++-- .../io/legado/app/ui/book/read/config/PaddingConfigDialog.kt | 2 -- .../java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 8fe683273..5d61aefe1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -54,8 +54,8 @@ class BgTextConfigDialog : DialogFragment() { it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { - it.setBackgroundDrawableResource(R.color.transparent) - it.decorView.setPadding(0, 0, 0, 0) + it.setBackgroundDrawableResource(R.color.background) + it.decorView.setPadding(0, 5, 0, 0) val attr = it.attributes attr.dimAmount = 0.0f attr.gravity = Gravity.BOTTOM diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 3251cfc94..e18f32c0b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -29,8 +29,8 @@ class MoreConfigDialog : DialogFragment() { it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { - it.setBackgroundDrawableResource(R.color.transparent) - it.decorView.setPadding(0, 0, 0, 0) + it.setBackgroundDrawableResource(R.color.background) + it.decorView.setPadding(0, 5, 0, 0) val attr = it.attributes attr.dimAmount = 0.0f attr.gravity = Gravity.BOTTOM diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index fe04055e9..19ce7e100 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -26,8 +26,6 @@ class PaddingConfigDialog : DialogFragment() { it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { - it.setBackgroundDrawableResource(R.color.transparent) - it.decorView.setPadding(0, 0, 0, 0) val attr = it.attributes attr.dimAmount = 0.0f it.attributes = attr diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 3bc5060b0..8a1327a85 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -37,8 +37,8 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { it.windowManager?.defaultDisplay?.getMetrics(dm) } dialog?.window?.let { - it.setBackgroundDrawableResource(R.color.transparent) - it.decorView.setPadding(0, 0, 0, 0) + it.setBackgroundDrawableResource(R.color.background) + it.decorView.setPadding(0, 5, 0, 0) val attr = it.attributes attr.dimAmount = 0.0f attr.gravity = Gravity.BOTTOM From 4839c853fe1df564c5caeba0a95c2f34654071f6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 16:15:09 +0800 Subject: [PATCH 372/852] =?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/res/layout/dialog_read_aloud.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/dialog_read_aloud.xml b/app/src/main/res/layout/dialog_read_aloud.xml index 5cc10c6c3..37c5cc0d6 100644 --- a/app/src/main/res/layout/dialog_read_aloud.xml +++ b/app/src/main/res/layout/dialog_read_aloud.xml @@ -57,6 +57,7 @@ + Date: Wed, 5 Feb 2020 16:46:32 +0800 Subject: [PATCH 373/852] =?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/res/layout/dialog_page_key.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/dialog_page_key.xml b/app/src/main/res/layout/dialog_page_key.xml index 9ee5fd289..9ec5d3d06 100644 --- a/app/src/main/res/layout/dialog_page_key.xml +++ b/app/src/main/res/layout/dialog_page_key.xml @@ -3,6 +3,7 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@color/background" android:padding="16dp"> Date: Wed, 5 Feb 2020 17:18:40 +0800 Subject: [PATCH 374/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/lib/theme/TintHelper.kt | 5 +- .../app/ui/chapterlist/BookmarkFragment.kt | 4 +- .../app/ui/explore/ExploreShowViewModel.kt | 2 +- .../app/ui/filechooser/adapter/FileAdapter.kt | 2 +- .../app/ui/filechooser/adapter/PathAdapter.kt | 1 + .../app/ui/filechooser/utils/FileUtils.kt | 40 ++--- .../explosion_field/ExplosionAnimator.kt | 10 +- .../widget/recycler/scroller/FastScroller.kt | 23 ++- .../java/io/legado/app/utils/Snackbars.kt | 158 +++--------------- .../main/java/io/legado/app/utils/Toasts.kt | 8 +- 10 files changed, 63 insertions(+), 190 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt index 7b3653eb2..f7b52aa61 100644 --- a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt @@ -254,11 +254,10 @@ object TintHelper { if (!skipIndeterminate) progressBar.indeterminateTintList = sl } else { - val mode = PorterDuff.Mode.SRC_IN if (!skipIndeterminate && progressBar.indeterminateDrawable != null) - progressBar.indeterminateDrawable.setColorFilter(color, mode) + progressBar.indeterminateDrawable.setTint(color) if (progressBar.progressDrawable != null) - progressBar.progressDrawable.setColorFilter(color, mode) + progressBar.progressDrawable.setTint(color) } } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt index 803fe2e11..77eaad04f 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt @@ -74,8 +74,6 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ } override fun delBookmark(bookmark: Bookmark) { - bookmark?.let { - App.db.bookmarkDao().delByBookmark(it.bookUrl, it.chapterName) - } + App.db.bookmarkDao().delByBookmark(bookmark.bookUrl, bookmark.chapterName) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt index cf7ea9ebc..849b1ca87 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowViewModel.kt @@ -21,7 +21,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application execute { val sourceUrl = intent.getStringExtra("sourceUrl") exploreUrl = intent.getStringExtra("exploreUrl") - if (bookSource == null) { + if (bookSource == null && sourceUrl != null) { bookSource = App.db.bookSourceDao().getBookSource(sourceUrl) } explore() diff --git a/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt b/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt index a34c705b9..da58d501a 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt @@ -64,7 +64,7 @@ class FileAdapter(context: Context, val callBack: CallBack) : fileParent.icon = upIcon fileParent.name = DIR_PARENT fileParent.size = 0 - fileParent.path = File(path).parent + fileParent.path = File(path).parent ?: "" data.add(fileParent) } currentPath?.let { currentPath -> diff --git a/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt b/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt index afa8ab4e6..b735ef5da 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt @@ -15,6 +15,7 @@ import java.util.* class PathAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_path_filepicker) { private val paths = LinkedList() + @Suppress("DEPRECATION") private val sdCardDirectory = Environment.getExternalStorageDirectory().absolutePath private val arrowIcon = ConvertUtils.toDrawable(FilePickerIcon.getARROW()) diff --git a/app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt b/app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt index 71e838cae..f06054bb4 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt @@ -34,13 +34,13 @@ object FileUtils { * 将目录分隔符统一为平台默认的分隔符,并为目录结尾添加分隔符 */ fun separator(path: String): String { - var path = path + var path1 = path val separator = File.separator - path = path.replace("\\", separator) - if (!path.endsWith(separator)) { - path += separator + path1 = path1.replace("\\", separator) + if (!path1.endsWith(separator)) { + path1 += separator } - return path + return path1 } fun closeSilently(c: Closeable?) { @@ -62,7 +62,7 @@ object FileUtils { startDirPath: String, excludeDirs: Array? = null, @SortType sortType: Int = BY_NAME_ASC ): Array { - var excludeDirs = excludeDirs + var excludeDirs1 = excludeDirs val dirList = ArrayList() val startDir = File(startDirPath) if (!startDir.isDirectory) { @@ -75,12 +75,12 @@ object FileUtils { f.isDirectory }) ?: return arrayOfNulls(0) - if (excludeDirs == null) { - excludeDirs = arrayOfNulls(0) + if (excludeDirs1 == null) { + excludeDirs1 = arrayOfNulls(0) } for (dir in dirs) { val file = dir.absoluteFile - if (!excludeDirs.contentDeepToString().contains(file.name)) { + if (!excludeDirs1.contentDeepToString().contains(file.name)) { dirList.add(file) } } @@ -191,7 +191,7 @@ object FileUtils { */ fun listFiles(startDirPath: String, allowExtensions: Array): Array? { val file = File(startDirPath) - return file.listFiles { dir, name -> + return file.listFiles { _, name -> //返回当前目录所有以某些扩展名结尾的文件 val extension = getExtension(name) allowExtensions.contentDeepToString().contains(extension) @@ -294,10 +294,8 @@ object FileUtils { bis.close() bos.close() } else if (src.isDirectory) { - val files = src.listFiles() - tar.mkdirs() - for (file in files) { + src.listFiles()?.forEach { file -> copy(file.absoluteFile, File(tar.absoluteFile, file.name)) } } @@ -399,18 +397,16 @@ object FileUtils { fun writeBytes(filepath: String, data: ByteArray): Boolean { val file = File(filepath) var fos: FileOutputStream? = null - try { + return try { if (!file.exists()) { - - file.parentFile.mkdirs() - + file.parentFile?.mkdirs() file.createNewFile() } fos = FileOutputStream(filepath) fos.write(data) - return true + true } catch (e: IOException) { - return false + false } finally { closeSilently(fos) } @@ -422,16 +418,16 @@ object FileUtils { fun appendText(path: String, content: String): Boolean { val file = File(path) var writer: FileWriter? = null - try { + return try { if (!file.exists()) { file.createNewFile() } writer = FileWriter(file, true) writer.write(content) - return true + true } catch (e: IOException) { - return false + false } finally { closeSilently(writer) } diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt index 28bb1602a..9b80b1825 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt @@ -23,13 +23,11 @@ import java.util.* class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rect) : ValueAnimator() { - private val mPaint: Paint + private val mPaint: Paint = Paint() private val mParticles: Array - private val mBound: Rect + private val mBound: Rect = Rect(bound) init { - mPaint = Paint() - mBound = Rect(bound) val partLen = 15 mParticles = arrayOfNulls(partLen * partLen) val random = Random(System.currentTimeMillis()) @@ -97,7 +95,7 @@ class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rec override fun start() { super.start() - mContainer.invalidate(mBound) + mContainer.invalidate() } private inner class Particle { @@ -141,7 +139,7 @@ class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rec internal var DEFAULT_DURATION: Long = 0x400 private val DEFAULT_INTERPOLATOR = AccelerateInterpolator(0.6f) - private val END_VALUE = 1.4f + private const val END_VALUE = 1.4f private val X = Utils.dp2Px(5).toFloat() private val Y = Utils.dp2Px(20).toFloat() private val V = Utils.dp2Px(2).toFloat() diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt index 25af39c6a..20f638d61 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt @@ -482,18 +482,17 @@ class FastScroller : LinearLayout { var showTrack = true if (attrs != null) { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.FastScroller, 0, 0) - if (typedArray != null) { - try { - bubbleColor = typedArray.getColor(R.styleable.FastScroller_bubbleColor, bubbleColor) - handleColor = typedArray.getColor(R.styleable.FastScroller_handleColor, handleColor) - trackColor = typedArray.getColor(R.styleable.FastScroller_trackColor, trackColor) - textColor = typedArray.getColor(R.styleable.FastScroller_bubbleTextColor, textColor) - fadeScrollbar = typedArray.getBoolean(R.styleable.FastScroller_fadeScrollbar, fadeScrollbar) - showBubble = typedArray.getBoolean(R.styleable.FastScroller_showBubble, showBubble) - showTrack = typedArray.getBoolean(R.styleable.FastScroller_showTrack, showTrack) - } finally { - typedArray.recycle() - } + try { + bubbleColor = typedArray.getColor(R.styleable.FastScroller_bubbleColor, bubbleColor) + handleColor = typedArray.getColor(R.styleable.FastScroller_handleColor, handleColor) + trackColor = typedArray.getColor(R.styleable.FastScroller_trackColor, trackColor) + textColor = typedArray.getColor(R.styleable.FastScroller_bubbleTextColor, textColor) + fadeScrollbar = + typedArray.getBoolean(R.styleable.FastScroller_fadeScrollbar, fadeScrollbar) + showBubble = typedArray.getBoolean(R.styleable.FastScroller_showBubble, showBubble) + showTrack = typedArray.getBoolean(R.styleable.FastScroller_showTrack, showTrack) + } finally { + typedArray.recycle() } } setTrackColor(trackColor) diff --git a/app/src/main/java/io/legado/app/utils/Snackbars.kt b/app/src/main/java/io/legado/app/utils/Snackbars.kt index f60def01f..2706bd7ca 100644 --- a/app/src/main/java/io/legado/app/utils/Snackbars.kt +++ b/app/src/main/java/io/legado/app/utils/Snackbars.kt @@ -4,139 +4,13 @@ import android.view.View import androidx.annotation.StringRes import com.google.android.material.snackbar.Snackbar -/** - * Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. - * - * @param message the message text resource. - */ -@Deprecated("Use 'View.snackbar(Int)' instead.", ReplaceWith("view.snackbar(message)")) -inline fun snackbar(view: View, message: Int) = Snackbar - .make(view, message, Snackbar.LENGTH_SHORT) - .apply { show() } - -/** - * Display Snackbar with the [Snackbar.LENGTH_LONG] duration. - * - * @param message the message text resource. - */ -@Deprecated("Use 'View.longSnackbar(Int)' instead.", ReplaceWith("view.longSnackbar(message)")) -inline fun longSnackbar(view: View, message: Int) = Snackbar - .make(view, message, Snackbar.LENGTH_LONG) - .apply { show() } - -/** - * Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. - * - * @param message the message text resource. - */ -@Deprecated("Use 'View.indefiniteSnackbar(Int)' instead.", ReplaceWith("view.indefiniteSnackbar(message)")) -inline fun indefiniteSnackbar(view: View, message: Int) = Snackbar - .make(view, message, Snackbar.LENGTH_INDEFINITE) - .apply { show() } - -/** - * Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. - * - * @param message the message text. - */ -@Deprecated("Use 'View.snackbar(CharSequence)' instead.", ReplaceWith("view.snackbar(message)")) -inline fun snackbar(view: View, message: CharSequence) = Snackbar - .make(view, message, Snackbar.LENGTH_SHORT) - .apply { show() } - -/** - * Display Snackbar with the [Snackbar.LENGTH_LONG] duration. - * - * @param message the message text. - */ -@Deprecated("Use 'View.longSnackbar(CharSequence)' instead.", ReplaceWith("view.longSnackbar(message)")) -inline fun longSnackbar(view: View, message: CharSequence) = Snackbar - .make(view, message, Snackbar.LENGTH_LONG) - .apply { show() } - -/** - * Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. - * - * @param message the message text. - */ -@Deprecated("Use 'View.indefiniteSnackbar(CharSequence)' instead.", ReplaceWith("view.indefiniteSnackbar(message)")) -inline fun indefiniteSnackbar(view: View, message: CharSequence) = Snackbar - .make(view, message, Snackbar.LENGTH_INDEFINITE) - .apply { show() } - -/** - * Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. - * - * @param message the message text resource. - */ -@Deprecated("Use 'View.snackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.snackbar(message, actionText, action)")) -inline fun snackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar - .make(view, message, Snackbar.LENGTH_SHORT) - .setAction(actionText, action) - .apply { show() } - -/** - * Display Snackbar with the [Snackbar.LENGTH_LONG] duration. - * - * @param message the message text resource. - */ -@Deprecated("Use 'View.longSnackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.longSnackbar(message, actionText, action)")) -inline fun longSnackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar - .make(view, message, Snackbar.LENGTH_LONG) - .setAction(actionText, action) - .apply { show() } - -/** - * Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. - * - * @param message the message text resource. - */ -@Deprecated("Use 'View.indefiniteSnackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.indefiniteSnackbar(message, actionText, action)")) -inline fun indefiniteSnackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar - .make(view, message, Snackbar.LENGTH_INDEFINITE) - .setAction(actionText, action) - .apply { show() } - -/** - * Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. - * - * @param message the message text. - */ -@Deprecated("Use 'View.snackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.snackbar(message, actionText, action)")) -inline fun snackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar - .make(view, message, Snackbar.LENGTH_SHORT) - .setAction(actionText, action) - .apply { show() } - -/** - * Display Snackbar with the [Snackbar.LENGTH_LONG] duration. - * - * @param message the message text. - */ -@Deprecated("Use 'View.longSnackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.longSnackbar(message, actionText, action)")) -inline fun longSnackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar - .make(view, message, Snackbar.LENGTH_LONG) - .setAction(actionText, action) - .apply { show() } - -/** - * Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. - * - * @param message the message text. - */ -@Deprecated("Use 'View.indefiniteSnackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.indefiniteSnackbar(message, actionText, action)")) -inline fun indefiniteSnackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar - .make(view, message, Snackbar.LENGTH_INDEFINITE) - .setAction(actionText, action) - .apply { show() } - /** * Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. * * @param message the message text resource. */ @JvmName("snackbar2") -inline fun View.snackbar(@StringRes message: Int) = Snackbar +fun View.snackbar(@StringRes message: Int) = Snackbar .make(this, message, Snackbar.LENGTH_SHORT) .apply { show() } @@ -146,7 +20,7 @@ inline fun View.snackbar(@StringRes message: Int) = Snackbar * @param message the message text resource. */ @JvmName("longSnackbar2") -inline fun View.longSnackbar(@StringRes message: Int) = Snackbar +fun View.longSnackbar(@StringRes message: Int) = Snackbar .make(this, message, Snackbar.LENGTH_LONG) .apply { show() } @@ -156,7 +30,7 @@ inline fun View.longSnackbar(@StringRes message: Int) = Snackbar * @param message the message text resource. */ @JvmName("indefiniteSnackbar2") -inline fun View.indefiniteSnackbar(@StringRes message: Int) = Snackbar +fun View.indefiniteSnackbar(@StringRes message: Int) = Snackbar .make(this, message, Snackbar.LENGTH_INDEFINITE) .apply { show() } @@ -166,7 +40,7 @@ inline fun View.indefiniteSnackbar(@StringRes message: Int) = Snackbar * @param message the message text. */ @JvmName("snackbar2") -inline fun View.snackbar(message: CharSequence) = Snackbar +fun View.snackbar(message: CharSequence) = Snackbar .make(this, message, Snackbar.LENGTH_SHORT) .apply { show() } @@ -176,7 +50,7 @@ inline fun View.snackbar(message: CharSequence) = Snackbar * @param message the message text. */ @JvmName("longSnackbar2") -inline fun View.longSnackbar(message: CharSequence) = Snackbar +fun View.longSnackbar(message: CharSequence) = Snackbar .make(this, message, Snackbar.LENGTH_LONG) .apply { show() } @@ -186,7 +60,7 @@ inline fun View.longSnackbar(message: CharSequence) = Snackbar * @param message the message text. */ @JvmName("indefiniteSnackbar2") -inline fun View.indefiniteSnackbar(message: CharSequence) = Snackbar +fun View.indefiniteSnackbar(message: CharSequence) = Snackbar .make(this, message, Snackbar.LENGTH_INDEFINITE) .apply { show() } @@ -196,7 +70,7 @@ inline fun View.indefiniteSnackbar(message: CharSequence) = Snackbar * @param message the message text resource. */ @JvmName("snackbar2") -inline fun View.snackbar(message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar +fun View.snackbar(message: Int, @StringRes actionText: Int, action: (View) -> Unit) = Snackbar .make(this, message, Snackbar.LENGTH_SHORT) .setAction(actionText, action) .apply { show() } @@ -207,7 +81,8 @@ inline fun View.snackbar(message: Int, @StringRes actionText: Int, noinline acti * @param message the message text resource. */ @JvmName("longSnackbar2") -inline fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar +fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int, action: (View) -> Unit) = + Snackbar .make(this, message, Snackbar.LENGTH_LONG) .setAction(actionText, action) .apply { show() } @@ -218,7 +93,8 @@ inline fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int * @param message the message text resource. */ @JvmName("indefiniteSnackbar2") -inline fun View.indefiniteSnackbar(@StringRes message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar +fun View.indefiniteSnackbar(@StringRes message: Int, @StringRes actionText: Int, action: (View) -> Unit) = + Snackbar .make(this, message, Snackbar.LENGTH_INDEFINITE) .setAction(actionText, action) .apply { show() } @@ -229,7 +105,8 @@ inline fun View.indefiniteSnackbar(@StringRes message: Int, @StringRes actionTex * @param message the message text. */ @JvmName("snackbar2") -inline fun View.snackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar +fun View.snackbar(message: CharSequence, actionText: CharSequence, action: (View) -> Unit) = + Snackbar .make(this, message, Snackbar.LENGTH_SHORT) .setAction(actionText, action) .apply { show() } @@ -240,7 +117,8 @@ inline fun View.snackbar(message: CharSequence, actionText: CharSequence, noinli * @param message the message text. */ @JvmName("longSnackbar2") -inline fun View.longSnackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar +fun View.longSnackbar(message: CharSequence, actionText: CharSequence, action: (View) -> Unit) = + Snackbar .make(this, message, Snackbar.LENGTH_LONG) .setAction(actionText, action) .apply { show() } @@ -251,7 +129,11 @@ inline fun View.longSnackbar(message: CharSequence, actionText: CharSequence, no * @param message the message text. */ @JvmName("indefiniteSnackbar2") -inline fun View.indefiniteSnackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar +fun View.indefiniteSnackbar( + message: CharSequence, + actionText: CharSequence, + action: (View) -> Unit +) = Snackbar .make(this, message, Snackbar.LENGTH_INDEFINITE) .setAction(actionText, action) .apply { show() } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/Toasts.kt b/app/src/main/java/io/legado/app/utils/Toasts.kt index 16c032fa0..4348b4daf 100644 --- a/app/src/main/java/io/legado/app/utils/Toasts.kt +++ b/app/src/main/java/io/legado/app/utils/Toasts.kt @@ -11,25 +11,25 @@ import org.jetbrains.anko.toast * * @param message the message text resource. */ -inline fun Fragment.toast(message: Int) = requireActivity().toast(message) +fun Fragment.toast(message: Int) = requireActivity().toast(message) /** * Display the simple Toast message with the [Toast.LENGTH_SHORT] duration. * * @param message the message text. */ -inline fun Fragment.toast(message: CharSequence) = requireActivity().toast(message) +fun Fragment.toast(message: CharSequence) = requireActivity().toast(message) /** * Display the simple Toast message with the [Toast.LENGTH_LONG] duration. * * @param message the message text resource. */ -inline fun Fragment.longToast(message: Int) = requireActivity().longToast(message) +fun Fragment.longToast(message: Int) = requireActivity().longToast(message) /** * Display the simple Toast message with the [Toast.LENGTH_LONG] duration. * * @param message the message text. */ -inline fun Fragment.longToast(message: CharSequence) = requireActivity().longToast(message) +fun Fragment.longToast(message: CharSequence) = requireActivity().longToast(message) From 7c25389a4dc9b917afdbb4e1dad75839091dfe14 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 17:30:18 +0800 Subject: [PATCH 375/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/search/HistoryKeyAdapter.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index 213157e90..2be9e6409 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.search -import android.content.Context import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -15,8 +14,10 @@ import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick -class HistoryKeyAdapter(context: Context, val callBack: CallBack) : - SimpleRecyclerAdapter(context, R.layout.item_text) { +class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : + SimpleRecyclerAdapter(activity, R.layout.item_text) { + + private val explosionField = ExplosionField.attach2Window(activity) override fun convert(holder: ItemViewHolder, item: SearchKeyword, payloads: MutableList) { with(holder.itemView) { @@ -26,7 +27,7 @@ class HistoryKeyAdapter(context: Context, val callBack: CallBack) : } onLongClick { it?.let { - ExplosionField(context).explode(it, true) + explosionField.explode(it, true) } GlobalScope.launch(IO) { App.db.searchKeywordDao().delete(item) From 232ca67c37cd1d78bc4c88772957d9efbfbde77a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 17:39:39 +0800 Subject: [PATCH 376/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anima/explosion_field/ExplosionField.kt | 190 +----------------- .../anima/explosion_field/ExplosionView.kt | 173 ++++++++++++++++ 2 files changed, 183 insertions(+), 180 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionField.kt b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionField.kt index 1332a3969..9b014b7d2 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionField.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionField.kt @@ -1,191 +1,21 @@ -/* - * Copyright (C) 2015 tyrantgit - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package io.legado.app.ui.widget.anima.explosion_field -import android.animation.Animator -import android.animation.AnimatorListenerAdapter -import android.animation.ValueAnimator import android.app.Activity -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.Rect -import android.media.MediaPlayer -import android.util.AttributeSet -import android.util.Log import android.view.View import android.view.ViewGroup import android.view.Window -import java.util.* +object ExplosionField { -class ExplosionField : View { - - private var customDuration = ExplosionAnimator.DEFAULT_DURATION - private var idPlayAnimationEffect = 0 - private var mZAnimatorListener: OnAnimatorListener? = null - private var mOnClickListener: View.OnClickListener? = null - - private val mExplosions = ArrayList() - private val mExpandInset = IntArray(2) - - constructor(context: Context) : super(context) { - init() - } - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { - init() - } - - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( - context, - attrs, - defStyleAttr - ) { - init() - } - - private fun init() { - - Arrays.fill(mExpandInset, Utils.dp2Px(32)) - } - - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - for (explosion in mExplosions) { - explosion.draw(canvas) - } - } - - fun playSoundAnimationEffect(id: Int) { - this.idPlayAnimationEffect = id - } - - fun setCustomDuration(customDuration: Long) { - this.customDuration = customDuration - } - - fun addActionEvent(ievents: OnAnimatorListener) { - this.mZAnimatorListener = ievents - } - - - fun expandExplosionBound(dx: Int, dy: Int) { - mExpandInset[0] = dx - mExpandInset[1] = dy - } - - @JvmOverloads - fun explode(bitmap: Bitmap?, bound: Rect, startDelay: Long, view: View? = null) { - val currentDuration = customDuration - val explosion = ExplosionAnimator(this, bitmap!!, bound) - explosion.addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator) { - mExplosions.remove(animation) - if (view != null) { - view.scaleX = 1f - view.scaleY = 1f - view.alpha = 1f - view.setOnClickListener(mOnClickListener)//set event - - } - } - }) - explosion.startDelay = startDelay - explosion.duration = currentDuration - mExplosions.add(explosion) - explosion.start() - } - - @JvmOverloads - fun explode(view: View, restartState: Boolean? = false) { - - val r = Rect() - view.getGlobalVisibleRect(r) - val location = IntArray(2) - getLocationOnScreen(location) - // getLocationInWindow(location); - // view.getLocationInWindow(location); - r.offset(-location[0], -location[1]) - r.inset(-mExpandInset[0], -mExpandInset[1]) - val startDelay = 100 - val animator = ValueAnimator.ofFloat(0f, 1f).setDuration(150) - animator.addUpdateListener(object : ValueAnimator.AnimatorUpdateListener { - - internal var random = Random() - - override fun onAnimationUpdate(animation: ValueAnimator) { - view.translationX = (random.nextFloat() - 0.5f) * view.width.toFloat() * 0.05f - view.translationY = (random.nextFloat() - 0.5f) * view.height.toFloat() * 0.05f - } - }) - - animator.addListener(object : Animator.AnimatorListener { - override fun onAnimationStart(animator: Animator) { - if (idPlayAnimationEffect != 0) - MediaPlayer.create(context, idPlayAnimationEffect).start() - } - - override fun onAnimationEnd(animator: Animator) { - if (mZAnimatorListener != null) { - mZAnimatorListener!!.onAnimationEnd(animator, this@ExplosionField) - } - } - - override fun onAnimationCancel(animator: Animator) { - Log.i("PRUEBA", "CANCEL") - } - - override fun onAnimationRepeat(animator: Animator) { - Log.i("PRUEBA", "REPEAT") - } - }) - - animator.start() - view.animate().setDuration(150).setStartDelay(startDelay.toLong()).scaleX(0f).scaleY(0f) - .alpha(0f).start() - if (restartState!!) - explode(Utils.createBitmapFromView(view), r, startDelay.toLong(), view) - else - explode(Utils.createBitmapFromView(view), r, startDelay.toLong()) - - } - - fun clear() { - mExplosions.clear() - invalidate() - } - - override fun setOnClickListener(mOnClickListener: View.OnClickListener?) { - this.mOnClickListener = mOnClickListener - } - - companion object { - - fun attach2Window(activity: Activity): ExplosionField { - val rootView = activity.findViewById(Window.ID_ANDROID_CONTENT) as ViewGroup - val explosionField = ExplosionField(activity) - rootView.addView( - explosionField, ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT - ) + fun attach2Window(activity: Activity): ExplosionView { + val rootView = activity.findViewById(Window.ID_ANDROID_CONTENT) as ViewGroup + val explosionField = ExplosionView(activity) + rootView.addView( + explosionField, ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) - return explosionField - } + ) + return explosionField } - -} +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt new file mode 100644 index 000000000..c79695a51 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2015 tyrantgit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.legado.app.ui.widget.anima.explosion_field + +import android.animation.Animator +import android.animation.AnimatorListenerAdapter +import android.animation.ValueAnimator +import android.content.Context +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Rect +import android.media.MediaPlayer +import android.util.AttributeSet +import android.util.Log +import android.view.View +import java.util.* + + +class ExplosionView : View { + + private var customDuration = ExplosionAnimator.DEFAULT_DURATION + private var idPlayAnimationEffect = 0 + private var mZAnimatorListener: OnAnimatorListener? = null + private var mOnClickListener: OnClickListener? = null + + private val mExplosions = ArrayList() + private val mExpandInset = IntArray(2) + + constructor(context: Context) : super(context) { + init() + } + + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { + init() + } + + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( + context, + attrs, + defStyleAttr + ) { + init() + } + + private fun init() { + + Arrays.fill(mExpandInset, Utils.dp2Px(32)) + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + for (explosion in mExplosions) { + explosion.draw(canvas) + } + } + + fun playSoundAnimationEffect(id: Int) { + this.idPlayAnimationEffect = id + } + + fun setCustomDuration(customDuration: Long) { + this.customDuration = customDuration + } + + fun addActionEvent(ievents: OnAnimatorListener) { + this.mZAnimatorListener = ievents + } + + + fun expandExplosionBound(dx: Int, dy: Int) { + mExpandInset[0] = dx + mExpandInset[1] = dy + } + + @JvmOverloads + fun explode(bitmap: Bitmap?, bound: Rect, startDelay: Long, view: View? = null) { + val currentDuration = customDuration + val explosion = ExplosionAnimator(this, bitmap!!, bound) + explosion.addListener(object : AnimatorListenerAdapter() { + override fun onAnimationEnd(animation: Animator) { + mExplosions.remove(animation) + if (view != null) { + view.scaleX = 1f + view.scaleY = 1f + view.alpha = 1f + view.setOnClickListener(mOnClickListener)//set event + + } + } + }) + explosion.startDelay = startDelay + explosion.duration = currentDuration + mExplosions.add(explosion) + explosion.start() + } + + @JvmOverloads + fun explode(view: View, restartState: Boolean? = false) { + + val r = Rect() + view.getGlobalVisibleRect(r) + val location = IntArray(2) + getLocationOnScreen(location) + // getLocationInWindow(location); + // view.getLocationInWindow(location); + r.offset(-location[0], -location[1]) + r.inset(-mExpandInset[0], -mExpandInset[1]) + val startDelay = 100 + val animator = ValueAnimator.ofFloat(0f, 1f).setDuration(150) + animator.addUpdateListener(object : ValueAnimator.AnimatorUpdateListener { + + var random = Random() + + override fun onAnimationUpdate(animation: ValueAnimator) { + view.translationX = (random.nextFloat() - 0.5f) * view.width.toFloat() * 0.05f + view.translationY = (random.nextFloat() - 0.5f) * view.height.toFloat() * 0.05f + } + }) + + animator.addListener(object : Animator.AnimatorListener { + override fun onAnimationStart(animator: Animator) { + if (idPlayAnimationEffect != 0) + MediaPlayer.create(context, idPlayAnimationEffect).start() + } + + override fun onAnimationEnd(animator: Animator) { + if (mZAnimatorListener != null) { + mZAnimatorListener!!.onAnimationEnd(animator, this@ExplosionView) + } + } + + override fun onAnimationCancel(animator: Animator) { + Log.i("PRUEBA", "CANCEL") + } + + override fun onAnimationRepeat(animator: Animator) { + Log.i("PRUEBA", "REPEAT") + } + }) + + animator.start() + view.animate().setDuration(150).setStartDelay(startDelay.toLong()).scaleX(0f).scaleY(0f) + .alpha(0f).start() + if (restartState!!) + explode(Utils.createBitmapFromView(view), r, startDelay.toLong(), view) + else + explode(Utils.createBitmapFromView(view), r, startDelay.toLong()) + + } + + fun clear() { + mExplosions.clear() + invalidate() + } + + override fun setOnClickListener(mOnClickListener: OnClickListener?) { + this.mOnClickListener = mOnClickListener + } + +} From 1e185b0ee939889fc917e9e5d8a68ca0b0f6b596 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 18:10:11 +0800 Subject: [PATCH 377/852] =?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/constant/{Bus.kt => EventBus.kt} | 2 +- .../constant/{Action.kt => IntentAction.kt} | 2 +- .../app/receiver/MediaButtonReceiver.kt | 6 +- .../app/receiver/TimeElectricityReceiver.kt | 6 +- .../io/legado/app/service/AudioPlayService.kt | 56 +++++++++---------- .../app/service/BaseReadAloudService.kt | 34 +++++------ .../legado/app/service/CheckSourceService.kt | 25 ++++++++- .../io/legado/app/service/DownloadService.kt | 14 ++--- .../app/service/HttpReadAloudService.kt | 6 +- .../legado/app/service/TTSReadAloudService.kt | 6 +- .../java/io/legado/app/service/WebService.kt | 12 ++-- .../io/legado/app/service/help/AudioPlay.kt | 18 +++--- .../io/legado/app/service/help/Download.kt | 4 +- .../io/legado/app/service/help/ReadAloud.kt | 18 +++--- .../legado/app/ui/audio/AudioPlayActivity.kt | 14 ++--- .../app/ui/book/read/ReadBookActivity.kt | 22 ++++---- .../ui/book/read/config/BgTextConfigDialog.kt | 8 +-- .../ui/book/read/config/MoreConfigDialog.kt | 6 +- .../book/read/config/PaddingConfigDialog.kt | 26 ++++----- .../book/read/config/ReadAloudConfigDialog.kt | 4 +- .../ui/book/read/config/ReadAloudDialog.kt | 6 +- .../ui/book/read/config/ReadStyleDialog.kt | 28 +++++----- .../read/page/ContentSelectActionCallback.kt | 4 +- .../app/ui/config/OtherConfigFragment.kt | 4 +- .../app/ui/config/ThemeConfigFragment.kt | 4 +- .../app/ui/download/DownloadActivity.kt | 4 +- .../io/legado/app/ui/main/MainActivity.kt | 6 +- .../io/legado/app/ui/main/MainViewModel.kt | 8 +-- .../ui/main/bookshelf/BookshelfFragment.kt | 4 +- .../ui/main/bookshelf/books/BooksFragment.kt | 4 +- .../io/legado/app/ui/main/my/MyFragment.kt | 4 +- 31 files changed, 192 insertions(+), 173 deletions(-) rename app/src/main/java/io/legado/app/constant/{Bus.kt => EventBus.kt} (97%) rename app/src/main/java/io/legado/app/constant/{Action.kt => IntentAction.kt} (96%) diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt similarity index 97% rename from app/src/main/java/io/legado/app/constant/Bus.kt rename to app/src/main/java/io/legado/app/constant/EventBus.kt index eb1dd14dd..3fc80e3ac 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -1,6 +1,6 @@ package io.legado.app.constant -object Bus { +object EventBus { const val MEDIA_BUTTON = "mediaButton" const val RECREATE = "RECREATE" const val UP_BOOK = "sourceDebugLog" diff --git a/app/src/main/java/io/legado/app/constant/Action.kt b/app/src/main/java/io/legado/app/constant/IntentAction.kt similarity index 96% rename from app/src/main/java/io/legado/app/constant/Action.kt rename to app/src/main/java/io/legado/app/constant/IntentAction.kt index a13a8cca3..0dffe87a1 100644 --- a/app/src/main/java/io/legado/app/constant/Action.kt +++ b/app/src/main/java/io/legado/app/constant/IntentAction.kt @@ -1,6 +1,6 @@ package io.legado.app.constant -object Action { +object IntentAction { const val start = "start" const val play = "play" const val stop = "stop" diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 5cc36a680..12083c652 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -5,7 +5,7 @@ import android.content.Context import android.content.Intent import android.view.KeyEvent import io.legado.app.App -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.data.entities.Book import io.legado.app.help.ActivityHelp import io.legado.app.ui.audio.AudioPlayActivity @@ -51,9 +51,9 @@ class MediaButtonReceiver : BroadcastReceiver() { private fun readAloud(context: Context) { when { ActivityHelp.isExist(AudioPlayActivity::class.java) -> - postEvent(Bus.MEDIA_BUTTON, true) + postEvent(EventBus.MEDIA_BUTTON, true) ActivityHelp.isExist(ReadBookActivity::class.java) -> - postEvent(Bus.MEDIA_BUTTON, true) + postEvent(EventBus.MEDIA_BUTTON, true) else -> { GlobalScope.launch(Main) { val lastBook: Book? = withContext(IO) { diff --git a/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt b/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt index 613db4fe4..765d05b3e 100644 --- a/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt @@ -5,7 +5,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.BatteryManager -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.utils.postEvent @@ -28,11 +28,11 @@ class TimeElectricityReceiver : BroadcastReceiver() { intent?.action?.let { when (it) { Intent.ACTION_TIME_TICK -> { - postEvent(Bus.TIME_CHANGED, "") + postEvent(EventBus.TIME_CHANGED, "") } Intent.ACTION_BATTERY_CHANGED -> { val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) - postEvent(Bus.BATTERY_CHANGED, level) + postEvent(EventBus.BATTERY_CHANGED, level) } } } diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index ef2638c29..c165f3142 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -18,9 +18,9 @@ import androidx.core.app.NotificationCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.Action +import io.legado.app.constant.IntentAction import io.legado.app.constant.AppConst -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.Status import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp @@ -81,21 +81,21 @@ class AudioPlayService : BaseService(), override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { intent?.action?.let { action -> when (action) { - Action.play -> { + IntentAction.play -> { AudioPlay.book?.let { title = it.name position = it.durChapterPos loadContent(it.durChapterIndex) } } - Action.pause -> pause(true) - Action.resume -> resume() - Action.prev -> moveToPrev() - Action.next -> moveToNext() - Action.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) - Action.addTimer -> addTimer() - Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) - Action.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) + IntentAction.pause -> pause(true) + IntentAction.resume -> resume() + IntentAction.prev -> moveToPrev() + IntentAction.next -> moveToNext() + IntentAction.adjustSpeed -> upSpeed(intent.getFloatExtra("adjust", 1f)) + IntentAction.addTimer -> addTimer() + IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0)) + IntentAction.adjustProgress -> adjustProgress(intent.getIntExtra("position", position)) else -> stopSelf() } } @@ -112,7 +112,7 @@ class AudioPlayService : BaseService(), unregisterReceiver(broadcastReceiver) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) AudioPlay.status = Status.STOP - postEvent(Bus.AUDIO_STATE, Status.STOP) + postEvent(EventBus.AUDIO_STATE, Status.STOP) } private fun play() { @@ -120,7 +120,7 @@ class AudioPlayService : BaseService(), if (requestFocus()) { try { AudioPlay.status = Status.PLAY - postEvent(Bus.AUDIO_STATE, Status.PLAY) + postEvent(EventBus.AUDIO_STATE, Status.PLAY) mediaPlayer.reset() val analyzeUrl = AnalyzeUrl(url, headerMapF = AudioPlay.headers(), useWebView = true) @@ -146,7 +146,7 @@ class AudioPlayService : BaseService(), mediaPlayer.pause() upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) AudioPlay.status = Status.PAUSE - postEvent(Bus.AUDIO_STATE, Status.PAUSE) + postEvent(EventBus.AUDIO_STATE, Status.PAUSE) upNotification() } } @@ -159,7 +159,7 @@ class AudioPlayService : BaseService(), handler.postDelayed(mpRunnable, 1000) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) AudioPlay.status = Status.PLAY - postEvent(Bus.AUDIO_STATE, Status.PLAY) + postEvent(EventBus.AUDIO_STATE, Status.PLAY) upNotification() } @@ -178,7 +178,7 @@ class AudioPlayService : BaseService(), if (isPlaying) { playbackParams = playbackParams.apply { speed += adjust } } - postEvent(Bus.AUDIO_SPEED, playbackParams.speed) + postEvent(EventBus.AUDIO_SPEED, playbackParams.speed) } } } @@ -191,7 +191,7 @@ class AudioPlayService : BaseService(), if (pause) return mediaPlayer.start() mediaPlayer.seekTo(position) - postEvent(Bus.AUDIO_SIZE, mediaPlayer.duration) + postEvent(EventBus.AUDIO_SIZE, mediaPlayer.duration) bookChapter?.let { it.end = mediaPlayer.duration.toLong() } @@ -205,7 +205,7 @@ class AudioPlayService : BaseService(), override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { if (!mediaPlayer.isPlaying) { AudioPlay.status = Status.STOP - postEvent(Bus.AUDIO_STATE, Status.STOP) + postEvent(EventBus.AUDIO_STATE, Status.STOP) launch { toast("error: $what $extra $url") } } return true @@ -238,7 +238,7 @@ class AudioPlayService : BaseService(), handler.removeCallbacks(dsRunnable) handler.postDelayed(dsRunnable, 60000) } - postEvent(Bus.TTS_DS, timeMinute) + postEvent(EventBus.TTS_DS, timeMinute) upNotification() } @@ -247,7 +247,7 @@ class AudioPlayService : BaseService(), */ private fun upPlayProgress() { saveProgress() - postEvent(Bus.AUDIO_PROGRESS, mediaPlayer.currentPosition) + postEvent(EventBus.AUDIO_PROGRESS, mediaPlayer.currentPosition) handler.postDelayed(mpRunnable, 1000) } @@ -260,9 +260,9 @@ class AudioPlayService : BaseService(), if (index == AudioPlay.durChapterIndex) { bookChapter = chapter subtitle = chapter.title - postEvent(Bus.AUDIO_SUB_TITLE, subtitle) - postEvent(Bus.AUDIO_SIZE, chapter.end?.toInt() ?: 0) - postEvent(Bus.AUDIO_PROGRESS, position) + postEvent(EventBus.AUDIO_SUB_TITLE, subtitle) + postEvent(EventBus.AUDIO_SIZE, chapter.end?.toInt() ?: 0) + postEvent(EventBus.AUDIO_PROGRESS, position) } loadContent(chapter) } ?: removeLoading(index) @@ -376,7 +376,7 @@ class AudioPlayService : BaseService(), handler.postDelayed(dsRunnable, 60000) } } - postEvent(Bus.TTS_DS, timeMinute) + postEvent(EventBus.TTS_DS, timeMinute) upNotification() } @@ -485,24 +485,24 @@ class AudioPlayService : BaseService(), builder.addAction( R.drawable.ic_play_24dp, getString(R.string.resume), - thisPendingIntent(Action.resume) + thisPendingIntent(IntentAction.resume) ) } else { builder.addAction( R.drawable.ic_pause_24dp, getString(R.string.pause), - thisPendingIntent(Action.pause) + thisPendingIntent(IntentAction.pause) ) } builder.addAction( R.drawable.ic_stop_black_24dp, getString(R.string.stop), - thisPendingIntent(Action.stop) + thisPendingIntent(IntentAction.stop) ) builder.addAction( R.drawable.ic_time_add_24dp, getString(R.string.set_timer), - thisPendingIntent(Action.addTimer) + thisPendingIntent(IntentAction.addTimer) ) builder.setStyle( androidx.media.app.NotificationCompat.MediaStyle() diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 5603da72c..cb946d145 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -70,7 +70,7 @@ abstract class BaseReadAloudService : BaseService(), isRun = false pause = true unregisterReceiver(broadcastReceiver) - postEvent(Bus.ALOUD_STATE, Status.STOP) + postEvent(EventBus.ALOUD_STATE, Status.STOP) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) mediaSessionCompat?.release() } @@ -78,7 +78,7 @@ abstract class BaseReadAloudService : BaseService(), override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { intent?.action?.let { action -> when (action) { - Action.play -> { + IntentAction.play -> { title = intent.getStringExtra("title") ?: "" subtitle = intent.getStringExtra("subtitle") ?: "" pageIndex = intent.getIntExtra("pageIndex", 0) @@ -87,13 +87,13 @@ abstract class BaseReadAloudService : BaseService(), intent.getBooleanExtra("play", true) ) } - Action.pause -> pauseReadAloud(true) - Action.resume -> resumeReadAloud() - Action.upTtsSpeechRate -> upSpeechRate(true) - Action.prevParagraph -> prevP() - Action.nextParagraph -> nextP() - Action.addTimer -> addTimer() - Action.setTimer -> setTimer(intent.getIntExtra("minute", 0)) + IntentAction.pause -> pauseReadAloud(true) + IntentAction.resume -> resumeReadAloud() + IntentAction.upTtsSpeechRate -> upSpeechRate(true) + IntentAction.prevParagraph -> prevP() + IntentAction.nextParagraph -> nextP() + IntentAction.addTimer -> addTimer() + IntentAction.setTimer -> setTimer(intent.getIntExtra("minute", 0)) else -> stopSelf() } } @@ -124,13 +124,13 @@ abstract class BaseReadAloudService : BaseService(), open fun play() { pause = false - postEvent(Bus.ALOUD_STATE, Status.PLAY) + postEvent(EventBus.ALOUD_STATE, Status.PLAY) upNotification() } @CallSuper open fun pauseReadAloud(pause: Boolean) { - postEvent(Bus.ALOUD_STATE, Status.PAUSE) + postEvent(EventBus.ALOUD_STATE, Status.PAUSE) BaseReadAloudService.pause = pause upNotification() upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) @@ -167,7 +167,7 @@ abstract class BaseReadAloudService : BaseService(), handler.removeCallbacks(dsRunnable) handler.postDelayed(dsRunnable, 60000) } - postEvent(Bus.TTS_DS, timeMinute) + postEvent(EventBus.TTS_DS, timeMinute) upNotification() } @@ -183,7 +183,7 @@ abstract class BaseReadAloudService : BaseService(), handler.postDelayed(dsRunnable, 60000) } } - postEvent(Bus.TTS_DS, timeMinute) + postEvent(EventBus.TTS_DS, timeMinute) upNotification() } @@ -298,24 +298,24 @@ abstract class BaseReadAloudService : BaseService(), builder.addAction( R.drawable.ic_play_24dp, getString(R.string.resume), - aloudServicePendingIntent(Action.resume) + aloudServicePendingIntent(IntentAction.resume) ) } else { builder.addAction( R.drawable.ic_pause_24dp, getString(R.string.pause), - aloudServicePendingIntent(Action.pause) + aloudServicePendingIntent(IntentAction.pause) ) } builder.addAction( R.drawable.ic_stop_black_24dp, getString(R.string.stop), - aloudServicePendingIntent(Action.stop) + aloudServicePendingIntent(IntentAction.stop) ) builder.addAction( R.drawable.ic_time_add_24dp, getString(R.string.set_timer), - aloudServicePendingIntent(Action.addTimer) + aloudServicePendingIntent(IntentAction.addTimer) ) builder.setStyle( androidx.media.app.NotificationCompat.MediaStyle() diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index ba36d1e8b..6507cb219 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -1,10 +1,11 @@ package io.legado.app.service +import android.content.Context import android.content.Intent import androidx.core.app.NotificationCompat import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.Action +import io.legado.app.constant.IntentAction import io.legado.app.constant.AppConst import io.legado.app.data.entities.BookSource import io.legado.app.help.AppConfig @@ -14,6 +15,24 @@ import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors class CheckSourceService : BaseService() { + + companion object{ + fun start(context: Context, selectedIds: Array) { + Intent(context, CheckSourceService::class.java).let { + it.action = IntentAction.start + it.putExtra("selectIds", selectedIds) + context.startService(it) + } + } + + fun stop(context: Context) { + Intent(context, CheckSourceService::class.java).let { + it.action = IntentAction.stop + context.startService(it) + } + } + } + private var searchPool = Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() private var sourceList: List? = null @@ -25,7 +44,7 @@ class CheckSourceService : BaseService() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { when (intent?.action) { - Action.start -> { + IntentAction.start -> { } else -> stopSelf() } @@ -52,7 +71,7 @@ class CheckSourceService : BaseService() { .addAction( R.drawable.ic_stop_black_24dp, getString(R.string.cancel), - IntentHelp.servicePendingIntent(this, Action.stop) + IntentHelp.servicePendingIntent(this, IntentAction.stop) ) sourceList?.let { builder.setProgress(it.size, state, false) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 9c2e7a2f3..df49e24d9 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -6,9 +6,9 @@ import androidx.core.app.NotificationCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.Action +import io.legado.app.constant.IntentAction import io.legado.app.constant.AppConst -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.IntentHelp @@ -34,7 +34,7 @@ class DownloadService : BaseService() { builder.addAction( R.drawable.ic_stop_black_24dp, getString(R.string.cancel), - IntentHelp.servicePendingIntent(this, Action.stop) + IntentHelp.servicePendingIntent(this, IntentAction.stop) ) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) } @@ -48,12 +48,12 @@ class DownloadService : BaseService() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { intent?.action?.let { action -> when (action) { - Action.start -> download( + IntentAction.start -> download( intent.getStringExtra("bookUrl"), intent.getIntExtra("start", 0), intent.getIntExtra("end", 0) ) - Action.stop -> stopDownload() + IntentAction.stop -> stopDownload() } } return super.onStartCommand(intent, flags, startId) @@ -64,7 +64,7 @@ class DownloadService : BaseService() { searchPool.close() handler.removeCallbacks(runnable) super.onDestroy() - postEvent(Bus.UP_DOWNLOAD, false) + postEvent(EventBus.UP_DOWNLOAD, false) } private fun download(bookUrl: String?, start: Int, end: Int) { @@ -105,7 +105,7 @@ class DownloadService : BaseService() { private fun upDownload() { updateNotification(notificationContent) - postEvent(Bus.UP_DOWNLOAD, true) + postEvent(EventBus.UP_DOWNLOAD, true) handler.removeCallbacks(runnable) handler.postDelayed(runnable, 1000) } diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index f8048af54..1cf40fc8c 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -2,7 +2,7 @@ package io.legado.app.service import android.app.PendingIntent import android.media.MediaPlayer -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.IntentHelp import io.legado.app.help.http.HttpHelper @@ -98,7 +98,7 @@ class HttpReadAloudService : BaseReadAloudService(), mediaPlayer.reset() mediaPlayer.setDataSource(fd) mediaPlayer.prepareAsync() - postEvent(Bus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_START, readAloudNumber + 1) } catch (e: Exception) { e.printStackTrace() } @@ -187,7 +187,7 @@ class HttpReadAloudService : BaseReadAloudService(), ReadBook.moveToNextPage() } } - postEvent(Bus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_START, readAloudNumber + 1) } override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 977e8b0ac..4c5357ce6 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -6,7 +6,7 @@ import android.speech.tts.TextToSpeech import android.speech.tts.UtteranceProgressListener import io.legado.app.R import io.legado.app.constant.AppConst -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.help.IntentHelp import io.legado.app.help.MediaHelp import io.legado.app.service.help.ReadBook @@ -152,7 +152,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener ReadBook.moveToNextPage() } } - postEvent(Bus.TTS_START, readAloudNumber + 1) + postEvent(EventBus.TTS_START, readAloudNumber + 1) } override fun onDone(s: String) { @@ -169,7 +169,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener if (readAloudNumber + start > it.getReadLength(pageIndex + 1)) { pageIndex++ ReadBook.moveToNextPage() - postEvent(Bus.TTS_START, readAloudNumber + start) + postEvent(EventBus.TTS_START, readAloudNumber + start) } } } diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 25f2b6822..e9d223956 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -6,9 +6,9 @@ import androidx.core.app.NotificationCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.Action +import io.legado.app.constant.IntentAction import io.legado.app.constant.AppConst -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.help.IntentHelp import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getPrefInt @@ -32,7 +32,7 @@ class WebService : BaseService() { fun stop(context: Context) { if (isRun) { val intent = Intent(context, WebService::class.java) - intent.action = Action.stop + intent.action = IntentAction.stop context.startService(intent) } } @@ -56,12 +56,12 @@ class WebService : BaseService() { if (webSocketServer?.isAlive == true) { webSocketServer?.stop() } - postEvent(Bus.WEB_SERVICE_STOP, true) + postEvent(EventBus.WEB_SERVICE_STOP, true) } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { when (intent?.action) { - Action.stop -> stopSelf() + IntentAction.stop -> stopSelf() else -> upWebServer() } return super.onStartCommand(intent, flags, startId) @@ -115,7 +115,7 @@ class WebService : BaseService() { builder.addAction( R.drawable.ic_stop_black_24dp, getString(R.string.cancel), - IntentHelp.servicePendingIntent(this, Action.stop) + IntentHelp.servicePendingIntent(this, IntentAction.stop) ) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) val notification = builder.build() diff --git a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt index add1a3fab..7c8d120b3 100644 --- a/app/src/main/java/io/legado/app/service/help/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/service/help/AudioPlay.kt @@ -3,7 +3,7 @@ package io.legado.app.service.help import android.content.Context import android.content.Intent import androidx.lifecycle.MutableLiveData -import io.legado.app.constant.Action +import io.legado.app.constant.IntentAction import io.legado.app.constant.Status import io.legado.app.data.entities.Book import io.legado.app.model.WebBook @@ -27,14 +27,14 @@ object AudioPlay { fun play(context: Context) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.play + intent.action = IntentAction.play context.startService(intent) } fun pause(context: Context) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.pause + intent.action = IntentAction.pause context.startService(intent) } } @@ -42,7 +42,7 @@ object AudioPlay { fun resume(context: Context) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.resume + intent.action = IntentAction.resume context.startService(intent) } } @@ -50,7 +50,7 @@ object AudioPlay { fun stop(context: Context) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.stop + intent.action = IntentAction.stop context.startService(intent) } } @@ -58,7 +58,7 @@ object AudioPlay { fun adjustSpeed(context: Context, adjust: Float) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.adjustSpeed + intent.action = IntentAction.adjustSpeed intent.putExtra("adjust", adjust) context.startService(intent) } @@ -67,7 +67,7 @@ object AudioPlay { fun adjustProgress(context: Context, position: Int) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.adjustProgress + intent.action = IntentAction.adjustProgress intent.putExtra("position", position) context.startService(intent) } @@ -76,7 +76,7 @@ object AudioPlay { fun prev(context: Context) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.prev + intent.action = IntentAction.prev context.startService(intent) } } @@ -84,7 +84,7 @@ object AudioPlay { fun next(context: Context) { if (AudioPlayService.isRun) { val intent = Intent(context, AudioPlayService::class.java) - intent.action = Action.next + intent.action = IntentAction.next context.startService(intent) } } diff --git a/app/src/main/java/io/legado/app/service/help/Download.kt b/app/src/main/java/io/legado/app/service/help/Download.kt index 1c17a7ee1..86accbceb 100644 --- a/app/src/main/java/io/legado/app/service/help/Download.kt +++ b/app/src/main/java/io/legado/app/service/help/Download.kt @@ -2,14 +2,14 @@ package io.legado.app.service.help import android.content.Context import android.content.Intent -import io.legado.app.constant.Action +import io.legado.app.constant.IntentAction import io.legado.app.service.DownloadService object Download { fun start(context: Context, bookUrl: String, start: Int, end: Int) { Intent(context, DownloadService::class.java).let { - it.action = Action.start + it.action = IntentAction.start it.putExtra("bookUrl", bookUrl) it.putExtra("start", start) it.putExtra("end", end) diff --git a/app/src/main/java/io/legado/app/service/help/ReadAloud.kt b/app/src/main/java/io/legado/app/service/help/ReadAloud.kt index 49285eeff..b5c12a965 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadAloud.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadAloud.kt @@ -3,7 +3,7 @@ package io.legado.app.service.help import android.content.Context import android.content.Intent import io.legado.app.App -import io.legado.app.constant.Action +import io.legado.app.constant.IntentAction import io.legado.app.constant.PreferKey import io.legado.app.service.BaseReadAloudService import io.legado.app.service.HttpReadAloudService @@ -30,7 +30,7 @@ object ReadAloud { play: Boolean = true ) { val intent = Intent(context, aloudClass) - intent.action = Action.play + intent.action = IntentAction.play intent.putExtra("title", title) intent.putExtra("subtitle", subtitle) intent.putExtra("pageIndex", pageIndex) @@ -42,7 +42,7 @@ object ReadAloud { fun pause(context: Context) { if (BaseReadAloudService.isRun) { val intent = Intent(context, aloudClass) - intent.action = Action.pause + intent.action = IntentAction.pause context.startService(intent) } } @@ -50,7 +50,7 @@ object ReadAloud { fun resume(context: Context) { if (BaseReadAloudService.isRun) { val intent = Intent(context, aloudClass) - intent.action = Action.resume + intent.action = IntentAction.resume context.startService(intent) } } @@ -58,7 +58,7 @@ object ReadAloud { fun stop(context: Context) { if (BaseReadAloudService.isRun) { val intent = Intent(context, aloudClass) - intent.action = Action.stop + intent.action = IntentAction.stop context.startService(intent) } } @@ -66,7 +66,7 @@ object ReadAloud { fun prevParagraph(context: Context) { if (BaseReadAloudService.isRun) { val intent = Intent(context, aloudClass) - intent.action = Action.prevParagraph + intent.action = IntentAction.prevParagraph context.startService(intent) } } @@ -74,7 +74,7 @@ object ReadAloud { fun nextParagraph(context: Context) { if (BaseReadAloudService.isRun) { val intent = Intent(context, aloudClass) - intent.action = Action.nextParagraph + intent.action = IntentAction.nextParagraph context.startService(intent) } } @@ -82,7 +82,7 @@ object ReadAloud { fun upTtsSpeechRate(context: Context) { if (BaseReadAloudService.isRun) { val intent = Intent(context, aloudClass) - intent.action = Action.upTtsSpeechRate + intent.action = IntentAction.upTtsSpeechRate context.startService(intent) } } @@ -90,7 +90,7 @@ object ReadAloud { fun setTimer(context: Context, minute: Int) { if (BaseReadAloudService.isRun) { val intent = Intent(context, aloudClass) - intent.action = Action.setTimer + intent.action = IntentAction.setTimer intent.putExtra("minute", minute) context.startService(intent) } diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index a348b6e1e..dffd6a50f 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -14,7 +14,7 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions import io.legado.app.R import io.legado.app.base.VMBaseActivity -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.Status import io.legado.app.constant.Theme import io.legado.app.data.entities.Book @@ -193,12 +193,12 @@ class AudioPlayActivity : } override fun observeLiveBus() { - observeEvent(Bus.MEDIA_BUTTON) { + observeEvent(EventBus.MEDIA_BUTTON) { if (it) { playButton() } } - observeEventSticky(Bus.AUDIO_STATE) { + observeEventSticky(EventBus.AUDIO_STATE) { AudioPlay.status = it if (it == Status.PLAY) { fab_play_stop.setImageResource(R.drawable.ic_pause_24dp) @@ -206,19 +206,19 @@ class AudioPlayActivity : fab_play_stop.setImageResource(R.drawable.ic_play_24dp) } } - observeEventSticky(Bus.AUDIO_SUB_TITLE) { + observeEventSticky(EventBus.AUDIO_SUB_TITLE) { tv_sub_title.text = it } - observeEventSticky(Bus.AUDIO_SIZE) { + observeEventSticky(EventBus.AUDIO_SIZE) { player_progress.max = it tv_all_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") } - observeEventSticky(Bus.AUDIO_PROGRESS) { + observeEventSticky(EventBus.AUDIO_PROGRESS) { AudioPlay.durPageIndex = it if (!adjustProgress) player_progress.progress = it tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") } - observeEventSticky(Bus.AUDIO_SPEED) { + observeEventSticky(EventBus.AUDIO_SPEED) { tv_speed.text = String.format("%.1fX", it) tv_speed.visible() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 60057a622..e35a50a9e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -21,7 +21,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.constant.Status import io.legado.app.data.entities.Book @@ -498,12 +498,12 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo when (dialogId) { TEXT_COLOR -> { setTextColor(color) - postEvent(Bus.UP_CONFIG, false) + postEvent(EventBus.UP_CONFIG, false) } BG_COLOR -> { setBg(0, "#${color.hexString}") ReadBookConfig.upBg() - postEvent(Bus.UP_CONFIG, false) + postEvent(EventBus.UP_CONFIG, false) } } } @@ -550,7 +550,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun observeLiveBus() { super.observeLiveBus() - observeEvent(Bus.ALOUD_STATE) { + observeEvent(EventBus.ALOUD_STATE) { if (it == Status.STOP || it == Status.PAUSE) { ReadBook.curTextChapter?.let { textChapter -> val page = textChapter.page(ReadBook.durPageIndex) @@ -561,20 +561,20 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } } - observeEvent(Bus.TIME_CHANGED) { page_view.upTime() } - observeEvent(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } - observeEvent(Bus.OPEN_CHAPTER) { + observeEvent(EventBus.TIME_CHANGED) { page_view.upTime() } + observeEvent(EventBus.BATTERY_CHANGED) { page_view.upBattery(it) } + observeEvent(EventBus.OPEN_CHAPTER) { viewModel.openChapter(it.index, ReadBook.durPageIndex) page_view.upContent() } - observeEvent(Bus.MEDIA_BUTTON) { + observeEvent(EventBus.MEDIA_BUTTON) { if (it) { onClickReadAloud() } else { ReadBook.readAloud(!BaseReadAloudService.pause) } } - observeEvent(Bus.UP_CONFIG) { + observeEvent(EventBus.UP_CONFIG) { upSystemUiVisibility() content_view.upStyle() page_view.upBg() @@ -585,7 +585,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo page_view.upContent() } } - observeEventSticky(Bus.TTS_START) { chapterStart -> + observeEventSticky(EventBus.TTS_START) { chapterStart -> launch(IO) { if (BaseReadAloudService.isPlay()) { ReadBook.curTextChapter?.let { @@ -598,7 +598,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } } - observeEvent(Bus.REPLACE) { + observeEvent(EventBus.REPLACE) { ReplaceEditDialog().show(supportFragmentManager, "replaceEditDialog") } observeEvent(PreferKey.keepLight) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 5d61aefe1..289658f80 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -20,7 +20,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialog import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.help.permission.Permissions @@ -154,7 +154,7 @@ class BgTextConfigDialog : DialogFragment() { this.onClick { ReadBookConfig.getConfig().setBg(1, item) ReadBookConfig.upBg() - postEvent(Bus.UP_CONFIG, false) + postEvent(EventBus.UP_CONFIG, false) } } } @@ -178,7 +178,7 @@ class BgTextConfigDialog : DialogFragment() { file.writeBytes(it) ReadBookConfig.getConfig().setBg(2, file.absolutePath) ReadBookConfig.upBg() - postEvent(Bus.UP_CONFIG, false) + postEvent(EventBus.UP_CONFIG, false) } } } else { @@ -192,7 +192,7 @@ class BgTextConfigDialog : DialogFragment() { FileUtils.getPath(requireContext(), uri)?.let { path -> ReadBookConfig.getConfig().setBg(2, path) ReadBookConfig.upBg() - postEvent(Bus.UP_CONFIG, false) + postEvent(EventBus.UP_CONFIG, false) } } .request() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index e18f32c0b..ecb7df170 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -12,7 +12,7 @@ import androidx.fragment.app.DialogFragment import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.read.Help @@ -92,8 +92,8 @@ class MoreConfigDialog : DialogFragment() { key: String? ) { when (key) { - PreferKey.hideStatusBar -> postEvent(Bus.UP_CONFIG, true) - PreferKey.hideNavigationBar -> postEvent(Bus.UP_CONFIG, true) + PreferKey.hideStatusBar -> postEvent(EventBus.UP_CONFIG, true) + PreferKey.hideNavigationBar -> postEvent(EventBus.UP_CONFIG, true) PreferKey.keepLight -> postEvent(PreferKey.keepLight, true) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index 19ce7e100..c1a9e5e8f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -8,7 +8,7 @@ import android.view.ViewGroup import android.widget.SeekBar import androidx.fragment.app.DialogFragment import io.legado.app.R -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.Help import io.legado.app.utils.postEvent @@ -61,35 +61,35 @@ class PaddingConfigDialog : DialogFragment() { private fun initView() = with(ReadBookConfig.getConfig()) { iv_padding_top_add.onClick { seek_padding_top.progressAdd(1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_padding_top_remove.onClick { seek_padding_top.progressAdd(-1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_padding_bottom_add.onClick { seek_padding_bottom.progressAdd(1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_padding_bottom_remove.onClick { seek_padding_bottom.progressAdd(-1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_padding_left_add.onClick { seek_padding_left.progressAdd(1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_padding_left_remove.onClick { seek_padding_left.progressAdd(-1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_padding_right_add.onClick { seek_padding_right.progressAdd(1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_padding_right_remove.onClick { seek_padding_right.progressAdd(-1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } seek_padding_top.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { @@ -101,7 +101,7 @@ class PaddingConfigDialog : DialogFragment() { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } }) seek_padding_bottom.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { @@ -113,7 +113,7 @@ class PaddingConfigDialog : DialogFragment() { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } }) seek_padding_left.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { @@ -125,7 +125,7 @@ class PaddingConfigDialog : DialogFragment() { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } }) seek_padding_right.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { @@ -137,7 +137,7 @@ class PaddingConfigDialog : DialogFragment() { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } }) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 14f5c0b9b..0cc2a1336 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -12,7 +12,7 @@ import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService @@ -89,7 +89,7 @@ class ReadAloudConfigDialog : DialogFragment() { when (key) { PreferKey.readAloudByPage -> { if (BaseReadAloudService.isRun) { - postEvent(Bus.MEDIA_BUTTON, false) + postEvent(EventBus.MEDIA_BUTTON, false) } } PreferKey.readAloudOnLine -> { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index f464d99b2..deeef204b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -9,7 +9,7 @@ import android.view.ViewGroup import android.widget.SeekBar import androidx.fragment.app.DialogFragment import io.legado.app.R -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook @@ -57,8 +57,8 @@ class ReadAloudDialog : DialogFragment() { } private fun initData() { - observeEvent(Bus.ALOUD_STATE) { upPlayState() } - observeEvent(Bus.TTS_DS) { seek_timer.progress = it } + observeEvent(EventBus.ALOUD_STATE) { upPlayState() } + observeEvent(EventBus.TTS_DS) { seek_timer.progress = it } upPlayState() seek_timer.progress = BaseReadAloudService.timeMinute tv_timer.text = diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 8a1327a85..10d3d3433 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -10,7 +10,7 @@ import android.widget.SeekBar import androidx.core.view.get import androidx.fragment.app.DialogFragment import io.legado.app.R -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig @@ -83,7 +83,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { textBold = !textBold tv_text_bold.isSelected = textBold } - postEvent(Bus.UP_CONFIG, false) + postEvent(EventBus.UP_CONFIG, false) } tv_text_font.onClick { FontSelectDialog().show(childFragmentManager, "fontSelectDialog") @@ -94,7 +94,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { items = resources.getStringArray(R.array.indent).toList() ) { _, index -> putPrefInt("textIndent", index) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } } tv_padding.onClick { @@ -112,16 +112,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } }) iv_text_size_add.onClick { seek_text_size.progressAdd(1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_text_size_remove.onClick { seek_text_size.progressAdd(-1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } seek_text_letter_spacing.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { @@ -134,16 +134,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } }) iv_text_letter_spacing_add.onClick { seek_text_letter_spacing.progressAdd(1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_text_letter_spacing_remove.onClick { seek_text_letter_spacing.progressAdd(-1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } seek_line_size.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { @@ -156,16 +156,16 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } }) iv_line_size_add.onClick { seek_line_size.progressAdd(1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } iv_line_size_remove.onClick { seek_line_size.progressAdd(-1) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } rg_page_anim.onCheckedChange { _, checkedId -> for (i in 0 until rg_page_anim.childCount) { @@ -197,7 +197,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { ReadBookConfig.upBg() upStyle() upBg() - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } } @@ -266,6 +266,6 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { override fun selectFile(path: String) { requireContext().putPrefString(PreferKey.readBookFont, path) - postEvent(Bus.UP_CONFIG, true) + postEvent(EventBus.UP_CONFIG, true) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt index cfce5f27b..f274b2744 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentSelectActionCallback.kt @@ -6,7 +6,7 @@ import android.view.MenuItem import android.widget.TextView import io.legado.app.R -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.utils.postEvent class ContentSelectActionCallback(private val textView: TextView) : ActionMode.Callback { @@ -15,7 +15,7 @@ class ContentSelectActionCallback(private val textView: TextView) : ActionMode.C when (item?.itemId) { R.id.menu_replace -> { val text = textView.text.substring(textView.selectionStart, textView.selectionEnd) - postEvent(Bus.REPLACE, text) + postEvent(EventBus.REPLACE, text) mode?.finish() return true } diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index ccfc88116..8f3a7e244 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -12,7 +12,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp @@ -90,7 +90,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), PreferKey.processText -> sharedPreferences?.let { setProcessTextEnable(it.getBoolean("process_text", true)) } - PreferKey.showRss -> postEvent(Bus.SHOW_RSS, "unused") + PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "unused") } } diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 2ee2f6621..856e6cbb3 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -9,7 +9,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton @@ -180,7 +180,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar } private fun recreateActivities() { - postEvent(Bus.RECREATE, "") + postEvent(EventBus.RECREATE, "") Handler().postDelayed({ activity?.recreate() }, 100L) } diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt index a2ff5d99e..dfa5f5b3d 100644 --- a/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt @@ -9,7 +9,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseActivity -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.data.entities.Book import io.legado.app.service.help.Download import io.legado.app.utils.applyTint @@ -67,7 +67,7 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) { } override fun observeLiveBus() { - observeEvent(Bus.UP_DOWNLOAD) { + observeEvent(EventBus.UP_DOWNLOAD) { if (it) { menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp) menu?.applyTint(this) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 5d9fee452..9fda82311 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -14,7 +14,7 @@ import io.legado.app.App import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine @@ -144,10 +144,10 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } override fun observeLiveBus() { - observeEvent(Bus.RECREATE) { + observeEvent(EventBus.RECREATE) { recreate() } - observeEvent(Bus.SHOW_RSS) { + observeEvent(EventBus.SHOW_RSS) { bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS upFragmentList() view_pager_main.adapter?.notifyDataSetChanged() diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 960f860c1..6af83db54 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -3,7 +3,7 @@ package io.legado.app.ui.main import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.data.entities.RssSource import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Restore @@ -24,14 +24,14 @@ class MainViewModel(application: Application) : BaseViewModel(application) { App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> synchronized(this) { updateList.add(book.bookUrl) - postEvent(Bus.UP_BOOK, book.bookUrl) + postEvent(EventBus.UP_BOOK, book.bookUrl) } WebBook(bookSource).getChapterList(book) .timeout(300000) .onSuccess(IO) { synchronized(this) { updateList.remove(book.bookUrl) - postEvent(Bus.UP_BOOK, book.bookUrl) + postEvent(EventBus.UP_BOOK, book.bookUrl) } it?.let { App.db.bookDao().update(book) @@ -42,7 +42,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) { .onError { synchronized(this) { updateList.remove(book.bookUrl) - postEvent(Bus.UP_BOOK, book.bookUrl) + postEvent(EventBus.UP_BOOK, book.bookUrl) } it.printStackTrace() } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 237e73567..a5fbb8bd5 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -14,7 +14,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.constant.AppConst -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup import io.legado.app.lib.dialogs.* @@ -87,7 +87,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b TabLayoutMediator(tab_layout, view_pager_bookshelf) { tab, position -> tab.text = bookGroups[position].groupName }.attach() - observeEvent(Bus.UP_TABS) { + observeEvent(EventBus.UP_TABS) { tab_layout.getTabAt(it)?.select() } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 2b92d361b..d7ffd7a34 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -11,7 +11,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.constant.BookType -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.help.IntentDataHelp @@ -56,7 +56,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), } initRecyclerView() upRecyclerData() - observeEvent(Bus.UP_BOOK) { + observeEvent(EventBus.UP_BOOK) { booksAdapter.notification(it) } } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 2c515dbb7..035ca4d26 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -14,7 +14,7 @@ import androidx.preference.PreferenceFragmentCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment -import io.legado.app.constant.Bus +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.BookHelp import io.legado.app.help.permission.Permissions @@ -182,7 +182,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { } addPreferencesFromResource(R.xml.pref_main) val webServicePre = findPreference(PreferKey.webService) - observeEvent(Bus.WEB_SERVICE_STOP) { + observeEvent(EventBus.WEB_SERVICE_STOP) { webServicePre?.isChecked = false } } From 5999e210433ff9b88d6038371e986546024ed85e Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 18:41:54 +0800 Subject: [PATCH 378/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/service/CheckSourceService.kt | 38 ++++++------------- .../io/legado/app/service/help/CheckSource.kt | 24 ++++++++++++ .../book/source/manage/BookSourceActivity.kt | 6 +-- 3 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/io/legado/app/service/help/CheckSource.kt diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 6507cb219..549d7fee2 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -1,13 +1,11 @@ package io.legado.app.service -import android.content.Context import android.content.Intent import androidx.core.app.NotificationCompat import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.IntentAction import io.legado.app.constant.AppConst -import io.legado.app.data.entities.BookSource +import io.legado.app.constant.IntentAction import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.ui.book.source.manage.BookSourceActivity @@ -15,27 +13,10 @@ import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors class CheckSourceService : BaseService() { - - companion object{ - fun start(context: Context, selectedIds: Array) { - Intent(context, CheckSourceService::class.java).let { - it.action = IntentAction.start - it.putExtra("selectIds", selectedIds) - context.startService(it) - } - } - - fun stop(context: Context) { - Intent(context, CheckSourceService::class.java).let { - it.action = IntentAction.stop - context.startService(it) - } - } - } - private var searchPool = Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() - private var sourceList: List? = null + private val allIds = LinkedHashSet() + private val unCheckIds = LinkedHashSet() override fun onCreate() { super.onCreate() @@ -44,7 +25,8 @@ class CheckSourceService : BaseService() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { when (intent?.action) { - IntentAction.start -> { + IntentAction.start -> intent.getStringArrayListExtra("selectIds")?.let { + check(it) } else -> stopSelf() } @@ -56,6 +38,12 @@ class CheckSourceService : BaseService() { searchPool.close() } + private fun check(ids: List) { + allIds.addAll(ids) + unCheckIds.addAll(ids) + + } + /** * 更新通知 */ @@ -73,9 +61,7 @@ class CheckSourceService : BaseService() { getString(R.string.cancel), IntentHelp.servicePendingIntent(this, IntentAction.stop) ) - sourceList?.let { - builder.setProgress(it.size, state, false) - } + builder.setProgress(allIds.size, state, false) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) val notification = builder.build() startForeground(112202, notification) diff --git a/app/src/main/java/io/legado/app/service/help/CheckSource.kt b/app/src/main/java/io/legado/app/service/help/CheckSource.kt new file mode 100644 index 000000000..47aa593f9 --- /dev/null +++ b/app/src/main/java/io/legado/app/service/help/CheckSource.kt @@ -0,0 +1,24 @@ +package io.legado.app.service.help + +import android.content.Context +import android.content.Intent +import io.legado.app.constant.IntentAction +import io.legado.app.service.CheckSourceService + +object CheckSource { + + fun start(context: Context, selectedIds: ArrayList) { + Intent(context, CheckSourceService::class.java).let { + it.action = IntentAction.start + it.putExtra("selectIds", selectedIds) + context.startService(it) + } + } + + fun stop(context: Context) { + Intent(context, CheckSourceService::class.java).let { + it.action = IntentAction.stop + context.startService(it) + } + } +} \ No newline at end of file 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 52b433a32..82d823a0a 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 @@ -30,7 +30,7 @@ import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView -import io.legado.app.service.CheckSourceService +import io.legado.app.service.help.CheckSource import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.qrcode.QrCodeActivity @@ -40,7 +40,6 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult -import org.jetbrains.anko.startService import org.jetbrains.anko.toast import java.io.FileNotFoundException @@ -94,8 +93,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelectionIds()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) - R.id.menu_check_source -> - startService(Pair("data", adapter.getSelectionIds())) + R.id.menu_check_source -> CheckSource.start(this, ArrayList(adapter.getSelectionIds())) R.id.menu_import_source_onLine -> showImportDialog() } if (item.groupId == R.id.source_group) { From a286831fd17736839d489769fe0049c5fb353113 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 19:58:15 +0800 Subject: [PATCH 379/852] =?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/base/BaseService.kt | 12 ++++++- .../io/legado/app/data/entities/BookSource.kt | 10 ++++++ .../legado/app/service/CheckSourceService.kt | 31 +++++++++++++++++++ .../io/legado/app/service/help/CheckSource.kt | 5 +++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/base/BaseService.kt b/app/src/main/java/io/legado/app/base/BaseService.kt index c67acb95c..163ac09ec 100644 --- a/app/src/main/java/io/legado/app/base/BaseService.kt +++ b/app/src/main/java/io/legado/app/base/BaseService.kt @@ -3,17 +3,27 @@ package io.legado.app.base import android.app.Service import android.content.Intent import android.os.IBinder +import io.legado.app.help.coroutine.Coroutine import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.MainScope import kotlinx.coroutines.cancel +import kotlin.coroutines.CoroutineContext abstract class BaseService : Service(), CoroutineScope by MainScope() { + fun execute( + scope: CoroutineScope = this, + context: CoroutineContext = Dispatchers.IO, + block: suspend CoroutineScope.() -> T + ): Coroutine { + return Coroutine.async(scope, context) { block() } + } + override fun onBind(intent: Intent?): IBinder? { return null } - override fun onDestroy() { super.onDestroy() cancel() diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 39b569565..bab3a7b5e 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -126,6 +126,16 @@ data class BookSource( return contentRuleV!! } + fun addGroup(group: String) { + bookSourceGroup?.let { + if (!it.contains(group)) { + bookSourceGroup = "$it;$group" + } + } ?: let { + bookSourceGroup = group + } + } + fun getExploreKinds(): ArrayList? { val exploreKinds = arrayListOf() exploreUrl?.let { diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 549d7fee2..bf4a268a8 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -2,19 +2,24 @@ package io.legado.app.service import android.content.Intent import androidx.core.app.NotificationCompat +import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.AppConst import io.legado.app.constant.IntentAction import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp +import io.legado.app.help.coroutine.Coroutine +import io.legado.app.model.WebBook import io.legado.app.ui.book.source.manage.BookSourceActivity +import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.Executors class CheckSourceService : BaseService() { private var searchPool = Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() + private var task: Coroutine<*>? = null private val allIds = LinkedHashSet() private val unCheckIds = LinkedHashSet() @@ -35,13 +40,39 @@ class CheckSourceService : BaseService() { override fun onDestroy() { super.onDestroy() + task?.cancel() searchPool.close() } private fun check(ids: List) { + task?.cancel() + allIds.clear() + unCheckIds.clear() allIds.addAll(ids) unCheckIds.addAll(ids) + task = execute { + unCheckIds.forEach { sourceUrl -> + App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> + val webBook = WebBook(source) + webBook.searchBook("我的", scope = this, context = searchPool) + .onError(IO) { + source.addGroup("失效") + App.db.bookSourceDao().update(source) + }.onFinally { + unCheckIds.remove(sourceUrl) + val checkedCount = allIds.size - unCheckIds.size + updateNotification( + checkedCount, + getString(R.string.progress_show, checkedCount, unCheckIds.size) + ) + } + } + } + } + task?.invokeOnCompletion { + stopSelf() + } } /** diff --git a/app/src/main/java/io/legado/app/service/help/CheckSource.kt b/app/src/main/java/io/legado/app/service/help/CheckSource.kt index 47aa593f9..11e140b10 100644 --- a/app/src/main/java/io/legado/app/service/help/CheckSource.kt +++ b/app/src/main/java/io/legado/app/service/help/CheckSource.kt @@ -2,12 +2,17 @@ package io.legado.app.service.help import android.content.Context import android.content.Intent +import io.legado.app.R import io.legado.app.constant.IntentAction import io.legado.app.service.CheckSourceService +import org.jetbrains.anko.toast object CheckSource { fun start(context: Context, selectedIds: ArrayList) { + if (selectedIds.isEmpty()) { + context.toast(R.string.non_select) + } Intent(context, CheckSourceService::class.java).let { it.action = IntentAction.start it.putExtra("selectIds", selectedIds) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b283bb42..ee33406df 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -252,6 +252,7 @@ 文字颜色和背景(长按自定义) 沉浸式状态栏 还剩%d章未下载 + 没有选择 长按输入颜色值 加载中… 追更区 From 3a2fe8f8e4a614f8c82ffa99202e0e51a5f872d4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 20:05:19 +0800 Subject: [PATCH 380/852] =?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/service/CheckSourceService.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index bf4a268a8..19d19ca0f 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -20,7 +20,7 @@ class CheckSourceService : BaseService() { private var searchPool = Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() private var task: Coroutine<*>? = null - private val allIds = LinkedHashSet() + private var idsCount = 0 private val unCheckIds = LinkedHashSet() override fun onCreate() { @@ -46,9 +46,8 @@ class CheckSourceService : BaseService() { private fun check(ids: List) { task?.cancel() - allIds.clear() unCheckIds.clear() - allIds.addAll(ids) + idsCount = ids.size unCheckIds.addAll(ids) task = execute { unCheckIds.forEach { sourceUrl -> @@ -60,10 +59,10 @@ class CheckSourceService : BaseService() { App.db.bookSourceDao().update(source) }.onFinally { unCheckIds.remove(sourceUrl) - val checkedCount = allIds.size - unCheckIds.size + val checkedCount = idsCount - unCheckIds.size updateNotification( checkedCount, - getString(R.string.progress_show, checkedCount, unCheckIds.size) + getString(R.string.progress_show, checkedCount, idsCount) ) } } @@ -92,7 +91,7 @@ class CheckSourceService : BaseService() { getString(R.string.cancel), IntentHelp.servicePendingIntent(this, IntentAction.stop) ) - builder.setProgress(allIds.size, state, false) + builder.setProgress(idsCount, state, false) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) val notification = builder.build() startForeground(112202, notification) From 4a79d959b05917ce8e08e40f64366a06732dc38a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 20:11:25 +0800 Subject: [PATCH 381/852] =?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/service/help/CheckSource.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/service/help/CheckSource.kt b/app/src/main/java/io/legado/app/service/help/CheckSource.kt index 11e140b10..057813337 100644 --- a/app/src/main/java/io/legado/app/service/help/CheckSource.kt +++ b/app/src/main/java/io/legado/app/service/help/CheckSource.kt @@ -12,6 +12,7 @@ object CheckSource { fun start(context: Context, selectedIds: ArrayList) { if (selectedIds.isEmpty()) { context.toast(R.string.non_select) + return } Intent(context, CheckSourceService::class.java).let { it.action = IntentAction.start From 83f3e0e0511b8914d08cfdb32f55222b0d08838d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 20:30:02 +0800 Subject: [PATCH 382/852] =?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/service/CheckSourceService.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 19d19ca0f..9d7d9dcc5 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -49,6 +49,7 @@ class CheckSourceService : BaseService() { unCheckIds.clear() idsCount = ids.size unCheckIds.addAll(ids) + updateNotification(0, getString(R.string.start)) task = execute { unCheckIds.forEach { sourceUrl -> App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> From baa8b952006a8df6a773db661e6309b93daefed9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 20:30:55 +0800 Subject: [PATCH 383/852] =?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/service/CheckSourceService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 9d7d9dcc5..18f704a6e 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -49,7 +49,7 @@ class CheckSourceService : BaseService() { unCheckIds.clear() idsCount = ids.size unCheckIds.addAll(ids) - updateNotification(0, getString(R.string.start)) + updateNotification(0, getString(R.string.progress_show, 0, idsCount)) task = execute { unCheckIds.forEach { sourceUrl -> App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> From db4f300064f287ad3e301d8b6b9fd5c1c251a81d Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 20:59:59 +0800 Subject: [PATCH 384/852] =?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/AndroidManifest.xml | 1 + app/src/main/java/io/legado/app/ui/README.md | 1 + .../ui/book/arrange/ArrangeBookActivity.kt | 23 +++++++++++++++++++ .../ui/book/arrange/ArrangeBookViewModel.kt | 9 ++++++++ .../main/res/layout/activity_arrange_book.xml | 7 ++++++ 5 files changed, 41 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt create mode 100644 app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt create mode 100644 app/src/main/res/layout/activity_arrange_book.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4be71d133..0f1381bf6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -78,6 +78,7 @@ + diff --git a/app/src/main/java/io/legado/app/ui/README.md b/app/src/main/java/io/legado/app/ui/README.md index 9809241ec..a8bf2b216 100644 --- a/app/src/main/java/io/legado/app/ui/README.md +++ b/app/src/main/java/io/legado/app/ui/README.md @@ -2,6 +2,7 @@ * about 关于界面 * audio 音频播放界面 +* book\arrange 书架整理界面 * book\info 书籍信息查看 * book\read 书籍阅读界面 * book\search 搜索书籍界面 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 new file mode 100644 index 000000000..1e5cedde4 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -0,0 +1,23 @@ +package io.legado.app.ui.book.arrange + +import android.os.Bundle +import androidx.lifecycle.LiveData +import io.legado.app.R +import io.legado.app.base.VMBaseActivity +import io.legado.app.data.entities.Book +import io.legado.app.utils.getViewModel + + +class ArrangeBookActivity : VMBaseActivity(R.layout.activity_arrange_book) { + override val viewModel: ArrangeBookViewModel + get() = getViewModel(ArrangeBookViewModel::class.java) + + private var booksLiveData: LiveData? = null + + override fun onActivityCreated(savedInstanceState: Bundle?) { + + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt new file mode 100644 index 000000000..a6fa9463f --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt @@ -0,0 +1,9 @@ +package io.legado.app.ui.book.arrange + +import android.app.Application +import io.legado.app.base.BaseViewModel + + +class ArrangeBookViewModel(application: Application) : BaseViewModel(application) { + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml new file mode 100644 index 000000000..d829e291c --- /dev/null +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file From 1aac80df4e107f15baa1067f97ebbd6e458b94f6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 21:03:12 +0800 Subject: [PATCH 385/852] =?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/ui/book/arrange/ArrangeBookAdapter.kt | 18 ++++++++++++++++++ app/src/main/res/layout/item_arrange_book.xml | 7 +++++++ 2 files changed, 25 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt create mode 100644 app/src/main/res/layout/item_arrange_book.xml 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 new file mode 100644 index 000000000..91fb157e1 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -0,0 +1,18 @@ +package io.legado.app.ui.book.arrange + +import android.content.Context +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.Book + + +class ArrangeBookAdapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_arrange_book) { + + + override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { + + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/item_arrange_book.xml b/app/src/main/res/layout/item_arrange_book.xml new file mode 100644 index 000000000..d829e291c --- /dev/null +++ b/app/src/main/res/layout/item_arrange_book.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file From b82e65b5618489e11838bf86f7be44102e1895d7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 21:46:56 +0800 Subject: [PATCH 386/852] =?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/arrange/ArrangeBookActivity.kt | 25 ++++++++++++++++--- .../ui/main/bookshelf/BookshelfFragment.kt | 4 +-- .../main/res/layout/activity_arrange_book.xml | 18 +++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) 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 1e5cedde4..ce614f24d 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 @@ -2,22 +2,41 @@ package io.legado.app.ui.book.arrange import android.os.Bundle import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book +import io.legado.app.lib.theme.ATH import io.legado.app.utils.getViewModel +import kotlinx.android.synthetic.main.activity_arrange_book.* class ArrangeBookActivity : VMBaseActivity(R.layout.activity_arrange_book) { override val viewModel: ArrangeBookViewModel get() = getViewModel(ArrangeBookViewModel::class.java) - - private var booksLiveData: LiveData? = null + private lateinit var adapter: ArrangeBookAdapter + private var booksLiveData: LiveData>? = null override fun onActivityCreated(savedInstanceState: Bundle?) { + initView() + initData() + } - + private fun initView() { + ATH.applyEdgeEffectColor(recycler_view) + recycler_view.layoutManager = LinearLayoutManager(this) + adapter = ArrangeBookAdapter(this) + recycler_view.adapter = adapter } + private fun initData() { + booksLiveData?.removeObservers(this) + booksLiveData = App.db.bookDao().observeAll() + booksLiveData?.observe(this, Observer { + + }) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index a5fbb8bd5..e3c68dcaa 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -21,6 +21,7 @@ import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView +import io.legado.app.ui.book.arrange.ArrangeBookActivity import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.download.DownloadActivity import io.legado.app.ui.importbook.ImportBookActivity @@ -64,8 +65,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b .show(childFragmentManager, "groupManageDialog") R.id.menu_add_local -> startActivity() R.id.menu_add_url -> addBookByUrl() - R.id.menu_arrange_bookshelf -> { - } + R.id.menu_arrange_bookshelf -> startActivity() R.id.menu_download -> startActivity() } } diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index d829e291c..fb728237a 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -1,7 +1,25 @@ + + + + + + + + \ No newline at end of file From e3ff04ed62652740bee56d64f63ff1d62550c3e0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 22:09:18 +0800 Subject: [PATCH 387/852] =?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/res/menu/arrange_book.xml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/src/main/res/menu/arrange_book.xml diff --git a/app/src/main/res/menu/arrange_book.xml b/app/src/main/res/menu/arrange_book.xml new file mode 100644 index 000000000..0b47d59ef --- /dev/null +++ b/app/src/main/res/menu/arrange_book.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file From 940a012fb472e85ad6045a21a3cc54e01adf08ce Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 22:27:44 +0800 Subject: [PATCH 388/852] =?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/arrange/ArrangeBookActivity.kt | 14 +++++++ .../main/res/layout/activity_arrange_book.xml | 41 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 53 insertions(+), 3 deletions(-) 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 ce614f24d..17a555863 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 @@ -1,6 +1,8 @@ package io.legado.app.ui.book.arrange import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager @@ -24,6 +26,18 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi initData() } + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.arrange_book, menu) + return super.onCompatCreateOptionsMenu(menu) + } + + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + + } + return super.onCompatOptionsItemSelected(item) + } + private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index fb728237a..40b9ce904 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -1,6 +1,7 @@ @@ -16,10 +17,44 @@ android:layout_height="0dp" android:layout_weight="1" /> - + + android:layout_height="50dp" + android:background="@color/background" + android:gravity="center_vertical" + android:padding="10dp" + android:elevation="2dp" + tools:ignore="RtlHardcoded,RtlSymmetry"> + - + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ee33406df..909c9cae5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -541,6 +541,7 @@ 分组管理 分组选择 编辑分组 + 移入分组 添加分组 新建替换 分组 From 15cc07e7bef19132585953ae49f6179c754e0d38 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 22:32:54 +0800 Subject: [PATCH 389/852] =?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/config/BackupConfigFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 2f153da3f..d10385945 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -129,6 +129,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(), if (doc?.canWrite() == true) { launch { Backup.backup(requireContext(), uri) + toast(R.string.backup_success) } } else { selectBackupFolder() From 3951bf01d1732b5a7f5f5d3a5f3c71996d27fd02 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 22:42:02 +0800 Subject: [PATCH 390/852] =?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/constant/PreferKey.kt | 3 + .../io/legado/app/help/storage/WebDavHelp.kt | 7 ++- .../app/ui/config/BackupConfigFragment.kt | 55 ++++++++++--------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 1bfd5b634..f6a1b33ef 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -26,4 +26,7 @@ object PreferKey { const val threadCount = "threadCount" const val keepLight = "keep_light" const val webService = "webService" + const val webDavUrl = "web_dav_url" + const val webDavAccount = "web_dav_account" + const val webDavPassword = "web_dav_password" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index abd7a8a8a..7612a6913 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -2,6 +2,7 @@ package io.legado.app.help.storage import android.content.Context import io.legado.app.App +import io.legado.app.constant.PreferKey import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth @@ -23,15 +24,15 @@ object WebDavHelp { } private fun getWebDavUrl(): String? { - var url = App.INSTANCE.getPrefString("web_dav_url") + var url = App.INSTANCE.getPrefString(PreferKey.webDavUrl) if (url.isNullOrBlank()) return null if (!url.endsWith("/")) url += "/" return url } private fun initWebDav(): Boolean { - val account = App.INSTANCE.getPrefString("web_dav_account") - val password = App.INSTANCE.getPrefString("web_dav_password") + val account = App.INSTANCE.getPrefString(PreferKey.webDavAccount) + val password = App.INSTANCE.getPrefString(PreferKey.webDavPassword) if (!account.isNullOrBlank() && !password.isNullOrBlank()) { HttpAuth.auth = HttpAuth.Auth(account, password) return true diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index d10385945..e27f82e11 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -51,19 +51,19 @@ class BackupConfigFragment : PreferenceFragmentCompat(), } } addPreferencesFromResource(R.xml.pref_config_backup) - findPreference("web_dav_url")?.let { + findPreference(PreferKey.webDavUrl)?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) } bindPreferenceSummaryToValue(it) } - findPreference("web_dav_account")?.let { + findPreference(PreferKey.webDavAccount)?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) } bindPreferenceSummaryToValue(it) } - findPreference("web_dav_password")?.let { + findPreference(PreferKey.webDavPassword)?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) editText.inputType = @@ -85,28 +85,33 @@ class BackupConfigFragment : PreferenceFragmentCompat(), } override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { - when { - preference?.key == "web_dav_password" -> if (newValue == null) { - preference.summary = getString(R.string.web_dav_pw_s) - } else { - preference.summary = "*".repeat(newValue.toString().length) - } - preference?.key == "web_dav_url" -> if (newValue == null) { - preference.summary = getString(R.string.web_dav_url_s) - } else { - preference.summary = newValue.toString() - } - preference?.key == "web_dav_account" -> if (newValue == null) { - preference.summary = getString(R.string.web_dav_account_s) - } else { - preference.summary = newValue.toString() - } - preference is ListPreference -> { - val index = preference.findIndexOfValue(newValue?.toString()) - // Set the summary to reflect the new value. - preference.setSummary(if (index >= 0) preference.entries[index] else null) - } - else -> preference?.summary = newValue?.toString() + when (preference?.key) { + PreferKey.webDavUrl -> + if (newValue == null) { + preference.summary = getString(R.string.web_dav_url_s) + } else { + preference.summary = newValue.toString() + } + PreferKey.webDavAccount -> + if (newValue == null) { + preference.summary = getString(R.string.web_dav_account_s) + } else { + preference.summary = newValue.toString() + } + PreferKey.webDavPassword -> + if (newValue == null) { + preference.summary = getString(R.string.web_dav_pw_s) + } else { + preference.summary = "*".repeat(newValue.toString().length) + } + else -> + if (preference is ListPreference) { + val index = preference.findIndexOfValue(newValue?.toString()) + // Set the summary to reflect the new value. + preference.setSummary(if (index >= 0) preference.entries[index] else null) + } else { + preference?.summary = newValue?.toString() + } } return false } From fd814edf0830193606e300140f1ead2055871a3f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 5 Feb 2020 22:47:14 +0800 Subject: [PATCH 391/852] =?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/config/BackupConfigFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index e27f82e11..38f5568fb 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -156,6 +156,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(), .onGranted { launch { Backup.backup(requireContext(), null) + toast(R.string.backup_success) } } .request() @@ -316,6 +317,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(), findPreference(PreferKey.backupPath)?.summary = uri.toString() launch { Backup.backup(requireContext(), uri) + toast(R.string.backup_success) } } } From 30be4ba3e036b6058557ba576dc3a1d904c9207b Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 10:07:22 +0800 Subject: [PATCH 392/852] =?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/constant/PreferKey.kt | 1 + app/src/main/java/io/legado/app/help/AppConfig.kt | 6 ++++++ .../java/io/legado/app/service/HttpReadAloudService.kt | 4 ++-- .../java/io/legado/app/service/TTSReadAloudService.kt | 4 ++-- .../app/ui/book/read/config/ReadAloudConfigDialog.kt | 4 +++- .../io/legado/app/ui/book/read/config/ReadAloudDialog.kt | 9 ++++++--- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index f6a1b33ef..ec5b3a4cd 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -10,6 +10,7 @@ object PreferKey { const val precisionSearch = "precisionSearch" const val readAloudOnLine = "readAloudOnLine" const val readAloudByPage = "readAloudByPage" + const val ttsSpeechRate = "ttsSpeechRate" const val ttsSpeechPer = "ttsSpeechPer" const val prevKey = "prevKeyCode" const val nextKey = "nextKeyCode" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 002fee5ff..84de0973c 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -50,6 +50,12 @@ object AppConfig { } } + var ttsSpeechRate: Int + get() = App.INSTANCE.getPrefInt(PreferKey.ttsSpeechRate, 5) + set(value) { + App.INSTANCE.putPrefInt(PreferKey.ttsSpeechRate, value) + } + val isEInkMode: Boolean get() = App.INSTANCE.getPrefBoolean("isEInkMode") diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 1cf40fc8c..00190d93b 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -4,12 +4,12 @@ import android.app.PendingIntent import android.media.MediaPlayer import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.api.HttpPostApi import io.legado.app.service.help.ReadBook import io.legado.app.utils.FileUtils -import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefString import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO @@ -112,7 +112,7 @@ class HttpReadAloudService : BaseReadAloudService(), private fun getAudioBody(content: String): Map { return mapOf( Pair("tex", encodeTwo(content)), - Pair("spd", ((getPrefInt("ttsSpeechRate", 25) + 5) / 5).toString()), + Pair("spd", ((AppConfig.ttsSpeechRate + 5) / 5).toString()), Pair("per", getPrefString(PreferKey.ttsSpeechPer) ?: "0"), Pair("cuid", "baidu_speech_demo"), Pair("idx", "1"), diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 4c5357ce6..1b1f40bcc 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -7,11 +7,11 @@ import android.speech.tts.UtteranceProgressListener import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus +import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.help.MediaHelp import io.legado.app.service.help.ReadBook import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getPrefInt import io.legado.app.utils.postEvent import kotlinx.coroutines.launch import org.jetbrains.anko.toast @@ -96,7 +96,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener textToSpeech = TextToSpeech(this, this) } } else { - textToSpeech?.setSpeechRate((this.getPrefInt("ttsSpeechRate", 5) + 5) / 10f) + textToSpeech?.setSpeechRate((AppConfig.ttsSpeechRate + 5) / 10f) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 0cc2a1336..7da1ac2e0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -96,7 +96,9 @@ class ReadAloudConfigDialog : DialogFragment() { ReadAloud.stop(requireContext()) ReadAloud.aloudClass = ReadAloud.getReadAloudClass() } - PreferKey.ttsSpeechPer -> ReadAloud.upTtsSpeechRate(requireContext()) + PreferKey.ttsSpeechPer -> { + ReadAloud.upTtsSpeechRate(requireContext()) + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index deeef204b..6040c0880 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -10,11 +10,14 @@ import android.widget.SeekBar import androidx.fragment.app.DialogFragment import io.legado.app.R import io.legado.app.constant.EventBus +import io.legado.app.help.AppConfig import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.Help -import io.legado.app.utils.* +import io.legado.app.utils.getPrefBoolean +import io.legado.app.utils.observeEvent +import io.legado.app.utils.putPrefBoolean import kotlinx.android.synthetic.main.dialog_read_aloud.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick @@ -65,7 +68,7 @@ class ReadAloudDialog : DialogFragment() { requireContext().getString(R.string.timer_m, BaseReadAloudService.timeMinute) cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true) seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked - seek_tts_SpeechRate.progress = requireContext().getPrefInt("ttsSpeechRate", 5) + seek_tts_SpeechRate.progress = AppConfig.ttsSpeechRate } private fun initOnChange() { @@ -83,7 +86,7 @@ class ReadAloudDialog : DialogFragment() { override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit override fun onStopTrackingTouch(seekBar: SeekBar?) { - requireContext().putPrefInt("ttsSpeechRate", seek_tts_SpeechRate.progress) + AppConfig.ttsSpeechRate = seek_tts_SpeechRate.progress upTtsSpeechRate() } }) From 84a042c54a667d9cc1bffc612e8aad27fae373d0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 10:20:40 +0800 Subject: [PATCH 393/852] =?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/service/HttpReadAloudService.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 00190d93b..1e91c3760 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -112,7 +112,7 @@ class HttpReadAloudService : BaseReadAloudService(), private fun getAudioBody(content: String): Map { return mapOf( Pair("tex", encodeTwo(content)), - Pair("spd", ((AppConfig.ttsSpeechRate + 5) / 5).toString()), + Pair("spd", ((AppConfig.ttsSpeechRate + 5) / 10 + 4).toString()), Pair("per", getPrefString(PreferKey.ttsSpeechPer) ?: "0"), Pair("cuid", "baidu_speech_demo"), Pair("idx", "1"), @@ -151,9 +151,6 @@ class HttpReadAloudService : BaseReadAloudService(), override fun upSpeechRate(reset: Boolean) { job?.cancel() mediaPlayer.reset() - for (i in 0 until nowSpeak) { - contentList.removeAt(0) - } nowSpeak = 0 playingIndex = -1 play() From d9d51ffd97e9eaad558b1ca47c05f246776df942 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 10:25:38 +0800 Subject: [PATCH 394/852] =?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/service/HttpReadAloudService.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 1e91c3760..dcb6b16e9 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -148,14 +148,21 @@ class HttpReadAloudService : BaseReadAloudService(), } } + /** + * 更新朗读速度 + */ override fun upSpeechRate(reset: Boolean) { job?.cancel() mediaPlayer.reset() nowSpeak = 0 playingIndex = -1 + readAloudNumber = 0 play() } + /** + * 上一段 + */ override fun prevP() { if (nowSpeak > 0) { mediaPlayer.stop() @@ -165,6 +172,9 @@ class HttpReadAloudService : BaseReadAloudService(), } } + /** + * 下一段 + */ override fun nextP() { if (nowSpeak < contentList.size - 1) { mediaPlayer.stop() From 3d187dfe3ca226582ddbbd0ee48200d6c456f326 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 10:35:43 +0800 Subject: [PATCH 395/852] =?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/service/HttpReadAloudService.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index dcb6b16e9..64b296d62 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -154,9 +154,7 @@ class HttpReadAloudService : BaseReadAloudService(), override fun upSpeechRate(reset: Boolean) { job?.cancel() mediaPlayer.reset() - nowSpeak = 0 - playingIndex = -1 - readAloudNumber = 0 + downloadAudio() play() } From e993d710f6eba7761b36570bb858bb2e4e04a7c8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 11:12:09 +0800 Subject: [PATCH 396/852] =?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/service/HttpReadAloudService.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 64b296d62..c65350739 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -10,6 +10,7 @@ import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.api.HttpPostApi import io.legado.app.service.help.ReadBook import io.legado.app.utils.FileUtils +import io.legado.app.utils.LogUtils import io.legado.app.utils.getPrefString import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO @@ -153,9 +154,10 @@ class HttpReadAloudService : BaseReadAloudService(), */ override fun upSpeechRate(reset: Boolean) { job?.cancel() - mediaPlayer.reset() + if (mediaPlayer.isPlaying) { + mediaPlayer.stop() + } downloadAudio() - play() } /** @@ -196,6 +198,10 @@ class HttpReadAloudService : BaseReadAloudService(), } override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { + LogUtils.d("mp", "what:$what extra:$extra") + if (what == -38 && extra == 0) { + return true + } handler.postDelayed({ readAloudNumber += contentList[nowSpeak].length + 1 if (nowSpeak < contentList.lastIndex) { From b2339ed0432e0bb459fac17b54839cbaef41df18 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 11:26:23 +0800 Subject: [PATCH 397/852] =?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/service/HttpReadAloudService.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index c65350739..014b1b778 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -94,11 +94,11 @@ class HttpReadAloudService : BaseReadAloudService(), @Synchronized private fun playAudio(fd: FileDescriptor) { if (playingIndex != nowSpeak && requestFocus()) { - playingIndex = nowSpeak try { mediaPlayer.reset() mediaPlayer.setDataSource(fd) mediaPlayer.prepareAsync() + playingIndex = nowSpeak postEvent(EventBus.TTS_START, readAloudNumber + 1) } catch (e: Exception) { e.printStackTrace() @@ -154,9 +154,8 @@ class HttpReadAloudService : BaseReadAloudService(), */ override fun upSpeechRate(reset: Boolean) { job?.cancel() - if (mediaPlayer.isPlaying) { - mediaPlayer.stop() - } + mediaPlayer.stop() + playingIndex = -1 downloadAudio() } From 3ac6d9807be454203e88b22cd8122654d3aa0ff4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 12:09:09 +0800 Subject: [PATCH 398/852] =?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/AppConfig.kt | 3 ++ .../app/service/HttpReadAloudService.kt | 4 +- .../book/read/config/ReadAloudConfigDialog.kt | 45 +++++++++---------- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_config_aloud.xml | 2 +- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 84de0973c..e1f80dfb5 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -56,6 +56,9 @@ object AppConfig { App.INSTANCE.putPrefInt(PreferKey.ttsSpeechRate, value) } + val ttsSpeechPer: String + get() = App.INSTANCE.getPrefString(PreferKey.ttsSpeechPer) ?: "0" + val isEInkMode: Boolean get() = App.INSTANCE.getPrefBoolean("isEInkMode") diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 014b1b778..798307652 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -3,7 +3,6 @@ package io.legado.app.service import android.app.PendingIntent import android.media.MediaPlayer import io.legado.app.constant.EventBus -import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.help.http.HttpHelper @@ -11,7 +10,6 @@ import io.legado.app.help.http.api.HttpPostApi import io.legado.app.service.help.ReadBook import io.legado.app.utils.FileUtils import io.legado.app.utils.LogUtils -import io.legado.app.utils.getPrefString import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Job @@ -114,7 +112,7 @@ class HttpReadAloudService : BaseReadAloudService(), return mapOf( Pair("tex", encodeTwo(content)), Pair("spd", ((AppConfig.ttsSpeechRate + 5) / 10 + 4).toString()), - Pair("per", getPrefString(PreferKey.ttsSpeechPer) ?: "0"), + Pair("per", AppConfig.ttsSpeechPer), Pair("cuid", "baidu_speech_demo"), Pair("idx", "1"), Pair("cod", "2"), diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 7da1ac2e0..294a1c127 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -14,11 +14,11 @@ import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.ui.book.read.Help -import io.legado.app.utils.getPrefString import io.legado.app.utils.postEvent class ReadAloudConfigDialog : DialogFragment() { @@ -59,17 +59,19 @@ class ReadAloudConfigDialog : DialogFragment() { } class ReadAloudPreferenceFragment : PreferenceFragmentCompat(), - SharedPreferences.OnSharedPreferenceChangeListener, - Preference.OnPreferenceChangeListener { + SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config_aloud) + upPreferenceSummary( + findPreference(PreferKey.ttsSpeechPer), + AppConfig.ttsSpeechPer + ) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ATH.applyEdgeEffectColor(listView) - bindPreferenceSummaryToValue(findPreference(PreferKey.ttsSpeechPer)) } override fun onResume() { @@ -97,32 +99,25 @@ class ReadAloudConfigDialog : DialogFragment() { ReadAloud.aloudClass = ReadAloud.getReadAloudClass() } PreferKey.ttsSpeechPer -> { + upPreferenceSummary( + findPreference(PreferKey.ttsSpeechPer), + AppConfig.ttsSpeechPer + ) ReadAloud.upTtsSpeechRate(requireContext()) } } } - override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { - val stringValue = newValue.toString() - - if (preference is ListPreference) { - val index = preference.findIndexOfValue(stringValue) - // Set the summary to reflect the new value. - preference.setSummary(if (index >= 0) preference.entries[index] else null) - } else { - // For all other preferences, set the summary to the value's - preference?.summary = stringValue - } - return false - } - - private fun bindPreferenceSummaryToValue(preference: Preference?) { - preference?.apply { - onPreferenceChangeListener = this@ReadAloudPreferenceFragment - onPreferenceChange( - this, - context.getPrefString(key) - ) + private fun upPreferenceSummary(preference: Preference?, value: String) { + when (preference) { + is ListPreference -> { + val index = preference.findIndexOfValue(value) + // Set the summary to reflect the new value. + preference.summary = if (index >= 0) preference.entries[index] else null + } + else -> { + preference?.summary = value + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 909c9cae5..f08aa7db8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -590,5 +590,6 @@ 自动切换夜间模式 夜间模式跟随系统 上级 + 在线朗读音色 diff --git a/app/src/main/res/xml/pref_config_aloud.xml b/app/src/main/res/xml/pref_config_aloud.xml index d142c526c..d78e3c687 100644 --- a/app/src/main/res/xml/pref_config_aloud.xml +++ b/app/src/main/res/xml/pref_config_aloud.xml @@ -16,7 +16,7 @@ Date: Thu, 6 Feb 2020 12:20:10 +0800 Subject: [PATCH 399/852] =?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/BookHelp.kt | 2 +- .../app/ui/config/OtherConfigFragment.kt | 47 +++++-------------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index fa6b63c39..de8c0a5a7 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -15,7 +15,7 @@ import kotlin.math.min object BookHelp { private const val cacheFolderName = "book_cache" - private var downloadPath: String = + var downloadPath: String = App.INSTANCE.getPrefString(PreferKey.downloadPath) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 8f3a7e244..6a77a8c99 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -27,7 +27,6 @@ import io.legado.app.utils.* class OtherConfigFragment : PreferenceFragmentCompat(), FileChooserDialog.CallBack, - Preference.OnPreferenceChangeListener, SharedPreferences.OnSharedPreferenceChangeListener { private val requestCodeDownloadPath = 25324 @@ -40,8 +39,8 @@ class OtherConfigFragment : PreferenceFragmentCompat(), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { putPrefBoolean("process_text", isProcessTextEnabled()) addPreferencesFromResource(R.xml.pref_config_other) - bindPreferenceSummaryToValue(findPreference(PreferKey.downloadPath)) - bindPreferenceSummaryToValue(findPreference(PreferKey.threadCount)) + upPreferenceSummary(findPreference(PreferKey.downloadPath), BookHelp.downloadPath) + upPreferenceSummary(findPreference(PreferKey.threadCount), AppConfig.threadCount.toString()) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -84,7 +83,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), when (key) { PreferKey.downloadPath -> { BookHelp.upDownloadPath() - findPreference(key)?.summary = getPreferenceString(key).toString() + findPreference(key)?.summary = BookHelp.downloadPath } PreferKey.recordLog -> LogUtils.upLevel() PreferKey.processText -> sharedPreferences?.let { @@ -94,38 +93,16 @@ class OtherConfigFragment : PreferenceFragmentCompat(), } } - override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { - val stringValue = newValue.toString() - when { - preference is ListPreference -> { - val index = preference.findIndexOfValue(stringValue) + private fun upPreferenceSummary(preference: Preference?, value: String) { + when (preference) { + is ListPreference -> { + val index = preference.findIndexOfValue(value) // Set the summary to reflect the new value. - preference.setSummary(if (index >= 0) preference.entries[index] else null) + preference.summary = if (index >= 0) preference.entries[index] else null + } + else -> { + preference?.summary = value } - preference?.key == PreferKey.threadCount -> preference.summary = - getString(R.string.threads_num, stringValue) - else -> preference?.summary = stringValue - } - return false - } - - private fun bindPreferenceSummaryToValue(preference: Preference?) { - preference?.let { - preference.onPreferenceChangeListener = this - onPreferenceChange( - preference, - getPreferenceString(preference.key) - ) - } - } - - private fun getPreferenceString(key: String): Any { - return when (key) { - PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath) - ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath - ?: App.INSTANCE.cacheDir.absolutePath - PreferKey.threadCount -> AppConfig.threadCount - else -> getPrefString(key) ?: "" } } @@ -166,7 +143,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), childFragmentManager, requestCodeDownloadPath, mode = FileChooserDialog.DIRECTORY, - initPath = getPreferenceString(PreferKey.downloadPath).toString() + initPath = BookHelp.downloadPath ) } .request() From 25d67acb36382e20f7126f651cee811a207d0453 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 12:22:52 +0800 Subject: [PATCH 400/852] =?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/config/ThemeConfigFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 856e6cbb3..c90db122d 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -104,7 +104,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar .setTitle("切换默认主题") .setItems(items){ _,which -> - preference.summary = "${items[which]}" + preference.summary = items[which] putPrefInt("default_theme", which) when (which) { 0 -> { From 8816450b12e2c111270e970c90d05fe9e7941f91 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 15:46:31 +0800 Subject: [PATCH 401/852] =?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/arrange/ArrangeBookActivity.kt | 2 +- .../app/ui/book/arrange/ArrangeBookAdapter.kt | 6 +- app/src/main/res/layout/item_arrange_book.xml | 58 ++++++++++++++++++- 3 files changed, 61 insertions(+), 5 deletions(-) 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 17a555863..7e349dcb6 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 @@ -49,7 +49,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi booksLiveData?.removeObservers(this) booksLiveData = App.db.bookDao().observeAll() booksLiveData?.observe(this, Observer { - + adapter.setItems(it) }) } 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 91fb157e1..3594119a6 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 @@ -5,6 +5,7 @@ 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.Book +import kotlinx.android.synthetic.main.item_arrange_book.view.* class ArrangeBookAdapter(context: Context) : @@ -12,7 +13,10 @@ class ArrangeBookAdapter(context: Context) : override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { - + with(holder.itemView) { + tv_name.text = item.name + tv_author.text = item.author + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/item_arrange_book.xml b/app/src/main/res/layout/item_arrange_book.xml index d829e291c..dec2b66bf 100644 --- a/app/src/main/res/layout/item_arrange_book.xml +++ b/app/src/main/res/layout/item_arrange_book.xml @@ -1,7 +1,59 @@ - + android:layout_height="wrap_content"> - \ No newline at end of file + + + + + + + + + + + \ No newline at end of file From 5fdd51427a29088bdb9ae234f2f66c15f44f9501 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 15:59:32 +0800 Subject: [PATCH 402/852] =?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/ArrangeBookAdapter.kt | 2 +- app/src/main/res/layout/item_arrange_book.xml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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 3594119a6..680ced2e3 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 @@ -15,7 +15,7 @@ class ArrangeBookAdapter(context: Context) : override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { tv_name.text = item.name - tv_author.text = item.author + tv_author.text = context.getString(R.string.author_show, item.author) } } diff --git a/app/src/main/res/layout/item_arrange_book.xml b/app/src/main/res/layout/item_arrange_book.xml index dec2b66bf..ea62f6d4f 100644 --- a/app/src/main/res/layout/item_arrange_book.xml +++ b/app/src/main/res/layout/item_arrange_book.xml @@ -21,6 +21,8 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:padding="3dp" + android:textSize="16sp" + android:text="@string/book_name" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/tv_author" app:layout_constraintLeft_toRightOf="@id/checkbox" @@ -31,6 +33,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:padding="3dp" + android:text="@string/author" app:layout_constraintLeft_toRightOf="@+id/checkbox" app:layout_constraintTop_toBottomOf="@id/tv_name" app:layout_constraintBottom_toBottomOf="parent" From 988388f53052ae3ab612c140884ad5c458b41a5b Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 16:58:28 +0800 Subject: [PATCH 403/852] =?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/res/layout/activity_arrange_book.xml | 11 ++++++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index 40b9ce904..993b58b77 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -30,12 +30,21 @@ + + 夜间模式跟随系统 上级 在线朗读音色 + (%d/%d) From fec631fecf01d8412341a775ba50f2b826837458 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 17:08:38 +0800 Subject: [PATCH 404/852] =?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/ui/book/arrange/ArrangeBookActivity.kt | 8 ++++++-- .../app/ui/book/arrange/ArrangeBookAdapter.kt | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) 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 7e349dcb6..5c9f9dfa4 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 @@ -10,14 +10,17 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookGroup import io.legado.app.lib.theme.ATH import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_arrange_book.* -class ArrangeBookActivity : VMBaseActivity(R.layout.activity_arrange_book) { +class ArrangeBookActivity : VMBaseActivity(R.layout.activity_arrange_book), + ArrangeBookAdapter.CallBack { override val viewModel: ArrangeBookViewModel get() = getViewModel(ArrangeBookViewModel::class.java) + override val groupList: List = arrayListOf() private lateinit var adapter: ArrangeBookAdapter private var booksLiveData: LiveData>? = null @@ -41,7 +44,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - adapter = ArrangeBookAdapter(this) + adapter = ArrangeBookAdapter(this, this) recycler_view.adapter = adapter } @@ -53,4 +56,5 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi }) } + } \ No newline at end of file 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 680ced2e3..718572606 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 @@ -5,10 +5,11 @@ 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.Book +import io.legado.app.data.entities.BookGroup import kotlinx.android.synthetic.main.item_arrange_book.view.* -class ArrangeBookAdapter(context: Context) : +class ArrangeBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_arrange_book) { @@ -16,7 +17,20 @@ class ArrangeBookAdapter(context: Context) : with(holder.itemView) { tv_name.text = item.name tv_author.text = context.getString(R.string.author_show, item.author) + tv_group.text = getGroupName(item.group) } } + private fun getGroupName(groupId: Int): String { + callBack.groupList.forEach { + if (it.groupId == groupId) { + return it.groupName + } + } + return context.getString(R.string.group) + } + + interface CallBack { + val groupList: List + } } \ No newline at end of file From 705c38cd09d0e092455812741b98d5046cf2835a Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 17:46:40 +0800 Subject: [PATCH 405/852] =?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/model/webBook/BookChapterList.kt | 27 +++++++++---------- .../ui/book/arrange/ArrangeBookActivity.kt | 10 ++++++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 8c92ae7ed..705321694 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -51,17 +51,17 @@ object BookChapterList { ruleUrl = nextUrl, book = book, headerMapF = bookSource.getHeaderMap() ).getResponseAwait() .body?.let { nextBody -> - chapterData = analyzeChapterList( - nextBody, nextUrl, tocRule, listRule, - book, bookSource, log = false - ) - nextUrl = if (chapterData.nextUrl.isNotEmpty()) - chapterData.nextUrl[0] - else "" - chapterData.chapterList?.let { - chapterList.addAll(it) - } + chapterData = analyzeChapterList( + nextBody, nextUrl, tocRule, listRule, + book, bookSource, log = false + ) + nextUrl = if (chapterData.nextUrl.isNotEmpty()) + chapterData.nextUrl[0] + else "" + chapterData.chapterList?.let { + chapterList.addAll(it) } + } } Debug.log(bookSource.bookSourceUrl, "◇目录总页数:${nextUrlList.size}") } else if (chapterData.nextUrl.size > 1) { @@ -100,11 +100,8 @@ object BookChapterList { item.index = index } book.latestChapterTitle = chapterList.last().title - if (book.durChapterIndex < chapterList.size) { - book.durChapterTitle = chapterList[book.durChapterIndex].title - } else { - book.durChapterTitle = book.latestChapterTitle - } + book.durChapterTitle = + chapterList.getOrNull(book.durChapterIndex)?.title ?: book.latestChapterTitle if (book.totalChapterNum < chapterList.size) { book.lastCheckCount = chapterList.size - book.totalChapterNum } 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 5c9f9dfa4..9354cce4c 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 @@ -20,8 +20,9 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi ArrangeBookAdapter.CallBack { override val viewModel: ArrangeBookViewModel get() = getViewModel(ArrangeBookViewModel::class.java) - override val groupList: List = arrayListOf() + override val groupList: ArrayList = arrayListOf() private lateinit var adapter: ArrangeBookAdapter + private var groupLiveData: LiveData>? = null private var booksLiveData: LiveData>? = null override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -49,6 +50,13 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi } private fun initData() { + groupLiveData?.removeObservers(this) + groupLiveData = App.db.bookGroupDao().liveDataAll() + groupLiveData?.observe(this, Observer { + groupList.clear() + groupList.addAll(it) + adapter.notifyDataSetChanged() + }) booksLiveData?.removeObservers(this) booksLiveData = App.db.bookDao().observeAll() booksLiveData?.observe(this, Observer { From 92dadc5842f90ff06d4897bdfce85d7716908e00 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 18:03:23 +0800 Subject: [PATCH 406/852] =?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/arrange/ArrangeBookActivity.kt | 15 +++++++++++++++ .../app/ui/book/arrange/ArrangeBookAdapter.kt | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) 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 9354cce4c..421bce7fd 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 @@ -64,5 +64,20 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi }) } + override fun upSelectCount() { + if (adapter.selectedBooks.size == 0) { + cb_selected_all.isChecked = false + } else { + cb_selected_all.isChecked = adapter.selectedBooks.size >= adapter.getItems().size + } + //重置全选的文字 + if (cb_selected_all.isChecked) { + cb_selected_all.setText(R.string.cancel) + } else { + cb_selected_all.setText(R.string.select_all) + } + tv_select_count.text = + getString(R.string.select_count, adapter.selectedBooks.size, adapter.getItems().size) + } } \ No newline at end of file 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 718572606..eefadb9b3 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 @@ -7,17 +7,35 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup import kotlinx.android.synthetic.main.item_arrange_book.view.* +import org.jetbrains.anko.sdk27.listeners.onClick class ArrangeBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_arrange_book) { + val selectedBooks: ArrayList = arrayListOf() override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { tv_name.text = item.name tv_author.text = context.getString(R.string.author_show, item.author) tv_group.text = getGroupName(item.group) + checkbox.isChecked = selectedBooks.contains(item.bookUrl) + checkbox.onClick { + if (checkbox.isChecked) { + selectedBooks.add(item.bookUrl) + } else { + selectedBooks.remove(item.bookUrl) + } + } + onClick { + checkbox.isChecked = !checkbox.isChecked + if (checkbox.isChecked) { + selectedBooks.add(item.bookUrl) + } else { + selectedBooks.remove(item.bookUrl) + } + } } } @@ -32,5 +50,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : interface CallBack { val groupList: List + fun upSelectCount() } } \ No newline at end of file From e3389ff8afd6fd1f542469abeaceb7dd24f12ea7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 18:12:58 +0800 Subject: [PATCH 407/852] =?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 | 1 + .../java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt | 2 ++ 2 files changed, 3 insertions(+) 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 421bce7fd..056b55999 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 @@ -61,6 +61,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi booksLiveData = App.db.bookDao().observeAll() booksLiveData?.observe(this, Observer { adapter.setItems(it) + upSelectCount() }) } 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 eefadb9b3..c24011ee4 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 @@ -27,6 +27,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : } else { selectedBooks.remove(item.bookUrl) } + callBack.upSelectCount() } onClick { checkbox.isChecked = !checkbox.isChecked @@ -35,6 +36,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : } else { selectedBooks.remove(item.bookUrl) } + callBack.upSelectCount() } } } From 15585965f4e7cf40ca0be00836459820e0c763fe Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 18:20:54 +0800 Subject: [PATCH 408/852] =?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/ui/book/arrange/ArrangeBookActivity.kt | 4 ++++ .../app/ui/book/arrange/ArrangeBookAdapter.kt | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) 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 056b55999..740afc1cc 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,6 +14,7 @@ import io.legado.app.data.entities.BookGroup import io.legado.app.lib.theme.ATH import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_arrange_book.* +import org.jetbrains.anko.sdk27.listeners.onClick class ArrangeBookActivity : VMBaseActivity(R.layout.activity_arrange_book), @@ -47,6 +48,9 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi recycler_view.layoutManager = LinearLayoutManager(this) adapter = ArrangeBookAdapter(this, this) recycler_view.adapter = adapter + cb_selected_all.onClick { + adapter.selectAll(cb_selected_all.isChecked) + } } private fun initData() { 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 c24011ee4..75bc12c85 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 @@ -13,7 +13,21 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ArrangeBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_arrange_book) { - val selectedBooks: ArrayList = arrayListOf() + val selectedBooks: HashSet = hashSetOf() + + fun selectAll(selectAll: Boolean) { + if (selectAll) { + selectedBooks.clear() + notifyDataSetChanged() + callBack.upSelectCount() + } else { + getItems().forEach { + selectedBooks.add(it.bookUrl) + } + notifyDataSetChanged() + callBack.upSelectCount() + } + } override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { with(holder.itemView) { From b4df33d92ae98fa70cba0cc7493c87f8728f2385 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 18:38:35 +0800 Subject: [PATCH 409/852] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d65e3dbdc..1a035aaf5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # legado ## 阅读3.0 +书源规则 https://celeter.github.io/?tdsourcetag=s_pctim_aiomsg From 0cce324ce375b5344d75f67171672ddc5f8e3eeb Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 18:40:32 +0800 Subject: [PATCH 410/852] =?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/ui/book/arrange/ArrangeBookActivity.kt | 8 ++------ .../app/ui/book/arrange/ArrangeBookAdapter.kt | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) 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 740afc1cc..936c7b70b 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 @@ -49,7 +49,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi adapter = ArrangeBookAdapter(this, this) recycler_view.adapter = adapter cb_selected_all.onClick { - adapter.selectAll(cb_selected_all.isChecked) + adapter.selectAll(!adapter.isSelectAll()) } } @@ -70,11 +70,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi } override fun upSelectCount() { - if (adapter.selectedBooks.size == 0) { - cb_selected_all.isChecked = false - } else { - cb_selected_all.isChecked = adapter.selectedBooks.size >= adapter.getItems().size - } + cb_selected_all.isChecked = adapter.isSelectAll() //重置全选的文字 if (cb_selected_all.isChecked) { cb_selected_all.setText(R.string.cancel) 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 75bc12c85..890f29bad 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 @@ -15,17 +15,25 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : val selectedBooks: HashSet = hashSetOf() + fun isSelectAll(): Boolean { + return if (selectedBooks.isEmpty()) { + false + } else { + selectedBooks.size >= itemCount + } + } + fun selectAll(selectAll: Boolean) { if (selectAll) { - selectedBooks.clear() - notifyDataSetChanged() - callBack.upSelectCount() - } else { getItems().forEach { selectedBooks.add(it.bookUrl) } notifyDataSetChanged() callBack.upSelectCount() + } else { + selectedBooks.clear() + notifyDataSetChanged() + callBack.upSelectCount() } } From 6dcadcd5d71ae2ec58067041fed920fcd719f570 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 19:17:26 +0800 Subject: [PATCH 411/852] =?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/arrange/ArrangeBookActivity.kt | 22 +++++++++++++++++++ .../app/ui/book/arrange/ArrangeBookAdapter.kt | 4 ++++ .../ui/book/arrange/ArrangeBookViewModel.kt | 5 +++++ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 33 insertions(+) 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 936c7b70b..2f3658f89 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 @@ -11,10 +11,14 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup +import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH +import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_arrange_book.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.toast class ArrangeBookActivity : VMBaseActivity(R.layout.activity_arrange_book), @@ -51,6 +55,17 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi cb_selected_all.onClick { adapter.selectAll(!adapter.isSelectAll()) } + btn_delete.onClick { + if (adapter.selectedBooks.isEmpty()) { + toast(R.string.non_select) + return@onClick + } + alert(titleResource = R.string.sure, messageResource = R.string.sure_del) { + okButton { + viewModel.deleteBook(*adapter.selectedBooks.toTypedArray()) + } + }.show().applyTint() + } } private fun initData() { @@ -81,4 +96,11 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi getString(R.string.select_count, adapter.selectedBooks.size, adapter.getItems().size) } + override fun deleteBook(bookUrl: String) { + alert(titleResource = R.string.sure, messageResource = R.string.sure_del) { + okButton { + viewModel.deleteBook(bookUrl) + } + }.show().applyTint() + } } \ No newline at end of file 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 890f29bad..0a4fb5a52 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 @@ -60,6 +60,9 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : } callBack.upSelectCount() } + tv_delete.onClick { + callBack.deleteBook(item.bookUrl) + } } } @@ -75,5 +78,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : interface CallBack { val groupList: List fun upSelectCount() + fun deleteBook(bookUrl: String) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt index a6fa9463f..76e890886 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt @@ -6,4 +6,9 @@ import io.legado.app.base.BaseViewModel class ArrangeBookViewModel(application: Application) : BaseViewModel(application) { + + fun deleteBook(vararg bookUrl: String) { + + } + } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7b6ebfbc4..fc4d73a1a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -457,6 +457,8 @@ 网络连接不可用 + 确认 + 是否确认删除? 是否删除全部书籍? 是否同时删除已下载的书籍目录? 扫描二维码需相机权限 From e35bafb0f72cfc0ad447c50668ab9476c292576c Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 19:21:15 +0800 Subject: [PATCH 412/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/arrange/ArrangeBookActivity.kt | 7 +++++++ app/src/main/res/layout/activity_arrange_book.xml | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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 2f3658f89..e985f8c8b 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 @@ -66,6 +66,13 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi } }.show().applyTint() } + btn_to_group.onClick { + if (adapter.selectedBooks.isEmpty()) { + toast(R.string.non_select) + return@onClick + } + + } } private fun initData() { diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index 993b58b77..795e1bfa4 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -46,7 +46,7 @@ tools:ignore="RelativeOverlap" /> \ No newline at end of file From 541c2cecf59fb5775227ffa4993ab9cffaa05c18 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 19:32:50 +0800 Subject: [PATCH 413/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bookshelf => book/group}/GroupManageDialog.kt | 10 ++++++++-- .../app/ui/book/{info => group}/GroupSelectDialog.kt | 7 +++++-- .../io/legado/app/ui/book/info/BookInfoActivity.kt | 1 + .../legado/app/ui/main/bookshelf/BookshelfFragment.kt | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) rename app/src/main/java/io/legado/app/ui/{main/bookshelf => book/group}/GroupManageDialog.kt (96%) rename app/src/main/java/io/legado/app/ui/book/{info => group}/GroupSelectDialog.kt (98%) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt similarity index 96% rename from app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt rename to app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 1022f4ed9..af3723e11 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.main.bookshelf +package io.legado.app.ui.book.group import android.annotation.SuppressLint import android.content.Context @@ -25,6 +25,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton +import io.legado.app.ui.main.bookshelf.BookshelfViewModel import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel import io.legado.app.utils.requestInputMethod @@ -77,7 +78,12 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { recycler_view.adapter = adapter App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { val diffResult = - DiffUtil.calculateDiff(GroupDiffCallBack(adapter.getItems(), it)) + DiffUtil.calculateDiff( + GroupDiffCallBack( + adapter.getItems(), + it + ) + ) adapter.setItems(it, false) diffResult.dispatchUpdatesTo(adapter) }) diff --git a/app/src/main/java/io/legado/app/ui/book/info/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/book/info/GroupSelectDialog.kt rename to app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 517f9dc9d..6dbdbd17b 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.info +package io.legado.app.ui.book.group import android.annotation.SuppressLint import android.content.Context @@ -44,7 +44,10 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { fun show(manager: FragmentManager) { val fragment = GroupSelectDialog() - fragment.show(manager, tag) + fragment.show( + manager, + tag + ) } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 6b0e5433f..cf86b2f04 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -21,6 +21,7 @@ import io.legado.app.help.BlurTransformation import io.legado.app.help.ImageLoader import io.legado.app.help.IntentDataHelp import io.legado.app.ui.audio.AudioPlayActivity +import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.ui.book.info.edit.BookInfoEditActivity import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index e3c68dcaa..c51bd46e2 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -22,6 +22,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.view.ATEAutoCompleteTextView import io.legado.app.ui.book.arrange.ArrangeBookActivity +import io.legado.app.ui.book.group.GroupManageDialog import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.download.DownloadActivity import io.legado.app.ui.importbook.ImportBookActivity From 9c7e5d9a279c9530227944aeaedfeb4b05d7c009 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 19:39:34 +0800 Subject: [PATCH 414/852] =?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/data/entities/Book.kt | 10 +++++----- .../legado/app/ui/book/arrange/ArrangeBookActivity.kt | 6 +++++- .../legado/app/ui/book/arrange/ArrangeBookAdapter.kt | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 0c43860f0..204d2de7a 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -21,14 +21,14 @@ data class Book( var tocUrl: String = "", // 目录页Url (toc=table of Contents) var origin: String = BookType.local, // 书源URL(默认BookType.local) var originName: String = "", //书源名称 or 本地书籍文件名 - var name: String = "", // 书籍名称(书源获取) - var author: String = "", // 作者名称(书源获取) - override var kind: String? = null, // 分类信息(书源获取) + var name: String = "", // 书籍名称(书源获取) + var author: String = "", // 作者名称(书源获取) + override var kind: String? = null, // 分类信息(书源获取) var customTag: String? = null, // 分类信息(用户修改) var coverUrl: String? = null, // 封面Url(书源获取) var customCoverUrl: String? = null, // 封面Url(用户修改) - var intro: String? = null, // 简介内容(书源获取) - var customIntro: String? = null, // 简介内容(用户修改) + var intro: String? = null, // 简介内容(书源获取) + var customIntro: String? = null, // 简介内容(用户修改) var charset: String? = null, // 自定义字符集名称(仅适用于本地书籍) var type: Int = 0, // @BookType var group: Int = 0, // 自定义分组索引号 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 e985f8c8b..3baabc568 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 @@ -71,7 +71,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi toast(R.string.non_select) return@onClick } - + selectGroup() } } @@ -91,6 +91,10 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi }) } + override fun selectGroup() { + + } + override fun upSelectCount() { cb_selected_all.isChecked = adapter.isSelectAll() //重置全选的文字 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 0a4fb5a52..44fdecda7 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 @@ -63,6 +63,9 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : tv_delete.onClick { callBack.deleteBook(item.bookUrl) } + tv_group.onClick { + callBack.selectGroup() + } } } @@ -79,5 +82,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : val groupList: List fun upSelectCount() fun deleteBook(bookUrl: String) + fun selectGroup() } } \ No newline at end of file From 07ca45d5aeeede74ec33f56095238c5b472562c3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 20:29:45 +0800 Subject: [PATCH 415/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookSourceDao.kt | 17 +------ .../io/legado/app/data/entities/BookSource.kt | 12 +++++ .../io/legado/app/service/help/CheckSource.kt | 9 +++- .../book/source/manage/BookSourceActivity.kt | 20 ++++---- .../book/source/manage/BookSourceAdapter.kt | 26 +++++----- .../book/source/manage/BookSourceViewModel.kt | 48 +++++++++---------- 6 files changed, 65 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 159622898..ce8dfe950 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -29,21 +29,6 @@ interface BookSourceDao { @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey") fun searchIsEnable(searchKey: String = ""): List - @Query("update book_sources set enabled = 1 where bookSourceUrl = :sourceUrl") - fun enableSection(sourceUrl: String) - - @Query("update book_sources set enabled = 0 where bookSourceUrl = :sourceUrl") - fun disableSection(sourceUrl: String) - - @Query("update book_sources set enabledExplore = 1 where bookSourceUrl = :sourceUrl") - fun enableSectionExplore(sourceUrl: String) - - @Query("update book_sources set enabledExplore = 0 where bookSourceUrl = :sourceUrl") - fun disableSectionExplore(sourceUrl: String) - - @Query("delete from book_sources where bookSourceUrl = :sourceUrl") - fun delSection(sourceUrl: String) - @Query("select * from book_sources where enabledExplore = 1 order by customOrder asc") fun observeFind(): DataSource.Factory @@ -78,7 +63,7 @@ interface BookSourceDao { fun update(vararg bookSource: BookSource) @Delete - fun delete(bookSource: BookSource) + fun delete(vararg bookSource: BookSource) @Query("delete from book_sources where bookSourceUrl = :key") fun delete(key: String) diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index bab3a7b5e..78852a4ec 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -47,6 +47,18 @@ data class BookSource( var ruleToc: String? = null, // 目录页规则 var ruleContent: String? = null // 正文页规则 ) : Parcelable, JsExtensions { + + override fun hashCode(): Int { + return bookSourceUrl.hashCode() + } + + override fun equals(other: Any?): Boolean { + if (other is BookSource) { + return other.bookSourceUrl == bookSourceUrl + } + return false + } + @Ignore @IgnoredOnParcel private var searchRuleV: SearchRule? = null diff --git a/app/src/main/java/io/legado/app/service/help/CheckSource.kt b/app/src/main/java/io/legado/app/service/help/CheckSource.kt index 057813337..1f13723a2 100644 --- a/app/src/main/java/io/legado/app/service/help/CheckSource.kt +++ b/app/src/main/java/io/legado/app/service/help/CheckSource.kt @@ -4,16 +4,21 @@ import android.content.Context import android.content.Intent import io.legado.app.R import io.legado.app.constant.IntentAction +import io.legado.app.data.entities.BookSource import io.legado.app.service.CheckSourceService import org.jetbrains.anko.toast object CheckSource { - fun start(context: Context, selectedIds: ArrayList) { - if (selectedIds.isEmpty()) { + fun start(context: Context, sources: LinkedHashSet) { + if (sources.isEmpty()) { context.toast(R.string.non_select) return } + val selectedIds: ArrayList = arrayListOf() + sources.map { + selectedIds.add(it.bookSourceUrl) + } Intent(context, CheckSourceService::class.java).let { it.action = IntentAction.start it.putExtra("selectIds", selectedIds) 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 82d823a0a..4f9fea1df 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 @@ -80,20 +80,18 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity when (item.itemId) { R.id.menu_add_book_source -> startActivity() R.id.menu_import_source_qr -> startActivityForResult(qrRequestCode) - R.id.menu_group_manage -> GroupManageDialog().show( - supportFragmentManager, - "groupManage" - ) + R.id.menu_group_manage -> + GroupManageDialog().show(supportFragmentManager, "groupManage") R.id.menu_import_source_local -> selectFileSys() R.id.menu_select_all -> adapter.selectAll() R.id.menu_revert_selection -> adapter.revertSelection() - R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds()) - R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) - R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelectionIds()) - R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelectionIds()) - R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) - R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) - R.id.menu_check_source -> CheckSource.start(this, ArrayList(adapter.getSelectionIds())) + R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) + R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) + R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelection()) + R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelection()) + R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) + R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) + R.id.menu_check_source -> CheckSource.start(this, adapter.getSelection()) R.id.menu_import_source_onLine -> showImportDialog() } if (item.groupId == R.id.source_group) { 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 c7c432e16..e29a39d2b 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 @@ -16,31 +16,31 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_book_source), OnItemTouchCallbackListener { - private val selectedIds = linkedSetOf() + private val selected = linkedSetOf() fun selectAll() { getItems().forEach { - selectedIds.add(it.bookSourceUrl) + selected.add(it) } notifyItemRangeChanged(0, itemCount, 1) } fun revertSelection() { getItems().forEach { - if (selectedIds.contains(it.bookSourceUrl)) { - selectedIds.remove(it.bookSourceUrl) + if (selected.contains(it)) { + selected.remove(it) } else { - selectedIds.add(it.bookSourceUrl) + selected.add(it) } } notifyItemRangeChanged(0, itemCount, 1) } - fun getSelectionIds(): LinkedHashSet { - val selection = linkedSetOf() + fun getSelection(): LinkedHashSet { + val selection = linkedSetOf() getItems().map { - if (selectedIds.contains(it.bookSourceUrl)) { - selection.add(it.bookSourceUrl) + if (selected.contains(it)) { + selection.add(it) } } return selection @@ -81,12 +81,12 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : item.enabled = swt_enabled.isChecked callBack.update(item) } - cb_book_source.isChecked = selectedIds.contains(item.bookSourceUrl) + cb_book_source.isChecked = selected.contains(item) cb_book_source.setOnClickListener { if (cb_book_source.isChecked) { - selectedIds.add(item.bookSourceUrl) + selected.add(item) } else { - selectedIds.remove(item.bookSourceUrl) + selected.remove(item) } } iv_edit.onClick { callBack.edit(item) } @@ -105,7 +105,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } else { when (payloads[0]) { - 1 -> cb_book_source.isChecked = selectedIds.contains(item.bookSourceUrl) + 1 -> cb_book_source.isChecked = selected.contains(item) 2 -> swt_enabled.isChecked = item.enabled } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 554ae4165..9bbaccfb9 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -43,56 +43,54 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) } } - fun enableSelection(ids: LinkedHashSet) { + fun enableSelection(sources: LinkedHashSet) { execute { - ids.forEach { - App.db.bookSourceDao().enableSection(it) + sources.forEach { + it.enabled = true } + App.db.bookSourceDao().update(*sources.toTypedArray()) } } - fun disableSelection(ids: LinkedHashSet) { + fun disableSelection(sources: LinkedHashSet) { execute { - ids.forEach { - App.db.bookSourceDao().disableSection(it) + sources.forEach { + it.enabled = false } + App.db.bookSourceDao().update(*sources.toTypedArray()) } } - fun enableSelectExplore(ids: LinkedHashSet) { + fun enableSelectExplore(sources: LinkedHashSet) { execute { - ids.forEach { - App.db.bookSourceDao().enableSectionExplore(it) + sources.forEach { + it.enabledExplore = true } + App.db.bookSourceDao().update(*sources.toTypedArray()) } } - fun disableSelectExplore(ids: LinkedHashSet) { + fun disableSelectExplore(sources: LinkedHashSet) { execute { - ids.forEach { - App.db.bookSourceDao().disableSectionExplore(it) + sources.forEach { + it.enabledExplore = false } + App.db.bookSourceDao().update(*sources.toTypedArray()) } } - fun delSelection(ids: LinkedHashSet) { + fun delSelection(sources: LinkedHashSet) { execute { - ids.forEach { - App.db.bookSourceDao().delSection(it) - } + App.db.bookSourceDao().delete(*sources.toTypedArray()) } } - fun exportSelection(ids: LinkedHashSet) { + fun exportSelection(sources: LinkedHashSet) { execute { - ids.map { - App.db.bookSourceDao().getBookSource(it) - }.let { - val json = GSON.toJson(it) - val file = - FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportBookSource.json") - file.writeText(json) - } + val json = GSON.toJson(sources) + val file = + FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportBookSource.json") + file.writeText(json) }.onSuccess { context.toast("成功导出至\n${Backup.exportPath}") }.onError { From 7712df964ef3b05bf8eb3c03892171702e5c4e78 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 20:31:59 +0800 Subject: [PATCH 416/852] =?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/ui/book/source/manage/BookSourceAdapter.kt | 1 - .../legado/app/ui/book/source/manage/DiffCallBack.kt | 10 ---------- 2 files changed, 11 deletions(-) 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 e29a39d2b..8f5c3c9bc 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 @@ -106,7 +106,6 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } else { when (payloads[0]) { 1 -> cb_book_source.isChecked = selected.contains(item) - 2 -> swt_enabled.isChecked = item.enabled } } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt index 0e8d9bead..6eb02037a 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt @@ -30,14 +30,4 @@ class DiffCallBack( && oldItem.enabled == newItem.enabled } - override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { - val oldItem = oldItems[oldItemPosition] - val newItem = newItems[newItemPosition] - return when { - oldItem.bookSourceName == newItem.bookSourceName - && oldItem.bookSourceGroup == newItem.bookSourceGroup - && oldItem.enabled != newItem.enabled -> 2 - else -> null - } - } } \ No newline at end of file From 5e6ddf402b1a3abcdef21433a36a5c8316e47f66 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 20:40:31 +0800 Subject: [PATCH 417/852] =?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/data/dao/BookDao.kt | 5 ++++- .../legado/app/ui/audio/AudioPlayViewModel.kt | 4 ++-- .../app/ui/book/arrange/ArrangeBookActivity.kt | 4 ++-- .../app/ui/book/arrange/ArrangeBookAdapter.kt | 18 +++++++++--------- .../ui/book/arrange/ArrangeBookViewModel.kt | 8 ++++++-- .../app/ui/book/info/BookInfoViewModel.kt | 4 ++-- .../app/ui/book/read/ReadBookViewModel.kt | 4 ++-- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index cbd0f61ce..30d275df7 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -60,7 +60,10 @@ interface BookDao { fun insert(vararg book: Book) @Update - fun update(vararg books: Book) + fun update(vararg book: Book) + + @Delete + fun delete(vararg book: Book) @Query("delete from books where bookUrl = :bookUrl") fun delete(bookUrl: String) diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index 5adc2c7be..b5dd5bfba 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -91,7 +91,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) fun changeTo(book1: Book) { execute { AudioPlay.book?.let { - App.db.bookDao().delete(it.bookUrl) + App.db.bookDao().delete(it) } withContext(Dispatchers.Main) { @@ -142,7 +142,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) fun removeFromBookshelf(success: (() -> Unit)?) { execute { AudioPlay.book?.let { - App.db.bookDao().delete(it.bookUrl) + App.db.bookDao().delete(it) } }.onSuccess { success?.invoke() 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 3baabc568..b6204e90b 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 @@ -107,10 +107,10 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi getString(R.string.select_count, adapter.selectedBooks.size, adapter.getItems().size) } - override fun deleteBook(bookUrl: String) { + override fun deleteBook(book: Book) { alert(titleResource = R.string.sure, messageResource = R.string.sure_del) { okButton { - viewModel.deleteBook(bookUrl) + viewModel.deleteBook(book) } }.show().applyTint() } 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 44fdecda7..dab74dc4b 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 @@ -13,7 +13,7 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ArrangeBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_arrange_book) { - val selectedBooks: HashSet = hashSetOf() + val selectedBooks: HashSet = hashSetOf() fun isSelectAll(): Boolean { return if (selectedBooks.isEmpty()) { @@ -26,7 +26,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : fun selectAll(selectAll: Boolean) { if (selectAll) { getItems().forEach { - selectedBooks.add(it.bookUrl) + selectedBooks.add(it) } notifyDataSetChanged() callBack.upSelectCount() @@ -42,26 +42,26 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : tv_name.text = item.name tv_author.text = context.getString(R.string.author_show, item.author) tv_group.text = getGroupName(item.group) - checkbox.isChecked = selectedBooks.contains(item.bookUrl) + checkbox.isChecked = selectedBooks.contains(item) checkbox.onClick { if (checkbox.isChecked) { - selectedBooks.add(item.bookUrl) + selectedBooks.add(item) } else { - selectedBooks.remove(item.bookUrl) + selectedBooks.remove(item) } callBack.upSelectCount() } onClick { checkbox.isChecked = !checkbox.isChecked if (checkbox.isChecked) { - selectedBooks.add(item.bookUrl) + selectedBooks.add(item) } else { - selectedBooks.remove(item.bookUrl) + selectedBooks.remove(item) } callBack.upSelectCount() } tv_delete.onClick { - callBack.deleteBook(item.bookUrl) + callBack.deleteBook(item) } tv_group.onClick { callBack.selectGroup() @@ -81,7 +81,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : interface CallBack { val groupList: List fun upSelectCount() - fun deleteBook(bookUrl: String) + fun deleteBook(book: Book) fun selectGroup() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt index 76e890886..c7e571447 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt @@ -1,14 +1,18 @@ package io.legado.app.ui.book.arrange import android.app.Application +import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.Book class ArrangeBookViewModel(application: Application) : BaseViewModel(application) { - fun deleteBook(vararg bookUrl: String) { - + fun deleteBook(vararg book: Book) { + execute { + App.db.bookDao().delete() + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 0a54aaeac..d7ff22277 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -137,7 +137,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { execute { if (inBookshelf) { bookData.value?.let { - App.db.bookDao().delete(it.bookUrl) + App.db.bookDao().delete(it) } App.db.bookDao().insert(book) } @@ -202,7 +202,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun delBook(success: (() -> Unit)?) { execute { bookData.value?.let { - App.db.bookDao().delete(it.bookUrl) + App.db.bookDao().delete(it) } inBookshelf = false }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index bb4ef95f0..ed5d9d04d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -128,7 +128,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun changeTo(book1: Book) { execute { ReadBook.book?.let { - App.db.bookDao().delete(it.bookUrl) + App.db.bookDao().delete(it) } ReadBook.prevTextChapter = null ReadBook.curTextChapter = null @@ -185,7 +185,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun removeFromBookshelf(success: (() -> Unit)?) { execute { ReadBook.book?.let { - App.db.bookDao().delete(it.bookUrl) + App.db.bookDao().delete(it) } }.onSuccess { success?.invoke() From eb54b86187eaeb2ca26e5be061263fc164cecccb Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 20:41:23 +0800 Subject: [PATCH 418/852] =?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/data/dao/BookDao.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 30d275df7..399f79c45 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -65,9 +65,6 @@ interface BookDao { @Delete fun delete(vararg book: Book) - @Query("delete from books where bookUrl = :bookUrl") - fun delete(bookUrl: String) - @Query("update books set durChapterPos = :pos where bookUrl = :bookUrl") fun upProgress(bookUrl: String, pos: Int) } \ No newline at end of file From e62f842635917835170180456df41e5b36a2a612 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 21:34:20 +0800 Subject: [PATCH 419/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceAdapter.kt | 22 ++++++++++---- .../app/ui/book/source/manage/DiffCallBack.kt | 29 +++++++++++++++++-- 2 files changed, 43 insertions(+), 8 deletions(-) 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 8f5c3c9bc..c5660e07d 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 @@ -1,8 +1,10 @@ package io.legado.app.ui.book.source.manage import android.content.Context +import android.os.Bundle import android.view.Menu import android.widget.PopupMenu +import androidx.core.os.bundleOf import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter @@ -22,7 +24,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : getItems().forEach { selected.add(it) } - notifyItemRangeChanged(0, itemCount, 1) + notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) } fun revertSelection() { @@ -33,7 +35,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : selected.add(it) } } - notifyItemRangeChanged(0, itemCount, 1) + notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) } fun getSelection(): LinkedHashSet { @@ -68,7 +70,8 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList) { with(holder.itemView) { - if (payloads.isEmpty()) { + val payload = payloads.getOrNull(0) as? Bundle + if (payload == null) { this.setBackgroundColor(context.backgroundColor) if (item.bookSourceGroup.isNullOrEmpty()) { cb_book_source.text = item.bookSourceName @@ -104,8 +107,17 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : popupMenu.show() } } else { - when (payloads[0]) { - 1 -> cb_book_source.isChecked = selected.contains(item) + payload.keySet().map { + when (it) { + "select" -> cb_book_source.isChecked = selected.contains(item) + "name", "group" -> if (item.bookSourceGroup.isNullOrEmpty()) { + cb_book_source.text = item.bookSourceName + } else { + cb_book_source.text = + String.format("%s (%s)", item.bookSourceName, item.bookSourceGroup) + } + "enabled" -> swt_enabled.isChecked = payload.getBoolean(it) + } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt index 6eb02037a..da0d1292e 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/DiffCallBack.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.source.manage +import android.os.Bundle import androidx.recyclerview.widget.DiffUtil import io.legado.app.data.entities.BookSource @@ -25,9 +26,31 @@ class DiffCallBack( override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - return oldItem.bookSourceName == newItem.bookSourceName - && oldItem.bookSourceGroup == newItem.bookSourceGroup - && oldItem.enabled == newItem.enabled + if (oldItem.bookSourceName != newItem.bookSourceName) + return false + if (oldItem.bookSourceGroup != newItem.bookSourceGroup) + return false + if (oldItem.enabled != newItem.enabled) + return false + return true } + override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + val payload = Bundle() + if (oldItem.bookSourceName != newItem.bookSourceName) { + payload.putString("name", newItem.bookSourceName) + } + if (oldItem.bookSourceGroup != newItem.bookSourceGroup) { + payload.putString("group", newItem.bookSourceGroup) + } + if (oldItem.enabled != newItem.enabled) { + payload.putBoolean("enabled", newItem.enabled) + } + if (payload.isEmpty) { + return null + } + return payload + } } \ No newline at end of file From 30d61c61c9abbf43f7716b2a746082390e1c5679 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 22:05:44 +0800 Subject: [PATCH 420/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceActivity.kt | 2 +- .../book/source/manage/BookSourceAdapter.kt | 2 +- .../legado/app/ui/replacerule/DiffCallBack.kt | 32 ++++++++++++++----- .../app/ui/replacerule/ReplaceRuleActivity.kt | 3 +- .../app/ui/replacerule/ReplaceRuleAdapter.kt | 24 ++++++++++---- 5 files changed, 46 insertions(+), 17 deletions(-) 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 4f9fea1df..c38b549bb 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 @@ -151,7 +151,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity bookSourceLiveDate?.observe(this, Observer { search_view.queryHint = getString(R.string.search_book_source_num, it.size) val diffResult = DiffUtil - .calculateDiff(DiffCallBack(adapter.getItems(), it)) + .calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it, false) diffResult.dispatchUpdatesTo(adapter) }) 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 c5660e07d..3413cdd0e 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 @@ -109,7 +109,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } else { payload.keySet().map { when (it) { - "select" -> cb_book_source.isChecked = selected.contains(item) + "selected" -> cb_book_source.isChecked = selected.contains(item) "name", "group" -> if (item.bookSourceGroup.isNullOrEmpty()) { cb_book_source.text = item.bookSourceName } else { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/replacerule/DiffCallBack.kt index 1824313b3..62fe0cec3 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/DiffCallBack.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.replacerule +import android.os.Bundle import androidx.recyclerview.widget.DiffUtil import io.legado.app.data.entities.ReplaceRule @@ -24,19 +25,34 @@ class DiffCallBack( override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - return oldItem.name == newItem.name - && oldItem.group == newItem.group - && oldItem.isEnabled == newItem.isEnabled + if (oldItem.name != newItem.name) { + return false + } + if (oldItem.group != newItem.group) { + return false + } + if (oldItem.isEnabled != newItem.isEnabled) { + return false + } + return true } override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - return when { - oldItem.name == newItem.name - && oldItem.group == newItem.group - && oldItem.isEnabled != newItem.isEnabled -> 2 - else -> null + val payload = Bundle() + if (oldItem.name != newItem.name) { + payload.putString("name", newItem.name) + } + if (oldItem.group != newItem.group) { + payload.putString("group", newItem.group) + } + if (oldItem.isEnabled != newItem.isEnabled) { + payload.putBoolean("enabled", newItem.isEnabled) + } + if (payload.isEmpty) { + return null } + return payload } } \ No newline at end of file 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 5c53e91e1..db37febd7 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 @@ -127,7 +127,8 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi if (dataInit) { setResult(Activity.RESULT_OK) } - val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), it)) + val diffResult = + DiffUtil.calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it, false) diffResult.dispatchUpdatesTo(adapter) dataInit = true 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 49f01a828..ece158dd9 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 @@ -1,8 +1,10 @@ package io.legado.app.ui.replacerule import android.content.Context +import android.os.Bundle import android.view.Menu import android.widget.PopupMenu +import androidx.core.os.bundleOf import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter @@ -23,7 +25,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : getItems().forEach { selectedIds.add(it.id) } - notifyItemRangeChanged(0, itemCount, 1) + notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) } fun revertSelection() { @@ -34,7 +36,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : selectedIds.add(it.id) } } - notifyItemRangeChanged(0, itemCount, 1) + notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) } fun getSelectionIds(): LinkedHashSet { @@ -49,7 +51,8 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : override fun convert(holder: ItemViewHolder, item: ReplaceRule, payloads: MutableList) { with(holder.itemView) { - if (payloads.isEmpty()) { + val bundle = payloads.getOrNull(0) as? Bundle + if (bundle == null) { this.setBackgroundColor(context.backgroundColor) if (item.group.isNullOrEmpty()) { cb_name.text = item.name @@ -87,9 +90,18 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : popupMenu.show() } } else { - when (payloads[0]) { - 1 -> cb_name.isChecked = selectedIds.contains(item.id) - 2 -> swt_enabled.isChecked = item.isEnabled + bundle.keySet().map { + when (it) { + "name", "group" -> + if (item.group.isNullOrEmpty()) { + cb_name.text = item.name + } else { + cb_name.text = + String.format("%s (%s)", item.name, item.group) + } + "enabled" -> swt_enabled.isChecked = item.isEnabled + "selected" -> cb_name.isChecked = selectedIds.contains(item.id) + } } } } From 78988d72e8aca353938924646321d7bb975f74e8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 22:07:14 +0800 Subject: [PATCH 421/852] =?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/replacerule/ReplaceRuleAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ece158dd9..5fc617f38 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 @@ -92,6 +92,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } else { bundle.keySet().map { when (it) { + "selected" -> cb_name.isChecked = selectedIds.contains(item.id) "name", "group" -> if (item.group.isNullOrEmpty()) { cb_name.text = item.name @@ -100,7 +101,6 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : String.format("%s (%s)", item.name, item.group) } "enabled" -> swt_enabled.isChecked = item.isEnabled - "selected" -> cb_name.isChecked = selectedIds.contains(item.id) } } } From 11182403f53ee4a2941c28f958d75be5c506d562 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 22:11:21 +0800 Subject: [PATCH 422/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/ReplaceRule.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt index 269325e5d..8744ce2cb 100644 --- a/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt @@ -24,4 +24,17 @@ data class ReplaceRule( var isRegex: Boolean = true, @ColumnInfo(name = "sortOrder") var order: Int = 0 -) : Parcelable \ No newline at end of file +) : Parcelable { + + + override fun equals(other: Any?): Boolean { + if (other is ReplaceRule) { + return other.id == id + } + return super.equals(other) + } + + override fun hashCode(): Int { + return id.hashCode() + } +} \ No newline at end of file From 4840b7913983eb97d430bf38c527ce9a8c4d13f1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 22:30:12 +0800 Subject: [PATCH 423/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceViewModel.kt | 20 ++++++----- .../app/ui/replacerule/ReplaceRuleActivity.kt | 8 ++--- .../app/ui/replacerule/ReplaceRuleAdapter.kt | 26 +++++++------- .../ui/replacerule/ReplaceRuleViewModel.kt | 34 +++++++++++-------- 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 9bbaccfb9..58618d88c 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -45,37 +45,41 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun enableSelection(sources: LinkedHashSet) { execute { - sources.forEach { + val list = ArrayList(sources) + list.forEach { it.enabled = true } - App.db.bookSourceDao().update(*sources.toTypedArray()) + App.db.bookSourceDao().update(*list.toTypedArray()) } } fun disableSelection(sources: LinkedHashSet) { execute { - sources.forEach { + val list = ArrayList(sources) + list.forEach { it.enabled = false } - App.db.bookSourceDao().update(*sources.toTypedArray()) + App.db.bookSourceDao().update(*list.toTypedArray()) } } fun enableSelectExplore(sources: LinkedHashSet) { execute { - sources.forEach { + val list = ArrayList(sources) + list.forEach { it.enabledExplore = true } - App.db.bookSourceDao().update(*sources.toTypedArray()) + App.db.bookSourceDao().update(*list.toTypedArray()) } } fun disableSelectExplore(sources: LinkedHashSet) { execute { - sources.forEach { + val list = ArrayList(sources) + list.forEach { it.enabledExplore = false } - App.db.bookSourceDao().update(*sources.toTypedArray()) + App.db.bookSourceDao().update(*list.toTypedArray()) } } 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 db37febd7..bb2335128 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 @@ -80,12 +80,12 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi GroupManageDialog().show(supportFragmentManager, "groupManage") R.id.menu_select_all -> adapter.selectAll() R.id.menu_revert_selection -> adapter.revertSelection() - R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds()) - R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) - R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) + R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) + R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) + R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_local -> selectFileSys() - R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) + R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) } return super.onCompatOptionsItemSelected(item) } 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 5fc617f38..f25c0e523 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 @@ -19,31 +19,31 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_replace_rule), ItemTouchCallback.OnItemTouchCallbackListener { - private val selectedIds = linkedSetOf() + private val selected = linkedSetOf() fun selectAll() { getItems().forEach { - selectedIds.add(it.id) + selected.add(it) } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) } fun revertSelection() { getItems().forEach { - if (selectedIds.contains(it.id)) { - selectedIds.remove(it.id) + if (selected.contains(it)) { + selected.remove(it) } else { - selectedIds.add(it.id) + selected.add(it) } } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) } - fun getSelectionIds(): LinkedHashSet { - val selection = linkedSetOf() + fun getSelection(): LinkedHashSet { + val selection = linkedSetOf() getItems().map { - if (selectedIds.contains(it.id)) { - selection.add(it.id) + if (selected.contains(it)) { + selection.add(it) } } return selection @@ -68,12 +68,12 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : iv_edit.onClick { callBack.edit(item) } - cb_name.isChecked = selectedIds.contains(item.id) + cb_name.isChecked = selected.contains(item) cb_name.onClick { if (cb_name.isChecked) { - selectedIds.add(item.id) + selected.add(item) } else { - selectedIds.remove(item.id) + selected.remove(item) } } iv_menu_more.onClick { @@ -92,7 +92,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } else { bundle.keySet().map { when (it) { - "selected" -> cb_name.isChecked = selectedIds.contains(item.id) + "selected" -> cb_name.isChecked = selected.contains(item) "name", "group" -> if (item.group.isNullOrEmpty()) { cb_name.text = item.name diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index f8c9dda24..6390d69e7 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -63,34 +63,38 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application } } - fun enableSelection(ids: LinkedHashSet) { + fun enableSelection(rules: LinkedHashSet) { execute { - App.db.replaceRuleDao().enableSection(*ids.toLongArray()) + val list = ArrayList(rules) + list.forEach { + it.isEnabled = true + } + App.db.replaceRuleDao().update(*list.toTypedArray()) } } - fun disableSelection(ids: LinkedHashSet) { + fun disableSelection(rules: LinkedHashSet) { execute { - App.db.replaceRuleDao().disableSection(*ids.toLongArray()) + val list = ArrayList(rules) + list.forEach { + it.isEnabled = false + } + App.db.replaceRuleDao().update(*list.toTypedArray()) } } - fun delSelection(ids: LinkedHashSet) { + fun delSelection(rules: LinkedHashSet) { execute { - App.db.replaceRuleDao().delSection(*ids.toLongArray()) + App.db.replaceRuleDao().delete(*rules.toTypedArray()) } } - fun exportSelection(ids: LinkedHashSet) { + fun exportSelection(rules: LinkedHashSet) { execute { - ids.map { - App.db.replaceRuleDao().findById(it) - }.let { - val json = GSON.toJson(it) - val file = - FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportReplaceRule.json") - file.writeText(json) - } + val json = GSON.toJson(rules) + val file = + FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportReplaceRule.json") + file.writeText(json) }.onSuccess { context.toast("成功导出至\n${Backup.exportPath}") }.onError { From 51bf5f8bdaa661a35a95ce731b793b2af7b35a9f Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 22:53:44 +0800 Subject: [PATCH 424/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceViewModel.kt | 24 +++++++++---------- .../ui/replacerule/ReplaceRuleViewModel.kt | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 58618d88c..ec5c50020 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -45,9 +45,9 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun enableSelection(sources: LinkedHashSet) { execute { - val list = ArrayList(sources) - list.forEach { - it.enabled = true + val list = arrayListOf() + sources.forEach { + list.add(it.copy(enabled = true)) } App.db.bookSourceDao().update(*list.toTypedArray()) } @@ -55,9 +55,9 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun disableSelection(sources: LinkedHashSet) { execute { - val list = ArrayList(sources) - list.forEach { - it.enabled = false + val list = arrayListOf() + sources.forEach { + list.add(it.copy(enabled = false)) } App.db.bookSourceDao().update(*list.toTypedArray()) } @@ -65,9 +65,9 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun enableSelectExplore(sources: LinkedHashSet) { execute { - val list = ArrayList(sources) - list.forEach { - it.enabledExplore = true + val list = arrayListOf() + sources.forEach { + list.add(it.copy(enabledExplore = true)) } App.db.bookSourceDao().update(*list.toTypedArray()) } @@ -75,9 +75,9 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) fun disableSelectExplore(sources: LinkedHashSet) { execute { - val list = ArrayList(sources) - list.forEach { - it.enabledExplore = false + val list = arrayListOf() + sources.forEach { + list.add(it.copy(enabledExplore = false)) } App.db.bookSourceDao().update(*list.toTypedArray()) } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 6390d69e7..c54f126d8 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -65,9 +65,9 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application fun enableSelection(rules: LinkedHashSet) { execute { - val list = ArrayList(rules) - list.forEach { - it.isEnabled = true + val list = arrayListOf() + rules.forEach { + list.add(it.copy(isEnabled = true)) } App.db.replaceRuleDao().update(*list.toTypedArray()) } @@ -75,9 +75,9 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application fun disableSelection(rules: LinkedHashSet) { execute { - val list = ArrayList(rules) - list.forEach { - it.isEnabled = false + val list = arrayListOf() + rules.forEach { + list.add(it.copy(isEnabled = false)) } App.db.replaceRuleDao().update(*list.toTypedArray()) } From ff1c9979d65cdc5da57c63902be84a652e800d73 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 22:55:52 +0800 Subject: [PATCH 425/852] =?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/data/dao/ReplaceRuleDao.kt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt index 5940272af..e57a2251b 100644 --- a/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt @@ -32,15 +32,6 @@ interface ReplaceRuleDao { @Query("SELECT * FROM replace_rules WHERE id in (:ids)") fun findByIds(vararg ids: Long): List - @Query("update replace_rules set isEnabled = 1 where id in (:ids)") - fun enableSection(vararg ids: Long) - - @Query("update replace_rules set isEnabled = 0 where id in (:ids)") - fun disableSection(vararg ids: Long) - - @Query("delete from replace_rules where id in (:ids)") - fun delSection(vararg ids: Long) - @Query( """SELECT * FROM replace_rules WHERE isEnabled = 1 AND (scope LIKE '%' || :scope || '%' or scope = null or scope = '')""" From aa49a88b76ebfb3d7844ba9bfe1ced6cd0ce367e Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 22:59:06 +0800 Subject: [PATCH 426/852] =?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/data/entities/Book.kt | 11 +++++++++++ .../app/ui/book/arrange/ArrangeBookViewModel.kt | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 204d2de7a..b7ecf828a 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -57,6 +57,17 @@ data class Book( return isLocalBook() && originName.endsWith(".txt", true) } + override fun equals(other: Any?): Boolean { + if (other is Book) { + return other.bookUrl == bookUrl + } + return false + } + + override fun hashCode(): Int { + return bookUrl.hashCode() + } + @Ignore @IgnoredOnParcel override var variableMap: HashMap? = null diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt index c7e571447..173678b15 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt @@ -11,7 +11,7 @@ class ArrangeBookViewModel(application: Application) : BaseViewModel(application fun deleteBook(vararg book: Book) { execute { - App.db.bookDao().delete() + App.db.bookDao().delete(*book) } } From 64cb64dc6eaeb3d4e003e100334cad568f77e5e6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 23:20:50 +0800 Subject: [PATCH 427/852] =?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/bookshelf/books/BaseBooksAdapter.kt | 3 +- .../main/bookshelf/books/BooksAdapterList.kt | 15 ++++-- .../main/bookshelf/books/BooksDiffCallBack.kt | 47 ++++++++++++++++--- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt index 9103d3c3c..1e8fda88b 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BaseBooksAdapter.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.main.bookshelf.books import android.content.Context +import androidx.core.os.bundleOf import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book @@ -11,7 +12,7 @@ abstract class BaseBooksAdapter(context: Context, layoutId: Int) : for (i in 0 until itemCount) { getItem(i)?.let { if (it.bookUrl == bookUrl) { - notifyItemChanged(i, 5) + notifyItemChanged(i, bundleOf(Pair("refresh", null))) return } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt index b35d6fd21..1c500a786 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.main.bookshelf.books import android.content.Context +import android.os.Bundle import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.constant.BookType @@ -15,8 +16,9 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : BaseBooksAdapter(context, R.layout.item_bookshelf_list) { override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) { + val bundle = payloads.getOrNull(0) as? Bundle with(holder.itemView) { - if (payloads.isEmpty()) { + if (bundle == null) { ATH.applyBackgroundTint(this) tv_name.text = item.name tv_author.text = item.author @@ -37,9 +39,14 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : bv_unread.setHighlight(item.lastCheckCount > 0) } } else { - when (payloads[0]) { - 5 -> { - if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) { + bundle.keySet().map { + when (it) { + "name" -> tv_name.text = item.name + "author" -> tv_author.text = item.author + "durTitle" -> tv_read.text = item.durChapterTitle + "latestTitle" -> tv_last.text = item.latestChapterTitle + "cover" -> iv_cover.load(item.getDisplayCover(), item.name, item.author) + "refresh" -> if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) { bv_unread.invisible() rl_loading.show() } else { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt index fc4358f5e..481411bba 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.main.bookshelf.books +import androidx.core.os.bundleOf import androidx.recyclerview.widget.DiffUtil import io.legado.app.data.entities.Book @@ -22,13 +23,45 @@ class BooksDiffCallBack(private val oldItems: List, private val newItems: override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - return oldItem.name == newItem.name - && oldItem.author == newItem.author - && oldItem.durChapterTitle == newItem.durChapterTitle - && oldItem.latestChapterTitle == newItem.latestChapterTitle - && oldItem.getDisplayCover() == newItem.getDisplayCover() - && oldItem.getUnreadChapterNum() == newItem.getUnreadChapterNum() - && oldItem.lastCheckCount == newItem.lastCheckCount + if (oldItem.name != newItem.name) + return false + if (oldItem.author != newItem.author) + return false + if (oldItem.durChapterTitle != newItem.durChapterTitle) + return false + if (oldItem.latestChapterTitle != newItem.latestChapterTitle) + return false + if (oldItem.lastCheckCount != newItem.lastCheckCount) + return false + if (oldItem.getDisplayCover() != newItem.getDisplayCover()) + return false + if (oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum()) + return false + return true + } + + override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + val bundle = bundleOf() + if (oldItem.name != newItem.name) + bundle.putString("name", null) + if (oldItem.author != newItem.author) + bundle.putString("author", null) + if (oldItem.durChapterTitle != newItem.durChapterTitle) + bundle.putString("durTitle", null) + if (oldItem.latestChapterTitle != newItem.latestChapterTitle) + bundle.putString("latestTitle", null) + if (oldItem.getDisplayCover() != newItem.getDisplayCover()) + bundle.putString("cover", null) + if (oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum() + || oldItem.lastCheckCount != newItem.lastCheckCount + ) + bundle.putString("refresh", null) + if (bundle.isEmpty) { + return null + } + return bundle } } \ No newline at end of file From 4f3239779f47588e4f92a1c6b0c9bfa4b987fd7e Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Feb 2020 23:21:41 +0800 Subject: [PATCH 428/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt index 481411bba..9f7afd8bb 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt @@ -56,8 +56,10 @@ class BooksDiffCallBack(private val oldItems: List, private val newItems: bundle.putString("cover", null) if (oldItem.getUnreadChapterNum() != newItem.getUnreadChapterNum() || oldItem.lastCheckCount != newItem.lastCheckCount - ) + ) { bundle.putString("refresh", null) + } + if (bundle.isEmpty) { return null } From 96b3846313137ed0c9302be0805bb8d0789c8f12 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 09:24:23 +0800 Subject: [PATCH 429/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/search/DiffCallBack.kt | 49 ++++-- .../app/ui/book/search/SearchAdapter.kt | 156 ++++++++---------- 2 files changed, 103 insertions(+), 102 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt index 37158ea5b..a4467c1f7 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt @@ -3,21 +3,48 @@ package io.legado.app.ui.book.search import androidx.recyclerview.widget.DiffUtil import io.legado.app.data.entities.SearchBook -class DiffCallBack : DiffUtil.ItemCallback() { - override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { - return oldItem.name == newItem.name - && oldItem.author == newItem.author +class DiffCallBack(private val oldItems: List, private val newItems: List) : + DiffUtil.Callback() { + + override fun getNewListSize(): Int { + return newItems.size + } + + override fun getOldListSize(): Int { + return oldItems.size } - override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean { - return oldItem.origins?.size == newItem.origins?.size - && (oldItem.coverUrl == newItem.coverUrl || !oldItem.coverUrl.isNullOrEmpty()) - && (oldItem.kind == newItem.kind || !oldItem.kind.isNullOrEmpty()) - && (oldItem.latestChapterTitle == newItem.latestChapterTitle || !oldItem.kind.isNullOrEmpty()) - && oldItem.intro?.length ?: 0 > newItem.intro?.length ?: 0 + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return true + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + if (oldItem.name != newItem.name) { + return false + } + if (oldItem.author != newItem.author) { + return false + } + if (oldItem.kind != newItem.kind) { + return false + } + if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { + return false + } + if (oldItem.intro != newItem.intro) { + return false + } + if (oldItem.coverUrl != newItem.coverUrl) { + return false + } + return true } - override fun getChangePayload(oldItem: SearchBook, newItem: SearchBook): Any? { + override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] return when { oldItem.origins?.size != newItem.origins?.size -> 1 oldItem.coverUrl != newItem.coverUrl -> 2 diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 4a725e854..c95f5eb7e 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -1,12 +1,12 @@ package io.legado.app.ui.book.search import android.content.Context +import android.os.Bundle import android.view.View 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.SearchBook -import io.legado.app.help.ImageLoader import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_bookshelf_list.view.iv_cover @@ -18,10 +18,11 @@ class SearchAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_search) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { - if (payloads.isEmpty()) { + val bundle = payloads.getOrNull(0) as? Bundle + if (bundle == null) { bind(holder.itemView, item) } else { - bindChange(holder.itemView, item, payloads) + bindChange(holder.itemView, item, bundle) } } @@ -30,43 +31,9 @@ class SearchAdapter(context: Context, val callBack: CallBack) : tv_name.text = searchBook.name tv_author.text = context.getString(R.string.author_show, searchBook.author) bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) - if (searchBook.latestChapterTitle.isNullOrEmpty()) { - tv_lasted.gone() - } else { - tv_lasted.text = context.getString(R.string.lasted_show, searchBook.latestChapterTitle) - tv_lasted.visible() - } + upLasted(itemView, searchBook.latestChapterTitle) tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) - val kinds = searchBook.getKindList() - if (kinds.isEmpty()) { - ll_kind.gone() - } else { - ll_kind.visible() - for (index in 0..2) { - if (kinds.size > index) { - when (index) { - 0 -> { - tv_kind.text = kinds[index] - tv_kind.visible() - } - 1 -> { - tv_kind_1.text = kinds[index] - tv_kind_1.visible() - } - 2 -> { - tv_kind_2.text = kinds[index] - tv_kind_2.visible() - } - } - } else { - when (index) { - 0 -> tv_kind.gone() - 1 -> tv_kind_1.gone() - 2 -> tv_kind_2.gone() - } - } - } - } + upKind(itemView, searchBook.getKindList()) iv_cover.load(searchBook.coverUrl, searchBook.name, searchBook.author) onClick { callBack.showBookInfo(searchBook.name, searchBook.author) @@ -74,64 +41,71 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } } - private fun bindChange(itemView: View, searchBook: SearchBook, payloads: MutableList) { + private fun bindChange(itemView: View, searchBook: SearchBook, bundle: Bundle) { with(itemView) { - when (payloads[0]) { - 1 -> bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) - 2 -> searchBook.coverUrl.let { - ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.image_cover_default) - .error(R.drawable.image_cover_default) - .centerCrop() - .into(iv_cover) + bundle.keySet().map { + when (it) { + "name" -> tv_name.text = searchBook.name + "author" -> tv_author.text = + context.getString(R.string.author_show, searchBook.author) + "originCount" -> bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) + "lasted" -> upLasted(itemView, searchBook.latestChapterTitle) + "introduce" -> tv_introduce.text = + context.getString(R.string.intro_show, searchBook.intro) + "kind" -> upKind(itemView, searchBook.getKindList()) + "cover" -> iv_cover.load( + searchBook.coverUrl, + searchBook.name, + searchBook.author + ) } - 3 -> { - val kinds = searchBook.getKindList() - if (kinds.isEmpty()) { - ll_kind.gone() - } else { - ll_kind.visible() - for (index in 0..2) { - if (kinds.size > index) { - when (index) { - 0 -> { - tv_kind.text = kinds[index] - tv_kind.visible() - } - 1 -> { - tv_kind_1.text = kinds[index] - tv_kind_1.visible() - } - 2 -> { - tv_kind_2.text = kinds[index] - tv_kind_2.visible() - } - } - } else { - when (index) { - 0 -> tv_kind.gone() - 1 -> tv_kind_1.gone() - 2 -> tv_kind_2.gone() - } - } + } + } + } + + private fun upLasted(itemView: View, latestChapterTitle: String?) { + with(itemView) { + if (latestChapterTitle.isNullOrEmpty()) { + tv_lasted.gone() + } else { + tv_lasted.text = + context.getString( + R.string.lasted_show, + latestChapterTitle + ) + tv_lasted.visible() + } + } + } + + private fun upKind(itemView: View, kinds: List) = with(itemView) { + if (kinds.isEmpty()) { + ll_kind.gone() + } else { + ll_kind.visible() + for (index in 0..2) { + if (kinds.size > index) { + when (index) { + 0 -> { + tv_kind.text = kinds[index] + tv_kind.visible() + } + 1 -> { + tv_kind_1.text = kinds[index] + tv_kind_1.visible() + } + 2 -> { + tv_kind_2.text = kinds[index] + tv_kind_2.visible() } } - } - 4 -> { - if (searchBook.latestChapterTitle.isNullOrEmpty()) { - tv_lasted.gone() - } else { - tv_lasted.text = context.getString( - R.string.lasted_show, - searchBook.latestChapterTitle - ) - tv_lasted.visible() + } else { + when (index) { + 0 -> tv_kind.gone() + 1 -> tv_kind_1.gone() + 2 -> tv_kind_2.gone() } } - 5 -> tv_introduce.text = - context.getString(R.string.intro_show, searchBook.intro) - else -> { - } } } } From 675aa0cb88850f7cdd9d44ced089c9bbb4f6ab97 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 10:12:47 +0800 Subject: [PATCH 430/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/ToTopListUpCallback.kt | 34 +++++++++++++++++++ .../ui/main/bookshelf/books/BooksFragment.kt | 6 +++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/legado/app/help/ToTopListUpCallback.kt diff --git a/app/src/main/java/io/legado/app/help/ToTopListUpCallback.kt b/app/src/main/java/io/legado/app/help/ToTopListUpCallback.kt new file mode 100644 index 000000000..6fdef3dca --- /dev/null +++ b/app/src/main/java/io/legado/app/help/ToTopListUpCallback.kt @@ -0,0 +1,34 @@ +package io.legado.app.help + +import androidx.recyclerview.widget.ListUpdateCallback +import androidx.recyclerview.widget.RecyclerView +import io.legado.app.base.adapter.ItemViewHolder + +class ToTopListUpCallback : ListUpdateCallback { + var firstInsert = -1 + lateinit var adapter: RecyclerView.Adapter + + override fun onChanged(position: Int, count: Int, payload: Any?) { + adapter.notifyItemRangeChanged(position, count, payload) + } + + override fun onMoved(fromPosition: Int, toPosition: Int) { + if (toPosition == 0) { + firstInsert = 0 + } + adapter.notifyItemMoved(fromPosition, toPosition) + } + + override fun onInserted(position: Int, count: Int) { + if (firstInsert == -1 || firstInsert > position) { + firstInsert = position + } + adapter.notifyItemRangeInserted(position, count) + } + + override fun onRemoved(position: Int, count: Int) { + adapter.notifyItemRangeRemoved(position, count) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index d7ffd7a34..496792c62 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -15,6 +15,7 @@ import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.help.IntentDataHelp +import io.legado.app.help.ToTopListUpCallback import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.audio.AudioPlayActivity @@ -88,6 +89,8 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), else -> App.db.bookDao().observeByGroup(groupId) } bookshelfLiveData?.observe(this, Observer { + val listUpCallback = ToTopListUpCallback() + listUpCallback.adapter = booksAdapter val diffResult = DiffUtil.calculateDiff( BooksDiffCallBack( @@ -96,7 +99,8 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), ) ) booksAdapter.setItems(it, false) - diffResult.dispatchUpdatesTo(booksAdapter) + diffResult.dispatchUpdatesTo(listUpCallback) + rv_bookshelf.scrollToPosition(listUpCallback.firstInsert) }) } From d8c518281b4b712bf84e6da7e2d428206e3334c8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 10:20:46 +0800 Subject: [PATCH 431/852] =?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/main/bookshelf/books/BooksFragment.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 496792c62..3c9f99b21 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseFragment @@ -15,7 +16,6 @@ import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.help.IntentDataHelp -import io.legado.app.help.ToTopListUpCallback import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.audio.AudioPlayActivity @@ -78,6 +78,21 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), booksAdapter = BooksAdapterGrid(requireContext(),this) } rv_bookshelf.adapter = booksAdapter + booksAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { + override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { + super.onItemRangeInserted(positionStart, itemCount) + if (positionStart == 0) { + rv_bookshelf.scrollToPosition(0) + } + } + + override fun onItemRangeMoved(fromPosition: Int, toPosition: Int, itemCount: Int) { + super.onItemRangeMoved(fromPosition, toPosition, itemCount) + if (toPosition == 0) { + rv_bookshelf.scrollToPosition(0) + } + } + }) } private fun upRecyclerData() { @@ -89,8 +104,6 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), else -> App.db.bookDao().observeByGroup(groupId) } bookshelfLiveData?.observe(this, Observer { - val listUpCallback = ToTopListUpCallback() - listUpCallback.adapter = booksAdapter val diffResult = DiffUtil.calculateDiff( BooksDiffCallBack( @@ -99,8 +112,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), ) ) booksAdapter.setItems(it, false) - diffResult.dispatchUpdatesTo(listUpCallback) - rv_bookshelf.scrollToPosition(listUpCallback.firstInsert) + diffResult.dispatchUpdatesTo(booksAdapter) }) } From 73f3af16062c93aab6c5e3bd0c79bf0b1e416cb6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 10:38:15 +0800 Subject: [PATCH 432/852] =?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/bookshelf/books/BooksDiffCallBack.kt | 9 +++-- .../ui/main/bookshelf/books/BooksFragment.kt | 9 ++--- .../ui/main/explore/ExploreDiffCallBack.kt | 34 +++++++++++++++++++ .../app/ui/main/explore/ExploreFragment.kt | 14 ++++++++ 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffCallBack.kt diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt index 9f7afd8bb..40ceecf40 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksDiffCallBack.kt @@ -7,11 +7,6 @@ import io.legado.app.data.entities.Book class BooksDiffCallBack(private val oldItems: List, private val newItems: List) : DiffUtil.Callback() { - - override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return oldItems[oldItemPosition].bookUrl == newItems[newItemPosition].bookUrl - } - override fun getOldListSize(): Int { return oldItems.size } @@ -20,6 +15,10 @@ class BooksDiffCallBack(private val oldItems: List, private val newItems: return newItems.size } + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return oldItems[oldItemPosition].bookUrl == newItems[newItemPosition].bookUrl + } + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 3c9f99b21..cc62f2cb1 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -104,13 +104,8 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), else -> App.db.bookDao().observeByGroup(groupId) } bookshelfLiveData?.observe(this, Observer { - val diffResult = - DiffUtil.calculateDiff( - BooksDiffCallBack( - booksAdapter.getItems(), - it - ) - ) + val diffResult = DiffUtil + .calculateDiff(BooksDiffCallBack(ArrayList(booksAdapter.getItems()), it)) booksAdapter.setItems(it, false) diffResult.dispatchUpdatesTo(booksAdapter) }) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffCallBack.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffCallBack.kt new file mode 100644 index 000000000..7f3c7d020 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreDiffCallBack.kt @@ -0,0 +1,34 @@ +package io.legado.app.ui.main.explore + +import androidx.recyclerview.widget.DiffUtil +import io.legado.app.data.entities.BookSource + + +class ExploreDiffCallBack( + private val oldItems: List, + private val newItems: List +) : + DiffUtil.Callback() { + + override fun getOldListSize(): Int { + return oldItems.size + } + + override fun getNewListSize(): Int { + return newItems.size + } + + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return true + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + if (oldItem.bookSourceName != newItem.bookSourceName) { + return false + } + return true + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index ea23c0909..80fb39212 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -5,7 +5,9 @@ import android.view.View import androidx.appcompat.widget.SearchView import androidx.lifecycle.LiveData import androidx.lifecycle.Observer +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment @@ -61,6 +63,15 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ rv_find.layoutManager = linearLayoutManager adapter = ExploreAdapter(requireContext(), this, this) rv_find.adapter = adapter + adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { + + override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { + super.onItemRangeInserted(positionStart, itemCount) + if (positionStart == 0) { + rv_find.scrollToPosition(0) + } + } + }) } private fun initData(key: String? = null) { @@ -71,7 +82,10 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ App.db.bookSourceDao().liveExplore("%$key%") } liveExplore?.observe(viewLifecycleOwner, Observer { + val diffResult = DiffUtil + .calculateDiff(ExploreDiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it) + diffResult.dispatchUpdatesTo(adapter) }) } From dbee2f6c0480ad3f860f6100a3149e1913f64c84 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 10:47:34 +0800 Subject: [PATCH 433/852] =?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/assets/updateLog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 50ee128dc..dac73cd09 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,11 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/07** +* 优化 +* 书源校验 +* 书架整理 + **2020/02/05** * 修复bug * Rss收藏功能完成 From 586130c2fe5679ebea8b5c567f66dd1a104e137a Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 10:57:22 +0800 Subject: [PATCH 434/852] =?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/ui/book/group/GroupSelectDialog.kt | 21 ++++++++++++------- .../app/ui/book/info/BookInfoActivity.kt | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) 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 6dbdbd17b..86fc619e3 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 @@ -42,15 +42,17 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { companion object { const val tag = "groupSelectDialog" - fun show(manager: FragmentManager) { - val fragment = GroupSelectDialog() - fragment.show( - manager, - tag - ) + fun show(manager: FragmentManager, requestCode: Int = -1) { + val fragment = GroupSelectDialog().apply { + val bundle = Bundle() + bundle.putInt("requestCode", requestCode) + arguments = bundle + } + fragment.show(manager, tag) } } + private var requestCode: Int = -1 private lateinit var viewModel: BookshelfViewModel private lateinit var adapter: GroupAdapter private var callBack: CallBack? = null @@ -74,6 +76,9 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) callBack = activity as? CallBack + arguments?.getInt("requestCode")?.let { + requestCode = it + } initData() } @@ -157,7 +162,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tv_edit.onClick { editGroup(item) } tv_del.onClick { viewModel.delGroup(item) } this.onClick { - callBack?.upGroup(item) + callBack?.upGroup(requestCode, item) dismiss() } } @@ -181,6 +186,6 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } interface CallBack { - fun upGroup(group: BookGroup) + fun upGroup(requestCode: Int, group: BookGroup) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index cf86b2f04..9efde78b9 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -306,7 +306,7 @@ class BookInfoActivity : return viewModel.durChapterIndex } - override fun upGroup(group: BookGroup) { + override fun upGroup(requestCode: Int, group: BookGroup) { viewModel.groupData.postValue(group) viewModel.bookData.value?.group = group.groupId if (viewModel.inBookshelf) { From 079f6ff5aed720fa0575b4db4a21cc4decde4727 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 11:19:16 +0800 Subject: [PATCH 435/852] =?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/arrange/ArrangeBookActivity.kt | 25 ++++++++++++++++--- .../app/ui/book/arrange/ArrangeBookAdapter.kt | 8 +++--- .../ui/book/arrange/ArrangeBookViewModel.kt | 5 ++++ 3 files changed, 32 insertions(+), 6 deletions(-) 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 b6204e90b..ea61cd1d3 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,6 +14,7 @@ import io.legado.app.data.entities.BookGroup import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH +import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_arrange_book.* @@ -22,10 +23,11 @@ import org.jetbrains.anko.toast class ArrangeBookActivity : VMBaseActivity(R.layout.activity_arrange_book), - ArrangeBookAdapter.CallBack { + ArrangeBookAdapter.CallBack, GroupSelectDialog.CallBack { override val viewModel: ArrangeBookViewModel get() = getViewModel(ArrangeBookViewModel::class.java) override val groupList: ArrayList = arrayListOf() + private val groupRequestCode = 22 private lateinit var adapter: ArrangeBookAdapter private var groupLiveData: LiveData>? = null private var booksLiveData: LiveData>? = null @@ -71,7 +73,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi toast(R.string.non_select) return@onClick } - selectGroup() + selectGroup(groupRequestCode) } } @@ -91,8 +93,25 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi }) } - override fun selectGroup() { + override fun selectGroup(requestCode: Int) { + GroupSelectDialog.show(supportFragmentManager, requestCode) + } + override fun upGroup(requestCode: Int, group: BookGroup) { + when (requestCode) { + groupRequestCode -> { + val books = arrayListOf() + adapter.selectedBooks.forEach { + books.add(it.copy(group = group.groupId)) + } + viewModel.updateBook(*books.toTypedArray()) + } + adapter.groupRequestCode -> { + adapter.actionItem?.let { + viewModel.updateBook(it.copy(group = group.groupId)) + } + } + } } override fun upSelectCount() { 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 dab74dc4b..21a3516eb 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 @@ -12,8 +12,9 @@ import org.jetbrains.anko.sdk27.listeners.onClick class ArrangeBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_arrange_book) { - + val groupRequestCode = 12 val selectedBooks: HashSet = hashSetOf() + var actionItem: Book? = null fun isSelectAll(): Boolean { return if (selectedBooks.isEmpty()) { @@ -64,7 +65,8 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : callBack.deleteBook(item) } tv_group.onClick { - callBack.selectGroup() + actionItem = item + callBack.selectGroup(groupRequestCode) } } } @@ -82,6 +84,6 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : val groupList: List fun upSelectCount() fun deleteBook(book: Book) - fun selectGroup() + fun selectGroup(requestCode: Int) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt index 173678b15..4f4972de9 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookViewModel.kt @@ -8,6 +8,11 @@ import io.legado.app.data.entities.Book class ArrangeBookViewModel(application: Application) : BaseViewModel(application) { + fun updateBook(vararg book: Book) { + execute { + App.db.bookDao().update(*book) + } + } fun deleteBook(vararg book: Book) { execute { From 44570d07275e8a8fd990dbd5fc9721b3902a0198 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 11:46:18 +0800 Subject: [PATCH 436/852] =?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/ui/book/arrange/ArrangeBookActivity.kt | 2 ++ .../app/ui/replacerule/ReplaceRuleActivity.kt | 9 +-------- .../io/legado/app/utils/RecyclerViewExtensions.kt | 15 +++++++++++++++ app/src/main/res/layout/item_arrange_book.xml | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/RecyclerViewExtensions.kt 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 ea61cd1d3..509c15bbe 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 @@ -16,6 +16,7 @@ import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.utils.applyTint +import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_arrange_book.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -52,6 +53,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) adapter = ArrangeBookAdapter(this, this) recycler_view.adapter = adapter cb_selected_all.onClick { 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 bb2335128..72446092c 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 @@ -8,11 +8,9 @@ import android.view.Menu import android.view.MenuItem import android.view.SubMenu import androidx.appcompat.widget.SearchView -import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.snackbar.Snackbar @@ -95,12 +93,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi recycler_view.layoutManager = LinearLayoutManager(this) adapter = ReplaceRuleAdapter(this, this) recycler_view.adapter = adapter - recycler_view.addItemDecoration( - DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { - ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { - this.setDrawable(it) - } - }) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) val itemTouchCallback = ItemTouchCallback() itemTouchCallback.onItemTouchCallbackListener = adapter itemTouchCallback.isCanDrag = true diff --git a/app/src/main/java/io/legado/app/utils/RecyclerViewExtensions.kt b/app/src/main/java/io/legado/app/utils/RecyclerViewExtensions.kt new file mode 100644 index 000000000..7dbed87ce --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/RecyclerViewExtensions.kt @@ -0,0 +1,15 @@ +package io.legado.app.utils + +import androidx.core.content.ContextCompat +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.RecyclerView +import io.legado.app.R + + +fun RecyclerView.getVerticalDivider(): DividerItemDecoration { + return DividerItemDecoration(context, DividerItemDecoration.VERTICAL).apply { + ContextCompat.getDrawable(context, R.drawable.ic_divider)?.let { + this.setDrawable(it) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/item_arrange_book.xml b/app/src/main/res/layout/item_arrange_book.xml index ea62f6d4f..f79fda576 100644 --- a/app/src/main/res/layout/item_arrange_book.xml +++ b/app/src/main/res/layout/item_arrange_book.xml @@ -3,7 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + android:padding="6dp"> Date: Fri, 7 Feb 2020 11:52:47 +0800 Subject: [PATCH 437/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/group/GroupManageDialog.kt | 9 +++++---- .../io/legado/app/ui/book/group/GroupSelectDialog.kt | 7 ++----- .../app/ui/book/source/manage/BookSourceActivity.kt | 9 +-------- .../app/ui/book/source/manage/GroupManageDialog.kt | 11 ++--------- .../legado/app/ui/changesource/ChangeSourceDialog.kt | 7 ++----- .../io/legado/app/ui/chapterlist/BookmarkFragment.kt | 10 ++-------- .../legado/app/ui/chapterlist/ChapterListFragment.kt | 10 ++-------- .../io/legado/app/ui/explore/ExploreShowActivity.kt | 4 ++-- .../io/legado/app/ui/filechooser/FileChooserDialog.kt | 9 ++------- .../io/legado/app/ui/replacerule/GroupManageDialog.kt | 11 ++--------- .../legado/app/ui/rss/article/RssArticlesActivity.kt | 10 ++-------- .../app/ui/rss/favorites/RssFavoritesActivity.kt | 10 ++-------- .../app/ui/rss/source/manage/GroupManageDialog.kt | 11 ++--------- .../app/ui/rss/source/manage/RssSourceActivity.kt | 9 +-------- 14 files changed, 29 insertions(+), 98 deletions(-) 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 af3723e11..e9892dae0 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 @@ -12,7 +12,9 @@ import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer -import androidx.recyclerview.widget.* +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ItemTouchHelper +import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -27,6 +29,7 @@ import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.ui.main.bookshelf.BookshelfViewModel import io.legado.app.utils.applyTint +import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import io.legado.app.utils.requestInputMethod import kotlinx.android.synthetic.main.dialog_edit_text.view.* @@ -72,9 +75,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { .isChecked = AppConst.bookGroupAudioShow adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration( - DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) - ) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { val diffResult = 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 86fc619e3..aebbcb603 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 @@ -13,10 +13,8 @@ import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -30,6 +28,7 @@ import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.ui.main.bookshelf.BookshelfViewModel import io.legado.app.utils.applyTint +import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import io.legado.app.utils.requestInputMethod import kotlinx.android.synthetic.main.dialog_edit_text.view.* @@ -91,9 +90,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.menu.findItem(R.id.menu_group_audio).isVisible = false adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration( - DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) - ) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { adapter.setItems(it) 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 c38b549bb..ff1d48987 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 @@ -8,11 +8,9 @@ import android.view.Menu import android.view.MenuItem import android.view.SubMenu import androidx.appcompat.widget.SearchView -import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.snackbar.Snackbar @@ -119,12 +117,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration( - DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { - ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { - this.setDrawable(it) - } - }) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) adapter = BookSourceAdapter(this, this) recycler_view.adapter = adapter val itemTouchCallback = ItemTouchCallback() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 068f6f56f..55cbe6ae0 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -12,9 +12,7 @@ import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -24,10 +22,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModelOfActivity -import io.legado.app.utils.requestInputMethod -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -65,9 +60,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.setOnMenuItemClickListener(this) adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration( - DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) - ) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter App.db.bookSourceDao().liveGroup().observe(viewLifecycleOwner, Observer { val groups = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index c05e171b1..626dce0d6 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -5,16 +5,15 @@ import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.LinearLayout import androidx.appcompat.widget.SearchView import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentManager import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchBook +import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.dialog_change_source.* @@ -89,9 +88,7 @@ class ChangeSourceDialog : DialogFragment(), private fun initRecyclerView() { changeSourceAdapter = ChangeSourceAdapter(requireContext(), this) recycler_view.layoutManager = LinearLayoutManager(context) - recycler_view.addItemDecoration( - DividerItemDecoration(requireContext(), LinearLayout.VERTICAL) - ) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = changeSourceAdapter } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt index 77eaad04f..2febb43fb 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt @@ -4,18 +4,17 @@ import android.app.Activity import android.content.Intent import android.os.Bundle import android.view.View -import android.widget.LinearLayout import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.paging.LivePagedListBuilder import androidx.paging.PagedList -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.data.entities.Bookmark import io.legado.app.lib.theme.ATH +import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModelOfActivity import kotlinx.android.synthetic.main.fragment_bookmark.* @@ -40,12 +39,7 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ ATH.applyEdgeEffectColor(recycler_view) adapter = BookmarkAdapter(this) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration( - DividerItemDecoration( - requireContext(), - LinearLayout.VERTICAL - ) - ) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 2ead9c56d..3f79f6da6 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -4,9 +4,7 @@ import android.app.Activity.RESULT_OK import android.content.Intent import android.os.Bundle import android.view.View -import android.widget.LinearLayout import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment @@ -14,6 +12,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.UpLinearLayoutManager +import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModelOfActivity import kotlinx.android.synthetic.main.fragment_chapter_list.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -40,12 +39,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme adapter = ChapterListAdapter(requireContext(), this) mLayoutManager = UpLinearLayoutManager(requireContext()) recycler_view.layoutManager = mLayoutManager - recycler_view.addItemDecoration( - DividerItemDecoration( - requireContext(), - LinearLayout.VERTICAL - ) - ) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter } diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt index 312129fd7..267aafd89 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt @@ -2,7 +2,6 @@ package io.legado.app.ui.explore import android.os.Bundle import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -11,6 +10,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchBook import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.widget.LoadMoreView +import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_explore_show.* import org.jetbrains.anko.startActivity @@ -34,7 +34,7 @@ class ExploreShowActivity : VMBaseActivity(R.layout.activi private fun initRecyclerView() { adapter = ExploreShowAdapter(this, this) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration(DividerItemDecoration(this, RecyclerView.VERTICAL)) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter loadMoreView = LoadMoreView(this) adapter.addFooterView(loadMoreView) diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt index b2d72a021..ff757cb09 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt @@ -6,11 +6,9 @@ import android.view.LayoutInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup -import android.widget.LinearLayout import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentManager -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -18,10 +16,7 @@ import io.legado.app.constant.Theme import io.legado.app.lib.theme.ATH import io.legado.app.ui.filechooser.adapter.FileAdapter import io.legado.app.ui.filechooser.adapter.PathAdapter -import io.legado.app.utils.FileUtils -import io.legado.app.utils.applyTint -import io.legado.app.utils.gone -import io.legado.app.utils.visible +import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_file_chooser.* @@ -142,7 +137,7 @@ class FileChooserDialog : DialogFragment(), fileAdapter = FileAdapter(requireContext(), this) pathAdapter = PathAdapter(requireContext(), this) - rv_file.addItemDecoration(DividerItemDecoration(activity, LinearLayout.VERTICAL)) + rv_file.addItemDecoration(rv_file.getVerticalDivider()) rv_file.layoutManager = LinearLayoutManager(activity) rv_file.adapter = fileAdapter diff --git a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt index 2dffe8b8d..b7b836896 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt @@ -12,9 +12,7 @@ import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -24,10 +22,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModelOfActivity -import io.legado.app.utils.requestInputMethod -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -65,9 +60,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.setOnMenuItemClickListener(this) adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration( - DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) - ) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter App.db.replaceRuleDao().liveGroup().observe(viewLifecycleOwner, Observer { val groups = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 4c042c579..1b87581c6 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -3,10 +3,8 @@ package io.legado.app.ui.rss.article import android.os.Bundle import android.view.Menu import android.view.MenuItem -import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.App @@ -17,6 +15,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.widget.LoadMoreView +import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_rss_artivles.* import kotlinx.android.synthetic.main.view_load_more.view.* @@ -71,12 +70,7 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration( - DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { - ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { - this.setDrawable(it) - } - }) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) adapter = RssArticlesAdapter(this, this) recycler_view.adapter = adapter loadMoreView = LoadMoreView(this) diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt index 0188fe104..a8eb39cea 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt @@ -1,10 +1,8 @@ package io.legado.app.ui.rss.favorites import android.os.Bundle -import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R @@ -12,6 +10,7 @@ import io.legado.app.base.BaseActivity import io.legado.app.data.entities.RssStar import io.legado.app.lib.theme.ATH import io.legado.app.ui.rss.read.ReadRssActivity +import io.legado.app.utils.getVerticalDivider import kotlinx.android.synthetic.main.view_refresh_recycler.* import org.jetbrains.anko.startActivity @@ -30,12 +29,7 @@ class RssFavoritesActivity : BaseActivity(R.layout.activity_rss_favorites), private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration( - DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { - ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { - this.setDrawable(it) - } - }) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) adapter = RssFavoritesAdapter(this, this) recycler_view.adapter = adapter } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index 32ce74791..7645bebe3 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -12,9 +12,7 @@ import android.widget.EditText import androidx.appcompat.widget.Toolbar import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -24,10 +22,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModelOfActivity -import io.legado.app.utils.requestInputMethod -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -65,9 +60,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.setOnMenuItemClickListener(this) adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration( - DividerItemDecoration(requireContext(), RecyclerView.VERTICAL) - ) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter App.db.rssSourceDao().liveGroup().observe(viewLifecycleOwner, Observer { val groups = linkedSetOf() 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 b536a0b84..ae491e14c 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 @@ -8,11 +8,9 @@ import android.view.Menu import android.view.MenuItem import android.view.SubMenu import androidx.appcompat.widget.SearchView -import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.snackbar.Snackbar @@ -99,12 +97,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration( - DividerItemDecoration(this, DividerItemDecoration.VERTICAL).apply { - ContextCompat.getDrawable(baseContext, R.drawable.ic_divider)?.let { - this.setDrawable(it) - } - }) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) adapter = RssSourceAdapter(this, this) recycler_view.adapter = adapter val itemTouchCallback = ItemTouchCallback() From 3773bad385d5601ee2a9f55aa644ef6d646ca2f9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 12:08:05 +0800 Subject: [PATCH 438/852] =?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 | 4 ++-- .../java/io/legado/app/ui/filechooser/utils/FileUtils.kt | 8 ++++---- .../main/java/io/legado/app/utils/FragmentExtensions.kt | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f5886b609..835fcda25 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -106,14 +106,14 @@ dependencies { implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' //androidX - implementation 'androidx.core:core-ktx:1.2.0-rc01' + implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.media:media:1.1.0' implementation 'androidx.preference:preference:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' - implementation 'com.google.android.material:material:1.2.0-alpha04' + implementation 'com.google.android.material:material:1.1.0' implementation 'com.google.android:flexbox:1.1.0' //lifecycle diff --git a/app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt b/app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt index f06054bb4..309dee0a2 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/utils/FileUtils.kt @@ -147,15 +147,15 @@ object FileUtils { if (!f.isDirectory) { return arrayOfNulls(0) } - val files = f.listFiles(FileFilter { f -> - if (f == null) { + val files = f.listFiles(FileFilter { file -> + if (file == null) { return@FileFilter false } - if (f.isDirectory) { + if (file.isDirectory) { return@FileFilter false } - filterPattern?.matcher(f.name)?.find() ?: true + filterPattern?.matcher(file.name)?.find() ?: true }) ?: return arrayOfNulls(0) for (file in files) { diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index b2379e89a..de7f10b96 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -13,6 +13,7 @@ import org.jetbrains.anko.connectivityManager import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.internals.AnkoInternals +@Suppress("DEPRECATION") fun Fragment.isOnline() = requireContext().connectivityManager.activeNetworkInfo?.isConnected == true fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = From 5dee9565e93259fadbf43bd39272c3c9ba1a66e8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 12:31:59 +0800 Subject: [PATCH 439/852] =?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/permission/RequestManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/help/permission/RequestManager.kt b/app/src/main/java/io/legado/app/help/permission/RequestManager.kt index b3fede03f..18bedb800 100644 --- a/app/src/main/java/io/legado/app/help/permission/RequestManager.kt +++ b/app/src/main/java/io/legado/app/help/permission/RequestManager.kt @@ -33,6 +33,7 @@ internal object RequestManager : OnPermissionsResultCallback { if (index >= 0) { val to = it.size - 1 if (index != to) { + @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") Collections.swap(requests, index, to) } } else { From 5ad242739d3133c221b9d59b7c0ea08e41688269 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 12:34:26 +0800 Subject: [PATCH 440/852] =?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/model/analyzeRule/AnalyzeUrl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index 4c278e7f9..adced171a 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -162,7 +162,7 @@ class AnalyzeUrl( } if (urlArray.size > 1) { val options = GSON.fromJsonObject>(urlArray[1]) - options?.let { + options?.let { _ -> options["method"]?.let { if (it.equals("POST", true)) method = RequestMethod.POST } options["headers"]?.let { headers -> GSON.fromJsonObject>(headers)?.let { headerMap.putAll(it) } From cf89594c9a4f34355acf40b6fd84f809caa62997 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 13:28:55 +0800 Subject: [PATCH 441/852] =?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/arrange/ArrangeBookActivity.kt | 49 +++++++++++++++++-- .../main/res/layout/activity_arrange_book.xml | 1 + app/src/main/res/menu/arrange_book.xml | 20 +++++++- 3 files changed, 64 insertions(+), 6 deletions(-) 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 509c15bbe..58dfd7ec7 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,6 +14,7 @@ import io.legado.app.data.entities.BookGroup import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.okButton 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.utils.applyTint import io.legado.app.utils.getVerticalDivider @@ -32,10 +33,13 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi private lateinit var adapter: ArrangeBookAdapter private var groupLiveData: LiveData>? = null private var booksLiveData: LiveData>? = null + private var menu: Menu? = null + private var groupId: Int = -1 override fun onActivityCreated(savedInstanceState: Bundle?) { initView() - initData() + initGroupData() + initBookData() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -43,9 +47,28 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi return super.onCompatCreateOptionsMenu(menu) } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + this.menu = menu + upMenu() + return super.onPrepareOptionsMenu(menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - + R.id.menu_group_manage -> GroupManageDialog() + .show(supportFragmentManager, "groupManage") + R.id.menu_all -> { + title_bar.subtitle = item.title + groupId = -1 + adapter.selectedBooks.clear() + initBookData() + } + else -> { + title_bar.subtitle = item.title + groupId = item.itemId + adapter.selectedBooks.clear() + initBookData() + } } return super.onCompatOptionsItemSelected(item) } @@ -79,22 +102,40 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi } } - private fun initData() { + private fun initGroupData() { groupLiveData?.removeObservers(this) groupLiveData = App.db.bookGroupDao().liveDataAll() groupLiveData?.observe(this, Observer { groupList.clear() groupList.addAll(it) adapter.notifyDataSetChanged() + upMenu() }) + } + + private fun initBookData() { booksLiveData?.removeObservers(this) - booksLiveData = App.db.bookDao().observeAll() + booksLiveData = + if (groupId == -1) { + App.db.bookDao().observeAll() + } else { + App.db.bookDao().observeByGroup(groupId) + } booksLiveData?.observe(this, Observer { adapter.setItems(it) upSelectCount() }) } + private fun upMenu() { + menu?.findItem(R.id.menu_book_group)?.subMenu?.let { subMenu -> + subMenu.removeGroup(R.id.menu_group) + groupList.forEach { bookGroup -> + subMenu.add(R.id.menu_group, bookGroup.groupId, Menu.NONE, bookGroup.groupName) + } + } + } + override fun selectGroup(requestCode: Int) { GroupSelectDialog.show(supportFragmentManager, requestCode) } diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index 795e1bfa4..45919b240 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -7,6 +7,7 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/menu/arrange_book.xml b/app/src/main/res/menu/arrange_book.xml index 0b47d59ef..f5dcc2d39 100644 --- a/app/src/main/res/menu/arrange_book.xml +++ b/app/src/main/res/menu/arrange_book.xml @@ -1,9 +1,25 @@ - + + android:icon="@drawable/ic_groups" + app:showAsAction="always"> + + + + + + + + + + \ No newline at end of file From b4f119b4139be63da87b4a611f933e636598135f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 13:33:00 +0800 Subject: [PATCH 442/852] =?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 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 58dfd7ec7..c4ec013eb 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 @@ -63,7 +63,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi adapter.selectedBooks.clear() initBookData() } - else -> { + else -> if (item.groupId == R.id.menu_group) { title_bar.subtitle = item.title groupId = item.itemId adapter.selectedBooks.clear() From f73852db6ce354956dd56168fa7438f1fd161c98 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 13:41:36 +0800 Subject: [PATCH 443/852] =?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/ui/book/arrange/ArrangeBookActivity.kt | 12 ++++++++++++ app/src/main/res/menu/arrange_book.xml | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) 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 c4ec013eb..47e912322 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 @@ -63,6 +63,18 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi adapter.selectedBooks.clear() initBookData() } + R.id.menu_local -> { + title_bar.subtitle = item.title + groupId = -2 + adapter.selectedBooks.clear() + initBookData() + } + R.id.menu_audio -> { + title_bar.subtitle = item.title + groupId = -3 + adapter.selectedBooks.clear() + initBookData() + } else -> if (item.groupId == R.id.menu_group) { title_bar.subtitle = item.title groupId = item.itemId diff --git a/app/src/main/res/menu/arrange_book.xml b/app/src/main/res/menu/arrange_book.xml index f5dcc2d39..25f88a1fc 100644 --- a/app/src/main/res/menu/arrange_book.xml +++ b/app/src/main/res/menu/arrange_book.xml @@ -16,7 +16,15 @@ + android:title="@string/all" /> + + + + From 727da9ae4675657a757245513280c70f3a51e9b0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 13:55:50 +0800 Subject: [PATCH 444/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/arrange/ArrangeBookActivity.kt | 2 ++ .../io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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 47e912322..783e7e6da 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 @@ -37,6 +37,8 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi private var groupId: Int = -1 override fun onActivityCreated(savedInstanceState: Bundle?) { + groupId = intent.getIntExtra("groupId", -1) + title_bar.subtitle = intent.getStringExtra("groupName") ?: getString(R.string.all) initView() initGroupData() initBookData() diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index c51bd46e2..8b76c7412 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -66,7 +66,10 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b .show(childFragmentManager, "groupManageDialog") R.id.menu_add_local -> startActivity() R.id.menu_add_url -> addBookByUrl() - R.id.menu_arrange_bookshelf -> startActivity() + R.id.menu_arrange_bookshelf -> startActivity( + Pair("groupId", selectedGroup.groupId), + Pair("groupName", selectedGroup.groupName) + ) R.id.menu_download -> startActivity() } } @@ -78,6 +81,9 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b return bookGroups[position] } + val selectedGroup: BookGroup + get() = bookGroups[view_pager_bookshelf.currentItem] + private fun initRecyclerView() { tab_layout.isTabIndicatorFullWidth = false tab_layout.tabMode = TabLayout.MODE_SCROLLABLE From 3fcf511e174359fe78bb41afbbffd1144fd13718 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 14:09:42 +0800 Subject: [PATCH 445/852] =?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/AppConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index e1f80dfb5..a5c0352aa 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -29,7 +29,7 @@ object AppConfig { } var isShowRSS: Boolean - get() = App.INSTANCE.getPrefBoolean(PreferKey.showRss) + get() = App.INSTANCE.getPrefBoolean(PreferKey.showRss, true) set(value) { App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) } From c2b9433a6d2a1133b98c668f0d6e82dcfb353379 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 14:11:55 +0800 Subject: [PATCH 446/852] =?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/res/values/strings.xml | 1 + app/src/main/res/xml/pref_config_other.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc4d73a1a..d2c337e8c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -594,5 +594,6 @@ 上级 在线朗读音色 (%d/%d) + 显示订阅 diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 6c38cf624..92cb3426a 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -19,7 +19,7 @@ Date: Fri, 7 Feb 2020 14:14:26 +0800 Subject: [PATCH 447/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/filechooser/adapter/PathAdapter.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt b/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt index b735ef5da..d0e7ec481 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt @@ -36,9 +36,11 @@ class PathAdapter(context: Context, val callBack: CallBack) : path1 = path1.replace(sdCardDirectory, "") paths.clear() if (path1 != "/" && path1 != "") { - val tmps = path1.substring(path1.indexOf("/") + 1).split("/".toRegex()) - .dropLastWhile { it.isEmpty() }.toTypedArray() - Collections.addAll(paths, *tmps) + val subDirs = path1.substring(path1.indexOf("/") + 1) + .split("/".toRegex()) + .dropLastWhile { it.isEmpty() } + .toTypedArray() + Collections.addAll(paths, *subDirs) } paths.addFirst(ROOT_HINT) setItems(paths) From 158be0770bbbb651d32a1618f0449f2b9722c2b9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 14:19:31 +0800 Subject: [PATCH 448/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...pterDataObserverProxy.kt => AdapterDataObserverHeader.kt} | 5 ++++- .../{ToTopListUpCallback.kt => FirstTopListUpCallback.kt} | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) rename app/src/main/java/io/legado/app/help/{AdapterDataObserverProxy.kt => AdapterDataObserverHeader.kt} (86%) rename app/src/main/java/io/legado/app/help/{ToTopListUpCallback.kt => FirstTopListUpCallback.kt} (94%) diff --git a/app/src/main/java/io/legado/app/help/AdapterDataObserverProxy.kt b/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt similarity index 86% rename from app/src/main/java/io/legado/app/help/AdapterDataObserverProxy.kt rename to app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt index 9ef120e15..24f0c0f2b 100644 --- a/app/src/main/java/io/legado/app/help/AdapterDataObserverProxy.kt +++ b/app/src/main/java/io/legado/app/help/AdapterDataObserverHeader.kt @@ -2,7 +2,10 @@ package io.legado.app.help import androidx.recyclerview.widget.RecyclerView -internal class AdapterDataObserverProxy(var adapterDataObserver: RecyclerView.AdapterDataObserver, var headerCount: Int) : RecyclerView.AdapterDataObserver() { +internal class AdapterDataObserverHeader( + var adapterDataObserver: RecyclerView.AdapterDataObserver, + var headerCount: Int +) : RecyclerView.AdapterDataObserver() { override fun onChanged() { adapterDataObserver.onChanged() } diff --git a/app/src/main/java/io/legado/app/help/ToTopListUpCallback.kt b/app/src/main/java/io/legado/app/help/FirstTopListUpCallback.kt similarity index 94% rename from app/src/main/java/io/legado/app/help/ToTopListUpCallback.kt rename to app/src/main/java/io/legado/app/help/FirstTopListUpCallback.kt index 6fdef3dca..a35f0cd8c 100644 --- a/app/src/main/java/io/legado/app/help/ToTopListUpCallback.kt +++ b/app/src/main/java/io/legado/app/help/FirstTopListUpCallback.kt @@ -4,7 +4,7 @@ import androidx.recyclerview.widget.ListUpdateCallback import androidx.recyclerview.widget.RecyclerView import io.legado.app.base.adapter.ItemViewHolder -class ToTopListUpCallback : ListUpdateCallback { +class FirstTopListUpCallback : ListUpdateCallback { var firstInsert = -1 lateinit var adapter: RecyclerView.Adapter From f3bb8e55179ccbf79405eb87b7944874d698a130 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 14:21:48 +0800 Subject: [PATCH 449/852] =?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/Preferences.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Preferences.kt b/app/src/main/java/io/legado/app/help/storage/Preferences.kt index 11907e83f..d0674f01e 100644 --- a/app/src/main/java/io/legado/app/help/storage/Preferences.kt +++ b/app/src/main/java/io/legado/app/help/storage/Preferences.kt @@ -30,7 +30,6 @@ object Preferences { val fieldMPreferencesDir = objMBase.javaClass.getDeclaredField("mPreferencesDir") fieldMPreferencesDir.isAccessible = true // 创建自定义路径 - // String FILE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Android"; val file = File(dir) // 修改mPreferencesDir变量的值 fieldMPreferencesDir.set(objMBase, file) From 70b062570079b991ee4c91ea66de80b49d640103 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 14:42:02 +0800 Subject: [PATCH 450/852] =?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/http/SSLHelper.kt | 2 +- .../main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/SSLHelper.kt b/app/src/main/java/io/legado/app/help/http/SSLHelper.kt index 1d95aae58..800304b62 100644 --- a/app/src/main/java/io/legado/app/help/http/SSLHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/SSLHelper.kt @@ -139,7 +139,7 @@ object SSLHelper { val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()) keyStore.load(null) for ((index, certStream) in certificates.withIndex()) { - val certificateAlias = Integer.toString(index) + val certificateAlias = index.toString() // 证书工厂根据证书文件的流生成证书 cert val cert = certificateFactory.generateCertificate(certStream) // 将 cert 作为可信证书放入到keyStore中 diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 79d3c9512..47d4ac1a1 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -34,7 +34,7 @@ class FontSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener, CoroutineScope, FontAdapter.CallBack { - lateinit var job: Job + private lateinit var job: Job private val fontFolderRequestCode = 35485 private val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator From fdca17fc9051f52d0a3ac54d140474cbf3801da1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 14:44:06 +0800 Subject: [PATCH 451/852] =?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/ui/widget/image/CircleImageView.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt index 31a23f623..4a7eb307c 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt @@ -243,7 +243,11 @@ class CircleImageView : AppCompatImageView { return try { val bitmap: Bitmap = if (drawable is ColorDrawable) { - Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG) + Bitmap.createBitmap( + COLOR_DRAWABLE_DIMENSION, + COLOR_DRAWABLE_DIMENSION, + BITMAP_CONFIG + ) } else { Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, BITMAP_CONFIG) } @@ -260,10 +264,10 @@ class CircleImageView : AppCompatImageView { } private fun initializeBitmap() { - if (isDisableCircularTransformation) { - mBitmap = null + mBitmap = if (isDisableCircularTransformation) { + null } else { - mBitmap = getBitmapFromDrawable(drawable) + getBitmapFromDrawable(drawable) } setup() } @@ -371,12 +375,9 @@ class CircleImageView : AppCompatImageView { } companion object { - private val SCALE_TYPE = ScaleType.CENTER_CROP - private val BITMAP_CONFIG = Bitmap.Config.ARGB_8888 - private const val COLORDRAWABLE_DIMENSION = 2 - + private const val COLOR_DRAWABLE_DIMENSION = 2 private const val DEFAULT_BORDER_WIDTH = 0 private const val DEFAULT_BORDER_COLOR = Color.BLACK private const val DEFAULT_CIRCLE_BACKGROUND_COLOR = Color.TRANSPARENT From 4c602387896a63f3ac39a4a619db30e60fd5ba8a Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 15:08:08 +0800 Subject: [PATCH 452/852] =?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/ui/chapterlist/ChapterListActivity.kt | 8 ++-- .../app/ui/chapterlist/ChapterListFragment.kt | 46 ++++++++++++------- .../ui/chapterlist/ChapterListViewModel.kt | 15 +----- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index 920b0dd24..a0d401a5e 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -28,11 +28,9 @@ class ChapterListActivity : VMBaseActivity(R.layout.activi override fun onActivityCreated(savedInstanceState: Bundle?) { tab_layout.isTabIndicatorFullWidth = false tab_layout.setSelectedTabIndicatorColor(accentColor) - viewModel.bookUrl = intent.getStringExtra("bookUrl") - viewModel.loadBook { - view_pager.adapter = TabFragmentPageAdapter(supportFragmentManager) - tab_layout.setupWithViewPager(view_pager) - } + viewModel.bookUrl = intent.getStringExtra("bookUrl") ?: "" + view_pager.adapter = TabFragmentPageAdapter(supportFragmentManager) + tab_layout.setupWithViewPager(view_pager) } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 3f79f6da6..1f6f5dfe2 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -4,6 +4,7 @@ import android.app.Activity.RESULT_OK import android.content.Intent import android.os.Bundle import android.view.View +import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import io.legado.app.App import io.legado.app.R @@ -15,6 +16,8 @@ import io.legado.app.ui.widget.recycler.UpLinearLayoutManager import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModelOfActivity import kotlinx.android.synthetic.main.fragment_chapter_list.* +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.launch import org.jetbrains.anko.sdk27.listeners.onClick class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list), @@ -24,15 +27,18 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme get() = getViewModelOfActivity(ChapterListViewModel::class.java) lateinit var adapter: ChapterListAdapter + private var book: Book? = null private var durChapterIndex = 0 private lateinit var mLayoutManager: UpLinearLayoutManager + private var tocLiveData: LiveData>? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) viewModel.chapterCallBack = this initRecyclerView() initView() - initData() + initBook() + initDoc() } private fun initRecyclerView() { @@ -43,20 +49,26 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme recycler_view.adapter = adapter } - private fun initData() { - viewModel.bookUrl?.let { bookUrl -> - App.db.bookChapterDao().observeByBook(bookUrl).observe(viewLifecycleOwner, Observer { - adapter.setItems(it) - if (it.isEmpty()) return@Observer - viewModel.book?.let { book -> - durChapterIndex = book.durChapterIndex - tv_current_chapter_info.text = it[durChapterIndex()].title - mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) - } - }) + private fun initBook() { + launch(IO) { + book = App.db.bookDao().getBook(viewModel.bookUrl) } } + private fun initDoc() { + tocLiveData?.removeObservers(this@ChapterListFragment) + tocLiveData = App.db.bookChapterDao().observeByBook(viewModel.bookUrl) + tocLiveData?.observe(viewLifecycleOwner, Observer { + adapter.setItems(it) + if (it.isEmpty()) return@Observer + book?.let { book -> + durChapterIndex = book.durChapterIndex + tv_current_chapter_info.text = it[durChapterIndex()].title + mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) + } + }) + } + private fun initView() { ll_chapter_base_info.setBackgroundColor(backgroundColor) iv_chapter_top.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } @@ -66,7 +78,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } } tv_current_chapter_info.onClick { - viewModel.book?.let { + book?.let { mLayoutManager.scrollToPositionWithOffset(it.durChapterIndex, 0) } } @@ -74,9 +86,11 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme override fun startChapterListSearch(newText: String?) { if (newText.isNullOrBlank()) { - initData() + initDoc() } else { - App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl ?: "", newText).observe(viewLifecycleOwner, Observer { + tocLiveData?.removeObservers(this) + tocLiveData = App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl, newText) + tocLiveData?.observe(viewLifecycleOwner, Observer { adapter.setItems(it) mLayoutManager.scrollToPositionWithOffset(0, 0) }) @@ -93,6 +107,6 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } override fun book(): Book? { - return viewModel.book + return book } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt index 5ac2e68d9..4156c4ac9 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt @@ -2,26 +2,13 @@ package io.legado.app.ui.chapterlist import android.app.Application -import io.legado.app.App import io.legado.app.base.BaseViewModel -import io.legado.app.data.entities.Book class ChapterListViewModel(application: Application) : BaseViewModel(application) { - var bookUrl: String? = null - var book: Book? = null + var bookUrl: String = "" var chapterCallBack: ChapterListCallBack? = null var bookMarkCallBack: BookmarkCallBack? = null - fun loadBook(success: () -> Unit) { - execute { - bookUrl?.let { - book = App.db.bookDao().getBook(it) - } - }.onSuccess { - success() - } - } - fun startChapterListSearch(newText: String?) { chapterCallBack?.startChapterListSearch(newText) } From 9f5863e80eaf746330073620ca457c8b280b0479 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 15:19:06 +0800 Subject: [PATCH 453/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/chapterlist/ChapterListFragment.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 1f6f5dfe2..29cea56a3 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -18,6 +18,7 @@ import io.legado.app.utils.getViewModelOfActivity import kotlinx.android.synthetic.main.fragment_chapter_list.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.jetbrains.anko.sdk27.listeners.onClick class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list), @@ -50,8 +51,11 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } private fun initBook() { - launch(IO) { - book = App.db.bookDao().getBook(viewModel.bookUrl) + launch { + withContext(IO) { + book = App.db.bookDao().getBook(viewModel.bookUrl) + } + tv_current_chapter_info.text = book?.durChapterTitle } } @@ -63,7 +67,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme if (it.isEmpty()) return@Observer book?.let { book -> durChapterIndex = book.durChapterIndex - tv_current_chapter_info.text = it[durChapterIndex()].title + tv_current_chapter_info.text = it[durChapterIndex].title mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) } }) From 32415395227095cde1fdeade7261ec88e79c78a5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 15:23:05 +0800 Subject: [PATCH 454/852] =?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/ui/chapterlist/ChapterListFragment.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 29cea56a3..9c7254b84 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -55,7 +55,11 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme withContext(IO) { book = App.db.bookDao().getBook(viewModel.bookUrl) } - tv_current_chapter_info.text = book?.durChapterTitle + book?.let { + durChapterIndex = it.durChapterIndex + tv_current_chapter_info.text = it.durChapterTitle + mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) + } } } @@ -64,12 +68,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme tocLiveData = App.db.bookChapterDao().observeByBook(viewModel.bookUrl) tocLiveData?.observe(viewLifecycleOwner, Observer { adapter.setItems(it) - if (it.isEmpty()) return@Observer - book?.let { book -> - durChapterIndex = book.durChapterIndex - tv_current_chapter_info.text = it[durChapterIndex].title - mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) - } + mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) }) } @@ -96,7 +95,6 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme tocLiveData = App.db.bookChapterDao().liveDataSearch(viewModel.bookUrl, newText) tocLiveData?.observe(viewLifecycleOwner, Observer { adapter.setItems(it) - mLayoutManager.scrollToPositionWithOffset(0, 0) }) } } From 8bb6d178f7714200138791e2431716544da2012e Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 15:24:40 +0800 Subject: [PATCH 455/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/chapterlist/ChapterListFragment.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 9c7254b84..3a9ed036d 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -39,7 +39,6 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme initRecyclerView() initView() initBook() - initDoc() } private fun initRecyclerView() { @@ -60,6 +59,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme tv_current_chapter_info.text = it.durChapterTitle mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) } + initDoc() } } @@ -81,9 +81,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } } tv_current_chapter_info.onClick { - book?.let { - mLayoutManager.scrollToPositionWithOffset(it.durChapterIndex, 0) - } + mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) } } From 3b560ac028496c85bbe2b9de2a3dc7c84ba27b01 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 15:52:11 +0800 Subject: [PATCH 456/852] =?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/book/read/ReadBookActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index e35a50a9e..1dd86033b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -91,6 +91,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ReadBook.titleDate.observe(this, Observer { title_bar.title = it upMenu() + upView() }) viewModel.initData(intent) } From ef57cdd28227f143dc382052b59d305e87f9cae8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 15:59:12 +0800 Subject: [PATCH 457/852] =?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/book/read/ReadBookActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 1dd86033b..430aea351 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -408,6 +408,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo tv_chapter_url.visible() } seek_read_page.max = it.pageSize().minus(1) + seek_read_page.progress = ReadBook.durPageIndex tv_pre.isEnabled = ReadBook.durChapterIndex != 0 tv_next.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1 } From bed30afef5ece39512eac009ebbec7b93aced2d9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 18:27:20 +0800 Subject: [PATCH 458/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/utils/EncodingDetect.java | 487 ++---------------- 1 file changed, 44 insertions(+), 443 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/EncodingDetect.java b/app/src/main/java/io/legado/app/utils/EncodingDetect.java index 08b43b228..29174b88e 100644 --- a/app/src/main/java/io/legado/app/utils/EncodingDetect.java +++ b/app/src/main/java/io/legado/app/utils/EncodingDetect.java @@ -120,26 +120,23 @@ public class EncodingDetect { class BytesEncodingDetect extends Encoding { // Frequency tables to hold the GB, Big5, and EUC-TW character // frequencies - int[][] GBFreq; + private int[][] GBFreq; - int[][] GBKFreq; + private int[][] GBKFreq; - int[][] Big5Freq; + private int[][] Big5Freq; - int[][] Big5PFreq; + private int[][] Big5PFreq; - int[][] EUC_TWFreq; + private int[][] EUC_TWFreq; - int[][] KRFreq; + private int[][] KRFreq; - int[][] JPFreq; + private int[][] JPFreq; - // int UnicodeFreq[94][128]; - // public static String[] nicename; - // public static String[] codings; public boolean debug; - public BytesEncodingDetect() { + BytesEncodingDetect() { super(); debug = false; GBFreq = new int[94][94]; @@ -187,12 +184,12 @@ class BytesEncodingDetect extends Encoding { * score for each encoding type. The encoding type with the highest * probability is returned. */ - public int detectEncoding(File testfile) { + int detectEncoding(File testfile) { byte[] rawtext = getFileBytes(testfile); return detectEncoding(rawtext); } - public static byte[] getFileBytes(File testfile) { + static byte[] getFileBytes(File testfile) { FileInputStream chinesefile; byte[] rawtext; rawtext = new byte[2000]; @@ -214,7 +211,7 @@ class BytesEncodingDetect extends Encoding { * it a probability score for each encoding type. The encoding type with the * highest probability is returned. */ - public int detectEncoding(byte[] rawtext) { + int detectEncoding(byte[] rawtext) { int[] scores; int index, maxscore = 0; int encoding_guess = OTHER; @@ -423,15 +420,6 @@ class BytesEncodingDetect extends Encoding { && (byte) 0x30 <= rawtext[i + 3] && rawtext[i + 3] <= (byte) 0x39) { gbchars++; - /* - * totalfreq += 500; row = rawtext[i] + 256 - 0x81; if (0x40 - * <= rawtext[i+1] && rawtext[i+1] <= 0x7E) { column = - * rawtext[i+1] - 0x40; } else { column = rawtext[i+1] + 256 - * - 0x40; } //System.out.println("extended row " + row + " - * column " + column + " rawtext[i] " + rawtext[i]); if - * (GBKFreq[row][column] != 0) { gbfreq += - * GBKFreq[row][column]; } - */ } i++; } @@ -812,33 +800,12 @@ class BytesEncodingDetect extends Encoding { * Unicode, guess based on BOM // NOT VERY GENERAL, NEEDS MUCH MORE WORK */ int utf16_probability(byte[] rawtext) { - // int score = 0; - // int i, rawtextlen = 0; - // int goodbytes = 0, asciibytes = 0; if (rawtext.length > 1 && ((byte) 0xFE == rawtext[0] && (byte) 0xFF == rawtext[1]) || // Big-endian ((byte) 0xFF == rawtext[0] && (byte) 0xFE == rawtext[1])) { // Little-endian return 100; } return 0; - /* - * // Check to see if characters fit into acceptable ranges rawtextlen = - * rawtext.length; for (i = 0; i < rawtextlen; i++) { if ((rawtext[i] & - * (byte)0x7F) == rawtext[i]) { // One byte goodbytes += 1; - * asciibytes++; } else if ((rawtext[i] & (byte)0xDF) == rawtext[i]) { - * // Two bytes if (i+1 < rawtextlen && (rawtext[i+1] & (byte)0xBF) == - * rawtext[i+1]) { goodbytes += 2; i++; } } else if ((rawtext[i] & - * (byte)0xEF) == rawtext[i]) { // Three bytes if (i+2 < rawtextlen && - * (rawtext[i+1] & (byte)0xBF) == rawtext[i+1] && (rawtext[i+2] & - * (byte)0xBF) == rawtext[i+2]) { goodbytes += 3; i+=2; } } } - * - * score = (int)(100 * ((float)goodbytes/(float)rawtext.length)); // An - * all ASCII file is also a good UTF8 file, but I'd rather it // get - * identified as ASCII. Can delete following 3 lines otherwise if - * (goodbytes == asciibytes) { score = 0; } // If not above 90, reduce - * to zero to prevent coincidental matches if (score > 90) { return - * score; } else { return 0; } - */ } /* @@ -1091,22 +1058,16 @@ class BytesEncodingDetect extends Encoding { GBKFreq[i][j] = 0; } } - // for (i = 0; i < 94; i++) { - // for (j = 0; j < 158; j++) { for (i = 93; i >= 0; i--) { for (j = 157; j >= 0; j--) { Big5Freq[i][j] = 0; } } - // for (i = 0; i < 126; i++) { - // for (j = 0; j < 191; j++) { for (i = 125; i >= 0; i--) { for (j = 190; j >= 0; j--) { Big5PFreq[i][j] = 0; } } - // for (i = 0; i < 94; i++) { - // for (j = 0; j < 94; j++) { for (i = 93; i >= 0; i--) { for (j = 93; j >= 0; j--) { EUC_TWFreq[i][j] = 0; @@ -1517,76 +1478,7 @@ class BytesEncodingDetect extends Encoding { GBFreq[20][24] = 202; GBFreq[45][19] = 201; GBFreq[18][53] = 200; - /* - * GBFreq[39][0] = 199; GBFreq[40][71] = 198; GBFreq[41][27] = 197; - * GBFreq[15][69] = 196; GBFreq[42][10] = 195; GBFreq[31][89] = 194; - * GBFreq[51][28] = 193; GBFreq[41][22] = 192; GBFreq[40][43] = 191; - * GBFreq[38][6] = 190; GBFreq[37][11] = 189; GBFreq[39][60] = 188; - * GBFreq[48][47] = 187; GBFreq[46][80] = 186; GBFreq[52][49] = 185; - * GBFreq[50][48] = 184; GBFreq[25][1] = 183; GBFreq[52][29] = 182; - * GBFreq[24][66] = 181; GBFreq[23][35] = 180; GBFreq[49][72] = 179; - * GBFreq[47][45] = 178; GBFreq[45][14] = 177; GBFreq[51][70] = 176; - * GBFreq[22][30] = 175; GBFreq[49][83] = 174; GBFreq[26][79] = 173; - * GBFreq[27][41] = 172; GBFreq[51][81] = 171; GBFreq[41][54] = 170; - * GBFreq[20][4] = 169; GBFreq[29][60] = 168; GBFreq[20][27] = 167; - * GBFreq[50][15] = 166; GBFreq[41][6] = 165; GBFreq[35][34] = 164; - * GBFreq[44][87] = 163; GBFreq[46][66] = 162; GBFreq[42][37] = 161; - * GBFreq[42][24] = 160; GBFreq[54][7] = 159; GBFreq[41][14] = 158; - * GBFreq[39][83] = 157; GBFreq[16][87] = 156; GBFreq[20][59] = 155; - * GBFreq[42][12] = 154; GBFreq[47][2] = 153; GBFreq[21][32] = 152; - * GBFreq[53][29] = 151; GBFreq[22][40] = 150; GBFreq[24][58] = 149; - * GBFreq[52][88] = 148; GBFreq[29][30] = 147; GBFreq[15][91] = 146; - * GBFreq[54][72] = 145; GBFreq[51][75] = 144; GBFreq[33][67] = 143; - * GBFreq[41][50] = 142; GBFreq[27][34] = 141; GBFreq[46][17] = 140; - * GBFreq[31][74] = 139; GBFreq[42][67] = 138; GBFreq[54][87] = 137; - * GBFreq[27][14] = 136; GBFreq[16][63] = 135; GBFreq[16][5] = 134; - * GBFreq[43][23] = 133; GBFreq[23][13] = 132; GBFreq[31][12] = 131; - * GBFreq[25][57] = 130; GBFreq[38][49] = 129; GBFreq[42][69] = 128; - * GBFreq[23][80] = 127; GBFreq[29][0] = 126; GBFreq[28][2] = 125; - * GBFreq[28][17] = 124; GBFreq[17][27] = 123; GBFreq[40][16] = 122; - * GBFreq[45][1] = 121; GBFreq[36][33] = 120; GBFreq[35][23] = 119; - * GBFreq[20][86] = 118; GBFreq[29][53] = 117; GBFreq[23][88] = 116; - * GBFreq[51][87] = 115; GBFreq[54][27] = 114; GBFreq[44][36] = 113; - * GBFreq[21][45] = 112; GBFreq[53][52] = 111; GBFreq[31][53] = 110; - * GBFreq[38][47] = 109; GBFreq[27][21] = 108; GBFreq[30][42] = 107; - * GBFreq[29][10] = 106; GBFreq[35][35] = 105; GBFreq[24][56] = 104; - * GBFreq[41][29] = 103; GBFreq[18][68] = 102; GBFreq[29][24] = 101; - * GBFreq[25][84] = 100; GBFreq[35][47] = 99; GBFreq[29][56] = 98; - * GBFreq[30][44] = 97; GBFreq[53][3] = 96; GBFreq[30][63] = 95; - * GBFreq[52][52] = 94; GBFreq[54][1] = 93; GBFreq[22][48] = 92; - * GBFreq[54][66] = 91; GBFreq[21][90] = 90; GBFreq[52][47] = 89; - * GBFreq[39][25] = 88; GBFreq[39][39] = 87; GBFreq[44][37] = 86; - * GBFreq[44][76] = 85; GBFreq[46][75] = 84; GBFreq[18][37] = 83; - * GBFreq[47][42] = 82; GBFreq[19][92] = 81; GBFreq[51][27] = 80; - * GBFreq[48][83] = 79; GBFreq[23][70] = 78; GBFreq[29][9] = 77; - * GBFreq[33][79] = 76; GBFreq[52][90] = 75; GBFreq[53][6] = 74; - * GBFreq[24][36] = 73; GBFreq[25][25] = 72; GBFreq[44][26] = 71; - * GBFreq[25][36] = 70; GBFreq[29][87] = 69; GBFreq[48][0] = 68; - * GBFreq[15][40] = 67; GBFreq[17][45] = 66; GBFreq[30][14] = 65; - * GBFreq[48][38] = 64; GBFreq[23][19] = 63; GBFreq[40][42] = 62; - * GBFreq[31][63] = 61; GBFreq[16][23] = 60; GBFreq[26][21] = 59; - * GBFreq[32][76] = 58; GBFreq[23][58] = 57; GBFreq[41][37] = 56; - * GBFreq[30][43] = 55; GBFreq[47][38] = 54; GBFreq[21][46] = 53; - * GBFreq[18][33] = 52; GBFreq[52][37] = 51; GBFreq[36][8] = 50; - * GBFreq[49][24] = 49; GBFreq[15][66] = 48; GBFreq[35][77] = 47; - * GBFreq[27][58] = 46; GBFreq[35][51] = 45; GBFreq[24][69] = 44; - * GBFreq[20][54] = 43; GBFreq[24][41] = 42; GBFreq[41][0] = 41; - * GBFreq[33][71] = 40; GBFreq[23][52] = 39; GBFreq[29][67] = 38; - * GBFreq[46][51] = 37; GBFreq[46][90] = 36; GBFreq[49][33] = 35; - * GBFreq[33][28] = 34; GBFreq[37][86] = 33; GBFreq[39][22] = 32; - * GBFreq[37][37] = 31; GBFreq[29][62] = 30; GBFreq[29][50] = 29; - * GBFreq[36][89] = 28; GBFreq[42][44] = 27; GBFreq[51][82] = 26; - * GBFreq[28][83] = 25; GBFreq[15][78] = 24; GBFreq[46][62] = 23; - * GBFreq[19][69] = 22; GBFreq[51][23] = 21; GBFreq[37][69] = 20; - * GBFreq[25][5] = 19; GBFreq[51][85] = 18; GBFreq[48][77] = 17; - * GBFreq[32][46] = 16; GBFreq[53][60] = 15; GBFreq[28][57] = 14; - * GBFreq[54][82] = 13; GBFreq[54][15] = 12; GBFreq[49][54] = 11; - * GBFreq[53][87] = 10; GBFreq[27][16] = 9; GBFreq[29][34] = 8; - * GBFreq[20][44] = 7; GBFreq[42][73] = 6; GBFreq[47][71] = 5; - * GBFreq[29][37] = 4; GBFreq[25][50] = 3; GBFreq[18][84] = 2; - * GBFreq[50][45] = 1; GBFreq[48][46] = 0; - */ - // GBFreq[43][89] = -1; GBFreq[54][68] = -2; + Big5Freq[9][89] = 600; Big5Freq[11][15] = 599; Big5Freq[3][66] = 598; @@ -1987,81 +1879,7 @@ class BytesEncodingDetect extends Encoding { Big5Freq[26][124] = 203; Big5Freq[4][19] = 202; Big5Freq[9][152] = 201; - /* - * Big5Freq[5][0] = 200; Big5Freq[26][57] = 199; Big5Freq[13][155] = - * 198; Big5Freq[3][38] = 197; Big5Freq[9][155] = 196; Big5Freq[28][53] - * = 195; Big5Freq[15][71] = 194; Big5Freq[21][95] = 193; - * Big5Freq[15][112] = 192; Big5Freq[14][138] = 191; Big5Freq[8][18] = - * 190; Big5Freq[20][151] = 189; Big5Freq[37][27] = 188; - * Big5Freq[32][48] = 187; Big5Freq[23][66] = 186; Big5Freq[9][2] = 185; - * Big5Freq[13][133] = 184; Big5Freq[7][127] = 183; Big5Freq[3][11] = - * 182; Big5Freq[12][118] = 181; Big5Freq[13][101] = 180; - * Big5Freq[30][153] = 179; Big5Freq[4][65] = 178; Big5Freq[5][25] = - * 177; Big5Freq[5][140] = 176; Big5Freq[6][25] = 175; Big5Freq[4][52] = - * 174; Big5Freq[30][156] = 173; Big5Freq[16][13] = 172; Big5Freq[21][8] - * = 171; Big5Freq[19][74] = 170; Big5Freq[15][145] = 169; - * Big5Freq[9][15] = 168; Big5Freq[13][82] = 167; Big5Freq[26][86] = - * 166; Big5Freq[18][52] = 165; Big5Freq[6][109] = 164; Big5Freq[10][99] - * = 163; Big5Freq[18][101] = 162; Big5Freq[25][49] = 161; - * Big5Freq[31][79] = 160; Big5Freq[28][20] = 159; Big5Freq[12][115] = - * 158; Big5Freq[15][66] = 157; Big5Freq[11][104] = 156; - * Big5Freq[23][106] = 155; Big5Freq[34][157] = 154; Big5Freq[32][94] = - * 153; Big5Freq[29][88] = 152; Big5Freq[10][46] = 151; - * Big5Freq[13][118] = 150; Big5Freq[20][37] = 149; Big5Freq[12][30] = - * 148; Big5Freq[21][4] = 147; Big5Freq[16][33] = 146; Big5Freq[13][52] - * = 145; Big5Freq[4][7] = 144; Big5Freq[21][49] = 143; Big5Freq[3][27] - * = 142; Big5Freq[16][91] = 141; Big5Freq[5][155] = 140; - * Big5Freq[29][130] = 139; Big5Freq[3][125] = 138; Big5Freq[14][26] = - * 137; Big5Freq[15][39] = 136; Big5Freq[24][110] = 135; - * Big5Freq[7][141] = 134; Big5Freq[21][15] = 133; Big5Freq[32][104] = - * 132; Big5Freq[8][31] = 131; Big5Freq[34][112] = 130; Big5Freq[10][75] - * = 129; Big5Freq[21][23] = 128; Big5Freq[34][131] = 127; - * Big5Freq[12][3] = 126; Big5Freq[10][62] = 125; Big5Freq[9][120] = - * 124; Big5Freq[32][149] = 123; Big5Freq[8][44] = 122; Big5Freq[24][2] - * = 121; Big5Freq[6][148] = 120; Big5Freq[15][103] = 119; - * Big5Freq[36][54] = 118; Big5Freq[36][134] = 117; Big5Freq[11][7] = - * 116; Big5Freq[3][90] = 115; Big5Freq[36][73] = 114; Big5Freq[8][102] - * = 113; Big5Freq[12][87] = 112; Big5Freq[25][64] = 111; Big5Freq[9][1] - * = 110; Big5Freq[24][121] = 109; Big5Freq[5][75] = 108; - * Big5Freq[17][83] = 107; Big5Freq[18][57] = 106; Big5Freq[8][95] = - * 105; Big5Freq[14][36] = 104; Big5Freq[28][113] = 103; - * Big5Freq[12][56] = 102; Big5Freq[14][61] = 101; Big5Freq[25][138] = - * 100; Big5Freq[4][34] = 99; Big5Freq[11][152] = 98; Big5Freq[35][0] = - * 97; Big5Freq[4][15] = 96; Big5Freq[8][82] = 95; Big5Freq[20][73] = - * 94; Big5Freq[25][52] = 93; Big5Freq[24][6] = 92; Big5Freq[21][78] = - * 91; Big5Freq[17][32] = 90; Big5Freq[17][91] = 89; Big5Freq[5][76] = - * 88; Big5Freq[15][60] = 87; Big5Freq[15][150] = 86; Big5Freq[5][80] = - * 85; Big5Freq[15][81] = 84; Big5Freq[28][108] = 83; Big5Freq[18][14] = - * 82; Big5Freq[19][109] = 81; Big5Freq[28][133] = 80; Big5Freq[21][97] - * = 79; Big5Freq[5][105] = 78; Big5Freq[18][114] = 77; Big5Freq[16][95] - * = 76; Big5Freq[5][51] = 75; Big5Freq[3][148] = 74; Big5Freq[22][102] - * = 73; Big5Freq[4][123] = 72; Big5Freq[8][88] = 71; Big5Freq[25][111] - * = 70; Big5Freq[8][149] = 69; Big5Freq[9][48] = 68; Big5Freq[16][126] - * = 67; Big5Freq[33][150] = 66; Big5Freq[9][54] = 65; Big5Freq[29][104] - * = 64; Big5Freq[3][3] = 63; Big5Freq[11][49] = 62; Big5Freq[24][109] = - * 61; Big5Freq[28][116] = 60; Big5Freq[34][113] = 59; Big5Freq[5][3] = - * 58; Big5Freq[21][106] = 57; Big5Freq[4][98] = 56; Big5Freq[12][135] = - * 55; Big5Freq[16][101] = 54; Big5Freq[12][147] = 53; Big5Freq[27][55] - * = 52; Big5Freq[3][5] = 51; Big5Freq[11][101] = 50; Big5Freq[16][157] - * = 49; Big5Freq[22][114] = 48; Big5Freq[18][46] = 47; Big5Freq[4][29] - * = 46; Big5Freq[8][103] = 45; Big5Freq[16][151] = 44; Big5Freq[8][29] - * = 43; Big5Freq[15][114] = 42; Big5Freq[22][70] = 41; - * Big5Freq[13][121] = 40; Big5Freq[7][112] = 39; Big5Freq[20][83] = 38; - * Big5Freq[3][36] = 37; Big5Freq[10][103] = 36; Big5Freq[3][96] = 35; - * Big5Freq[21][79] = 34; Big5Freq[25][120] = 33; Big5Freq[29][121] = - * 32; Big5Freq[23][71] = 31; Big5Freq[21][22] = 30; Big5Freq[18][89] = - * 29; Big5Freq[25][104] = 28; Big5Freq[10][124] = 27; Big5Freq[26][4] = - * 26; Big5Freq[21][136] = 25; Big5Freq[6][112] = 24; Big5Freq[12][103] - * = 23; Big5Freq[17][66] = 22; Big5Freq[13][151] = 21; - * Big5Freq[33][152] = 20; Big5Freq[11][148] = 19; Big5Freq[13][57] = - * 18; Big5Freq[13][41] = 17; Big5Freq[7][60] = 16; Big5Freq[21][29] = - * 15; Big5Freq[9][157] = 14; Big5Freq[24][95] = 13; Big5Freq[15][148] = - * 12; Big5Freq[15][122] = 11; Big5Freq[6][125] = 10; Big5Freq[11][25] = - * 9; Big5Freq[20][55] = 8; Big5Freq[19][84] = 7; Big5Freq[21][82] = 6; - * Big5Freq[24][3] = 5; Big5Freq[13][70] = 4; Big5Freq[6][21] = 3; - * Big5Freq[21][86] = 2; Big5Freq[12][23] = 1; Big5Freq[3][85] = 0; - * EUC_TWFreq[45][90] = 600; - */ + Big5PFreq[41][122] = 600; Big5PFreq[35][0] = 599; Big5PFreq[43][15] = 598; @@ -3062,94 +2880,7 @@ class BytesEncodingDetect extends Encoding { EUC_TWFreq[74][69] = 203; EUC_TWFreq[36][82] = 202; EUC_TWFreq[46][59] = 201; - /* - * EUC_TWFreq[38][32] = 200; EUC_TWFreq[74][2] = 199; EUC_TWFreq[53][31] - * = 198; EUC_TWFreq[35][38] = 197; EUC_TWFreq[46][62] = 196; - * EUC_TWFreq[77][31] = 195; EUC_TWFreq[55][74] = 194; EUC_TWFreq[66][6] - * = 193; EUC_TWFreq[56][21] = 192; EUC_TWFreq[54][78] = 191; - * EUC_TWFreq[43][51] = 190; EUC_TWFreq[64][93] = 189; EUC_TWFreq[92][7] - * = 188; EUC_TWFreq[83][89] = 187; EUC_TWFreq[69][9] = 186; - * EUC_TWFreq[45][4] = 185; EUC_TWFreq[53][9] = 184; EUC_TWFreq[43][2] = - * 183; EUC_TWFreq[35][11] = 182; EUC_TWFreq[51][25] = 181; - * EUC_TWFreq[52][71] = 180; EUC_TWFreq[81][67] = 179; - * EUC_TWFreq[37][33] = 178; EUC_TWFreq[38][57] = 177; - * EUC_TWFreq[39][77] = 176; EUC_TWFreq[40][26] = 175; - * EUC_TWFreq[37][21] = 174; EUC_TWFreq[81][70] = 173; - * EUC_TWFreq[56][80] = 172; EUC_TWFreq[65][14] = 171; - * EUC_TWFreq[62][47] = 170; EUC_TWFreq[56][54] = 169; - * EUC_TWFreq[45][17] = 168; EUC_TWFreq[52][52] = 167; - * EUC_TWFreq[74][30] = 166; EUC_TWFreq[60][57] = 165; - * EUC_TWFreq[41][15] = 164; EUC_TWFreq[47][69] = 163; - * EUC_TWFreq[61][11] = 162; EUC_TWFreq[72][25] = 161; - * EUC_TWFreq[82][56] = 160; EUC_TWFreq[76][92] = 159; - * EUC_TWFreq[51][22] = 158; EUC_TWFreq[55][69] = 157; - * EUC_TWFreq[49][43] = 156; EUC_TWFreq[69][49] = 155; - * EUC_TWFreq[88][42] = 154; EUC_TWFreq[84][41] = 153; - * EUC_TWFreq[79][33] = 152; EUC_TWFreq[47][17] = 151; - * EUC_TWFreq[52][88] = 150; EUC_TWFreq[63][74] = 149; - * EUC_TWFreq[50][32] = 148; EUC_TWFreq[65][10] = 147; EUC_TWFreq[57][6] - * = 146; EUC_TWFreq[52][23] = 145; EUC_TWFreq[36][70] = 144; - * EUC_TWFreq[65][55] = 143; EUC_TWFreq[35][27] = 142; - * EUC_TWFreq[57][63] = 141; EUC_TWFreq[39][92] = 140; - * EUC_TWFreq[79][75] = 139; EUC_TWFreq[36][30] = 138; - * EUC_TWFreq[53][60] = 137; EUC_TWFreq[55][43] = 136; - * EUC_TWFreq[71][22] = 135; EUC_TWFreq[43][16] = 134; - * EUC_TWFreq[65][21] = 133; EUC_TWFreq[84][51] = 132; - * EUC_TWFreq[43][64] = 131; EUC_TWFreq[87][91] = 130; - * EUC_TWFreq[47][45] = 129; EUC_TWFreq[65][29] = 128; - * EUC_TWFreq[88][16] = 127; EUC_TWFreq[50][5] = 126; EUC_TWFreq[47][33] - * = 125; EUC_TWFreq[46][27] = 124; EUC_TWFreq[85][2] = 123; - * EUC_TWFreq[43][77] = 122; EUC_TWFreq[70][9] = 121; EUC_TWFreq[41][54] - * = 120; EUC_TWFreq[56][12] = 119; EUC_TWFreq[90][65] = 118; - * EUC_TWFreq[91][50] = 117; EUC_TWFreq[48][41] = 116; - * EUC_TWFreq[35][89] = 115; EUC_TWFreq[90][83] = 114; - * EUC_TWFreq[44][40] = 113; EUC_TWFreq[50][88] = 112; - * EUC_TWFreq[72][39] = 111; EUC_TWFreq[45][3] = 110; EUC_TWFreq[71][33] - * = 109; EUC_TWFreq[39][12] = 108; EUC_TWFreq[59][24] = 107; - * EUC_TWFreq[60][62] = 106; EUC_TWFreq[44][33] = 105; - * EUC_TWFreq[53][70] = 104; EUC_TWFreq[77][90] = 103; - * EUC_TWFreq[50][58] = 102; EUC_TWFreq[54][1] = 101; EUC_TWFreq[73][19] - * = 100; EUC_TWFreq[37][3] = 99; EUC_TWFreq[49][91] = 98; - * EUC_TWFreq[88][43] = 97; EUC_TWFreq[36][78] = 96; EUC_TWFreq[44][20] - * = 95; EUC_TWFreq[64][15] = 94; EUC_TWFreq[72][28] = 93; - * EUC_TWFreq[70][13] = 92; EUC_TWFreq[65][83] = 91; EUC_TWFreq[58][68] - * = 90; EUC_TWFreq[59][32] = 89; EUC_TWFreq[39][13] = 88; - * EUC_TWFreq[55][64] = 87; EUC_TWFreq[56][59] = 86; EUC_TWFreq[39][17] - * = 85; EUC_TWFreq[55][84] = 84; EUC_TWFreq[77][85] = 83; - * EUC_TWFreq[60][19] = 82; EUC_TWFreq[62][82] = 81; EUC_TWFreq[78][16] - * = 80; EUC_TWFreq[66][8] = 79; EUC_TWFreq[39][42] = 78; - * EUC_TWFreq[61][24] = 77; EUC_TWFreq[57][67] = 76; EUC_TWFreq[38][83] - * = 75; EUC_TWFreq[36][53] = 74; EUC_TWFreq[67][76] = 73; - * EUC_TWFreq[37][91] = 72; EUC_TWFreq[44][26] = 71; EUC_TWFreq[72][86] - * = 70; EUC_TWFreq[44][87] = 69; EUC_TWFreq[45][50] = 68; - * EUC_TWFreq[58][4] = 67; EUC_TWFreq[86][65] = 66; EUC_TWFreq[45][56] = - * 65; EUC_TWFreq[79][49] = 64; EUC_TWFreq[35][3] = 63; - * EUC_TWFreq[48][83] = 62; EUC_TWFreq[71][21] = 61; EUC_TWFreq[77][93] - * = 60; EUC_TWFreq[87][92] = 59; EUC_TWFreq[38][35] = 58; - * EUC_TWFreq[66][17] = 57; EUC_TWFreq[37][66] = 56; EUC_TWFreq[51][42] - * = 55; EUC_TWFreq[57][73] = 54; EUC_TWFreq[51][54] = 53; - * EUC_TWFreq[75][64] = 52; EUC_TWFreq[35][5] = 51; EUC_TWFreq[49][40] = - * 50; EUC_TWFreq[58][35] = 49; EUC_TWFreq[67][88] = 48; - * EUC_TWFreq[60][51] = 47; EUC_TWFreq[36][92] = 46; EUC_TWFreq[44][41] - * = 45; EUC_TWFreq[58][29] = 44; EUC_TWFreq[43][62] = 43; - * EUC_TWFreq[56][23] = 42; EUC_TWFreq[67][44] = 41; EUC_TWFreq[52][91] - * = 40; EUC_TWFreq[42][81] = 39; EUC_TWFreq[64][25] = 38; - * EUC_TWFreq[35][36] = 37; EUC_TWFreq[47][73] = 36; EUC_TWFreq[36][1] = - * 35; EUC_TWFreq[65][84] = 34; EUC_TWFreq[73][1] = 33; - * EUC_TWFreq[79][66] = 32; EUC_TWFreq[69][14] = 31; EUC_TWFreq[65][28] - * = 30; EUC_TWFreq[60][93] = 29; EUC_TWFreq[72][79] = 28; - * EUC_TWFreq[48][0] = 27; EUC_TWFreq[73][43] = 26; EUC_TWFreq[66][47] = - * 25; EUC_TWFreq[41][18] = 24; EUC_TWFreq[51][10] = 23; - * EUC_TWFreq[59][7] = 22; EUC_TWFreq[53][27] = 21; EUC_TWFreq[86][67] = - * 20; EUC_TWFreq[49][87] = 19; EUC_TWFreq[52][28] = 18; - * EUC_TWFreq[52][12] = 17; EUC_TWFreq[42][30] = 16; EUC_TWFreq[65][35] - * = 15; EUC_TWFreq[46][64] = 14; EUC_TWFreq[71][7] = 13; - * EUC_TWFreq[56][57] = 12; EUC_TWFreq[56][31] = 11; EUC_TWFreq[41][31] - * = 10; EUC_TWFreq[48][59] = 9; EUC_TWFreq[63][92] = 8; - * EUC_TWFreq[62][57] = 7; EUC_TWFreq[65][87] = 6; EUC_TWFreq[70][10] = - * 5; EUC_TWFreq[52][40] = 4; EUC_TWFreq[40][22] = 3; EUC_TWFreq[65][91] - * = 2; EUC_TWFreq[50][25] = 1; EUC_TWFreq[35][84] = 0; - */ + GBKFreq[52][132] = 600; GBKFreq[73][135] = 599; GBKFreq[49][123] = 598; @@ -3452,113 +3183,7 @@ class BytesEncodingDetect extends Encoding { GBKFreq[58][174] = 301; GBKFreq[80][144] = 300; GBKFreq[85][113] = 299; - /* - * GBKFreq[83][15] = 298; GBKFreq[105][80] = 297; GBKFreq[7][179] = 296; - * GBKFreq[93][4] = 295; GBKFreq[123][40] = 294; GBKFreq[85][120] = 293; - * GBKFreq[77][165] = 292; GBKFreq[86][67] = 291; GBKFreq[25][162] = - * 290; GBKFreq[77][183] = 289; GBKFreq[83][71] = 288; GBKFreq[78][99] = - * 287; GBKFreq[72][177] = 286; GBKFreq[71][97] = 285; GBKFreq[58][111] - * = 284; GBKFreq[77][175] = 283; GBKFreq[76][181] = 282; - * GBKFreq[71][142] = 281; GBKFreq[64][150] = 280; GBKFreq[5][142] = - * 279; GBKFreq[73][128] = 278; GBKFreq[73][156] = 277; GBKFreq[60][188] - * = 276; GBKFreq[64][56] = 275; GBKFreq[74][128] = 274; - * GBKFreq[48][163] = 273; GBKFreq[54][116] = 272; GBKFreq[73][127] = - * 271; GBKFreq[16][176] = 270; GBKFreq[62][149] = 269; GBKFreq[105][96] - * = 268; GBKFreq[55][186] = 267; GBKFreq[4][51] = 266; GBKFreq[48][113] - * = 265; GBKFreq[48][152] = 264; GBKFreq[23][9] = 263; GBKFreq[56][102] - * = 262; GBKFreq[11][81] = 261; GBKFreq[82][112] = 260; GBKFreq[65][85] - * = 259; GBKFreq[69][125] = 258; GBKFreq[68][31] = 257; GBKFreq[5][20] - * = 256; GBKFreq[60][176] = 255; GBKFreq[82][81] = 254; - * GBKFreq[72][107] = 253; GBKFreq[3][52] = 252; GBKFreq[71][157] = 251; - * GBKFreq[24][46] = 250; GBKFreq[69][108] = 249; GBKFreq[78][178] = - * 248; GBKFreq[9][69] = 247; GBKFreq[73][144] = 246; GBKFreq[63][187] = - * 245; GBKFreq[68][36] = 244; GBKFreq[47][151] = 243; GBKFreq[14][74] = - * 242; GBKFreq[47][114] = 241; GBKFreq[80][171] = 240; GBKFreq[75][152] - * = 239; GBKFreq[86][40] = 238; GBKFreq[93][43] = 237; GBKFreq[2][50] = - * 236; GBKFreq[62][66] = 235; GBKFreq[1][183] = 234; GBKFreq[74][124] = - * 233; GBKFreq[58][104] = 232; GBKFreq[83][106] = 231; GBKFreq[60][144] - * = 230; GBKFreq[48][99] = 229; GBKFreq[54][157] = 228; - * GBKFreq[70][179] = 227; GBKFreq[61][127] = 226; GBKFreq[57][135] = - * 225; GBKFreq[59][190] = 224; GBKFreq[77][116] = 223; GBKFreq[26][17] - * = 222; GBKFreq[60][13] = 221; GBKFreq[71][38] = 220; GBKFreq[85][177] - * = 219; GBKFreq[59][73] = 218; GBKFreq[50][150] = 217; - * GBKFreq[79][102] = 216; GBKFreq[76][118] = 215; GBKFreq[67][132] = - * 214; GBKFreq[73][146] = 213; GBKFreq[83][184] = 212; GBKFreq[86][159] - * = 211; GBKFreq[95][120] = 210; GBKFreq[23][139] = 209; - * GBKFreq[64][183] = 208; GBKFreq[85][103] = 207; GBKFreq[41][90] = - * 206; GBKFreq[87][72] = 205; GBKFreq[62][104] = 204; GBKFreq[79][168] - * = 203; GBKFreq[79][150] = 202; GBKFreq[104][20] = 201; - * GBKFreq[56][114] = 200; GBKFreq[84][26] = 199; GBKFreq[57][99] = 198; - * GBKFreq[62][154] = 197; GBKFreq[47][98] = 196; GBKFreq[61][64] = 195; - * GBKFreq[112][18] = 194; GBKFreq[123][19] = 193; GBKFreq[4][98] = 192; - * GBKFreq[47][163] = 191; GBKFreq[66][188] = 190; GBKFreq[81][85] = - * 189; GBKFreq[82][30] = 188; GBKFreq[65][83] = 187; GBKFreq[67][24] = - * 186; GBKFreq[68][179] = 185; GBKFreq[55][177] = 184; GBKFreq[2][122] - * = 183; GBKFreq[47][139] = 182; GBKFreq[79][158] = 181; - * GBKFreq[64][143] = 180; GBKFreq[100][24] = 179; GBKFreq[73][103] = - * 178; GBKFreq[50][148] = 177; GBKFreq[86][97] = 176; GBKFreq[59][116] - * = 175; GBKFreq[64][173] = 174; GBKFreq[99][91] = 173; GBKFreq[11][99] - * = 172; GBKFreq[78][179] = 171; GBKFreq[18][17] = 170; - * GBKFreq[58][185] = 169; GBKFreq[47][165] = 168; GBKFreq[67][131] = - * 167; GBKFreq[94][40] = 166; GBKFreq[74][153] = 165; GBKFreq[79][142] - * = 164; GBKFreq[57][98] = 163; GBKFreq[1][164] = 162; GBKFreq[55][168] - * = 161; GBKFreq[13][141] = 160; GBKFreq[51][31] = 159; - * GBKFreq[57][178] = 158; GBKFreq[50][189] = 157; GBKFreq[60][167] = - * 156; GBKFreq[80][34] = 155; GBKFreq[109][80] = 154; GBKFreq[85][54] = - * 153; GBKFreq[69][183] = 152; GBKFreq[67][143] = 151; GBKFreq[47][120] - * = 150; GBKFreq[45][75] = 149; GBKFreq[82][98] = 148; GBKFreq[83][22] - * = 147; GBKFreq[13][103] = 146; GBKFreq[49][174] = 145; - * GBKFreq[57][181] = 144; GBKFreq[64][127] = 143; GBKFreq[61][131] = - * 142; GBKFreq[52][180] = 141; GBKFreq[74][134] = 140; GBKFreq[84][187] - * = 139; GBKFreq[81][189] = 138; GBKFreq[47][160] = 137; - * GBKFreq[66][148] = 136; GBKFreq[7][4] = 135; GBKFreq[85][134] = 134; - * GBKFreq[88][13] = 133; GBKFreq[88][80] = 132; GBKFreq[69][166] = 131; - * GBKFreq[86][18] = 130; GBKFreq[79][141] = 129; GBKFreq[50][108] = - * 128; GBKFreq[94][69] = 127; GBKFreq[81][110] = 126; GBKFreq[69][119] - * = 125; GBKFreq[72][161] = 124; GBKFreq[106][45] = 123; - * GBKFreq[73][124] = 122; GBKFreq[94][28] = 121; GBKFreq[63][174] = - * 120; GBKFreq[3][149] = 119; GBKFreq[24][160] = 118; GBKFreq[113][94] - * = 117; GBKFreq[56][138] = 116; GBKFreq[64][185] = 115; - * GBKFreq[86][56] = 114; GBKFreq[56][150] = 113; GBKFreq[110][55] = - * 112; GBKFreq[28][13] = 111; GBKFreq[54][190] = 110; GBKFreq[8][180] = - * 109; GBKFreq[73][149] = 108; GBKFreq[80][155] = 107; GBKFreq[83][172] - * = 106; GBKFreq[67][174] = 105; GBKFreq[64][180] = 104; - * GBKFreq[84][46] = 103; GBKFreq[91][74] = 102; GBKFreq[69][134] = 101; - * GBKFreq[61][107] = 100; GBKFreq[47][171] = 99; GBKFreq[59][51] = 98; - * GBKFreq[109][74] = 97; GBKFreq[64][174] = 96; GBKFreq[52][151] = 95; - * GBKFreq[51][176] = 94; GBKFreq[80][157] = 93; GBKFreq[94][31] = 92; - * GBKFreq[79][155] = 91; GBKFreq[72][174] = 90; GBKFreq[69][113] = 89; - * GBKFreq[83][167] = 88; GBKFreq[83][122] = 87; GBKFreq[8][178] = 86; - * GBKFreq[70][186] = 85; GBKFreq[59][153] = 84; GBKFreq[84][68] = 83; - * GBKFreq[79][39] = 82; GBKFreq[47][180] = 81; GBKFreq[88][53] = 80; - * GBKFreq[57][154] = 79; GBKFreq[47][153] = 78; GBKFreq[3][153] = 77; - * GBKFreq[76][134] = 76; GBKFreq[51][166] = 75; GBKFreq[58][176] = 74; - * GBKFreq[27][138] = 73; GBKFreq[73][126] = 72; GBKFreq[76][185] = 71; - * GBKFreq[52][186] = 70; GBKFreq[81][151] = 69; GBKFreq[26][50] = 68; - * GBKFreq[76][173] = 67; GBKFreq[106][56] = 66; GBKFreq[85][142] = 65; - * GBKFreq[11][103] = 64; GBKFreq[69][159] = 63; GBKFreq[53][142] = 62; - * GBKFreq[7][6] = 61; GBKFreq[84][59] = 60; GBKFreq[86][3] = 59; - * GBKFreq[64][144] = 58; GBKFreq[1][187] = 57; GBKFreq[82][128] = 56; - * GBKFreq[3][66] = 55; GBKFreq[68][133] = 54; GBKFreq[55][167] = 53; - * GBKFreq[52][130] = 52; GBKFreq[61][133] = 51; GBKFreq[72][181] = 50; - * GBKFreq[25][98] = 49; GBKFreq[84][149] = 48; GBKFreq[91][91] = 47; - * GBKFreq[47][188] = 46; GBKFreq[68][130] = 45; GBKFreq[22][44] = 44; - * GBKFreq[81][121] = 43; GBKFreq[72][140] = 42; GBKFreq[55][133] = 41; - * GBKFreq[55][185] = 40; GBKFreq[56][105] = 39; GBKFreq[60][30] = 38; - * GBKFreq[70][103] = 37; GBKFreq[62][141] = 36; GBKFreq[70][144] = 35; - * GBKFreq[59][111] = 34; GBKFreq[54][17] = 33; GBKFreq[18][190] = 32; - * GBKFreq[65][164] = 31; GBKFreq[83][125] = 30; GBKFreq[61][121] = 29; - * GBKFreq[48][13] = 28; GBKFreq[51][189] = 27; GBKFreq[65][68] = 26; - * GBKFreq[7][0] = 25; GBKFreq[76][188] = 24; GBKFreq[85][117] = 23; - * GBKFreq[45][33] = 22; GBKFreq[78][187] = 21; GBKFreq[106][48] = 20; - * GBKFreq[59][52] = 19; GBKFreq[86][185] = 18; GBKFreq[84][121] = 17; - * GBKFreq[82][189] = 16; GBKFreq[68][156] = 15; GBKFreq[55][125] = 14; - * GBKFreq[65][175] = 13; GBKFreq[7][140] = 12; GBKFreq[50][106] = 11; - * GBKFreq[59][124] = 10; GBKFreq[67][115] = 9; GBKFreq[82][114] = 8; - * GBKFreq[74][121] = 7; GBKFreq[106][69] = 6; GBKFreq[94][27] = 5; - * GBKFreq[78][98] = 4; GBKFreq[85][186] = 3; GBKFreq[108][90] = 2; - * GBKFreq[62][160] = 1; GBKFreq[60][169] = 0; - */ + KRFreq[31][43] = 600; KRFreq[19][56] = 599; KRFreq[38][46] = 598; @@ -4766,71 +4391,47 @@ class BytesEncodingDetect extends Encoding { class Encoding { // Supported Encoding Types - public static int GB2312 = 0; - - public static int GBK = 1; - - public static int GB18030 = 2; - - public static int HZ = 3; - - public static int BIG5 = 4; - - public static int CNS11643 = 5; - - public static int UTF8 = 6; - - public static int UTF8T = 7; - - public static int UTF8S = 8; - - public static int UNICODE = 9; - - public static int UNICODET = 10; - - public static int UNICODES = 11; - - public static int ISO2022CN = 12; - - public static int ISO2022CN_CNS = 13; - - public static int ISO2022CN_GB = 14; - - public static int EUC_KR = 15; - - public static int CP949 = 16; - - public static int ISO2022KR = 17; - - public static int JOHAB = 18; - - public static int SJIS = 19; - - public static int EUC_JP = 20; - - public static int ISO2022JP = 21; - - public static int ASCII = 22; - - public static int OTHER = 23; - - public static int TOTALTYPES = 24; + static int GB2312 = 0; + static int GBK = 1; + static int GB18030 = 2; + static int HZ = 3; + static int BIG5 = 4; + static int CNS11643 = 5; + static int UTF8 = 6; + static int UTF8T = 7; + static int UTF8S = 8; + static int UNICODE = 9; + static int UNICODET = 10; + static int UNICODES = 11; + static int ISO2022CN = 12; + static int ISO2022CN_CNS = 13; + static int ISO2022CN_GB = 14; + static int EUC_KR = 15; + static int CP949 = 16; + static int ISO2022KR = 17; + static int JOHAB = 18; + static int SJIS = 19; + static int EUC_JP = 20; + static int ISO2022JP = 21; + static int ASCII = 22; + static int OTHER = 23; + static int TOTALTYPES = 24; public final static int SIMP = 0; public final static int TRAD = 1; // Names of the encodings as understood by Java - public static String[] javaname; + static String[] javaname; // Names of the encodings for human viewing - public static String[] nicename; + static String[] nicename; // Names of charsets as used in charset parameter of HTML Meta tag - public static String[] htmlname; + static String[] htmlname; // Constructor - public Encoding() { + Encoding() { javaname = new String[TOTALTYPES]; nicename = new String[TOTALTYPES]; htmlname = new String[TOTALTYPES]; From 054f9433a1014b8d4bc4d060a573238401cca304 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 19:00:11 +0800 Subject: [PATCH 459/852] =?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/main/bookshelf/BookshelfFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 8b76c7412..2e22da815 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -81,7 +81,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b return bookGroups[position] } - val selectedGroup: BookGroup + private val selectedGroup: BookGroup get() = bookGroups[view_pager_bookshelf.currentItem] private fun initRecyclerView() { From fdf32fd55906ebea914aa52a5a9b653b9cf18058 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 19:17:26 +0800 Subject: [PATCH 460/852] =?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/main/bookshelf/BookshelfFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 2e22da815..9cf04d20a 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -140,7 +140,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b if (getPrefBoolean("bookGroupLocal", true)) { bookGroups.add(1, AppConst.bookGroupLocal) } - view_pager_bookshelf.adapter?.notifyDataSetChanged() + bookshelfAdapter.notifyDataSetChanged() } } From a845fe192f460bdda9f58e3b0b008a934e39bccc Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 21:20:58 +0800 Subject: [PATCH 461/852] =?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/ui/book/group/GroupManageDialog.kt | 5 ++- .../app/ui/book/group/GroupSelectDialog.kt | 5 ++- .../app/ui/book/group/GroupViewModel.kt | 34 +++++++++++++++++++ .../app/ui/main/bookshelf/BookshelfAdapter.kt | 11 ++++++ .../ui/main/bookshelf/BookshelfViewModel.kt | 25 -------------- 5 files changed, 49 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt 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 e9892dae0..ac49119bd 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 @@ -27,7 +27,6 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.ui.main.bookshelf.BookshelfViewModel import io.legado.app.utils.applyTint import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel @@ -38,7 +37,7 @@ import kotlinx.android.synthetic.main.item_group_manage.view.* import org.jetbrains.anko.sdk27.listeners.onClick class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { - private lateinit var viewModel: BookshelfViewModel + private lateinit var viewModel: GroupViewModel private lateinit var adapter: GroupAdapter private var callBack: CallBack? = null @@ -54,7 +53,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - viewModel = getViewModel(BookshelfViewModel::class.java) + viewModel = getViewModel(GroupViewModel::class.java) return inflater.inflate(R.layout.dialog_recycler_view, container) } 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 aebbcb603..3541defb4 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 @@ -26,7 +26,6 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.ui.main.bookshelf.BookshelfViewModel import io.legado.app.utils.applyTint import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel @@ -52,7 +51,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } private var requestCode: Int = -1 - private lateinit var viewModel: BookshelfViewModel + private lateinit var viewModel: GroupViewModel private lateinit var adapter: GroupAdapter private var callBack: CallBack? = null @@ -68,7 +67,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - viewModel = getViewModel(BookshelfViewModel::class.java) + viewModel = getViewModel(GroupViewModel::class.java) return inflater.inflate(R.layout.dialog_recycler_view, container) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt new file mode 100644 index 000000000..610eff778 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt @@ -0,0 +1,34 @@ +package io.legado.app.ui.book.group + +import android.app.Application +import io.legado.app.App +import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.BookGroup + +class GroupViewModel(application: Application) : BaseViewModel(application) { + + fun addGroup(groupName: String) { + execute { + val bookGroup = BookGroup( + groupId = App.db.bookGroupDao().maxId.plus(1), + groupName = groupName, + order = App.db.bookGroupDao().maxOrder.plus(1) + ) + App.db.bookGroupDao().insert(bookGroup) + } + } + + fun upGroup(vararg bookGroup: BookGroup) { + execute { + App.db.bookGroupDao().update(*bookGroup) + } + } + + fun delGroup(vararg bookGroup: BookGroup) { + execute { + App.db.bookGroupDao().delete(*bookGroup) + } + } + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt index 4caa119cd..55115ad94 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt @@ -9,12 +9,23 @@ import io.legado.app.ui.main.bookshelf.books.BooksFragment class BookshelfAdapter(fragment: Fragment, val callBack: CallBack) : FragmentStateAdapter(fragment) { + private val ids = hashSetOf() + override fun getItemCount(): Int { return callBack.groupSize } + override fun getItemId(position: Int): Long { + return callBack.getGroup(position).groupId.toLong() + } + + override fun containsItem(itemId: Long): Boolean { + return ids.contains(itemId) + } + override fun createFragment(position: Int): Fragment { val groupId = callBack.getGroup(position).groupId + ids.add(groupId.toLong()) return BooksFragment.newInstance(position, groupId) } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 74c963763..d0ab47c0d 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -5,7 +5,6 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book -import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookSource import io.legado.app.model.WebBook import io.legado.app.utils.NetworkUtils @@ -13,30 +12,6 @@ import kotlinx.coroutines.Dispatchers.IO class BookshelfViewModel(application: Application) : BaseViewModel(application) { - - fun addGroup(groupName: String) { - execute { - val bookGroup = BookGroup( - groupId = App.db.bookGroupDao().maxId.plus(1), - groupName = groupName, - order = App.db.bookGroupDao().maxOrder.plus(1) - ) - App.db.bookGroupDao().insert(bookGroup) - } - } - - fun upGroup(vararg bookGroup: BookGroup) { - execute { - App.db.bookGroupDao().update(*bookGroup) - } - } - - fun delGroup(vararg bookGroup: BookGroup) { - execute { - App.db.bookGroupDao().delete(*bookGroup) - } - } - fun addBookByUrl(bookUrls: String) { var successCount = 0 execute { From 153830e14318293b168523c6a183688110f26a43 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 21:34:38 +0800 Subject: [PATCH 462/852] =?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/ui/book/group/GroupManageDialog.kt | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) 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 ac49119bd..e4956c85b 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 @@ -78,12 +78,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { recycler_view.adapter = adapter App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { val diffResult = - DiffUtil.calculateDiff( - GroupDiffCallBack( - adapter.getItems(), - it - ) - ) + DiffUtil.calculateDiff(GroupDiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it, false) diffResult.dispatchUpdatesTo(adapter) }) @@ -154,13 +149,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private class GroupDiffCallBack( private val oldItems: List, private val newItems: List - ) : - DiffUtil.Callback() { - override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - val oldItem = oldItems[oldItemPosition] - val newItem = newItems[newItemPosition] - return oldItem.groupId == newItem.groupId - } + ) : DiffUtil.Callback() { override fun getOldListSize(): Int { return oldItems.size @@ -170,11 +159,14 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { return newItems.size } + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return true + } + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] return oldItem.groupName == newItem.groupName - && oldItem.order == newItem.order } } From 413f6028090a313b5c97be0ca0cc0a389d679e31 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 22:33:49 +0800 Subject: [PATCH 463/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/ItemTouchCallback.kt | 19 ++++++- .../app/ui/book/group/GroupManageDialog.kt | 26 ++++++---- .../app/ui/book/group/GroupSelectDialog.kt | 25 +++++---- .../book/source/manage/BookSourceAdapter.kt | 51 +++++++++++-------- .../app/ui/replacerule/ReplaceRuleAdapter.kt | 14 ++++- .../ui/replacerule/ReplaceRuleViewModel.kt | 2 +- .../ui/rss/source/manage/RssSourceAdapter.kt | 21 +++++--- 7 files changed, 107 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt b/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt index 5454b6e56..0e9a29351 100644 --- a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt +++ b/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt @@ -104,13 +104,21 @@ class ItemTouchCallback : ItemTouchHelper.Callback() { viewPager?.requestDisallowInterceptTouchEvent(swiping) } + override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + super.clearView(recyclerView, viewHolder) + onItemTouchCallbackListener?.clearView(recyclerView, viewHolder) + } + interface OnItemTouchCallbackListener { + /** * 当某个Item被滑动删除的时候 * * @param adapterPosition item的position */ - fun onSwiped(adapterPosition: Int) + fun onSwiped(adapterPosition: Int) { + + } /** * 当两个Item位置互换的时候被回调 @@ -119,6 +127,13 @@ class ItemTouchCallback : ItemTouchHelper.Callback() { * @param targetPosition 目的地的Item的position * @return 开发者处理了操作应该返回true,开发者没有处理就返回false */ - fun onMove(srcPosition: Int, targetPosition: Int): Boolean + fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + return false + } + + fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + + } + } } 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 e4956c85b..051081e10 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 @@ -15,6 +15,7 @@ import androidx.lifecycle.Observer import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -35,6 +36,8 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import java.util.* +import kotlin.collections.ArrayList class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var viewModel: GroupViewModel @@ -175,6 +178,8 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { SimpleRecyclerAdapter(context, R.layout.item_group_manage), ItemTouchCallback.OnItemTouchCallbackListener { + private var isMoved = false + override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList) { with(holder.itemView) { tv_group.text = item.groupName @@ -184,19 +189,20 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { - val srcItem = getItem(srcPosition) - val targetItem = getItem(targetPosition) - if (srcItem != null && targetItem != null) { - val order = srcItem.order - srcItem.order = targetItem.order - targetItem.order = order - viewModel.upGroup(srcItem, targetItem) - } + Collections.swap(getItems(), srcPosition, targetPosition) + notifyItemMoved(srcPosition, targetPosition) + isMoved = true return true } - override fun onSwiped(adapterPosition: Int) { - + override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + if (isMoved) { + for ((index, item) in getItems().withIndex()) { + item.order = index + 1 + } + viewModel.upGroup(*getItems().toTypedArray()) + } + isMoved = false } } 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 3541defb4..89c1b4b87 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 @@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentManager import androidx.lifecycle.Observer import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -34,6 +35,7 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import java.util.* class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { @@ -152,6 +154,8 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { SimpleRecyclerAdapter(context, R.layout.item_group_manage), ItemTouchCallback.OnItemTouchCallbackListener { + private var isMoved: Boolean = false + override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList) { with(holder.itemView) { tv_group.text = item.groupName @@ -165,19 +169,20 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { } override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { - val srcItem = getItem(srcPosition) - val targetItem = getItem(targetPosition) - if (srcItem != null && targetItem != null) { - val order = srcItem.order - srcItem.order = targetItem.order - targetItem.order = order - viewModel.upGroup(srcItem, targetItem) - } + Collections.swap(getItems(), srcPosition, targetPosition) + notifyItemMoved(srcPosition, targetPosition) + isMoved = true return true } - override fun onSwiped(adapterPosition: Int) { - + override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + if (isMoved) { + for ((index, item) in getItems().withIndex()) { + item.order = index + 1 + } + viewModel.upGroup(*getItems().toTypedArray()) + } + isMoved = false } } 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 3413cdd0e..8e873422b 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 @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.Menu import android.widget.PopupMenu import androidx.core.os.bundleOf +import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter @@ -13,6 +14,7 @@ import io.legado.app.help.ItemTouchCallback.OnItemTouchCallbackListener import io.legado.app.lib.theme.backgroundColor import kotlinx.android.synthetic.main.item_book_source.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import java.util.* class BookSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_book_source), @@ -48,26 +50,6 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : return selection } - override fun onSwiped(adapterPosition: Int) { - - } - - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { - val srcItem = getItem(srcPosition) - val targetItem = getItem(targetPosition) - if (srcItem != null && targetItem != null) { - if (srcItem.customOrder == targetItem.customOrder) { - callBack.upOrder() - } else { - val srcOrder = srcItem.customOrder - srcItem.customOrder = targetItem.customOrder - targetItem.customOrder = srcOrder - callBack.update(srcItem, targetItem) - } - } - return true - } - override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList) { with(holder.itemView) { val payload = payloads.getOrNull(0) as? Bundle @@ -121,6 +103,35 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } } + + } + + override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + val srcItem = getItem(srcPosition) + val targetItem = getItem(targetPosition) + if (srcItem != null && targetItem != null) { + if (srcItem.customOrder == targetItem.customOrder) { + callBack.upOrder() + } else { + val srcOrder = srcItem.customOrder + srcItem.customOrder = targetItem.customOrder + targetItem.customOrder = srcOrder + movedItems.add(srcItem) + movedItems.add(targetItem) + } + } + Collections.swap(getItems(), srcPosition, targetPosition) + notifyItemMoved(srcPosition, targetPosition) + return true + } + + private val movedItems = hashSetOf() + + override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + if (movedItems.isNotEmpty()) { + callBack.update(*movedItems.toTypedArray()) + movedItems.clear() + } } interface CallBack { 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 f25c0e523..0a08d2021 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 @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.Menu import android.widget.PopupMenu import androidx.core.os.bundleOf +import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter @@ -13,6 +14,7 @@ import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.theme.backgroundColor import kotlinx.android.synthetic.main.item_replace_rule.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import java.util.* class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : @@ -117,14 +119,22 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : val srcOrder = srcItem.order srcItem.order = targetItem.order targetItem.order = srcOrder - callBack.update(srcItem, targetItem) + movedItems.add(srcItem) + movedItems.add(targetItem) } } + Collections.swap(getItems(), srcPosition, targetPosition) + notifyItemMoved(srcPosition, targetPosition) return true } - override fun onSwiped(adapterPosition: Int) { + private val movedItems = linkedSetOf() + override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + if (movedItems.isNotEmpty()) { + callBack.update(*movedItems.toTypedArray()) + movedItems.clear() + } } interface CallBack { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index c54f126d8..9d1f2f1a0 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -56,7 +56,7 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application fun upOrder() { execute { val rules = App.db.replaceRuleDao().all - for ((index: Int, rule: ReplaceRule) in rules.withIndex()) { + for ((index, rule) in rules.withIndex()) { rule.order = index + 1 } App.db.replaceRuleDao().update(*rules.toTypedArray()) 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 708abb904..1ec7d8bbd 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 @@ -3,6 +3,7 @@ package io.legado.app.ui.rss.source.manage import android.content.Context import android.view.Menu import android.widget.PopupMenu +import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter @@ -11,6 +12,7 @@ import io.legado.app.help.ItemTouchCallback import io.legado.app.lib.theme.backgroundColor import kotlinx.android.synthetic.main.item_rss_source.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import java.util.* class RssSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_rss_source), @@ -92,11 +94,6 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : } } - - override fun onSwiped(adapterPosition: Int) { - - } - override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { val srcItem = getItem(srcPosition) val targetItem = getItem(targetPosition) @@ -107,12 +104,24 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : val srcOrder = srcItem.customOrder srcItem.customOrder = targetItem.customOrder targetItem.customOrder = srcOrder - callBack.update(srcItem, targetItem) + movedItems.add(srcItem) + movedItems.add(targetItem) } } + Collections.swap(getItems(), srcPosition, targetPosition) + notifyItemMoved(srcPosition, targetPosition) return true } + private val movedItems = hashSetOf() + + override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + if (movedItems.isNotEmpty()) { + callBack.update(*movedItems.toTypedArray()) + movedItems.clear() + } + } + interface CallBack { fun del(source: RssSource) fun edit(source: RssSource) From dc89592b5b265be3ad4e910796b8ba1bab27364b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 22:36:50 +0800 Subject: [PATCH 464/852] =?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/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index dac73cd09..1d972d265 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/08** +* 书架分组调整顺序后,书架及时变动 + **2020/02/07** * 优化 * 书源校验 From 2cf6f7c9fb7003ed80c1080703c4a7d5c0d3c9aa Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 23:23:10 +0800 Subject: [PATCH 465/852] =?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/main/MainAdapter.kt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/main/MainAdapter.kt diff --git a/app/src/main/java/io/legado/app/ui/main/MainAdapter.kt b/app/src/main/java/io/legado/app/ui/main/MainAdapter.kt new file mode 100644 index 000000000..874912da0 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/MainAdapter.kt @@ -0,0 +1,49 @@ +package io.legado.app.ui.main + +import androidx.fragment.app.Fragment +import androidx.viewpager2.adapter.FragmentStateAdapter +import io.legado.app.help.AppConfig +import io.legado.app.ui.main.bookshelf.BookshelfFragment +import io.legado.app.ui.main.explore.ExploreFragment +import io.legado.app.ui.main.my.MyFragment +import io.legado.app.ui.main.rss.RssFragment + +class MainAdapter(val activity: MainActivity) : FragmentStateAdapter(activity) { + + private val fid1 = 111.toLong() + private val fid2 = 222.toLong() + private val fid3 = 333.toLong() + private val fid4 = 444.toLong() + + private val ids: ArrayList + get() = if (AppConfig.isShowRSS) { + arrayListOf(fid1, fid2, fid3, fid4) + } else { + arrayListOf(fid1, fid2, fid4) + } + + private val createdIds = hashSetOf() + + override fun getItemCount(): Int { + return if (AppConfig.isShowRSS) 4 else 3 + } + + override fun getItemId(position: Int): Long { + return ids[position] + } + + override fun containsItem(itemId: Long): Boolean { + return createdIds.contains(itemId) + } + + override fun createFragment(position: Int): Fragment { + val id = ids[position] + createdIds.add(id) + return when (id) { + fid4 -> MyFragment() + fid3 -> RssFragment() + fid2 -> ExploreFragment() + else -> BookshelfFragment() + } + } +} \ No newline at end of file From 7662345e76ff76de6a5f76ca8ab5d2ae7f4bde64 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 7 Feb 2020 23:24:59 +0800 Subject: [PATCH 466/852] =?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/res/layout/activity_main.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6b4eb4487..a21e6de1c 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -21,5 +21,4 @@ app:layout_constraintBottom_toTopOf="@+id/bottom_navigation_view" app:layout_constraintTop_toTopOf="parent" /> - - + \ No newline at end of file From 60771172107552f9ae4823e1a103490782b939bf Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 10:31:02 +0800 Subject: [PATCH 467/852] delete MainAdapter --- .../java/io/legado/app/ui/main/MainAdapter.kt | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/main/MainAdapter.kt diff --git a/app/src/main/java/io/legado/app/ui/main/MainAdapter.kt b/app/src/main/java/io/legado/app/ui/main/MainAdapter.kt deleted file mode 100644 index 874912da0..000000000 --- a/app/src/main/java/io/legado/app/ui/main/MainAdapter.kt +++ /dev/null @@ -1,49 +0,0 @@ -package io.legado.app.ui.main - -import androidx.fragment.app.Fragment -import androidx.viewpager2.adapter.FragmentStateAdapter -import io.legado.app.help.AppConfig -import io.legado.app.ui.main.bookshelf.BookshelfFragment -import io.legado.app.ui.main.explore.ExploreFragment -import io.legado.app.ui.main.my.MyFragment -import io.legado.app.ui.main.rss.RssFragment - -class MainAdapter(val activity: MainActivity) : FragmentStateAdapter(activity) { - - private val fid1 = 111.toLong() - private val fid2 = 222.toLong() - private val fid3 = 333.toLong() - private val fid4 = 444.toLong() - - private val ids: ArrayList - get() = if (AppConfig.isShowRSS) { - arrayListOf(fid1, fid2, fid3, fid4) - } else { - arrayListOf(fid1, fid2, fid4) - } - - private val createdIds = hashSetOf() - - override fun getItemCount(): Int { - return if (AppConfig.isShowRSS) 4 else 3 - } - - override fun getItemId(position: Int): Long { - return ids[position] - } - - override fun containsItem(itemId: Long): Boolean { - return createdIds.contains(itemId) - } - - override fun createFragment(position: Int): Fragment { - val id = ids[position] - createdIds.add(id) - return when (id) { - fid4 -> MyFragment() - fid3 -> RssFragment() - fid2 -> ExploreFragment() - else -> BookshelfFragment() - } - } -} \ No newline at end of file From 37a560eb3972ed755890fd85a58f050d20208a94 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 10:38:39 +0800 Subject: [PATCH 468/852] =?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/main/MainActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 9fda82311..3b4bbb859 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -38,6 +38,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), private var pagePosition = 0 private val fragmentList = arrayListOf() + private var rssFragment: RssFragment? = null override fun onActivityCreated(savedInstanceState: Bundle?) { ATH.applyEdgeEffectColor(view_pager_main) @@ -69,7 +70,8 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), fragmentList.add(MyFragment()) } if (AppConfig.isShowRSS && fragmentList.size < 4) { - fragmentList.add(2, RssFragment()) + fragmentList.add(2, + rssFragment ?: RssFragment().apply { rssFragment = this }) } if (!AppConfig.isShowRSS && fragmentList.size == 4) { fragmentList.removeAt(2) From b887326d01ba69c06ada7a8e4423532f64b3bc51 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 10:52:16 +0800 Subject: [PATCH 469/852] =?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/main/my/MyFragment.kt | 4 ++-- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 035ca4d26..09969afda 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -208,10 +208,10 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { PreferKey.webService -> { if (requireContext().getPrefBoolean("webService")) { WebService.start(requireContext()) - toast("正在启动服务\n具体信息查看通知栏") + toast(R.string.service_start) }else{ WebService.stop(requireContext()) - toast("服务已停止") + toast(R.string.service_stop) } } PreferKey.downloadPath -> BookHelp.upDownloadPath() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d2c337e8c..246eda3a1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -595,5 +595,7 @@ 在线朗读音色 (%d/%d) 显示订阅 + 服务已停止 + 正在启动服务\n具体信息查看通知栏 From 76a3540e560f2226bc956bbe65be6a2cec6e639f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 12:22:21 +0800 Subject: [PATCH 470/852] =?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/model/localBook/AnalyzeTxtFile.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 82ec88179..9783dca3e 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -161,7 +161,6 @@ object AnalyzeTxtFile { lastChapter.end = curOffset } - //当添加的block太多的时候,执行GC //当添加的block太多的时候,执行GC if (blockPos % 15 == 0) { System.gc() From 5cda7c5fbe746f73eaa82eb70637fa6a032c892e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 12:52:03 +0800 Subject: [PATCH 471/852] =?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/res/layout/activity_book_source.xml | 1 + app/src/main/res/layout/item_import_book.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_book_source.xml b/app/src/main/res/layout/activity_book_source.xml index 839d228fb..8fd1a1630 100644 --- a/app/src/main/res/layout/activity_book_source.xml +++ b/app/src/main/res/layout/activity_book_source.xml @@ -25,4 +25,5 @@ + \ No newline at end of file diff --git a/app/src/main/res/layout/item_import_book.xml b/app/src/main/res/layout/item_import_book.xml index 67ac3aeda..d1ed4ac5b 100644 --- a/app/src/main/res/layout/item_import_book.xml +++ b/app/src/main/res/layout/item_import_book.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="60dp" - android:background="@drawable/selector_common_bg" + android:background="?attr/selectableItemBackground" android:orientation="horizontal" android:baselineAligned="false"> From c023444ff9ab2b84d437b83571d2d90978549161 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 14:08:48 +0800 Subject: [PATCH 472/852] =?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/arrange/ArrangeBookActivity.kt | 24 +++++++-- .../app/ui/importbook/ImportBookActivity.kt | 24 +++++---- .../main/res/layout/activity_arrange_book.xml | 49 +++++++------------ .../main/res/layout/activity_import_book.xml | 39 +++++++-------- app/src/main/res/values/strings.xml | 2 + 5 files changed, 71 insertions(+), 67 deletions(-) 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 783e7e6da..d1d0a01b7 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 @@ -175,12 +175,28 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi cb_selected_all.isChecked = adapter.isSelectAll() //重置全选的文字 if (cb_selected_all.isChecked) { - cb_selected_all.setText(R.string.cancel) + cb_selected_all.text = getString( + R.string.select_cancel_count, + adapter.selectedBooks.size, + adapter.getItems().size + ) } else { - cb_selected_all.setText(R.string.select_all) + cb_selected_all.text = getString( + R.string.select_all_count, + adapter.selectedBooks.size, + adapter.getItems().size + ) } - tv_select_count.text = - getString(R.string.select_count, adapter.selectedBooks.size, adapter.getItems().size) + setMenuClickable(adapter.selectedBooks.isNotEmpty()) + } + + private fun setMenuClickable(isClickable: Boolean) { + //设置是否可删除 + btn_delete.isEnabled = isClickable + btn_delete.isClickable = isClickable + //设置是否可添加书籍 + btn_to_group.isEnabled = isClickable + btn_to_group.isClickable = isClickable } override fun deleteBook(book: Book) { diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt index 2f67e8f90..bbcdf6954 100644 --- a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -186,17 +186,6 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity } override fun upCountView() { - if (adapter.selectedUris.isEmpty()) { - btn_add_book.setText(R.string.nb_file_add_shelf) - //设置某些按钮的是否可点击 - setMenuClickable(false) - } else { - btn_add_book.text = - getString(R.string.nb_file_add_shelves, adapter.selectedUris.size) - //设置某些按钮的是否可点击 - setMenuClickable(true) - } - if (adapter.checkableCount == 0) { cb_selected_all.isChecked = false } else { @@ -205,10 +194,19 @@ class ImportBookActivity : VMBaseActivity(R.layout.activity //重置全选的文字 if (cb_selected_all.isChecked) { - cb_selected_all.setText(R.string.cancel) + cb_selected_all.text = getString( + R.string.select_cancel_count, + adapter.selectedUris.size, + adapter.checkableCount + ) } else { - cb_selected_all.setText(R.string.select_all) + cb_selected_all.text = getString( + R.string.select_all_count, + adapter.selectedUris.size, + adapter.checkableCount + ) } + setMenuClickable(adapter.selectedUris.isNotEmpty()) } private fun setMenuClickable(isClickable: Boolean) { diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index 45919b240..9fdc30961 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -1,7 +1,6 @@ @@ -19,52 +18,42 @@ android:layout_weight="1" /> - + android:padding="6dp" + android:elevation="2dp"> - - + android:layout_weight="1" + android:padding="5dp" + android:text="@string/select_all_count" + android:textColor="@color/tv_text_default" /> - + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index 1d322fcfc..38bfab5d5 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -69,44 +69,43 @@ - + android:padding="6dp" + android:elevation="2dp"> - + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 246eda3a1..05117b38f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -205,6 +205,8 @@ 替换规则名称 选择操作 全选 + 全选(%d/%d) + 取消(%d/%d) 深色模式 启动页 开始下载 From 461da74963d63ef76f470e5a689b5c5f26c19320 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 14:32:17 +0800 Subject: [PATCH 473/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceActivity.kt | 50 +++++++++++++++++-- .../book/source/manage/BookSourceAdapter.kt | 4 ++ .../main/res/layout/activity_arrange_book.xml | 6 +-- .../main/res/layout/activity_book_source.xml | 42 +++++++++++++++- .../main/res/layout/activity_import_book.xml | 6 +-- app/src/main/res/menu/book_source.xml | 10 ---- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 99 insertions(+), 21 deletions(-) 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 ff1d48987..8152ae3c8 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 @@ -36,6 +36,7 @@ import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* +import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -61,6 +62,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity initSearchView() initLiveDataBookSource() initLiveDataGroup() + initViewEvent() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -81,8 +83,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity R.id.menu_group_manage -> GroupManageDialog().show(supportFragmentManager, "groupManage") R.id.menu_import_source_local -> selectFileSys() - R.id.menu_select_all -> adapter.selectAll() - R.id.menu_revert_selection -> adapter.revertSelection() R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelection()) @@ -142,11 +142,11 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity App.db.bookSourceDao().liveDataSearch("%$searchKey%") } bookSourceLiveDate?.observe(this, Observer { - search_view.queryHint = getString(R.string.search_book_source_num, it.size) val diffResult = DiffUtil .calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it, false) diffResult.dispatchUpdatesTo(adapter) + upCountView() }) } @@ -160,6 +160,16 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity }) } + private fun initViewEvent() { + cb_selected_all.onClick { + adapter.selectAll() + } + btn_revert_selection.onClick { + adapter.revertSelection() + } + + } + private fun upGroupMenu() { groupMenu?.removeGroup(R.id.source_group) groups.map { @@ -230,6 +240,40 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity ) } + override fun upCountView() { + val selectCount = adapter.getSelection().size + if (selectCount == 0) { + cb_selected_all.isChecked = false + } else { + cb_selected_all.isChecked = selectCount >= adapter.getActualItemCount() + } + + //重置全选的文字 + if (cb_selected_all.isChecked) { + cb_selected_all.text = getString( + R.string.select_cancel_count, + selectCount, + adapter.getActualItemCount() + ) + } else { + cb_selected_all.text = getString( + R.string.select_all_count, + selectCount, + adapter.getActualItemCount() + ) + } + setMenuClickable(selectCount > 0) + } + + private fun setMenuClickable(isClickable: Boolean) { + //设置是否可删除 + btn_delete.isEnabled = isClickable + btn_delete.isClickable = isClickable + //设置是否可添加书籍 + btn_revert_selection.isEnabled = isClickable + btn_revert_selection.isClickable = isClickable + } + override fun onFilePicked(requestCode: Int, currentPath: String) { if (requestCode == importSource) { Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() 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 8e873422b..1da9f5ae4 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 @@ -27,6 +27,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : selected.add(it) } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) + callBack.upCountView() } fun revertSelection() { @@ -38,6 +39,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } notifyItemRangeChanged(0, itemCount, bundleOf(Pair("selected", null))) + callBack.upCountView() } fun getSelection(): LinkedHashSet { @@ -73,6 +75,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } else { selected.remove(item) } + callBack.upCountView() } iv_edit.onClick { callBack.edit(item) } iv_menu_more.onClick { @@ -140,5 +143,6 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : fun update(vararg bookSource: BookSource) fun toTop(bookSource: BookSource) fun upOrder() + fun upCountView() } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index 9fdc30961..bafdbabe6 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -42,16 +42,16 @@ android:layout_margin="5dp" android:padding="5dp" android:gravity="center" - android:minWidth="100dp" + android:minWidth="90dp" android:text="@string/move_to_group" /> diff --git a/app/src/main/res/layout/activity_book_source.xml b/app/src/main/res/layout/activity_book_source.xml index 8fd1a1630..f3be2d751 100644 --- a/app/src/main/res/layout/activity_book_source.xml +++ b/app/src/main/res/layout/activity_book_source.xml @@ -16,7 +16,8 @@ + android:layout_height="0dp" + android:layout_weight="1"> + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index 38bfab5d5..4a4b16d92 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -93,16 +93,16 @@ android:layout_margin="5dp" android:padding="5dp" android:gravity="center" - android:minWidth="100dp" + android:minWidth="90dp" android:text="@string/add_to_shelf" /> diff --git a/app/src/main/res/menu/book_source.xml b/app/src/main/res/menu/book_source.xml index 5740683bd..8df8928e4 100644 --- a/app/src/main/res/menu/book_source.xml +++ b/app/src/main/res/menu/book_source.xml @@ -12,16 +12,6 @@ - - - - 朗读时音量键翻页 Tip边距跟随边距调整 允许更新 - 反转选择 + 反选 搜索书名、作者 书名、作者、URL 常见问题 From 272232291f1da0d5f969d9efea54f48ed95356dc Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 14:35:52 +0800 Subject: [PATCH 474/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/source/manage/BookSourceActivity.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 8152ae3c8..4cd6dbe2f 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 @@ -162,7 +162,11 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private fun initViewEvent() { cb_selected_all.onClick { - adapter.selectAll() + if (adapter.getSelection().size == adapter.getActualItemCount()) { + adapter.revertSelection() + } else { + adapter.selectAll() + } } btn_revert_selection.onClick { adapter.revertSelection() From e5d8441c54ef5783d6a4dcbdb6a4e655967ef428 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 14:59:52 +0800 Subject: [PATCH 475/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/source/manage/BookSourceActivity.kt | 28 ++++++++--- .../main/res/layout/activity_arrange_book.xml | 9 ++-- .../main/res/layout/activity_book_source.xml | 20 ++++++-- .../main/res/layout/activity_import_book.xml | 9 ++-- app/src/main/res/menu/book_source.xml | 49 ------------------- app/src/main/res/menu/book_source_sel.xml | 41 ++++++++++++++++ 6 files changed, 91 insertions(+), 65 deletions(-) create mode 100644 app/src/main/res/menu/book_source_sel.xml 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 4cd6dbe2f..d579b7529 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 @@ -7,6 +7,7 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.SubMenu +import android.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.lifecycle.LiveData import androidx.lifecycle.Observer @@ -43,6 +44,7 @@ import org.jetbrains.anko.toast import java.io.FileNotFoundException class BookSourceActivity : VMBaseActivity(R.layout.activity_book_source), + PopupMenu.OnMenuItemClickListener, BookSourceAdapter.CallBack, FileChooserDialog.CallBack, SearchView.OnQueryTextListener { @@ -55,6 +57,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private var bookSourceLiveDate: LiveData>? = null private var groups = hashSetOf() private var groupMenu: SubMenu? = null + private lateinit var selMenu: PopupMenu override fun onActivityCreated(savedInstanceState: Bundle?) { initUriScheme() @@ -83,13 +86,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity R.id.menu_group_manage -> GroupManageDialog().show(supportFragmentManager, "groupManage") R.id.menu_import_source_local -> selectFileSys() - R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) - R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) - R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelection()) - R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelection()) - R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) - R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) - R.id.menu_check_source -> CheckSource.start(this, adapter.getSelection()) R.id.menu_import_source_onLine -> showImportDialog() } if (item.groupId == R.id.source_group) { @@ -132,6 +128,9 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity search_view.queryHint = getString(R.string.search_book_source) search_view.clearFocus() search_view.setOnQueryTextListener(this) + selMenu = PopupMenu(this, iv_menu_more) + selMenu.inflate(R.menu.book_source_sel) + selMenu.setOnMenuItemClickListener(this) } private fun initLiveDataBookSource(searchKey: String? = null) { @@ -171,7 +170,22 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity btn_revert_selection.onClick { adapter.revertSelection() } + iv_menu_more.onClick { + selMenu.show() + } + } + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) + R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) + R.id.menu_enable_explore -> viewModel.enableSelectExplore(adapter.getSelection()) + R.id.menu_disable_explore -> viewModel.disableSelectExplore(adapter.getSelection()) + R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) + R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) + R.id.menu_check_source -> CheckSource.start(this, adapter.getSelection()) + } + return true } private fun upGroupMenu() { diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index bafdbabe6..66642e134 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -23,7 +23,10 @@ android:layout_height="wrap_content" android:background="@color/background" android:gravity="center_vertical" - android:padding="6dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:paddingTop="6dp" + android:paddingBottom="6dp" android:elevation="2dp"> diff --git a/app/src/main/res/layout/activity_book_source.xml b/app/src/main/res/layout/activity_book_source.xml index f3be2d751..a913920af 100644 --- a/app/src/main/res/layout/activity_book_source.xml +++ b/app/src/main/res/layout/activity_book_source.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical"> + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml index 4a4b16d92..41c8490e1 100644 --- a/app/src/main/res/layout/activity_import_book.xml +++ b/app/src/main/res/layout/activity_import_book.xml @@ -74,7 +74,10 @@ android:layout_height="wrap_content" android:background="@color/background" android:gravity="center_vertical" - android:padding="6dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:paddingTop="6dp" + android:paddingBottom="6dp" android:elevation="2dp"> diff --git a/app/src/main/res/menu/book_source.xml b/app/src/main/res/menu/book_source.xml index 8df8928e4..649060e9f 100644 --- a/app/src/main/res/menu/book_source.xml +++ b/app/src/main/res/menu/book_source.xml @@ -3,49 +3,6 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/menu/book_source_sel.xml b/app/src/main/res/menu/book_source_sel.xml new file mode 100644 index 000000000..dff64669a --- /dev/null +++ b/app/src/main/res/menu/book_source_sel.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + From 1c0e9731b80d8aa4d52d4a985ee1da5c8f6cab82 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 15:24:03 +0800 Subject: [PATCH 476/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/RssSourceDao.kt | 12 --- .../io/legado/app/data/entities/RssSource.kt | 11 +++ .../book/source/manage/BookSourceActivity.kt | 6 +- .../ui/rss/source/manage/RssSourceActivity.kt | 77 +++++++++++++++++-- .../ui/rss/source/manage/RssSourceAdapter.kt | 30 ++++---- .../rss/source/manage/RssSourceViewModel.kt | 32 ++++---- .../main/res/layout/activity_rss_source.xml | 57 +++++++++++++- app/src/main/res/menu/rss_source_sel.xml | 25 ++++++ 8 files changed, 202 insertions(+), 48 deletions(-) create mode 100644 app/src/main/res/menu/rss_source_sel.xml diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index df0bf605c..b4018f803 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -31,21 +31,12 @@ interface RssSourceDao { @Query("select sourceGroup from rssSources where sourceGroup is not null and sourceGroup <> ''") fun liveGroup(): LiveData> - @Query("update rssSources set enabled = 1 where sourceUrl in (:sourceUrls)") - fun enableSection(vararg sourceUrls: String) - - @Query("update rssSources set enabled = 0 where sourceUrl in (:sourceUrls)") - fun disableSection(vararg sourceUrls: String) - @get:Query("select min(customOrder) from rssSources") val minOrder: Int @get:Query("select max(customOrder) from rssSources") val maxOrder: Int - @Query("delete from rssSources where sourceUrl in (:sourceUrls)") - fun delSection(vararg sourceUrls: String) - @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg rssSource: RssSource) @@ -55,9 +46,6 @@ interface RssSourceDao { @Delete fun delete(vararg rssSource: RssSource) - @Query("delete from rssSources where sourceUrl = :sourceUrl") - fun delete(sourceUrl: String) - @get:Query("select * from rssSources where sourceGroup is null or sourceGroup = ''") val noGroup: List diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index 261611caf..999b12523 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -39,6 +39,17 @@ data class RssSource( var customOrder: Int = 0 ) : Parcelable, JsExtensions { + override fun equals(other: Any?): Boolean { + if (other is RssSource) { + return other.sourceUrl == sourceUrl + } + return false + } + + override fun hashCode(): Int { + return sourceUrl.hashCode() + } + @Throws(Exception::class) fun getHeaderMap(): Map { val headerMap = HashMap() 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 d579b7529..233ea5486 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 @@ -128,9 +128,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity search_view.queryHint = getString(R.string.search_book_source) search_view.clearFocus() search_view.setOnQueryTextListener(this) - selMenu = PopupMenu(this, iv_menu_more) - selMenu.inflate(R.menu.book_source_sel) - selMenu.setOnMenuItemClickListener(this) } private fun initLiveDataBookSource(searchKey: String? = null) { @@ -160,6 +157,9 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity } private fun initViewEvent() { + selMenu = PopupMenu(this, iv_menu_more) + selMenu.inflate(R.menu.book_source_sel) + selMenu.setOnMenuItemClickListener(this) cb_selected_all.onClick { if (adapter.getSelection().size == adapter.getActualItemCount()) { adapter.revertSelection() 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 ae491e14c..0176433c8 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 @@ -7,6 +7,7 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.SubMenu +import android.widget.PopupMenu import androidx.appcompat.widget.SearchView import androidx.lifecycle.LiveData import androidx.lifecycle.Observer @@ -35,6 +36,7 @@ import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_rss_source.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.view_search.* +import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.toast @@ -42,6 +44,7 @@ import java.io.FileNotFoundException class RssSourceActivity : VMBaseActivity(R.layout.activity_rss_source), + PopupMenu.OnMenuItemClickListener, FileChooserDialog.CallBack, RssSourceAdapter.CallBack { @@ -54,12 +57,14 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r private var sourceLiveData: LiveData>? = null private var groups = hashSetOf() private var groupMenu: SubMenu? = null + private lateinit var selMenu: PopupMenu override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() initSearchView() initLiveDataGroup() initLiveDataSource() + initViewEvent() } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -76,12 +81,6 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_add -> startActivity() - R.id.menu_select_all -> adapter.selectAll() - R.id.menu_revert_selection -> adapter.revertSelection() - R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelectionIds()) - R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelectionIds()) - R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelectionIds()) - R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelectionIds()) R.id.menu_import_source_local -> selectFileSys() R.id.menu_import_source_onLine -> showImportDialog() R.id.menu_import_source_qr -> startActivityForResult(qrRequestCode) @@ -94,6 +93,18 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r return super.onCompatOptionsItemSelected(item) } + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_select_all -> adapter.selectAll() + R.id.menu_revert_selection -> adapter.revertSelection() + R.id.menu_enable_selection -> viewModel.enableSelection(adapter.getSelection()) + R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) + R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) + R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) + } + return true + } + private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) @@ -133,6 +144,25 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r }) } + private fun initViewEvent() { + selMenu = PopupMenu(this, iv_menu_more) + selMenu.inflate(R.menu.rss_source_sel) + selMenu.setOnMenuItemClickListener(this) + cb_selected_all.onClick { + if (adapter.getSelection().size == adapter.getActualItemCount()) { + adapter.revertSelection() + } else { + adapter.selectAll() + } + } + btn_revert_selection.onClick { + adapter.revertSelection() + } + iv_menu_more.onClick { + selMenu.show() + } + } + private fun upGroupMenu() { groupMenu?.removeGroup(R.id.source_group) groups.map { @@ -153,9 +183,44 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r .calculateDiff(DiffCallBack(adapter.getItems(), it)) adapter.setItems(it, false) diffResult.dispatchUpdatesTo(adapter) + upCountView() }) } + override fun upCountView() { + val selectCount = adapter.getSelection().size + if (selectCount == 0) { + cb_selected_all.isChecked = false + } else { + cb_selected_all.isChecked = selectCount >= adapter.getActualItemCount() + } + + //重置全选的文字 + if (cb_selected_all.isChecked) { + cb_selected_all.text = getString( + R.string.select_cancel_count, + selectCount, + adapter.getActualItemCount() + ) + } else { + cb_selected_all.text = getString( + R.string.select_all_count, + selectCount, + adapter.getActualItemCount() + ) + } + setMenuClickable(selectCount > 0) + } + + private fun setMenuClickable(isClickable: Boolean) { + //设置是否可删除 + btn_delete.isEnabled = isClickable + btn_delete.isClickable = isClickable + //设置是否可添加书籍 + btn_revert_selection.isEnabled = isClickable + btn_revert_selection.isClickable = isClickable + } + @SuppressLint("InflateParams") private fun showImportDialog() { val aCache = ACache.get(this, cacheDir = false) 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 1ec7d8bbd..324a683c0 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 @@ -18,31 +18,33 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_rss_source), ItemTouchCallback.OnItemTouchCallbackListener { - private val selectedIds = linkedSetOf() + private val selected = linkedSetOf() fun selectAll() { getItems().forEach { - selectedIds.add(it.sourceUrl) + selected.add(it) } notifyItemRangeChanged(0, itemCount, 1) + callBack.upCountView() } fun revertSelection() { getItems().forEach { - if (selectedIds.contains(it.sourceUrl)) { - selectedIds.remove(it.sourceUrl) + if (selected.contains(it)) { + selected.remove(it) } else { - selectedIds.add(it.sourceUrl) + selected.add(it) } } notifyItemRangeChanged(0, itemCount, 1) + callBack.upCountView() } - fun getSelectionIds(): LinkedHashSet { - val selection = linkedSetOf() + fun getSelection(): LinkedHashSet { + val selection = linkedSetOf() getItems().forEach { - if (selectedIds.contains(it.sourceUrl)) { - selection.add(it.sourceUrl) + if (selected.contains(it)) { + selection.add(it) } } return selection @@ -63,13 +65,14 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : item.enabled = swt_enabled.isChecked callBack.update(item) } - cb_source.isChecked = selectedIds.contains(item.sourceUrl) + cb_source.isChecked = selected.contains(item) cb_source.setOnClickListener { if (cb_source.isChecked) { - selectedIds.add(item.sourceUrl) + selected.add(item) } else { - selectedIds.remove(item.sourceUrl) + selected.remove(item) } + callBack.upCountView() } iv_edit.onClick { callBack.edit(item) } iv_menu_more.onClick { @@ -87,7 +90,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : } } else { when (payloads[0]) { - 1 -> cb_source.isChecked = selectedIds.contains(item.sourceUrl) + 1 -> cb_source.isChecked = selected.contains(item) 2 -> swt_enabled.isChecked = item.enabled } } @@ -128,5 +131,6 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : fun update(vararg source: RssSource) fun toTop(source: RssSource) fun upOrder() + fun upCountView() } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index bed9a6e62..bb9e5f219 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -41,32 +41,38 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) } } - fun enableSelection(ids: LinkedHashSet) { + fun enableSelection(sources: LinkedHashSet) { execute { - App.db.rssSourceDao().enableSection(*ids.toTypedArray()) + val list = arrayListOf() + sources.forEach { + list.add(it.copy(enabled = true)) + } + App.db.rssSourceDao().update(*list.toTypedArray()) } } - fun disableSelection(ids: LinkedHashSet) { + fun disableSelection(sources: LinkedHashSet) { execute { - App.db.rssSourceDao().disableSection(*ids.toTypedArray()) + val list = arrayListOf() + sources.forEach { + list.add(it.copy(enabled = false)) + } + App.db.rssSourceDao().update(*list.toTypedArray()) } } - fun delSelection(ids: LinkedHashSet) { + fun delSelection(sources: LinkedHashSet) { execute { - App.db.rssSourceDao().delSection(*ids.toTypedArray()) + App.db.rssSourceDao().delete(*sources.toTypedArray()) } } - fun exportSelection(ids: LinkedHashSet) { + fun exportSelection(sources: LinkedHashSet) { execute { - App.db.rssSourceDao().getRssSources(*ids.toTypedArray()).let { - val json = GSON.toJson(it) - val file = - FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportRssSource.json") - file.writeText(json) - } + val json = GSON.toJson(sources) + val file = + FileUtils.createFileIfNotExist(Backup.exportPath + File.separator + "exportRssSource.json") + file.writeText(json) }.onSuccess { context.toast("成功导出至\n${Backup.exportPath}") }.onError { diff --git a/app/src/main/res/layout/activity_rss_source.xml b/app/src/main/res/layout/activity_rss_source.xml index e3c5bd53e..65f0b5722 100644 --- a/app/src/main/res/layout/activity_rss_source.xml +++ b/app/src/main/res/layout/activity_rss_source.xml @@ -3,6 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical"> + android:layout_height="0dp" + android:layout_weight="1"> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/rss_source_sel.xml b/app/src/main/res/menu/rss_source_sel.xml new file mode 100644 index 000000000..e1a5c9e2d --- /dev/null +++ b/app/src/main/res/menu/rss_source_sel.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + From 140f78aa9f4ef4c3e917e52c8ef3912364a17d6d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 15:27:11 +0800 Subject: [PATCH 477/852] =?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/data/dao/RssSourceDao.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index b4018f803..c1c1e85d9 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -46,6 +46,9 @@ interface RssSourceDao { @Delete fun delete(vararg rssSource: RssSource) + @Query("delete from rssSources where sourceUrl = :sourceUrl") + fun delete(sourceUrl: String) + @get:Query("select * from rssSources where sourceGroup is null or sourceGroup = ''") val noGroup: List From 3b8385903e7c8ae40c614b1c72f910ffccd1a95a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 15:32:21 +0800 Subject: [PATCH 478/852] =?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/res/menu/rss_source.xml | 6 ------ app/src/main/res/menu/rss_source_sel.xml | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/res/menu/rss_source.xml b/app/src/main/res/menu/rss_source.xml index 36bbef025..30510e262 100644 --- a/app/src/main/res/menu/rss_source.xml +++ b/app/src/main/res/menu/rss_source.xml @@ -91,12 +91,6 @@ android:title="@string/import_by_qr_code" app:showAsAction="never" /> - - + + From 5288185b62bbb5cd9fb1f2b7a3e57b0b3873c1ab Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 15:38:56 +0800 Subject: [PATCH 479/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/rss/source/manage/RssSourceActivity.kt | 2 ++ 1 file changed, 2 insertions(+) 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 0176433c8..6b1c40077 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 @@ -101,6 +101,8 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r R.id.menu_disable_selection -> viewModel.disableSelection(adapter.getSelection()) R.id.menu_del_selection -> viewModel.delSelection(adapter.getSelection()) R.id.menu_export_selection -> viewModel.exportSelection(adapter.getSelection()) + R.id.menu_check_source -> { + } } return true } From 33bbd59a8de260b5f48371c7d893d6636a4ec5eb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 15:46:11 +0800 Subject: [PATCH 480/852] =?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/res/menu/rss_source.xml | 43 ---------------------------- 1 file changed, 43 deletions(-) diff --git a/app/src/main/res/menu/rss_source.xml b/app/src/main/res/menu/rss_source.xml index 30510e262..d2ac21cec 100644 --- a/app/src/main/res/menu/rss_source.xml +++ b/app/src/main/res/menu/rss_source.xml @@ -3,49 +3,6 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> - - - - - - - - - - - - - - - - - - - - Date: Sat, 8 Feb 2020 16:52:48 +0800 Subject: [PATCH 481/852] =?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/ui/book/source/manage/BookSourceAdapter.kt | 4 +--- app/src/main/res/menu/book_source_item.xml | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/menu/book_source_item.xml 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 1da9f5ae4..a213f8f97 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 @@ -2,7 +2,6 @@ package io.legado.app.ui.book.source.manage import android.content.Context import android.os.Bundle -import android.view.Menu import android.widget.PopupMenu import androidx.core.os.bundleOf import androidx.recyclerview.widget.RecyclerView @@ -80,8 +79,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : iv_edit.onClick { callBack.edit(item) } iv_menu_more.onClick { val popupMenu = PopupMenu(context, it) - popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top) - popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete) + popupMenu.inflate(R.menu.book_source_item) popupMenu.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.menu_top -> callBack.toTop(item) diff --git a/app/src/main/res/menu/book_source_item.xml b/app/src/main/res/menu/book_source_item.xml new file mode 100644 index 000000000..17483eeec --- /dev/null +++ b/app/src/main/res/menu/book_source_item.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file From dbb2c19125c7e9bb93b8a9cc94c4c0d5a250ebd6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 16:55:47 +0800 Subject: [PATCH 482/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/replacerule/ReplaceRuleAdapter.kt | 4 +--- .../app/ui/rss/source/manage/RssSourceAdapter.kt | 4 +--- app/src/main/res/menu/replace_rule_item.xml | 12 ++++++++++++ app/src/main/res/menu/rss_source_item.xml | 12 ++++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/menu/replace_rule_item.xml create mode 100644 app/src/main/res/menu/rss_source_item.xml 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 0a08d2021..62b70de40 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 @@ -2,7 +2,6 @@ package io.legado.app.ui.replacerule import android.content.Context import android.os.Bundle -import android.view.Menu import android.widget.PopupMenu import androidx.core.os.bundleOf import androidx.recyclerview.widget.RecyclerView @@ -80,8 +79,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } iv_menu_more.onClick { val popupMenu = PopupMenu(context, it) - popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top) - popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete) + popupMenu.inflate(R.menu.replace_rule_item) popupMenu.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.menu_top -> callBack.toTop(item) 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 324a683c0..e388ffbc1 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 @@ -1,7 +1,6 @@ package io.legado.app.ui.rss.source.manage import android.content.Context -import android.view.Menu import android.widget.PopupMenu import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -77,8 +76,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : iv_edit.onClick { callBack.edit(item) } iv_menu_more.onClick { val popupMenu = PopupMenu(context, it) - popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top) - popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete) + popupMenu.inflate(R.menu.rss_source_item) popupMenu.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { R.id.menu_top -> callBack.toTop(item) diff --git a/app/src/main/res/menu/replace_rule_item.xml b/app/src/main/res/menu/replace_rule_item.xml new file mode 100644 index 000000000..17483eeec --- /dev/null +++ b/app/src/main/res/menu/replace_rule_item.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/rss_source_item.xml b/app/src/main/res/menu/rss_source_item.xml new file mode 100644 index 000000000..17483eeec --- /dev/null +++ b/app/src/main/res/menu/rss_source_item.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file From 89c8a72ce1cc23f19cfea754471f130df09b808a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 17:04:51 +0800 Subject: [PATCH 483/852] =?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/ui/main/explore/ExploreAdapter.kt | 11 ++++++---- app/src/main/res/menu/explore_item.xml | 20 +++++++++++++++++++ app/src/main/res/values/ids.xml | 3 --- 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/menu/explore_item.xml diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 144fa4e19..e3fb6f190 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -2,8 +2,8 @@ package io.legado.app.ui.main.explore import android.content.Context import android.view.LayoutInflater -import android.view.Menu import android.widget.PopupMenu +import io.legado.app.App import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter @@ -40,9 +40,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } ll_title.onLongClick { val popupMenu = PopupMenu(context, ll_title) - popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit) - popupMenu.menu.add(Menu.NONE, R.id.menu_top, Menu.NONE, R.string.to_top) - popupMenu.menu.add(Menu.NONE, R.id.menu_refresh, Menu.NONE, R.string.refresh) + popupMenu.inflate(R.menu.explore_item) popupMenu.setOnMenuItemClickListener { when (it.itemId) { R.id.menu_edit -> callBack.editSource(item.bookSourceUrl) @@ -51,6 +49,11 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca ACache.get(context, "explore").remove(item.bookSourceUrl) notifyItemChanged(holder.layoutPosition) } + R.id.menu_del -> { + Coroutine.async(scope) { + App.db.bookSourceDao().delete(item) + } + } } true } diff --git a/app/src/main/res/menu/explore_item.xml b/app/src/main/res/menu/explore_item.xml new file mode 100644 index 000000000..8cc2fe0c3 --- /dev/null +++ b/app/src/main/res/menu/explore_item.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 016946f36..cc2d9c170 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -1,8 +1,5 @@ - - - From f061f214873e9fe48902290c93922c9663b7c03e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 18:09:08 +0800 Subject: [PATCH 484/852] =?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/main/explore/ExploreAdapter.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index e3fb6f190..599268ed5 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -49,10 +49,8 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca ACache.get(context, "explore").remove(item.bookSourceUrl) notifyItemChanged(holder.layoutPosition) } - R.id.menu_del -> { - Coroutine.async(scope) { - App.db.bookSourceDao().delete(item) - } + R.id.menu_del -> Coroutine.async(scope) { + App.db.bookSourceDao().delete(item) } } true From 120dc86e3991a4f2640ce7c34e37eca32db93b1c Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 18:22:56 +0800 Subject: [PATCH 485/852] =?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/ui/book/search/SearchActivity.kt | 8 +++ .../app/ui/book/search/SearchViewModel.kt | 57 ++++++++++--------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index fb250fb46..1fed76755 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -141,6 +141,14 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se adapter = SearchAdapter(this, this) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter + adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { + override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { + super.onItemRangeInserted(positionStart, itemCount) + if (positionStart == 0) { + recycler_view.scrollToPosition(0) + } + } + }) loadMoreView = LoadMoreView(this) recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 125204062..17cd8b7bf 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -11,9 +11,10 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefString -import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.asCoroutineDispatcher -import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import java.util.concurrent.Executors class SearchViewModel(application: Application) : BaseViewModel(application) { @@ -56,7 +57,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { context = searchPool ) .timeout(30000L) - .onSuccess(Dispatchers.IO) { + .onSuccess { it?.let { list -> searchSuccess(list) } @@ -70,22 +71,24 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } - private fun searchSuccess(searchBooks: List) { - val books = arrayListOf() - searchBooks.forEach { searchBook -> - if (context.getPrefBoolean(PreferKey.precisionSearch)) { - if (searchBook.name.equals(searchKey, true) - || searchBook.author.equals(searchKey, true) - ) books.add(searchBook) - } else - books.add(searchBook) + private suspend fun searchSuccess(searchBooks: List) { + withContext(IO) { + val books = arrayListOf() + searchBooks.forEach { searchBook -> + if (context.getPrefBoolean(PreferKey.precisionSearch)) { + if (searchBook.name.equals(searchKey, true) + || searchBook.author.equals(searchKey, true) + ) books.add(searchBook) + } else + books.add(searchBook) + } + App.db.searchBookDao().insert(*books.toTypedArray()) + addToAdapter(books) } - App.db.searchBookDao().insert(*books.toTypedArray()) - addToAdapter(books) } @Synchronized - private fun addToAdapter(newDataS: List) { + private suspend fun addToAdapter(newDataS: List) { if (newDataS.isNotEmpty()) { val copyDataS = ArrayList(searchBooks) val searchBooksAdd = ArrayList() @@ -93,46 +96,46 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { copyDataS.addAll(newDataS) } else { //存在 - for (temp in newDataS) { + newDataS.forEach { item -> var hasSame = false for (i in copyDataS.indices) { val searchBook = copyDataS[i] - if (temp.name == searchBook.name - && temp.author == searchBook.author + if (item.name == searchBook.name + && item.author == searchBook.author ) { hasSame = true - searchBook.addOrigin(temp.bookUrl) + searchBook.addOrigin(item.bookUrl) break } } if (!hasSame) { - searchBooksAdd.add(temp) + searchBooksAdd.add(item) } } //添加 - for (temp in searchBooksAdd) { - if (searchKey == temp.name) { + searchBooksAdd.forEach { item -> + if (searchKey == item.name) { for (i in copyDataS.indices) { val searchBook = copyDataS[i] if (searchKey != searchBook.name) { - copyDataS.add(i, temp) + copyDataS.add(i, item) break } } - } else if (searchKey == temp.author) { + } else if (searchKey == item.author) { for (i in copyDataS.indices) { val searchBook = copyDataS[i] if (searchKey != searchBook.name && searchKey == searchBook.author) { - copyDataS.add(i, temp) + copyDataS.add(i, item) break } } } else { - copyDataS.add(temp) + copyDataS.add(item) } } } - launch { + withContext(Main) { searchBooks = copyDataS callBack?.adapter?.setItems(searchBooks) } From 1445410c207ccc234da296bd46d9ba7cab941f32 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 18:29:19 +0800 Subject: [PATCH 486/852] =?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/search/SearchViewModel.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 17cd8b7bf..1d0ff163a 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -98,8 +98,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { //存在 newDataS.forEach { item -> var hasSame = false - for (i in copyDataS.indices) { - val searchBook = copyDataS[i] + for (searchBook in copyDataS) { if (item.name == searchBook.name && item.author == searchBook.author ) { From 737f22997d770725ff6d2593044cf7d49e1a8b68 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 19:54:17 +0800 Subject: [PATCH 487/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/search/SearchActivity.kt | 14 ++++++++++++-- .../legado/app/ui/book/search/SearchViewModel.kt | 14 ++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 1fed76755..ddde45ec1 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -8,6 +8,7 @@ import android.view.View.VISIBLE import androidx.appcompat.widget.SearchView import androidx.lifecycle.LiveData import androidx.lifecycle.Observer +import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.App @@ -15,6 +16,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book +import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchKeyword import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor @@ -40,7 +42,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se override val viewModel: SearchViewModel get() = getViewModel(SearchViewModel::class.java) - override lateinit var adapter: SearchAdapter + lateinit var adapter: SearchAdapter private lateinit var bookAdapter: BookAdapter private lateinit var historyKeyAdapter: HistoryKeyAdapter private lateinit var loadMoreView: LoadMoreView @@ -176,6 +178,9 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se } upGroupMenu() }) + viewModel.searchBookLiveData.observe(this, Observer { + setSearchItems(it) + }) } private fun initIntent() { @@ -251,9 +256,14 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se }) } + private fun setSearchItems(items: List) { + val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), items)) + adapter.setItems(items, false) + diffResult.dispatchUpdatesTo(adapter) + } + override fun startSearch() { refresh_progress_bar.isAutoLoading = true - initData() fb_stop.visible() } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 1d0ff163a..2205f78fd 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.book.search import android.app.Application +import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.constant.PreferKey @@ -12,7 +13,6 @@ import io.legado.app.model.WebBook import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefString import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.withContext import java.util.concurrent.Executors @@ -22,6 +22,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() private var task: Coroutine<*>? = null var callBack: CallBack? = null + var searchBookLiveData = MutableLiveData>() var searchKey: String = "" var searchPage = 1 var isLoading = false @@ -83,12 +84,12 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { books.add(searchBook) } App.db.searchBookDao().insert(*books.toTypedArray()) - addToAdapter(books) + mergeItems(books) } } @Synchronized - private suspend fun addToAdapter(newDataS: List) { + private fun mergeItems(newDataS: List) { if (newDataS.isNotEmpty()) { val copyDataS = ArrayList(searchBooks) val searchBooksAdd = ArrayList() @@ -134,10 +135,8 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } } - withContext(Main) { - searchBooks = copyDataS - callBack?.adapter?.setItems(searchBooks) - } + searchBooks = copyDataS + searchBookLiveData.postValue(copyDataS) } } @@ -173,7 +172,6 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } interface CallBack { - var adapter: SearchAdapter fun startSearch() fun searchFinally() } From b5b5987efec941d7cd05e2b0d66cc4abfec644f6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 20:10:35 +0800 Subject: [PATCH 488/852] =?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/search/SearchViewModel.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 2205f78fd..185618d64 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -115,16 +115,14 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { //添加 searchBooksAdd.forEach { item -> if (searchKey == item.name) { - for (i in copyDataS.indices) { - val searchBook = copyDataS[i] + for ((index, searchBook) in copyDataS.withIndex()) { if (searchKey != searchBook.name) { - copyDataS.add(i, item) + copyDataS.add(index, item) break } } } else if (searchKey == item.author) { - for (i in copyDataS.indices) { - val searchBook = copyDataS[i] + for ((i, searchBook) in copyDataS.withIndex()) { if (searchKey != searchBook.name && searchKey == searchBook.author) { copyDataS.add(i, item) break From 1ac3a5cef20266e1019a0b4cff25ee7fc2997f40 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 20:35:27 +0800 Subject: [PATCH 489/852] =?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/service/help/ReadBook.kt | 10 ++++++---- .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index f5227f731..1f62d785a 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -39,14 +39,16 @@ object ReadBook { durChapterIndex = book.durChapterIndex durPageIndex = book.durChapterPos isLocalBook = book.origin == BookType.local - webBook = null - App.db.bookSourceDao().getBookSource(book.origin)?.let { - webBook = WebBook(it) - } chapterSize = 0 prevTextChapter = null curTextChapter = null nextTextChapter = null + upWebBook(book.origin) + } + + fun upWebBook(origin: String) { + val bookSource = App.db.bookSourceDao().getBookSource(origin) + webBook = if (bookSource != null) WebBook(bookSource) else null } fun moveToNextPage() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index ed5d9d04d..db7529cab 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -60,6 +60,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } else { isInitFinish = true ReadBook.titleDate.postValue(book.name) + ReadBook.upWebBook(book.origin) ReadBook.chapterSize = App.db.bookChapterDao().getChapterCount(book.bookUrl) if (ReadBook.chapterSize == 0) { if (book.tocUrl.isEmpty()) { From dbaef93f81226faaae8d52cccb64fb6d34020577 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 20:47:46 +0800 Subject: [PATCH 490/852] =?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/res/layout/activity_book_info.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index 53f69d1fb..cc9ae1926 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -192,7 +192,6 @@ android:maxHeight="160dp" android:minHeight="100dp" android:scrollbars="vertical" - android:textIsSelectable="true" android:textSize="14sp" /> Date: Sat, 8 Feb 2020 21:03:11 +0800 Subject: [PATCH 491/852] =?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/info/BookInfoActivity.kt | 2 ++ app/src/main/res/layout/activity_book_info.xml | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 9efde78b9..b515496c9 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Intent import android.graphics.drawable.Drawable import android.os.Bundle +import android.text.method.ScrollingMovementMethod import android.view.Menu import android.view.MenuItem import androidx.lifecycle.Observer @@ -53,6 +54,7 @@ class BookInfoActivity : override fun onActivityCreated(savedInstanceState: Bundle?) { title_bar.background.alpha = 0 + tv_intro.movementMethod = ScrollingMovementMethod.getInstance() viewModel.bookData.observe(this, Observer { showBook(it) }) viewModel.isLoadingData.observe(this, Observer { upLoading(it) }) viewModel.chapterListData.observe(this, Observer { showChapter(it) }) diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index cc9ae1926..d8c0b18a6 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -189,9 +189,7 @@ android:layout_weight="1" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" - android:maxHeight="160dp" android:minHeight="100dp" - android:scrollbars="vertical" android:textSize="14sp" /> Date: Sat, 8 Feb 2020 22:15:57 +0800 Subject: [PATCH 492/852] =?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/AppConfig.kt | 10 ++ .../main/java/io/legado/app/help/BookHelp.kt | 4 +- .../java/io/legado/app/help/storage/Backup.kt | 15 +-- .../app/model/localBook/AnalyzeTxtFile.kt | 2 +- .../app/ui/config/BackupConfigFragment.kt | 88 ++++++++++----- .../io/legado/app/ui/main/MainActivity.kt | 10 +- .../io/legado/app/ui/main/my/MyFragment.kt | 100 ++++++++++++------ .../java/io/legado/app/utils/FileUtils.kt | 2 +- 8 files changed, 156 insertions(+), 75 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index a5c0352aa..eab1acd6b 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -28,6 +28,16 @@ object AppConfig { App.INSTANCE.putPrefBoolean("transparentStatusBar", value) } + var backupPath: String? + get() = App.INSTANCE.getPrefString(PreferKey.backupPath) + set(value) { + if (value.isNullOrEmpty()) { + App.INSTANCE.removePref(PreferKey.backupPath) + } else { + App.INSTANCE.putPrefString(PreferKey.backupPath, value) + } + } + var isShowRSS: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.showRss, true) set(value) { diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index de8c0a5a7..67ea2bd30 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -75,7 +75,7 @@ object BookHelp { )?.uri?.writeText(App.INSTANCE, content) } } else { - FileUtils.createFileIfNotExist( + FileUtils.createFolderIfNotExist( File(downloadPath), subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) ).listFiles()?.forEach { @@ -101,7 +101,7 @@ object BookHelp { )?.listFiles()?.size ?: 0 } } else { - return FileUtils.createFileIfNotExist( + return FileUtils.createFolderIfNotExist( File(downloadPath), subDirs = *arrayOf(cacheFolderName, bookFolderName(book)) ).list()?.size ?: 0 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 30e77eab6..82485c363 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 @@ -8,6 +8,7 @@ import io.legado.app.help.ReadBookConfig import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON +import io.legado.app.utils.isContentPath import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.withContext import org.jetbrains.anko.defaultSharedPreferences @@ -43,7 +44,7 @@ object Backup { ) } - suspend fun backup(context: Context, uri: Uri?) { + suspend fun backup(context: Context, path: String = legadoPath) { withContext(IO) { writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath) @@ -70,10 +71,10 @@ object Backup { edit.commit() } WebDavHelp.backUpWebDav(backupPath) - if (uri != null) { - copyBackup(context, uri) + if (path.isContentPath()) { + copyBackup(context, Uri.parse(path)) } else { - copyBackup() + copyBackup(File(path)) } } } @@ -100,12 +101,12 @@ object Backup { } } - private fun copyBackup() { + private fun copyBackup(file: File) { try { for (fileName in backupFileNames) { - FileUtils.createFileIfNotExist(backupPath + File.separator + "bookshelf.json") + FileUtils.createFileIfNotExist(backupPath + File.separator + fileName) .copyTo( - FileUtils.createFileIfNotExist(legadoPath + File.separator + "bookshelf.json"), + FileUtils.createFileIfNotExist(file, fileName), true ) } diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 9783dca3e..99b6b95d3 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -24,7 +24,7 @@ object AnalyzeTxtFile { val rootFile = App.INSTANCE.getExternalFilesDir(null) ?: App.INSTANCE.externalCacheDir ?: App.INSTANCE.cacheDir - FileUtils.createFileIfNotExist(rootFile, subDirs = *arrayOf(folderName)) + FileUtils.createFolderIfNotExist(rootFile, subDirs = *arrayOf(folderName)) } fun analyze(context: Context, book: Book): ArrayList { diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 38f5568fb..76f9e92de 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -14,6 +14,7 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat @@ -127,40 +128,71 @@ class BackupConfigFragment : PreferenceFragmentCompat(), } private fun backup() { - val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(requireContext(), uri) - if (doc?.canWrite() == true) { - launch { - Backup.backup(requireContext(), uri) - toast(R.string.backup_success) + val backupPath = AppConfig.backupPath + if (backupPath.isNullOrEmpty()) { + selectBackupFolder() + } else { + if (backupPath.isContentPath()) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(requireContext(), uri) + if (doc?.canWrite() == true) { + launch { + Backup.backup(requireContext(), backupPath) + toast(R.string.backup_success) + } + } else { + selectBackupFolder() } } else { - selectBackupFolder() + backupUsePermission() } - } else { - selectBackupFolder() } } + private fun backupUsePermission(path: String = Backup.legadoPath) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + launch { + Backup.backup(requireContext(), path) + toast(R.string.backup_success) + } + } + .request() + } + private fun selectBackupFolder() { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, backupSelectRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - Backup.backup(requireContext(), null) - toast(R.string.backup_success) + alert { + titleResource = R.string.select_folder + items(arrayListOf("默认路径", "系统文件夹选择器", "自带文件夹选择器")) { _, index -> + when (index) { + 0 -> PermissionsCompat.Builder(this@BackupConfigFragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + launch { + AppConfig.backupPath = Backup.legadoPath + toast(R.string.backup_success) + } + } + .request() + 1 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, backupSelectRequestCode) + } catch (e: java.lang.Exception) { + e.printStackTrace() + toast(e.localizedMessage ?: "ERROR") + } + } + 2 -> { + } } - .request() - } + } + }.show() } fun restore() { @@ -313,10 +345,10 @@ class BackupConfigFragment : PreferenceFragmentCompat(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) - putPrefString(PreferKey.backupPath, uri.toString()) + AppConfig.backupPath = uri.toString() findPreference(PreferKey.backupPath)?.summary = uri.toString() launch { - Backup.backup(requireContext(), uri) + Backup.backup(requireContext(), uri.toString()) toast(R.string.backup_success) } } @@ -327,7 +359,7 @@ class BackupConfigFragment : PreferenceFragmentCompat(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) - putPrefString(PreferKey.backupPath, uri.toString()) + AppConfig.backupPath = uri.toString() findPreference(PreferKey.backupPath)?.summary = uri.toString() launch { Restore.restore(requireContext(), uri) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 3b4bbb859..c540a8448 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -128,14 +128,16 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), private fun backup() { Coroutine.async { val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { + if (backupPath.isNullOrEmpty()) { + Backup.backup(this@MainActivity) + } else { val uri = Uri.parse(backupPath) val doc = DocumentFile.fromTreeUri(this@MainActivity, uri) if (doc?.canWrite() == true) { - Backup.backup(this@MainActivity, uri) + Backup.backup(this@MainActivity, backupPath) + } else { + Backup.backup(this@MainActivity) } - } else { - Backup.backup(this@MainActivity, null) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 09969afda..af907c5a4 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -16,12 +16,14 @@ import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore import io.legado.app.help.storage.WebDavHelp +import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.prefs.ATESwitchPreference import io.legado.app.service.WebService @@ -45,7 +47,8 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { val fragmentTag = "prefFragment" var preferenceFragment = childFragmentManager.findFragmentByTag(fragmentTag) if (preferenceFragment == null) preferenceFragment = PreferenceFragment() - childFragmentManager.beginTransaction().replace(R.id.pre_fragment, preferenceFragment, fragmentTag).commit() + childFragmentManager.beginTransaction() + .replace(R.id.pre_fragment, preferenceFragment, fragmentTag).commit() } override fun onCompatCreateOptionsMenu(menu: Menu) { @@ -60,42 +63,72 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { } } - private fun backup() { - val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(requireContext(), uri) - if (doc?.canWrite() == true) { - launch { - Backup.backup(requireContext(), uri) - toast(R.string.backup_success) + val backupPath = AppConfig.backupPath + if (backupPath.isNullOrEmpty()) { + selectBackupFolder() + } else { + if (backupPath.isContentPath()) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(requireContext(), uri) + if (doc?.canWrite() == true) { + launch { + Backup.backup(requireContext(), backupPath) + toast(R.string.backup_success) + } + } else { + selectBackupFolder() } } else { - selectBackupFolder() + backupUsePermission() } - } else { - selectBackupFolder() } } + private fun backupUsePermission(path: String = Backup.legadoPath) { + PermissionsCompat.Builder(this) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + launch { + Backup.backup(requireContext(), path) + toast(R.string.backup_success) + } + } + .request() + } + private fun selectBackupFolder() { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, backupSelectRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - Backup.backup(requireContext(), null) - toast(R.string.backup_success) + alert { + titleResource = R.string.select_folder + items(arrayListOf("默认路径", "系统文件夹选择器", "自带文件夹选择器")) { _, index -> + when (index) { + 0 -> PermissionsCompat.Builder(this@MyFragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + launch { + AppConfig.backupPath = Backup.legadoPath + toast(R.string.backup_success) + } + } + .request() + 1 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, backupSelectRequestCode) + } catch (e: java.lang.Exception) { + e.printStackTrace() + toast(e.localizedMessage ?: "ERROR") + } + } + 2 -> { + } } - .request() - } + } + }.show() } fun restore() { @@ -148,9 +181,9 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) - putPrefString(PreferKey.backupPath, uri.toString()) + AppConfig.backupPath = uri.toString() launch { - Backup.backup(requireContext(), uri) + Backup.backup(requireContext(), uri.toString()) toast(R.string.backup_success) } } @@ -161,7 +194,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) - putPrefString(PreferKey.backupPath, uri.toString()) + AppConfig.backupPath = uri.toString() launch { Restore.restore(requireContext(), uri) toast(R.string.restore_success) @@ -202,14 +235,17 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { super.onPause() } - override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + override fun onSharedPreferenceChanged( + sharedPreferences: SharedPreferences?, + key: String? + ) { when (key) { PreferKey.themeMode -> App.INSTANCE.applyDayNight() PreferKey.webService -> { if (requireContext().getPrefBoolean("webService")) { WebService.start(requireContext()) toast(R.string.service_start) - }else{ + } else { WebService.stop(requireContext()) toast(R.string.service_stop) } diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index 13e55161d..8dbfa318f 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -22,7 +22,7 @@ object FileUtils { return createFileIfNotExist(filePath) } - fun createFileIfNotExist(root: File, vararg subDirs: String): File { + fun createFolderIfNotExist(root: File, vararg subDirs: String): File { val filePath = root.absolutePath + File.separator + subDirs.joinToString(File.separator) return createFolderIfNotExist(filePath) } From 65c02920ad037079e0ba20533a8a3fcec169db17 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 22:20:47 +0800 Subject: [PATCH 493/852] =?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/main/my/MyFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index af907c5a4..7919ced42 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -109,7 +109,6 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { .onGranted { launch { AppConfig.backupPath = Backup.legadoPath - toast(R.string.backup_success) } } .request() From bef1aea9e0b927bc0af8a3a2585afcefaecea8c9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 22:21:32 +0800 Subject: [PATCH 494/852] =?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/main/my/MyFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 7919ced42..057ea6a8d 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -109,6 +109,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { .onGranted { launch { AppConfig.backupPath = Backup.legadoPath + backupUsePermission() } } .request() From 112f8482de69c28ce122fc8fabcc836f7c8fedb8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 22:40:20 +0800 Subject: [PATCH 495/852] =?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/ui/config/BackupConfigFragment.kt | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 76f9e92de..936f1704f 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.config import android.app.Activity.RESULT_OK import android.content.Intent +import android.content.SharedPreferences import android.net.Uri import android.os.Build import android.os.Bundle @@ -33,7 +34,7 @@ import org.jetbrains.anko.toast import kotlin.coroutines.CoroutineContext class BackupConfigFragment : PreferenceFragmentCompat(), - Preference.OnPreferenceChangeListener, + SharedPreferences.OnSharedPreferenceChangeListener, CoroutineScope { private lateinit var job: Job private val oldDataRequestCode = 11 @@ -45,24 +46,17 @@ class BackupConfigFragment : PreferenceFragmentCompat(), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { job = Job() - fun bindPreferenceSummaryToValue(preference: Preference?) { - preference?.apply { - onPreferenceChangeListener = this@BackupConfigFragment - onPreferenceChange(this, context.getPrefString(key)) - } - } addPreferencesFromResource(R.xml.pref_config_backup) findPreference(PreferKey.webDavUrl)?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) } - bindPreferenceSummaryToValue(it) + } findPreference(PreferKey.webDavAccount)?.let { it.setOnBindEditTextListener { editText -> ATH.setTint(editText, requireContext().accentColor) } - bindPreferenceSummaryToValue(it) } findPreference(PreferKey.webDavPassword)?.let { it.setOnBindEditTextListener { editText -> @@ -70,9 +64,11 @@ class BackupConfigFragment : PreferenceFragmentCompat(), editText.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_CLASS_TEXT } - bindPreferenceSummaryToValue(it) } - bindPreferenceSummaryToValue(findPreference(PreferKey.backupPath)) + upPreferenceSummary(PreferKey.webDavUrl, getPrefString(PreferKey.webDavUrl)) + upPreferenceSummary(PreferKey.webDavAccount, getPrefString(PreferKey.webDavAccount)) + upPreferenceSummary(PreferKey.webDavPassword, getPrefString(PreferKey.webDavPassword)) + upPreferenceSummary(PreferKey.backupPath, getPrefString(PreferKey.backupPath)) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -80,41 +76,58 @@ class BackupConfigFragment : PreferenceFragmentCompat(), ATH.applyEdgeEffectColor(listView) } + override fun onResume() { + super.onResume() + preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + } + + override fun onPause() { + preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + super.onPause() + } + override fun onDestroy() { super.onDestroy() job.cancel() } - override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { - when (preference?.key) { + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + key?.let { + upPreferenceSummary(it, getPrefString(it)) + } + } + + private fun upPreferenceSummary(preferenceKey: String, value: String?) { + val preference = findPreference(preferenceKey) ?: return + when (preferenceKey) { PreferKey.webDavUrl -> - if (newValue == null) { + if (value == null) { preference.summary = getString(R.string.web_dav_url_s) } else { - preference.summary = newValue.toString() + preference.summary = value.toString() } PreferKey.webDavAccount -> - if (newValue == null) { + if (value == null) { preference.summary = getString(R.string.web_dav_account_s) } else { - preference.summary = newValue.toString() + preference.summary = value.toString() } PreferKey.webDavPassword -> - if (newValue == null) { + if (value == null) { preference.summary = getString(R.string.web_dav_pw_s) } else { - preference.summary = "*".repeat(newValue.toString().length) + preference.summary = "*".repeat(value.toString().length) } - else -> + else -> { if (preference is ListPreference) { - val index = preference.findIndexOfValue(newValue?.toString()) + val index = preference.findIndexOfValue(value) // Set the summary to reflect the new value. - preference.setSummary(if (index >= 0) preference.entries[index] else null) + preference.summary = if (index >= 0) preference.entries[index] else null } else { - preference?.summary = newValue?.toString() + preference.summary = value } + } } - return false } override fun onPreferenceTreeClick(preference: Preference?): Boolean { @@ -346,7 +359,6 @@ class BackupConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.backupPath = uri.toString() - findPreference(PreferKey.backupPath)?.summary = uri.toString() launch { Backup.backup(requireContext(), uri.toString()) toast(R.string.backup_success) @@ -360,7 +372,6 @@ class BackupConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.backupPath = uri.toString() - findPreference(PreferKey.backupPath)?.summary = uri.toString() launch { Restore.restore(requireContext(), uri) toast(R.string.restore_success) From 68804b2c24deafa74b015b67aa206f4ff22b01a1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 22:42:53 +0800 Subject: [PATCH 496/852] =?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/config/BackupConfigFragment.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 936f1704f..be621e76f 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -92,8 +92,10 @@ class BackupConfigFragment : PreferenceFragmentCompat(), } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { - key?.let { - upPreferenceSummary(it, getPrefString(it)) + when (key) { + PreferKey.webDavUrl, PreferKey.webDavAccount, PreferKey.webDavPassword, PreferKey.backupPath -> { + upPreferenceSummary(key, getPrefString(key)) + } } } From d7c1da569cdffc4b061668d49e6521a8c3c3a8d5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 22:49:39 +0800 Subject: [PATCH 497/852] =?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/res/layout/dialog_number_picker.xml | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/src/main/res/layout/dialog_number_picker.xml b/app/src/main/res/layout/dialog_number_picker.xml index ea6582170..6dbf5d4fd 100644 --- a/app/src/main/res/layout/dialog_number_picker.xml +++ b/app/src/main/res/layout/dialog_number_picker.xml @@ -1,24 +1,13 @@ - - + android:layout_gravity="center" /> - - - - - - - \ No newline at end of file + \ No newline at end of file From c97017e9619a52f1224b07d58bd82e165322e92b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 22:55:02 +0800 Subject: [PATCH 498/852] =?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/config/BackupConfigFragment.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index be621e76f..56322a265 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -93,7 +93,10 @@ class BackupConfigFragment : PreferenceFragmentCompat(), override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { - PreferKey.webDavUrl, PreferKey.webDavAccount, PreferKey.webDavPassword, PreferKey.backupPath -> { + PreferKey.webDavUrl, + PreferKey.webDavAccount, + PreferKey.webDavPassword, + PreferKey.backupPath -> { upPreferenceSummary(key, getPrefString(key)) } } @@ -188,7 +191,6 @@ class BackupConfigFragment : PreferenceFragmentCompat(), .onGranted { launch { AppConfig.backupPath = Backup.legadoPath - toast(R.string.backup_success) } } .request() From 952abab4f96602efd52e41631daa9de12182e50c Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 23:38:13 +0800 Subject: [PATCH 499/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/storage/WebDavHelp.kt | 9 +- .../app/ui/config/BackupConfigFragment.kt | 151 +-------------- .../legado/app/ui/config/BackupRestoreUi.kt | 173 ++++++++++++++++++ .../io/legado/app/ui/main/my/MyFragment.kt | 156 +--------------- 4 files changed, 191 insertions(+), 298 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 7612a6913..5576e9c11 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -10,6 +10,7 @@ import io.legado.app.utils.FileUtils import io.legado.app.utils.ZipUtils import io.legado.app.utils.getPrefString import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.withContext import org.jetbrains.anko.selector import java.io.File @@ -58,9 +59,11 @@ object WebDavHelp { suspend fun showRestoreDialog(context: Context, restoreSuccess: () -> Unit): Boolean { val names = withContext(IO) { getWebDavFileNames() } return if (names.isNotEmpty()) { - context.selector(title = "选择恢复文件", items = names) { _, index -> - if (index in 0 until names.size) { - restoreWebDav(names[index], restoreSuccess) + withContext(Main) { + context.selector(title = "选择恢复文件", items = names) { _, index -> + if (index in 0 until names.size) { + restoreWebDav(names[index], restoreSuccess) + } } } true diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 56322a265..2336dbd76 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -15,19 +15,19 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.PreferKey -import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat -import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore -import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor -import io.legado.app.utils.* +import io.legado.app.utils.DocumentUtils +import io.legado.app.utils.LogUtils +import io.legado.app.utils.applyTint +import io.legado.app.utils.getPrefString import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO import org.jetbrains.anko.toast @@ -38,8 +38,6 @@ class BackupConfigFragment : PreferenceFragmentCompat(), CoroutineScope { private lateinit var job: Job private val oldDataRequestCode = 11 - private val backupSelectRequestCode = 22 - private val restoreSelectRequestCode = 33 override val coroutineContext: CoroutineContext get() = job + Dispatchers.Main @@ -137,122 +135,14 @@ class BackupConfigFragment : PreferenceFragmentCompat(), override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - PreferKey.backupPath -> selectBackupFolder() - "web_dav_backup" -> backup() - "web_dav_restore" -> restore() + PreferKey.backupPath -> BackupRestoreUi.selectBackupFolder(this) + "web_dav_backup" -> BackupRestoreUi.backup(this) + "web_dav_restore" -> BackupRestoreUi.restore(this) "import_old" -> importOldData() } return super.onPreferenceTreeClick(preference) } - private fun backup() { - val backupPath = AppConfig.backupPath - if (backupPath.isNullOrEmpty()) { - selectBackupFolder() - } else { - if (backupPath.isContentPath()) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(requireContext(), uri) - if (doc?.canWrite() == true) { - launch { - Backup.backup(requireContext(), backupPath) - toast(R.string.backup_success) - } - } else { - selectBackupFolder() - } - } else { - backupUsePermission() - } - } - } - - private fun backupUsePermission(path: String = Backup.legadoPath) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - Backup.backup(requireContext(), path) - toast(R.string.backup_success) - } - } - .request() - } - - private fun selectBackupFolder() { - alert { - titleResource = R.string.select_folder - items(arrayListOf("默认路径", "系统文件夹选择器", "自带文件夹选择器")) { _, index -> - when (index) { - 0 -> PermissionsCompat.Builder(this@BackupConfigFragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - AppConfig.backupPath = Backup.legadoPath - } - } - .request() - 1 -> { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, backupSelectRequestCode) - } catch (e: java.lang.Exception) { - e.printStackTrace() - toast(e.localizedMessage ?: "ERROR") - } - } - 2 -> { - - } - } - } - }.show() - } - - fun restore() { - launch { - if (!WebDavHelp.showRestoreDialog(requireContext()) { - toast(R.string.restore_success) - }) { - val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(requireContext(), uri) - if (doc?.canWrite() == true) { - Restore.restore(requireContext(), uri) - toast(R.string.restore_success) - } else { - selectBackupFolder() - } - } else { - selectRestoreFolder() - } - } - } - } - - private fun selectRestoreFolder() { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, restoreSelectRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - Restore.restore(Backup.legadoPath) - toast(R.string.restore_success) - } - } - .request() - } - } - private fun importOldData() { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) @@ -351,37 +241,12 @@ class BackupConfigFragment : PreferenceFragmentCompat(), override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) + BackupRestoreUi.onActivityResult(requestCode, resultCode, data) when (requestCode) { oldDataRequestCode -> if (resultCode == RESULT_OK) data?.data?.let { uri -> importOldData(uri) } - backupSelectRequestCode -> if (resultCode == RESULT_OK) { - data?.data?.let { uri -> - requireContext().contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - AppConfig.backupPath = uri.toString() - launch { - Backup.backup(requireContext(), uri.toString()) - toast(R.string.backup_success) - } - } - } - restoreSelectRequestCode -> if (resultCode == RESULT_OK) { - data?.data?.let { uri -> - requireContext().contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - AppConfig.backupPath = uri.toString() - launch { - Restore.restore(requireContext(), uri) - toast(R.string.restore_success) - } - } - } } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt new file mode 100644 index 000000000..773a7ceb3 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -0,0 +1,173 @@ +package io.legado.app.ui.config + +import android.app.Activity.RESULT_OK +import android.content.Intent +import android.net.Uri +import androidx.documentfile.provider.DocumentFile +import androidx.fragment.app.Fragment +import io.legado.app.App +import io.legado.app.R +import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig +import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.permission.Permissions +import io.legado.app.help.permission.PermissionsCompat +import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.Restore +import io.legado.app.help.storage.WebDavHelp +import io.legado.app.lib.dialogs.alert +import io.legado.app.utils.getPrefString +import io.legado.app.utils.isContentPath +import io.legado.app.utils.toast +import kotlinx.coroutines.Dispatchers.Main +import org.jetbrains.anko.toast + +object BackupRestoreUi { + + private const val backupSelectRequestCode = 22 + private const val restoreSelectRequestCode = 33 + + fun backup(fragment: Fragment) { + val backupPath = AppConfig.backupPath + if (backupPath.isNullOrEmpty()) { + selectBackupFolder(fragment) + } else { + if (backupPath.isContentPath()) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri) + if (doc?.canWrite() == true) { + Coroutine.async { + Backup.backup(fragment.requireContext(), backupPath) + }.onSuccess { + fragment.toast(R.string.backup_success) + } + } else { + selectBackupFolder(fragment) + } + } else { + backupUsePermission(fragment) + } + } + } + + private fun backupUsePermission(fragment: Fragment, path: String = Backup.legadoPath) { + PermissionsCompat.Builder(fragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + Coroutine.async { + Backup.backup(fragment.requireContext(), path) + }.onSuccess { + fragment.toast(R.string.backup_success) + } + } + .request() + } + + fun selectBackupFolder(fragment: Fragment) { + fragment.alert { + titleResource = R.string.select_folder + items(arrayListOf("默认路径", "系统文件夹选择器", "自带文件夹选择器")) { _, index -> + when (index) { + 0 -> PermissionsCompat.Builder(fragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + AppConfig.backupPath = Backup.legadoPath + backupUsePermission(fragment) + } + .request() + 1 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + fragment.startActivityForResult(intent, backupSelectRequestCode) + } catch (e: java.lang.Exception) { + e.printStackTrace() + fragment.toast(e.localizedMessage ?: "ERROR") + } + } + 2 -> { + + } + } + } + }.show() + } + + fun restore(fragment: Fragment) { + Coroutine.async(context = Main) { + if (!WebDavHelp.showRestoreDialog(fragment.requireContext()) { + fragment.toast(R.string.restore_success) + }) { + val backupPath = fragment.getPrefString(PreferKey.backupPath) + if (backupPath?.isNotEmpty() == true) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri) + if (doc?.canWrite() == true) { + Restore.restore(fragment.requireContext(), uri) + fragment.toast(R.string.restore_success) + } else { + selectRestoreFolder(fragment) + } + } else { + selectRestoreFolder(fragment) + } + } + } + } + + private fun selectRestoreFolder(fragment: Fragment) { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + fragment.startActivityForResult(intent, restoreSelectRequestCode) + } catch (e: java.lang.Exception) { + PermissionsCompat.Builder(fragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + Coroutine.async { + Restore.restore(Backup.legadoPath) + }.onSuccess { + fragment.toast(R.string.restore_success) + } + } + .request() + } + } + + fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + when (requestCode) { + backupSelectRequestCode -> if (resultCode == RESULT_OK) { + data?.data?.let { uri -> + App.INSTANCE.contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + AppConfig.backupPath = uri.toString() + Coroutine.async { + Backup.backup(App.INSTANCE, uri.toString()) + }.onSuccess { + App.INSTANCE.toast(R.string.backup_success) + } + } + } + restoreSelectRequestCode -> if (resultCode == RESULT_OK) { + data?.data?.let { uri -> + App.INSTANCE.contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + AppConfig.backupPath = uri.toString() + Coroutine.async { + Restore.restore(App.INSTANCE, uri) + }.onSuccess { + App.INSTANCE.toast(R.string.restore_success) + } + } + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 057ea6a8d..58defc4d5 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -1,14 +1,11 @@ package io.legado.app.ui.main.my -import android.app.Activity import android.content.Intent import android.content.SharedPreferences -import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View -import androidx.documentfile.provider.DocumentFile import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.App @@ -16,31 +13,22 @@ import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey -import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat -import io.legado.app.help.storage.Backup -import io.legado.app.help.storage.Restore -import io.legado.app.help.storage.WebDavHelp -import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.prefs.ATESwitchPreference import io.legado.app.service.WebService import io.legado.app.ui.about.AboutActivity import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.book.source.manage.BookSourceActivity +import io.legado.app.ui.config.BackupRestoreUi import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_title_bar.* -import kotlinx.coroutines.launch import org.jetbrains.anko.startActivity class MyFragment : BaseFragment(R.layout.fragment_my_config) { - private val backupSelectRequestCode = 22 - private val restoreSelectRequestCode = 33 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) @@ -58,150 +46,14 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCompatOptionsItemSelected(item: MenuItem) { when (item.itemId) { R.id.menu_help -> startActivity() - R.id.menu_backup -> backup() - R.id.menu_restore -> restore() - } - } - - private fun backup() { - val backupPath = AppConfig.backupPath - if (backupPath.isNullOrEmpty()) { - selectBackupFolder() - } else { - if (backupPath.isContentPath()) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(requireContext(), uri) - if (doc?.canWrite() == true) { - launch { - Backup.backup(requireContext(), backupPath) - toast(R.string.backup_success) - } - } else { - selectBackupFolder() - } - } else { - backupUsePermission() - } - } - } - - private fun backupUsePermission(path: String = Backup.legadoPath) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - Backup.backup(requireContext(), path) - toast(R.string.backup_success) - } - } - .request() - } - - private fun selectBackupFolder() { - alert { - titleResource = R.string.select_folder - items(arrayListOf("默认路径", "系统文件夹选择器", "自带文件夹选择器")) { _, index -> - when (index) { - 0 -> PermissionsCompat.Builder(this@MyFragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - AppConfig.backupPath = Backup.legadoPath - backupUsePermission() - } - } - .request() - 1 -> { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, backupSelectRequestCode) - } catch (e: java.lang.Exception) { - e.printStackTrace() - toast(e.localizedMessage ?: "ERROR") - } - } - 2 -> { - - } - } - } - }.show() - } - - fun restore() { - launch { - if (!WebDavHelp.showRestoreDialog(requireContext()) { - toast(R.string.restore_success) - }) { - val backupPath = getPrefString(PreferKey.backupPath) - if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(requireContext(), uri) - if (doc?.canWrite() == true) { - Restore.restore(requireContext(), uri) - toast(R.string.restore_success) - } else { - selectBackupFolder() - } - } else { - selectRestoreFolder() - } - } - } - } - - private fun selectRestoreFolder() { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, restoreSelectRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - launch { - Restore.restore(Backup.legadoPath) - toast(R.string.restore_success) - } - } - .request() + R.id.menu_backup -> BackupRestoreUi.backup(this) + R.id.menu_restore -> BackupRestoreUi.restore(this) } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) - when (requestCode) { - backupSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { - data?.data?.let { uri -> - requireContext().contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - AppConfig.backupPath = uri.toString() - launch { - Backup.backup(requireContext(), uri.toString()) - toast(R.string.backup_success) - } - } - } - restoreSelectRequestCode -> if (resultCode == Activity.RESULT_OK) { - data?.data?.let { uri -> - requireContext().contentResolver.takePersistableUriPermission( - uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION - ) - AppConfig.backupPath = uri.toString() - launch { - Restore.restore(requireContext(), uri) - toast(R.string.restore_success) - } - } - } - } + BackupRestoreUi.onActivityResult(requestCode, resultCode, data) } class PreferenceFragment : PreferenceFragmentCompat(), From 25425e7c45ac1d4876e82987cdcf10c58cbbfc51 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 23:43:26 +0800 Subject: [PATCH 500/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/config/BackupConfigFragment.kt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 2336dbd76..9c4df2263 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -71,21 +71,13 @@ class BackupConfigFragment : PreferenceFragmentCompat(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - ATH.applyEdgeEffectColor(listView) - } - - override fun onResume() { - super.onResume() preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) - } - - override fun onPause() { - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) - super.onPause() + ATH.applyEdgeEffectColor(listView) } override fun onDestroy() { super.onDestroy() + preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) job.cancel() } From 61c4a3f242907d0bd566c6ad87329aaaf32f1ea8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 8 Feb 2020 23:57:05 +0800 Subject: [PATCH 501/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/config/BackupRestoreUi.kt | 47 ++++++++++++------- app/src/main/res/values/arrays.xml | 6 +++ app/src/main/res/values/strings.xml | 3 ++ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index 773a7ceb3..15731b226 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -67,7 +67,7 @@ object BackupRestoreUi { fun selectBackupFolder(fragment: Fragment) { fragment.alert { titleResource = R.string.select_folder - items(arrayListOf("默认路径", "系统文件夹选择器", "自带文件夹选择器")) { _, index -> + items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> when (index) { 0 -> PermissionsCompat.Builder(fragment) .addPermissions(*Permissions.Group.STORAGE) @@ -118,23 +118,38 @@ object BackupRestoreUi { } private fun selectRestoreFolder(fragment: Fragment) { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - fragment.startActivityForResult(intent, restoreSelectRequestCode) - } catch (e: java.lang.Exception) { - PermissionsCompat.Builder(fragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - Coroutine.async { - Restore.restore(Backup.legadoPath) - }.onSuccess { - fragment.toast(R.string.restore_success) + fragment.alert { + titleResource = R.string.select_folder + items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> + when (index) { + 0 -> PermissionsCompat.Builder(fragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + Coroutine.async { + AppConfig.backupPath = Backup.legadoPath + Restore.restore(Backup.legadoPath) + }.onSuccess { + fragment.toast(R.string.restore_success) + } + } + .request() + 1 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + fragment.startActivityForResult(intent, restoreSelectRequestCode) + } catch (e: java.lang.Exception) { + e.printStackTrace() + fragment.toast(e.localizedMessage ?: "ERROR") + } + } + 2 -> { + } } - .request() - } + } + }.show() } fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index b8cea9e3b..64a83e78a 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -98,6 +98,12 @@ -1 + + @string/default_path + @string/sys_folder_picker + @string/app_folder_picker + + @string/screen_unspecified @string/screen_portrait diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14787a449..584ac698a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -599,5 +599,8 @@ 显示订阅 服务已停止 正在启动服务\n具体信息查看通知栏 + 默认路径 + 系统文件夹选择器 + 自带选择器(Android10以上可能会失效) From 7de6d4ad4f476886b52556c2f27e14e025724a9a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 09:06:05 +0800 Subject: [PATCH 502/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/storage/Restore.kt | 23 ++--- .../app/ui/config/BackupConfigFragment.kt | 6 ++ .../legado/app/ui/config/BackupRestoreUi.kt | 90 +++++++++++++------ .../app/ui/filechooser/FileChooserDialog.kt | 28 +++--- .../io/legado/app/ui/main/my/MyFragment.kt | 7 +- 5 files changed, 98 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index ee58fffbd..edc0c1478 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -11,10 +11,7 @@ import io.legado.app.App import io.legado.app.constant.PreferKey import io.legado.app.data.entities.* import io.legado.app.help.ReadBookConfig -import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.FileUtils -import io.legado.app.utils.GSON -import io.legado.app.utils.fromJsonArray +import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.GlobalScope @@ -33,17 +30,21 @@ object Restore { ) } - suspend fun restore(context: Context, uri: Uri) { + suspend fun restore(context: Context, path: String) { withContext(IO) { - DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { doc -> - for (fileName in Backup.backupFileNames) { - if (doc.name == fileName) { - DocumentUtils.readText(context, doc.uri)?.let { - FileUtils.createFileIfNotExist(Backup.backupPath + File.separator + fileName) - .writeText(it) + if (path.isContentPath()) { + DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc -> + for (fileName in Backup.backupFileNames) { + if (doc.name == fileName) { + DocumentUtils.readText(context, doc.uri)?.let { + FileUtils.createFileIfNotExist(Backup.backupPath + File.separator + fileName) + .writeText(it) + } } } } + } else { + } } restore(Backup.backupPath) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index 9c4df2263..d7a9c54d2 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -24,6 +24,7 @@ import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.utils.DocumentUtils import io.legado.app.utils.LogUtils import io.legado.app.utils.applyTint @@ -35,6 +36,7 @@ import kotlin.coroutines.CoroutineContext class BackupConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener, + FileChooserDialog.CallBack, CoroutineScope { private lateinit var job: Job private val oldDataRequestCode = 11 @@ -231,6 +233,10 @@ class BackupConfigFragment : PreferenceFragmentCompat(), } } + override fun onFilePicked(requestCode: Int, currentPath: String) { + BackupRestoreUi.onFilePicked(requestCode, currentPath) + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) BackupRestoreUi.onActivityResult(requestCode, resultCode, data) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index 15731b226..a15f4ea33 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -16,6 +16,7 @@ import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.dialogs.alert +import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.utils.getPrefString import io.legado.app.utils.isContentPath import io.legado.app.utils.toast @@ -56,6 +57,7 @@ object BackupRestoreUi { .rationale(R.string.tip_perm_request_storage) .onGranted { Coroutine.async { + AppConfig.backupPath = Backup.legadoPath Backup.backup(fragment.requireContext(), path) }.onSuccess { fragment.toast(R.string.backup_success) @@ -69,14 +71,7 @@ object BackupRestoreUi { titleResource = R.string.select_folder items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> when (index) { - 0 -> PermissionsCompat.Builder(fragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - AppConfig.backupPath = Backup.legadoPath - backupUsePermission(fragment) - } - .request() + 0 -> backupUsePermission(fragment) 1 -> { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) @@ -88,7 +83,11 @@ object BackupRestoreUi { } } 2 -> { - + FileChooserDialog.show( + fragment.childFragmentManager, + backupSelectRequestCode, + mode = FileChooserDialog.DIRECTORY + ) } } } @@ -102,13 +101,17 @@ object BackupRestoreUi { }) { val backupPath = fragment.getPrefString(PreferKey.backupPath) if (backupPath?.isNotEmpty() == true) { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri) - if (doc?.canWrite() == true) { - Restore.restore(fragment.requireContext(), uri) - fragment.toast(R.string.restore_success) + if (backupPath.isContentPath()) { + val uri = Uri.parse(backupPath) + val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri) + if (doc?.canWrite() == true) { + Restore.restore(fragment.requireContext(), backupPath) + fragment.toast(R.string.restore_success) + } else { + selectRestoreFolder(fragment) + } } else { - selectRestoreFolder(fragment) + restoreUsePermission(fragment, backupPath) } } else { selectRestoreFolder(fragment) @@ -117,23 +120,27 @@ object BackupRestoreUi { } } + private fun restoreUsePermission(fragment: Fragment, path: String = Backup.legadoPath) { + PermissionsCompat.Builder(fragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + Coroutine.async { + AppConfig.backupPath = path + Restore.restore(path) + }.onSuccess { + fragment.toast(R.string.restore_success) + } + } + .request() + } + private fun selectRestoreFolder(fragment: Fragment) { fragment.alert { titleResource = R.string.select_folder items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> when (index) { - 0 -> PermissionsCompat.Builder(fragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - Coroutine.async { - AppConfig.backupPath = Backup.legadoPath - Restore.restore(Backup.legadoPath) - }.onSuccess { - fragment.toast(R.string.restore_success) - } - } - .request() + 0 -> restoreUsePermission(fragment) 1 -> { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) @@ -145,13 +152,38 @@ object BackupRestoreUi { } } 2 -> { - + FileChooserDialog.show( + fragment.childFragmentManager, + restoreSelectRequestCode, + mode = FileChooserDialog.DIRECTORY + ) } } } }.show() } + fun onFilePicked(requestCode: Int, currentPath: String) { + when (requestCode) { + backupSelectRequestCode -> { + AppConfig.backupPath = currentPath + Coroutine.async { + Backup.backup(App.INSTANCE, currentPath) + }.onSuccess { + App.INSTANCE.toast(R.string.backup_success) + } + } + restoreSelectRequestCode -> { + AppConfig.backupPath = currentPath + Coroutine.async { + Restore.restore(App.INSTANCE, currentPath) + }.onSuccess { + App.INSTANCE.toast(R.string.restore_success) + } + } + } + } + fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { when (requestCode) { backupSelectRequestCode -> if (resultCode == RESULT_OK) { @@ -176,7 +208,7 @@ object BackupRestoreUi { ) AppConfig.backupPath = uri.toString() Coroutine.async { - Restore.restore(App.INSTANCE, uri) + Restore.restore(App.INSTANCE, uri.toString()) }.onSuccess { App.INSTANCE.toast(R.string.restore_success) } diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt index ff757cb09..8cb1e5abe 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt @@ -42,21 +42,19 @@ class FileChooserDialog : DialogFragment(), allowExtensions: Array? = null, menus: Array? = null ) { - val fragment = (manager.findFragmentByTag(tag) as? FileChooserDialog) - ?: FileChooserDialog().apply { - val bundle = Bundle() - bundle.putInt("mode", mode) - bundle.putInt("requestCode", requestCode) - bundle.putString("title", title) - bundle.putBoolean("isShowHomeDir", isShowHomeDir) - bundle.putBoolean("isShowUpDir", isShowUpDir) - bundle.putBoolean("isShowHideDir", isShowHideDir) - bundle.putString("initPath", initPath) - bundle.putStringArray("allowExtensions", allowExtensions) - bundle.putStringArray("menus", menus) - arguments = bundle - } - fragment.show(manager, tag) + FileChooserDialog().apply { + val bundle = Bundle() + bundle.putInt("mode", mode) + bundle.putInt("requestCode", requestCode) + bundle.putString("title", title) + bundle.putBoolean("isShowHomeDir", isShowHomeDir) + bundle.putBoolean("isShowUpDir", isShowUpDir) + bundle.putBoolean("isShowHideDir", isShowHideDir) + bundle.putString("initPath", initPath) + bundle.putStringArray("allowExtensions", allowExtensions) + bundle.putStringArray("menus", menus) + arguments = bundle + }.show(manager, tag) } } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 58defc4d5..f39f7cd07 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -23,12 +23,13 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.config.BackupRestoreUi import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel +import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.replacerule.ReplaceRuleActivity import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.startActivity -class MyFragment : BaseFragment(R.layout.fragment_my_config) { +class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog.CallBack { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) @@ -51,6 +52,10 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { } } + override fun onFilePicked(requestCode: Int, currentPath: String) { + BackupRestoreUi.onFilePicked(requestCode, currentPath) + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) BackupRestoreUi.onActivityResult(requestCode, resultCode, data) From 7c2a5b28e7648161e70e5700e2d7d423229fadcc Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 09:10:01 +0800 Subject: [PATCH 503/852] =?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/main/MainActivity.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index c540a8448..b7a6746d8 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -1,10 +1,8 @@ package io.legado.app.ui.main -import android.net.Uri import android.os.Bundle import android.view.KeyEvent import android.view.MenuItem -import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentStatePagerAdapter @@ -131,13 +129,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), if (backupPath.isNullOrEmpty()) { Backup.backup(this@MainActivity) } else { - val uri = Uri.parse(backupPath) - val doc = DocumentFile.fromTreeUri(this@MainActivity, uri) - if (doc?.canWrite() == true) { - Backup.backup(this@MainActivity, backupPath) - } else { - Backup.backup(this@MainActivity) - } + Backup.backup(this@MainActivity, backupPath) } } } From 55c74c7565937e6274644f209fb066e2deb86d9a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 09:37:03 +0800 Subject: [PATCH 504/852] =?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/help/storage/Backup.kt | 4 - .../legado/app/help/storage/ImportOldData.kt | 149 ++++++++++++++++++ .../io/legado/app/help/storage/Restore.kt | 81 ---------- .../app/ui/config/BackupConfigFragment.kt | 132 +--------------- .../legado/app/ui/config/BackupRestoreUi.kt | 32 ++++ .../ui/replacerule/ReplaceRuleViewModel.kt | 6 +- 6 files changed, 186 insertions(+), 218 deletions(-) create mode 100644 app/src/main/java/io/legado/app/help/storage/ImportOldData.kt 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 82485c363..6a02fb696 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 @@ -19,10 +19,6 @@ object Backup { val backupPath = App.INSTANCE.filesDir.absolutePath + File.separator + "backup" - val defaultPath by lazy { - FileUtils.getSdCardPath() + File.separator + "YueDu" - } - val legadoPath by lazy { FileUtils.getSdCardPath() + File.separator + "YueDu3.0" } diff --git a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt new file mode 100644 index 000000000..7329705e9 --- /dev/null +++ b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt @@ -0,0 +1,149 @@ +package io.legado.app.help.storage + +import android.content.Context +import android.net.Uri +import androidx.documentfile.provider.DocumentFile +import io.legado.app.App +import io.legado.app.data.entities.BookSource +import io.legado.app.data.entities.ReplaceRule +import io.legado.app.help.coroutine.Coroutine +import io.legado.app.utils.DocumentUtils +import io.legado.app.utils.FileUtils +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import org.jetbrains.anko.toast +import java.io.File + +object ImportOldData { + val yueDuPath by lazy { + FileUtils.getSdCardPath() + File.separator + "YueDu" + } + + fun import(context: Context) { + GlobalScope.launch(Dispatchers.IO) { + try {// 导入书架 + val shelfFile = + FileUtils.createFileIfNotExist(yueDuPath + File.separator + "myBookShelf.json") + val json = shelfFile.readText() + val importCount = importOldBookshelf(json) + withContext(Dispatchers.Main) { + context.toast("成功导入书籍${importCount}") + } + } catch (e: Exception) { + withContext(Dispatchers.Main) { + context.toast("导入书籍失败\n${e.localizedMessage}") + } + } + + try {// Book source + val sourceFile = + FileUtils.createFileIfNotExist(yueDuPath + File.separator + "myBookSource.json") + val json = sourceFile.readText() + val importCount = importOldSource(json) + withContext(Dispatchers.Main) { + context.toast("成功导入书源${importCount}") + } + } catch (e: Exception) { + withContext(Dispatchers.Main) { + context.toast("导入源失败\n${e.localizedMessage}") + } + } + + try {// Replace rules + val ruleFile = + FileUtils.createFileIfNotExist(yueDuPath + File.separator + "myBookReplaceRule.json") + val json = ruleFile.readText() + val importCount = importOldReplaceRule(json) + withContext(Dispatchers.Main) { + context.toast("成功导入替换规则${importCount}") + } + } catch (e: Exception) { + withContext(Dispatchers.Main) { + context.toast("导入替换规则失败\n${e.localizedMessage}") + } + } + } + } + + fun importUri(uri: Uri) { + Coroutine.async { + DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { + when (it.name) { + "myBookShelf.json" -> + try { + DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> + val importCount = importOldBookshelf(json) + withContext(Dispatchers.Main) { + App.INSTANCE.toast("成功导入书籍${importCount}") + } + } + } catch (e: java.lang.Exception) { + withContext(Dispatchers.Main) { + App.INSTANCE.toast("导入书籍失败\n${e.localizedMessage}") + } + } + "myBookSource.json" -> + try { + DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> + val importCount = importOldSource(json) + withContext(Dispatchers.Main) { + App.INSTANCE.toast("成功导入书源${importCount}") + } + } + } catch (e: Exception) { + withContext(Dispatchers.Main) { + App.INSTANCE.toast("导入源失败\n${e.localizedMessage}") + } + } + "myBookReplaceRule.json" -> + try { + DocumentUtils.readText(App.INSTANCE, it.uri)?.let { json -> + val importCount = importOldReplaceRule(json) + withContext(Dispatchers.Main) { + App.INSTANCE.toast("成功导入替换规则${importCount}") + } + } + } catch (e: Exception) { + withContext(Dispatchers.Main) { + App.INSTANCE.toast("导入替换规则失败\n${e.localizedMessage}") + } + } + } + } + } + } + + fun importOldBookshelf(json: String): Int { + val books = OldBook.toNewBook(json) + App.db.bookDao().insert(*books.toTypedArray()) + return books.size + } + + fun importOldSource(json: String): Int { + val bookSources = mutableListOf() + val items: List> = Restore.jsonPath.parse(json).read("$") + for (item in items) { + val jsonItem = Restore.jsonPath.parse(item) + OldRule.jsonToBookSource(jsonItem.jsonString())?.let { + bookSources.add(it) + } + } + App.db.bookSourceDao().insert(*bookSources.toTypedArray()) + return bookSources.size + } + + fun importOldReplaceRule(json: String): Int { + val replaceRules = mutableListOf() + val items: List> = Restore.jsonPath.parse(json).read("$") + for (item in items) { + val jsonItem = Restore.jsonPath.parse(item) + OldRule.jsonToReplaceRule(jsonItem.jsonString())?.let { + replaceRules.add(it) + } + } + App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) + return replaceRules.size + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index edc0c1478..b7fa2a68a 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -13,12 +13,8 @@ import io.legado.app.data.entities.* import io.legado.app.help.ReadBookConfig import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Dispatchers.Main -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.jetbrains.anko.defaultSharedPreferences -import org.jetbrains.anko.toast import java.io.File object Restore { @@ -109,81 +105,4 @@ object Restore { return null } - fun importYueDuData(context: Context) { - GlobalScope.launch(IO) { - try {// 导入书架 - val shelfFile = - FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookShelf.json") - val json = shelfFile.readText() - val importCount = importOldBookshelf(json) - withContext(Main) { - context.toast("成功导入书籍${importCount}") - } - } catch (e: Exception) { - withContext(Main) { - context.toast("导入书籍失败\n${e.localizedMessage}") - } - } - - try {// Book source - val sourceFile = - FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookSource.json") - val json = sourceFile.readText() - val importCount = importOldSource(json) - withContext(Main) { - context.toast("成功导入书源${importCount}") - } - } catch (e: Exception) { - withContext(Main) { - context.toast("导入源失败\n${e.localizedMessage}") - } - } - - try {// Replace rules - val ruleFile = - FileUtils.createFileIfNotExist(Backup.defaultPath + File.separator + "myBookReplaceRule.json") - val json = ruleFile.readText() - val importCount = importOldReplaceRule(json) - withContext(Main) { - context.toast("成功导入替换规则${importCount}") - } - } catch (e: Exception) { - withContext(Main) { - context.toast("导入替换规则失败\n${e.localizedMessage}") - } - } - } - } - - fun importOldBookshelf(json: String): Int { - val books = OldBook.toNewBook(json) - App.db.bookDao().insert(*books.toTypedArray()) - return books.size - } - - fun importOldSource(json: String): Int { - val bookSources = mutableListOf() - val items: List> = jsonPath.parse(json).read("$") - for (item in items) { - val jsonItem = jsonPath.parse(item) - OldRule.jsonToBookSource(jsonItem.jsonString())?.let { - bookSources.add(it) - } - } - App.db.bookSourceDao().insert(*bookSources.toTypedArray()) - return bookSources.size - } - - fun importOldReplaceRule(json: String): Int { - val replaceRules = mutableListOf() - val items: List> = jsonPath.parse(json).read("$") - for (item in items) { - val jsonItem = jsonPath.parse(item) - OldRule.jsonToReplaceRule(jsonItem.jsonString())?.let { - replaceRules.add(it) - } - } - App.db.replaceRuleDao().insert(*replaceRules.toTypedArray()) - return replaceRules.size - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index d7a9c54d2..9df96e3f2 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -1,51 +1,26 @@ package io.legado.app.ui.config -import android.app.Activity.RESULT_OK import android.content.Intent import android.content.SharedPreferences -import android.net.Uri -import android.os.Build import android.os.Bundle import android.text.InputType import android.view.View -import androidx.documentfile.provider.DocumentFile import androidx.preference.EditTextPreference import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.PreferKey -import io.legado.app.help.IntentHelp -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat -import io.legado.app.help.storage.Restore -import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.noButton -import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.filechooser.FileChooserDialog -import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.LogUtils -import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString -import kotlinx.coroutines.* -import kotlinx.coroutines.Dispatchers.IO -import org.jetbrains.anko.toast -import kotlin.coroutines.CoroutineContext class BackupConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnSharedPreferenceChangeListener, - FileChooserDialog.CallBack, - CoroutineScope { - private lateinit var job: Job - private val oldDataRequestCode = 11 - - override val coroutineContext: CoroutineContext - get() = job + Dispatchers.Main + FileChooserDialog.CallBack { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - job = Job() addPreferencesFromResource(R.xml.pref_config_backup) findPreference(PreferKey.webDavUrl)?.let { it.setOnBindEditTextListener { editText -> @@ -80,7 +55,6 @@ class BackupConfigFragment : PreferenceFragmentCompat(), override fun onDestroy() { super.onDestroy() preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) - job.cancel() } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { @@ -132,107 +106,11 @@ class BackupConfigFragment : PreferenceFragmentCompat(), PreferKey.backupPath -> BackupRestoreUi.selectBackupFolder(this) "web_dav_backup" -> BackupRestoreUi.backup(this) "web_dav_restore" -> BackupRestoreUi.restore(this) - "import_old" -> importOldData() + "import_old" -> BackupRestoreUi.importOldData(this) } return super.onPreferenceTreeClick(preference) } - private fun importOldData() { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, oldDataRequestCode) - } catch (e: Exception) { - needInstallApps { - alert(title = "导入") { - message = "是否导入旧版本数据" - yesButton { - PermissionsCompat.Builder(this@BackupConfigFragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - Restore.importYueDuData(requireContext()) - } - .request() - } - noButton { - } - }.show().applyTint() - } - } - } - - private fun importOldData(uri: Uri) { - launch(IO) { - DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { - when (it.name) { - "myBookShelf.json" -> - try { - DocumentUtils.readText(requireContext(), it.uri)?.let { json -> - val importCount = Restore.importOldBookshelf(json) - withContext(Dispatchers.Main) { - requireContext().toast("成功导入书籍${importCount}") - } - } - } catch (e: java.lang.Exception) { - withContext(Dispatchers.Main) { - requireContext().toast("导入书籍失败\n${e.localizedMessage}") - } - } - "myBookSource.json" -> - try { - DocumentUtils.readText(requireContext(), it.uri)?.let { json -> - val importCount = Restore.importOldSource(json) - withContext(Dispatchers.Main) { - requireContext().toast("成功导入书源${importCount}") - } - } - } catch (e: Exception) { - withContext(Dispatchers.Main) { - requireContext().toast("导入源失败\n${e.localizedMessage}") - } - } - "myBookReplaceRule.json" -> - try { - DocumentUtils.readText(requireContext(), it.uri)?.let { json -> - val importCount = Restore.importOldReplaceRule(json) - withContext(Dispatchers.Main) { - requireContext().toast("成功导入替换规则${importCount}") - } - } - } catch (e: Exception) { - withContext(Dispatchers.Main) { - requireContext().toast("导入替换规则失败\n${e.localizedMessage}") - } - } - } - } - } - } - - private fun needInstallApps(callback: () -> Unit) { - - fun canRequestPackageInstalls(): Boolean { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { - return requireContext().packageManager.canRequestPackageInstalls() - } - return true - } - if (!canRequestPackageInstalls()) { - alert(title = "开启权限提示") { - message = "需要打开「安装外部来源应用」权限才能导入旧版数据,请去设置中开启" - yesButton { - IntentHelp.toInstallUnknown(requireContext()) - } - noButton { - } - }.show().applyTint() - } else { - LogUtils.d("xxx", "import old") - callback() - } - } - override fun onFilePicked(requestCode: Int, currentPath: String) { BackupRestoreUi.onFilePicked(requestCode, currentPath) } @@ -240,11 +118,5 @@ class BackupConfigFragment : PreferenceFragmentCompat(), override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) BackupRestoreUi.onActivityResult(requestCode, resultCode, data) - when (requestCode) { - oldDataRequestCode -> - if (resultCode == RESULT_OK) data?.data?.let { uri -> - importOldData(uri) - } - } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index a15f4ea33..5fde57fb7 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -13,10 +13,14 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.ImportOldData import io.legado.app.help.storage.Restore import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.noButton +import io.legado.app.lib.dialogs.yesButton import io.legado.app.ui.filechooser.FileChooserDialog +import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString import io.legado.app.utils.isContentPath import io.legado.app.utils.toast @@ -27,6 +31,7 @@ object BackupRestoreUi { private const val backupSelectRequestCode = 22 private const val restoreSelectRequestCode = 33 + private const val oldDataRequestCode = 11 fun backup(fragment: Fragment) { val backupPath = AppConfig.backupPath @@ -163,6 +168,29 @@ object BackupRestoreUi { }.show() } + fun importOldData(fragment: Fragment) { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + fragment.startActivityForResult(intent, oldDataRequestCode) + } catch (e: Exception) { + fragment.alert(title = "导入") { + message = "是否导入旧版本数据" + yesButton { + PermissionsCompat.Builder(fragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + ImportOldData.import(fragment.requireContext()) + } + .request() + } + noButton { + } + }.show().applyTint() + } + } + fun onFilePicked(requestCode: Int, currentPath: String) { when (requestCode) { backupSelectRequestCode -> { @@ -214,6 +242,10 @@ object BackupRestoreUi { } } } + oldDataRequestCode -> + if (resultCode == RESULT_OK) data?.data?.let { uri -> + ImportOldData.importUri(uri) + } } } diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index 9d1f2f1a0..42217ec18 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -8,7 +8,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Backup -import io.legado.app.help.storage.Restore +import io.legado.app.help.storage.ImportOldData import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON import io.legado.app.utils.isAbsUrl @@ -22,10 +22,10 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application execute { if (text.isAbsUrl()) { HttpHelper.simpleGet(text)?.let { - Restore.importOldReplaceRule(it) + ImportOldData.importOldReplaceRule(it) } } else { - Restore.importOldReplaceRule(text) + ImportOldData.importOldReplaceRule(text) } }.onError { showMsg(it.localizedMessage ?: "ERROR") From 77c36c577b4da8c2c04ab8308a3b9d6bae531d6d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 10:16:08 +0800 Subject: [PATCH 505/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/config/BackupRestoreUi.kt | 56 ++++++++++++------- app/src/main/res/values-zh/strings.xml | 5 -- app/src/main/res/values/strings.xml | 3 +- 3 files changed, 38 insertions(+), 26 deletions(-) delete mode 100644 app/src/main/res/values-zh/strings.xml diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index 5fde57fb7..ba1b8dd5a 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.config import android.app.Activity.RESULT_OK import android.content.Intent import android.net.Uri +import android.os.Build import androidx.documentfile.provider.DocumentFile import androidx.fragment.app.Fragment import io.legado.app.App @@ -17,10 +18,7 @@ import io.legado.app.help.storage.ImportOldData import io.legado.app.help.storage.Restore import io.legado.app.help.storage.WebDavHelp import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.noButton -import io.legado.app.lib.dialogs.yesButton import io.legado.app.ui.filechooser.FileChooserDialog -import io.legado.app.utils.applyTint import io.legado.app.utils.getPrefString import io.legado.app.utils.isContentPath import io.legado.app.utils.toast @@ -169,26 +167,44 @@ object BackupRestoreUi { } fun importOldData(fragment: Fragment) { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - fragment.startActivityForResult(intent, oldDataRequestCode) - } catch (e: Exception) { - fragment.alert(title = "导入") { - message = "是否导入旧版本数据" - yesButton { - PermissionsCompat.Builder(fragment) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - ImportOldData.import(fragment.requireContext()) + fragment.alert { + titleResource = R.string.select_folder + items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> + when (index) { + 0 -> importOldUsePermission(fragment) + 1 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + fragment.startActivityForResult(intent, oldDataRequestCode) + } catch (e: java.lang.Exception) { + e.printStackTrace() + fragment.toast(e.localizedMessage ?: "ERROR") } - .request() - } - noButton { + } + 2 -> { + FileChooserDialog.show( + fragment.childFragmentManager, + oldDataRequestCode, + mode = FileChooserDialog.DIRECTORY + ) + } } - }.show().applyTint() + } + }.show() + } + + private fun importOldUsePermission(fragment: Fragment) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { + fragment.toast(R.string.a10_permission_toast) } + PermissionsCompat.Builder(fragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + ImportOldData.import(fragment.requireContext()) + } + .request() } fun onFilePicked(requestCode: Int, currentPath: String) { diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml deleted file mode 100644 index 78554f9eb..000000000 --- a/app/src/main/res/values-zh/strings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 584ac698a..8094ad0df 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -601,6 +601,7 @@ 正在启动服务\n具体信息查看通知栏 默认路径 系统文件夹选择器 - 自带选择器(Android10以上可能会失效) + 自带选择器 + Android10以上因为权限限制可能无法读取文件 From e81918b94ec0cdd9f71e22f764ba3b4e99b061f9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 11:03:09 +0800 Subject: [PATCH 506/852] =?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/BookHelp.kt | 11 +-- .../app/ui/config/OtherConfigFragment.kt | 99 ++++++++++--------- .../io/legado/app/ui/main/my/MyFragment.kt | 2 - 3 files changed, 55 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 67ea2bd30..98e421e85 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -15,18 +15,11 @@ import kotlin.math.min object BookHelp { private const val cacheFolderName = "book_cache" - var downloadPath: String = - App.INSTANCE.getPrefString(PreferKey.downloadPath) + val downloadPath: String + get() = App.INSTANCE.getPrefString(PreferKey.downloadPath) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath - fun upDownloadPath() { - downloadPath = - App.INSTANCE.getPrefString(PreferKey.downloadPath) - ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath - ?: App.INSTANCE.cacheDir.absolutePath - } - private val downloadUri get() = Uri.parse(downloadPath) private fun bookFolderName(book: Book): String { diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 6a77a8c99..357b712af 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -18,6 +18,7 @@ import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat +import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.ui.filechooser.FileChooserDialog @@ -37,25 +38,21 @@ class OtherConfigFragment : PreferenceFragmentCompat(), ) override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - putPrefBoolean("process_text", isProcessTextEnabled()) + putPrefBoolean(PreferKey.processText, isProcessTextEnabled()) addPreferencesFromResource(R.xml.pref_config_other) - upPreferenceSummary(findPreference(PreferKey.downloadPath), BookHelp.downloadPath) - upPreferenceSummary(findPreference(PreferKey.threadCount), AppConfig.threadCount.toString()) + upPreferenceSummary(PreferKey.downloadPath, BookHelp.downloadPath) + upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString()) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - ATH.applyEdgeEffectColor(listView) - } - - override fun onResume() { - super.onResume() preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + ATH.applyEdgeEffectColor(listView) } - override fun onPause() { + override fun onDestroy() { + super.onDestroy() preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) - super.onPause() } override fun onPreferenceTreeClick(preference: Preference?): Boolean { @@ -66,11 +63,9 @@ class OtherConfigFragment : PreferenceFragmentCompat(), .setMinValue(1) .setValue(AppConfig.threadCount) .show { - requireContext().putPrefInt(PreferKey.threadCount, it) - findPreference(PreferKey.threadCount)?.summary = - getString(R.string.threads_num, it.toString()) + AppConfig.threadCount = it } - PreferKey.downloadPath -> selectDownloadPathSys() + PreferKey.downloadPath -> selectDownloadPath() PreferKey.cleanCache -> { BookHelp.clearCache() toast(R.string.clear_cache_success) @@ -82,26 +77,30 @@ class OtherConfigFragment : PreferenceFragmentCompat(), override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { PreferKey.downloadPath -> { - BookHelp.upDownloadPath() - findPreference(key)?.summary = BookHelp.downloadPath + upPreferenceSummary(key, BookHelp.downloadPath) } + PreferKey.threadCount -> upPreferenceSummary( + PreferKey.threadCount, + AppConfig.threadCount.toString() + ) PreferKey.recordLog -> LogUtils.upLevel() PreferKey.processText -> sharedPreferences?.let { - setProcessTextEnable(it.getBoolean("process_text", true)) + setProcessTextEnable(it.getBoolean(key, true)) } PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "unused") } } - private fun upPreferenceSummary(preference: Preference?, value: String) { - when (preference) { - is ListPreference -> { + private fun upPreferenceSummary(preferenceKey: String, value: String?) { + val preference = findPreference(preferenceKey) ?: return + when (preferenceKey) { + PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value) + else -> if (preference is ListPreference) { val index = preference.findIndexOfValue(value) // Set the summary to reflect the new value. preference.summary = if (index >= 0) preference.entries[index] else null - } - else -> { - preference?.summary = value + } else { + preference.summary = value } } } @@ -124,29 +123,39 @@ class OtherConfigFragment : PreferenceFragmentCompat(), } } - private fun selectDownloadPathSys() { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, requestCodeDownloadPath) - } catch (e: Exception) { - selectDownloadPath() - } - } - private fun selectDownloadPath() { - PermissionsCompat.Builder(this) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - FileChooserDialog.show( - childFragmentManager, - requestCodeDownloadPath, - mode = FileChooserDialog.DIRECTORY, - initPath = BookHelp.downloadPath - ) + alert { + titleResource = R.string.select_folder + items(resources.getStringArray(R.array.select_folder).toList()) { _, i -> + when (i) { + 1 -> { + removePref(PreferKey.downloadPath) + } + 2 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, requestCodeDownloadPath) + } catch (e: Exception) { + e.printStackTrace() + toast(e.localizedMessage ?: "ERROR") + } + } + 3 -> PermissionsCompat.Builder(this@OtherConfigFragment) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + FileChooserDialog.show( + childFragmentManager, + requestCodeDownloadPath, + mode = FileChooserDialog.DIRECTORY, + initPath = BookHelp.downloadPath + ) + } + .request() + } } - .request() + } } override fun onFilePicked(requestCode: Int, currentPath: String) { @@ -165,8 +174,6 @@ class OtherConfigFragment : PreferenceFragmentCompat(), Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) putPrefString(PreferKey.downloadPath, uri.toString()) - findPreference(PreferKey.downloadPath)?.summary = uri.toString() - BookHelp.upDownloadPath() } } } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index f39f7cd07..1fbd92bbc 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -13,7 +13,6 @@ import io.legado.app.R import io.legado.app.base.BaseFragment import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey -import io.legado.app.help.BookHelp import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.prefs.ATESwitchPreference import io.legado.app.service.WebService @@ -107,7 +106,6 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog. toast(R.string.service_stop) } } - PreferKey.downloadPath -> BookHelp.upDownloadPath() "recordLog" -> LogUtils.upLevel() } } From d40856f4487e512c25b17ea019d27be6a9aea85b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 11:03:51 +0800 Subject: [PATCH 507/852] =?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/config/OtherConfigFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 357b712af..89f7c48cc 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -155,7 +155,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), .request() } } - } + }.show() } override fun onFilePicked(requestCode: Int, currentPath: String) { From 5d83cf972669963f2848f2b32b4fec52dda63e1f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 11:15:21 +0800 Subject: [PATCH 508/852] =?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/config/OtherConfigFragment.kt | 6 +++--- app/src/main/res/values/strings.xml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 89f7c48cc..31c3d709f 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -128,10 +128,10 @@ class OtherConfigFragment : PreferenceFragmentCompat(), titleResource = R.string.select_folder items(resources.getStringArray(R.array.select_folder).toList()) { _, i -> when (i) { - 1 -> { + 0 -> { removePref(PreferKey.downloadPath) } - 2 -> { + 1 -> { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) @@ -141,7 +141,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), toast(e.localizedMessage ?: "ERROR") } } - 3 -> PermissionsCompat.Builder(this@OtherConfigFragment) + 2 -> PermissionsCompat.Builder(this@OtherConfigFragment) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) .onGranted { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8094ad0df..031dcaa48 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -601,7 +601,7 @@ 正在启动服务\n具体信息查看通知栏 默认路径 系统文件夹选择器 - 自带选择器 - Android10以上因为权限限制可能无法读取文件 + 自带选择器\n(Android10以上因权限限制可能无法使用) + Android10以上因权限限制可能无法读写文件 From cd4eda3b3bbe75ceeb724a1a4c78003960a5411b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 11:21:08 +0800 Subject: [PATCH 509/852] =?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/help/storage/Restore.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index b7fa2a68a..ed944012a 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -40,7 +40,21 @@ object Restore { } } } else { - + try { + val file = File(path) + for (fileName in Backup.backupFileNames) { + FileUtils.getFile(file, fileName).let { + if (it.exists()) { + it.copyTo( + FileUtils.createFileIfNotExist(Backup.backupPath + File.separator + fileName), + true + ) + } + } + } + } catch (e: Exception) { + e.printStackTrace() + } } } restore(Backup.backupPath) From 40a1cc60fed2902cdb7b9c80ec2ab9a9eb5bee0b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 11:22:54 +0800 Subject: [PATCH 510/852] =?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/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1d972d265..376e750cd 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/08** +* 优化书源管理,备份恢复 + **2020/02/08** * 书架分组调整顺序后,书架及时变动 From c2a8b9bd8b1d019c94c568ad594bfd86da577b6b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 11:59:09 +0800 Subject: [PATCH 511/852] =?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/help/storage/WebDavHelp.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 5576e9c11..b48a0b646 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -45,12 +45,16 @@ object WebDavHelp { val url = getWebDavUrl() val names = arrayListOf() if (!url.isNullOrBlank() && initWebDav()) { - var files = WebDav(url + "legado/").listFiles() - files = files.reversed() - for (index: Int in 0 until min(10, files.size)) { - files[index].displayName?.let { - names.add(it) + try { + var files = WebDav(url + "legado/").listFiles() + files = files.reversed() + for (index: Int in 0 until min(10, files.size)) { + files[index].displayName?.let { + names.add(it) + } } + } catch (e: Exception) { + return names } } return names From b9e369ac0e6aa825eadbb4d857e29aa0eda947e8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 13:02:02 +0800 Subject: [PATCH 512/852] =?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/AppConfig.kt | 4 ++++ app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 2 +- .../io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 8 ++++++++ app/src/main/res/xml/pref_config_other.xml | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index eab1acd6b..4189d9787 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -1,6 +1,7 @@ package io.legado.app.help import io.legado.app.App +import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.utils.* @@ -44,6 +45,9 @@ object AppConfig { App.INSTANCE.putPrefBoolean(PreferKey.showRss, value) } + val autoRefreshBook: Boolean + get() = App.INSTANCE.getPrefBoolean(App.INSTANCE.getString(R.string.pk_auto_refresh)) + var threadCount: Int get() = App.INSTANCE.getPrefInt(PreferKey.threadCount, 16) set(value) { diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 6af83db54..4fe57d758 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -15,7 +15,7 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.delay class MainViewModel(application: Application) : BaseViewModel(application) { - val updateList = arrayListOf() + val updateList = hashSetOf() fun upChapterList() { execute { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 9cf04d20a..9f71a4525 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -17,6 +17,7 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup +import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor @@ -26,7 +27,9 @@ import io.legado.app.ui.book.group.GroupManageDialog import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.download.DownloadActivity import io.legado.app.ui.importbook.ImportBookActivity +import io.legado.app.ui.main.MainViewModel import io.legado.app.utils.* +import kotlinx.android.synthetic.main.dialog_change_source.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* @@ -51,6 +54,11 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b setSupportToolbar(toolbar) initRecyclerView() initBookGroupData() + if (AppConfig.autoRefreshBook) { + recycler_view.postDelayed({ + getViewModelOfActivity(MainViewModel::class.java).updateList + }, 1000) + } } override fun onCompatCreateOptionsMenu(menu: Menu) { diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 92cb3426a..83fea5a15 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> Date: Sun, 9 Feb 2020 13:05:20 +0800 Subject: [PATCH 513/852] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 9f71a4525..cb6673bb4 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -29,7 +29,6 @@ import io.legado.app.ui.download.DownloadActivity import io.legado.app.ui.importbook.ImportBookActivity import io.legado.app.ui.main.MainViewModel import io.legado.app.utils.* -import kotlinx.android.synthetic.main.dialog_change_source.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* @@ -52,10 +51,10 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) - initRecyclerView() + initView() initBookGroupData() if (AppConfig.autoRefreshBook) { - recycler_view.postDelayed({ + tab_layout.postDelayed({ getViewModelOfActivity(MainViewModel::class.java).updateList }, 1000) } @@ -92,7 +91,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b private val selectedGroup: BookGroup get() = bookGroups[view_pager_bookshelf.currentItem] - private fun initRecyclerView() { + private fun initView() { tab_layout.isTabIndicatorFullWidth = false tab_layout.tabMode = TabLayout.MODE_SCROLLABLE tab_layout.setSelectedTabIndicatorColor(requireContext().accentColor) From f80c34691b3b911a933ccd0fe18f48b1318175b7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 13:18:37 +0800 Subject: [PATCH 514/852] =?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/main/bookshelf/BookshelfFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index cb6673bb4..7d5fb644d 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -55,7 +55,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b initBookGroupData() if (AppConfig.autoRefreshBook) { tab_layout.postDelayed({ - getViewModelOfActivity(MainViewModel::class.java).updateList + getViewModelOfActivity(MainViewModel::class.java).upChapterList() }, 1000) } } From 73aa53a363cf82ae8e778f5b0eb1649433e5df7b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 13:28:50 +0800 Subject: [PATCH 515/852] =?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/welcome/WelcomeActivity.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index 77ef26284..721257bf5 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -7,7 +7,9 @@ import android.os.Bundle import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainActivity +import io.legado.app.utils.getPrefBoolean import kotlinx.android.synthetic.main.activity_welcome.* import org.jetbrains.anko.startActivity @@ -28,7 +30,11 @@ class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { } welAnimator.addListener(object : Animator.AnimatorListener { override fun onAnimationStart(animation: Animator) { - startActivity() + if (getPrefBoolean(getString(R.string.pk_default_read))) { + startActivity() + } else { + startActivity() + } finish() } From 4620bb8b28abeff359ff8627afbb076a8f8b4f18 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 14:00:10 +0800 Subject: [PATCH 516/852] =?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/ActivityHelp.kt | 8 ++++---- .../java/io/legado/app/ui/book/read/ReadBookActivity.kt | 3 +++ .../main/java/io/legado/app/ui/welcome/WelcomeActivity.kt | 3 +-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ActivityHelp.kt b/app/src/main/java/io/legado/app/help/ActivityHelp.kt index ca7c20f5f..6138c0c7e 100644 --- a/app/src/main/java/io/legado/app/help/ActivityHelp.kt +++ b/app/src/main/java/io/legado/app/help/ActivityHelp.kt @@ -19,7 +19,7 @@ object ActivityHelp { * 判断指定Activity是否存在 */ fun isExist(activityClass: Class<*>): Boolean { - for (item in activities) { + activities.forEach { item -> if (item.get()?.javaClass == activityClass) { return true } @@ -63,7 +63,7 @@ object ActivityHelp { * 关闭指定 activity */ fun finishActivity(vararg activities: Activity) { - for (activity in activities) { + activities.forEach { activity -> activity.finish() } } @@ -81,8 +81,8 @@ object ActivityHelp { } } } - for (activityWeakReference in waitFinish) { - activityWeakReference.get()?.finish() + waitFinish.forEach { + it.get()?.finish() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 430aea351..7d7ef8c67 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -496,6 +496,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } + /** + * colorSelectDialog + */ override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.getConfig()) { when (dialogId) { TEXT_COLOR -> { diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index 721257bf5..4a1e12f82 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -30,10 +30,9 @@ class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { } welAnimator.addListener(object : Animator.AnimatorListener { override fun onAnimationStart(animation: Animator) { + startActivity() if (getPrefBoolean(getString(R.string.pk_default_read))) { startActivity() - } else { - startActivity() } finish() } From fa3071d9a92b1a0eb07a5917d1f591d55e66fc77 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 16:57:05 +0800 Subject: [PATCH 517/852] =?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/res/values/strings.xml | 5 +++-- app/src/main/res/xml/pref_config_other.xml | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 031dcaa48..22345a53f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -530,8 +530,6 @@ 切换软件显示在桌面的图标 帮助 我的 - - ]]> 阅读 %d%% %d分钟 @@ -603,5 +601,8 @@ 系统文件夹选择器 自带选择器\n(Android10以上因权限限制可能无法使用) Android10以上因权限限制可能无法读写文件 + 长按文字在操作菜单中显示阅读·搜索 + 文字操作显示搜索 + 记录日志 diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 83fea5a15..3eb6ede41 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -40,14 +40,14 @@ \ No newline at end of file From 58273c4b3dbf08e8b3114c22261d1adb67a202be Mon Sep 17 00:00:00 2001 From: Mupceet Date: Sun, 9 Feb 2020 12:39:57 +0800 Subject: [PATCH 518/852] chore: make project Commitizen-friendly --- .gitignore | 4 +++- README.md | 3 +++ package.json | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 5f0e23e18..2543443bb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ /captures .externalNativeBuild /release -/tmp \ No newline at end of file +/tmp +node_modules/ +package-lock.json diff --git a/README.md b/README.md index 1a035aaf5..ffe6dedd9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # legado + +[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) + ## 阅读3.0 书源规则 https://celeter.github.io/?tdsourcetag=s_pctim_aiomsg diff --git a/package.json b/package.json new file mode 100644 index 000000000..f834a918d --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "legado", + "version": "1.0.0", + "devDependencies": { + "cz-conventional-changelog": "^3.1.0" + }, + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + } +} From 035006b09ed0d30e0afe12e3a203289d35ce8887 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 18:00:45 +0800 Subject: [PATCH 519/852] =?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/model/webBook/BookChapterList.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index 705321694..33b536d1d 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -22,7 +22,7 @@ object BookChapterList { bookSource: BookSource, baseUrl: String ): List { - var chapterList = arrayListOf() + var chapterList = ArrayList() body ?: throw Exception( App.INSTANCE.getString(R.string.error_get_web_content, baseUrl) ) From 045198a904e5672c3b7a6f5c0ad5ad546f4d18d3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 18:32:59 +0800 Subject: [PATCH 520/852] =?UTF-8?q?docs:=20=E6=96=87=E6=A1=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9,=E6=96=87=E4=BB=B6=E4=BD=8D=E7=BD=AE=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit data\readme.md 修改 EditEntity.kt 移动 --- app/src/main/java/io/legado/app/data/README.md | 16 +++++++++++++++- .../book/source/edit/BookSourceEditActivity.kt | 1 - .../ui/book/source/edit/BookSourceEditAdapter.kt | 1 - .../legado/app/ui/book/source/edit/EditEntity.kt | 3 +++ .../rss/source/edit}/EditEntity.kt | 2 +- .../ui/rss/source/edit/RssSourceEditActivity.kt | 1 - .../ui/rss/source/edit/RssSourceEditAdapter.kt | 1 - 7 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/source/edit/EditEntity.kt rename app/src/main/java/io/legado/app/{data/entities => ui/rss/source/edit}/EditEntity.kt (56%) diff --git a/app/src/main/java/io/legado/app/data/README.md b/app/src/main/java/io/legado/app/data/README.md index ec1ddefbe..9b5f490b7 100644 --- a/app/src/main/java/io/legado/app/data/README.md +++ b/app/src/main/java/io/legado/app/data/README.md @@ -1,3 +1,17 @@ ## 存储数据用 * dao 数据操作 -* entities 数据模型 \ No newline at end of file +* entities 数据模型 +* \Book 书籍信息 +* \BookChapter 目录信息 +* \BookGroup 书籍分组 +* \Bookmark 书签 +* \BookSource 书源 +* \Cookie http cookie +* \ReplaceRule 替换规则 +* \RssArticle rss条目 +* \RssReadRecord rss阅读记录 +* \RssSource rss源 +* \RssStar rss收藏 +* \SearchBook 搜索结果 +* \SearchKeyword 搜索关键字 +* \TxtTocRule txt文件目录规则 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 cc63c93d4..082faa675 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 @@ -20,7 +20,6 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppConst import io.legado.app.data.entities.BookSource -import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.rule.* import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt index 37939e803..163d66584 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt @@ -7,7 +7,6 @@ import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import io.legado.app.R -import io.legado.app.data.entities.EditEntity import kotlinx.android.synthetic.main.item_source_edit.view.* class BookSourceEditAdapter : RecyclerView.Adapter() { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/EditEntity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/EditEntity.kt new file mode 100644 index 000000000..fb98c3c4e --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/EditEntity.kt @@ -0,0 +1,3 @@ +package io.legado.app.ui.book.source.edit + +data class EditEntity(var key: String, var value: String?, var hint: Int) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/EditEntity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/EditEntity.kt similarity index 56% rename from app/src/main/java/io/legado/app/data/entities/EditEntity.kt rename to app/src/main/java/io/legado/app/ui/rss/source/edit/EditEntity.kt index d4c1ecc1a..f0f23b32b 100644 --- a/app/src/main/java/io/legado/app/data/entities/EditEntity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/EditEntity.kt @@ -1,3 +1,3 @@ -package io.legado.app.data.entities +package io.legado.app.ui.rss.source.edit data class EditEntity(var key: String, var value: String?, var hint: Int) \ No newline at end of file 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 1ae70df5d..09d5d6b2f 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 @@ -16,7 +16,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppConst -import io.legado.app.data.entities.EditEntity import io.legado.app.data.entities.RssSource import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt index 78e0740ef..b467c9b48 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt @@ -7,7 +7,6 @@ import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import io.legado.app.R -import io.legado.app.data.entities.EditEntity import kotlinx.android.synthetic.main.item_source_edit.view.* class RssSourceEditAdapter : RecyclerView.Adapter() { From bad4038fd0b18cbababfd184d730349593f41f2d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 21:02:33 +0800 Subject: [PATCH 521/852] =?UTF-8?q?style(=E4=BC=98=E5=8C=96=E4=B8=BB?= =?UTF-8?q?=E9=A2=98):=20=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..ace01cdff --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# 1.0.0 (2020-02-09) + + + From 194343de01cf22a1136ff53fedcc0b654d6b65eb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 9 Feb 2020 21:10:54 +0800 Subject: [PATCH 522/852] =?UTF-8?q?style:=20=E9=BB=98=E8=AE=A4=E9=A2=9C?= =?UTF-8?q?=E8=89=B2=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 底部操作条更明显 --- .../app/ui/filechooser/FileChooserDialog.kt | 4 +--- app/src/main/res/drawable/item_bg_dark.xml | 2 +- app/src/main/res/drawable/item_bg_light.xml | 2 +- .../main/res/layout/activity_arrange_book.xml | 2 +- .../main/res/layout/activity_book_source.xml | 2 +- .../main/res/layout/activity_import_book.xml | 2 +- .../main/res/layout/activity_rss_source.xml | 2 +- .../main/res/layout/dialog_change_source.xml | 2 +- .../main/res/layout/dialog_file_chooser.xml | 1 + app/src/main/res/layout/dialog_font_select.xml | 1 + .../main/res/layout/dialog_recycler_view.xml | 1 + .../main/res/layout/dialog_replace_edit.xml | 1 + app/src/main/res/values-night/colors.xml | 6 +++--- app/src/main/res/values/colors.xml | 7 +++---- app/src/main/res/values/styles.xml | 2 +- package.json | 18 +++++++++++++++++- 16 files changed, 36 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt index 8cb1e5abe..46c1271fc 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt @@ -13,7 +13,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.constant.Theme -import io.legado.app.lib.theme.ATH import io.legado.app.ui.filechooser.adapter.FileAdapter import io.legado.app.ui.filechooser.adapter.PathAdapter import io.legado.app.utils.* @@ -90,8 +89,7 @@ class FileChooserDialog : DialogFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - ATH.applyBackgroundTint(view) - ATH.applyBackgroundTint(rv_path) + view.setBackgroundResource(R.color.background_card) arguments?.let { requestCode = it.getInt("requestCode") mode = it.getInt("mode", FILE) diff --git a/app/src/main/res/drawable/item_bg_dark.xml b/app/src/main/res/drawable/item_bg_dark.xml index 054b06f9a..341befb27 100644 --- a/app/src/main/res/drawable/item_bg_dark.xml +++ b/app/src/main/res/drawable/item_bg_dark.xml @@ -1,3 +1,3 @@ \ No newline at end of file + android:color="@color/md_grey_800" /> \ No newline at end of file diff --git a/app/src/main/res/drawable/item_bg_light.xml b/app/src/main/res/drawable/item_bg_light.xml index ef3428fe4..e336c3154 100644 --- a/app/src/main/res/drawable/item_bg_light.xml +++ b/app/src/main/res/drawable/item_bg_light.xml @@ -1,3 +1,3 @@ \ No newline at end of file + android:color="@color/md_grey_200" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_arrange_book.xml b/app/src/main/res/layout/activity_arrange_book.xml index 66642e134..c18e0ad14 100644 --- a/app/src/main/res/layout/activity_arrange_book.xml +++ b/app/src/main/res/layout/activity_arrange_book.xml @@ -21,7 +21,7 @@ diff --git a/app/src/main/res/layout/dialog_font_select.xml b/app/src/main/res/layout/dialog_font_select.xml index 60f080003..e4148f763 100644 --- a/app/src/main/res/layout/dialog_font_select.xml +++ b/app/src/main/res/layout/dialog_font_select.xml @@ -7,6 +7,7 @@ diff --git a/app/src/main/res/layout/dialog_recycler_view.xml b/app/src/main/res/layout/dialog_recycler_view.xml index 6ac7d8c01..0acc844ce 100644 --- a/app/src/main/res/layout/dialog_recycler_view.xml +++ b/app/src/main/res/layout/dialog_recycler_view.xml @@ -6,6 +6,7 @@ diff --git a/app/src/main/res/layout/dialog_replace_edit.xml b/app/src/main/res/layout/dialog_replace_edit.xml index 4f6a23c6e..b9ef6fb2f 100644 --- a/app/src/main/res/layout/dialog_replace_edit.xml +++ b/app/src/main/res/layout/dialog_replace_edit.xml @@ -7,6 +7,7 @@ diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 4933cfa2b..18ab012e0 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -4,9 +4,9 @@ @color/md_blue_grey_700 @color/md_deep_orange_800 - @color/md_grey_800 - #353535 - #282828 + @color/md_grey_900 + @color/md_grey_850 + @color/md_grey_800 #69000000 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index d150286a4..d6999a7ae 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,16 +7,15 @@ #FF578FCC #FF212227 - #FF272731 #eb4333 #439b53 #00000000 - @color/md_grey_100 - #dedede - #fcfcfc + @color/md_grey_50 + @color/md_grey_100 + @color/md_grey_200 #00000000 #30000000 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ec0b50735..d5c9e7104 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -41,7 +41,7 @@