contentProvider

pull/302/head
gedoor 4 years ago
parent ae2daeb798
commit 8beeea869d
  1. 15
      app/src/main/java/io/legado/app/api/ReaderProvider.kt

@ -14,7 +14,6 @@ import android.database.DataSetObserver
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import com.google.gson.Gson import com.google.gson.Gson
import io.legado.app.App
import io.legado.app.web.controller.BookshelfController import io.legado.app.web.controller.BookshelfController
import io.legado.app.web.controller.SourceController import io.legado.app.web.controller.SourceController
import io.legado.app.web.utils.ReturnData import io.legado.app.web.utils.ReturnData
@ -28,9 +27,10 @@ class ReaderProvider : ContentProvider() {
saveSource, saveSources, saveBook, deleteSources, getSource, getSources, getBookshelf, getChapterList, getBookContent saveSource, saveSources, saveBook, deleteSources, getSource, getSources, getBookshelf, getChapterList, getBookContent
} }
companion object { private val postBodyKey = "json"
const val POST_BODY_KEY = "json" private val authority by lazy {
private val authority = "${App.INSTANCE.packageName}.ReaderProvider" "${context?.applicationInfo?.packageName}.ReaderProvider"
}
private val sMatcher = UriMatcher(UriMatcher.NO_MATCH) private val sMatcher = UriMatcher(UriMatcher.NO_MATCH)
init { init {
@ -80,7 +80,6 @@ class ReaderProvider : ContentProvider() {
RequestCode.getBookContent.ordinal RequestCode.getBookContent.ordinal
) )
} }
}
override fun delete( override fun delete(
uri: Uri, uri: Uri,
@ -105,13 +104,13 @@ class ReaderProvider : ContentProvider() {
if (sMatcher.match(uri) < 0) return null if (sMatcher.match(uri) < 0) return null
when (RequestCode.values()[sMatcher.match(uri)]) { when (RequestCode.values()[sMatcher.match(uri)]) {
RequestCode.saveSource -> values?.let { RequestCode.saveSource -> values?.let {
SourceController.saveSource(values.getAsString(POST_BODY_KEY)) SourceController.saveSource(values.getAsString(postBodyKey))
} }
RequestCode.saveBook -> values?.let { RequestCode.saveBook -> values?.let {
BookshelfController.saveBook(values.getAsString(POST_BODY_KEY)) BookshelfController.saveBook(values.getAsString(postBodyKey))
} }
RequestCode.saveSources -> values?.let { RequestCode.saveSources -> values?.let {
SourceController.saveSources(values.getAsString(POST_BODY_KEY)) SourceController.saveSources(values.getAsString(postBodyKey))
} }
else -> throw IllegalStateException( else -> throw IllegalStateException(
"Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name "Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name

Loading…
Cancel
Save