|
|
@ -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,58 +27,58 @@ 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 { |
|
|
|
|
|
|
|
sMatcher.addURI( |
|
|
|
init { |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"source/insert", |
|
|
|
authority, |
|
|
|
RequestCode.saveSource.ordinal |
|
|
|
"source/insert", |
|
|
|
) |
|
|
|
RequestCode.saveSource.ordinal |
|
|
|
sMatcher.addURI( |
|
|
|
) |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"sources/insert", |
|
|
|
authority, |
|
|
|
RequestCode.saveSources.ordinal |
|
|
|
"sources/insert", |
|
|
|
) |
|
|
|
RequestCode.saveSources.ordinal |
|
|
|
sMatcher.addURI( |
|
|
|
) |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"book/insert", |
|
|
|
authority, |
|
|
|
RequestCode.saveBook.ordinal |
|
|
|
"book/insert", |
|
|
|
) |
|
|
|
RequestCode.saveBook.ordinal |
|
|
|
sMatcher.addURI( |
|
|
|
) |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"sources/delete", |
|
|
|
authority, |
|
|
|
RequestCode.deleteSources.ordinal |
|
|
|
"sources/delete", |
|
|
|
) |
|
|
|
RequestCode.deleteSources.ordinal |
|
|
|
sMatcher.addURI( |
|
|
|
) |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"source/query", |
|
|
|
authority, |
|
|
|
RequestCode.getSource.ordinal |
|
|
|
"source/query", |
|
|
|
) |
|
|
|
RequestCode.getSource.ordinal |
|
|
|
sMatcher.addURI( |
|
|
|
) |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"sources/query", |
|
|
|
authority, |
|
|
|
RequestCode.getSources.ordinal |
|
|
|
"sources/query", |
|
|
|
) |
|
|
|
RequestCode.getSources.ordinal |
|
|
|
sMatcher.addURI( |
|
|
|
) |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"books/query", |
|
|
|
authority, |
|
|
|
RequestCode.getBookshelf.ordinal |
|
|
|
"books/query", |
|
|
|
) |
|
|
|
RequestCode.getBookshelf.ordinal |
|
|
|
sMatcher.addURI( |
|
|
|
) |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"book/chapter/query", |
|
|
|
authority, |
|
|
|
RequestCode.getChapterList.ordinal |
|
|
|
"book/chapter/query", |
|
|
|
) |
|
|
|
RequestCode.getChapterList.ordinal |
|
|
|
sMatcher.addURI( |
|
|
|
) |
|
|
|
authority, |
|
|
|
sMatcher.addURI( |
|
|
|
"book/content/query", |
|
|
|
authority, |
|
|
|
RequestCode.getBookContent.ordinal |
|
|
|
"book/content/query", |
|
|
|
) |
|
|
|
RequestCode.getBookContent.ordinal |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun delete( |
|
|
|
override fun delete( |
|
|
@ -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 |
|
|
|