From 993a7cf1721899c63f65bd7897587d07f7452f3d Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 8 Oct 2021 09:11:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/api/ReaderProvider.kt | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/ReaderProvider.kt b/app/src/main/java/io/legado/app/api/ReaderProvider.kt index 251af9742..50ebca936 100644 --- a/app/src/main/java/io/legado/app/api/ReaderProvider.kt +++ b/app/src/main/java/io/legado/app/api/ReaderProvider.kt @@ -12,6 +12,7 @@ import android.net.Uri import com.google.gson.Gson import io.legado.app.api.controller.BookController import io.legado.app.api.controller.BookSourceController +import io.legado.app.api.controller.RssSourceController import java.util.* /** @@ -19,20 +20,26 @@ import java.util.* */ class ReaderProvider : ContentProvider() { private enum class RequestCode { - SaveSource, SaveSources, SaveBook, DeleteSources, GetSource, GetSources, - GetBookshelf, RefreshToc, GetChapterList, GetBookContent, GetBookCover + SaveBookSource, SaveBookSources, DeleteBookSources, GetBookSource, GetBookSources, + SaveRssSource, SaveRssSources, DeleteRssSources, GetRssSource, GetRssSources, + SaveBook, GetBookshelf, RefreshToc, GetChapterList, GetBookContent, GetBookCover } private val postBodyKey = "json" private val sMatcher by lazy { UriMatcher(UriMatcher.NO_MATCH).apply { "${context?.applicationInfo?.packageName}.readerProvider".also { authority -> - addURI(authority, "source/insert", RequestCode.SaveSource.ordinal) - addURI(authority, "sources/insert", RequestCode.SaveSources.ordinal) + addURI(authority, "bookSource/insert", RequestCode.SaveBookSource.ordinal) + addURI(authority, "bookSources/insert", RequestCode.SaveBookSources.ordinal) + addURI(authority, "bookSources/delete", RequestCode.DeleteBookSources.ordinal) + addURI(authority, "bookSource/query", RequestCode.GetBookSource.ordinal) + addURI(authority, "bookSources/query", RequestCode.GetBookSources.ordinal) + addURI(authority, "rssSource/insert", RequestCode.SaveBookSource.ordinal) + addURI(authority, "rssSources/insert", RequestCode.SaveBookSources.ordinal) + addURI(authority, "rssSources/delete", RequestCode.DeleteBookSources.ordinal) + addURI(authority, "rssSource/query", RequestCode.GetBookSource.ordinal) + addURI(authority, "rssSources/query", RequestCode.GetBookSources.ordinal) addURI(authority, "book/insert", RequestCode.SaveBook.ordinal) - addURI(authority, "sources/delete", RequestCode.DeleteSources.ordinal) - addURI(authority, "source/query", RequestCode.GetSource.ordinal) - addURI(authority, "sources/query", RequestCode.GetSources.ordinal) addURI(authority, "books/query", RequestCode.GetBookshelf.ordinal) addURI(authority, "book/refreshToc/query", RequestCode.RefreshToc.ordinal) addURI(authority, "book/chapter/query", RequestCode.GetChapterList.ordinal) @@ -51,7 +58,8 @@ class ReaderProvider : ContentProvider() { ): Int { if (sMatcher.match(uri) < 0) return -1 when (RequestCode.values()[sMatcher.match(uri)]) { - RequestCode.DeleteSources -> BookSourceController.deleteSources(selection) + RequestCode.DeleteBookSources -> BookSourceController.deleteSources(selection) + RequestCode.DeleteRssSources -> BookSourceController.deleteSources(selection) else -> throw IllegalStateException( "Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name ) @@ -64,15 +72,21 @@ class ReaderProvider : ContentProvider() { override fun insert(uri: Uri, values: ContentValues?): Uri? { if (sMatcher.match(uri) < 0) return null when (RequestCode.values()[sMatcher.match(uri)]) { - RequestCode.SaveSource -> values?.let { + RequestCode.SaveBookSource -> values?.let { BookSourceController.saveSource(values.getAsString(postBodyKey)) } + RequestCode.SaveBookSources -> values?.let { + BookSourceController.saveSources(values.getAsString(postBodyKey)) + } + RequestCode.SaveRssSource -> values?.let { + RssSourceController.saveSource(values.getAsString(postBodyKey)) + } + RequestCode.SaveRssSources -> values?.let { + RssSourceController.saveSources(values.getAsString(postBodyKey)) + } RequestCode.SaveBook -> values?.let { BookController.saveBook(values.getAsString(postBodyKey)) } - RequestCode.SaveSources -> values?.let { - BookSourceController.saveSources(values.getAsString(postBodyKey)) - } else -> throw IllegalStateException( "Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name ) @@ -95,8 +109,10 @@ class ReaderProvider : ContentProvider() { map["path"] = arrayListOf(it) } return if (sMatcher.match(uri) < 0) null else when (RequestCode.values()[sMatcher.match(uri)]) { - RequestCode.GetSource -> SimpleCursor(BookSourceController.getSource(map)) - RequestCode.GetSources -> SimpleCursor(BookSourceController.sources) + RequestCode.GetBookSource -> SimpleCursor(BookSourceController.getSource(map)) + RequestCode.GetBookSources -> SimpleCursor(BookSourceController.sources) + RequestCode.GetRssSource -> SimpleCursor(RssSourceController.getSource(map)) + RequestCode.GetRssSources -> SimpleCursor(RssSourceController.sources) RequestCode.GetBookshelf -> SimpleCursor(BookController.bookshelf) RequestCode.GetBookContent -> SimpleCursor(BookController.getBookContent(map)) RequestCode.RefreshToc -> SimpleCursor(BookController.refreshToc(map))