Merge pull request #367 from 1552980358/master

Modify several content
pull/368/head
kunfei 4 years ago committed by GitHub
commit 6f829893d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 183
      app/src/main/java/io/legado/app/api/ReaderProvider.kt
  2. 2
      gradle/wrapper/gradle-wrapper.properties

@ -24,29 +24,28 @@ import java.util.*
*/ */
class ReaderProvider : ContentProvider() { class ReaderProvider : ContentProvider() {
private enum class RequestCode { private enum class RequestCode {
saveSource, saveSources, saveBook, deleteSources, getSource, getSources, getBookshelf, getChapterList, getBookContent SaveSource, SaveSources, SaveBook, DeleteSources, GetSource, GetSources, GetBookshelf, GetChapterList, GetBookContent
} }
private val postBodyKey = "json" private val postBodyKey = "json"
private val sMatcher by lazy { private val sMatcher by lazy {
val uriMatcher = UriMatcher(UriMatcher.NO_MATCH) UriMatcher(UriMatcher.NO_MATCH).apply {
val authority = "${context?.applicationInfo?.packageName}.readerProvider" "${context?.applicationInfo?.packageName}.readerProvider".also { authority ->
uriMatcher.addURI(authority, "source/insert", RequestCode.saveSource.ordinal) addURI(authority, "source/insert", RequestCode.SaveSource.ordinal)
uriMatcher.addURI(authority, "sources/insert", RequestCode.saveSources.ordinal) addURI(authority, "sources/insert", RequestCode.SaveSources.ordinal)
uriMatcher.addURI(authority, "book/insert", RequestCode.saveBook.ordinal) addURI(authority, "book/insert", RequestCode.SaveBook.ordinal)
uriMatcher.addURI(authority, "sources/delete", RequestCode.deleteSources.ordinal) addURI(authority, "sources/delete", RequestCode.DeleteSources.ordinal)
uriMatcher.addURI(authority, "source/query", RequestCode.getSource.ordinal) addURI(authority, "source/query", RequestCode.GetSource.ordinal)
uriMatcher.addURI(authority, "sources/query", RequestCode.getSources.ordinal) addURI(authority, "sources/query", RequestCode.GetSources.ordinal)
uriMatcher.addURI(authority, "books/query", RequestCode.getBookshelf.ordinal) addURI(authority, "books/query", RequestCode.GetBookshelf.ordinal)
uriMatcher.addURI(authority, "book/chapter/query", RequestCode.getChapterList.ordinal) addURI(authority, "book/chapter/query", RequestCode.GetChapterList.ordinal)
uriMatcher.addURI(authority, "book/content/query", RequestCode.getBookContent.ordinal) addURI(authority, "book/content/query", RequestCode.GetBookContent.ordinal)
return@lazy uriMatcher }
} }
override fun onCreate(): Boolean {
return false
} }
override fun onCreate() = false
override fun delete( override fun delete(
uri: Uri, uri: Uri,
selection: String?, selection: String?,
@ -54,7 +53,7 @@ class ReaderProvider : ContentProvider() {
): Int { ): Int {
if (sMatcher.match(uri) < 0) return -1 if (sMatcher.match(uri) < 0) return -1
when (RequestCode.values()[sMatcher.match(uri)]) { when (RequestCode.values()[sMatcher.match(uri)]) {
RequestCode.deleteSources -> SourceController.deleteSources(selection) RequestCode.DeleteSources -> SourceController.deleteSources(selection)
else -> throw IllegalStateException( else -> throw IllegalStateException(
"Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name "Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name
) )
@ -62,20 +61,18 @@ class ReaderProvider : ContentProvider() {
return 0 return 0
} }
override fun getType(uri: Uri): String? { override fun getType(uri: Uri) = throw UnsupportedOperationException("Not yet implemented")
throw UnsupportedOperationException("Not yet implemented")
}
override fun insert(uri: Uri, values: ContentValues?): Uri? { override fun insert(uri: Uri, values: ContentValues?): Uri? {
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(postBodyKey)) SourceController.saveSource(values.getAsString(postBodyKey))
} }
RequestCode.saveBook -> values?.let { RequestCode.SaveBook -> values?.let {
BookshelfController.saveBook(values.getAsString(postBodyKey)) BookshelfController.saveBook(values.getAsString(postBodyKey))
} }
RequestCode.saveSources -> values?.let { RequestCode.SaveSources -> values?.let {
SourceController.saveSources(values.getAsString(postBodyKey)) SourceController.saveSources(values.getAsString(postBodyKey))
} }
else -> throw IllegalStateException( else -> throw IllegalStateException(
@ -97,11 +94,11 @@ class ReaderProvider : ContentProvider() {
map["index"] = arrayListOf(it) map["index"] = arrayListOf(it)
} }
return if (sMatcher.match(uri) < 0) null else when (RequestCode.values()[sMatcher.match(uri)]) { return if (sMatcher.match(uri) < 0) null else when (RequestCode.values()[sMatcher.match(uri)]) {
RequestCode.getSource -> SimpleCursor(SourceController.getSource(map)) RequestCode.GetSource -> SimpleCursor(SourceController.getSource(map))
RequestCode.getSources -> SimpleCursor(SourceController.sources) RequestCode.GetSources -> SimpleCursor(SourceController.sources)
RequestCode.getBookshelf -> SimpleCursor(BookshelfController.bookshelf) RequestCode.GetBookshelf -> SimpleCursor(BookshelfController.bookshelf)
RequestCode.getBookContent -> SimpleCursor(BookshelfController.getBookContent(map)) RequestCode.GetBookContent -> SimpleCursor(BookshelfController.getBookContent(map))
RequestCode.getChapterList -> SimpleCursor(BookshelfController.getChapterList(map)) RequestCode.GetChapterList -> SimpleCursor(BookshelfController.getChapterList(map))
else -> throw IllegalStateException( else -> throw IllegalStateException(
"Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name "Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name
) )
@ -111,9 +108,8 @@ class ReaderProvider : ContentProvider() {
override fun update( override fun update(
uri: Uri, values: ContentValues?, selection: String?, uri: Uri, values: ContentValues?, selection: String?,
selectionArgs: Array<String>? selectionArgs: Array<String>?
): Int { ) = throw UnsupportedOperationException("Not yet implemented")
throw UnsupportedOperationException("Not yet implemented")
}
/** /**
* Simple inner class to deliver json callback data. * Simple inner class to deliver json callback data.
@ -124,82 +120,46 @@ class ReaderProvider : ContentProvider() {
private val mData: String = Gson().toJson(data) private val mData: String = Gson().toJson(data)
override fun getCount(): Int { override fun getCount() = 1
return 1
}
override fun getPosition(): Int { override fun getPosition() = 0
return 0
}
override fun move(i: Int): Boolean { override fun move(i: Int) = true
return true
}
override fun moveToPosition(i: Int): Boolean { override fun moveToPosition(i: Int) = true
return true
}
override fun moveToFirst(): Boolean { override fun moveToFirst() = true
return true
}
override fun moveToLast(): Boolean { override fun moveToLast() = true
return true
}
override fun moveToNext(): Boolean { override fun moveToNext() = true
return true
}
override fun moveToPrevious(): Boolean { override fun moveToPrevious() = true
return true
}
override fun isFirst(): Boolean { override fun isFirst() = true
return true
}
override fun isLast(): Boolean { override fun isLast() = true
return true
}
override fun isBeforeFirst(): Boolean { override fun isBeforeFirst() = true
return false
}
override fun isAfterLast(): Boolean { override fun isAfterLast() = true
return false
}
override fun getColumnIndex(s: String): Int { override fun getColumnIndex(s: String) = 0
return 0
}
@Throws(IllegalArgumentException::class) @Throws(IllegalArgumentException::class)
override fun getColumnIndexOrThrow(s: String): Int { override fun getColumnIndexOrThrow(s: String): Int {
throw UnsupportedOperationException("Not yet implemented") throw UnsupportedOperationException("Not yet implemented")
} }
override fun getColumnName(i: Int): String? { override fun getColumnName(i: Int) = null as String?
return null
}
override fun getColumnNames(): Array<String> { override fun getColumnNames() = arrayOf<String>()
return arrayOf()
}
override fun getColumnCount(): Int { override fun getColumnCount() = 0
return 0
}
override fun getBlob(i: Int): ByteArray { override fun getBlob(i: Int) = ByteArray(0)
return ByteArray(0)
}
override fun getString(i: Int): String { override fun getString(i: Int) = mData
return mData
}
override fun copyStringToBuffer( override fun copyStringToBuffer(
i: Int, i: Int,
@ -207,43 +167,26 @@ class ReaderProvider : ContentProvider() {
) { ) {
} }
override fun getShort(i: Int): Short { override fun getShort(i: Int) = 0.toShort()
return 0
}
override fun getInt(i: Int): Int {
return 0
}
override fun getLong(i: Int): Long { override fun getInt(i: Int) = 0
return 0
}
override fun getFloat(i: Int): Float { override fun getLong(i: Int) = 0L
return 0f
}
override fun getDouble(i: Int): Double { override fun getFloat(i: Int) = 0F
return 0.0
}
override fun getType(i: Int): Int { override fun getDouble(i: Int) = 0.toDouble()
return 0
}
override fun isNull(i: Int): Boolean { override fun getType(i: Int) = 0
return false
} override fun isNull(i: Int) = false
override fun deactivate() {} override fun deactivate() {}
override fun requery(): Boolean { override fun requery() = false
return false
}
override fun close() {} override fun close() {}
override fun isClosed(): Boolean { override fun isClosed() = false
return false
}
override fun registerContentObserver(contentObserver: ContentObserver) {} override fun registerContentObserver(contentObserver: ContentObserver) {}
override fun unregisterContentObserver(contentObserver: ContentObserver) {} override fun unregisterContentObserver(contentObserver: ContentObserver) {}
@ -251,22 +194,14 @@ class ReaderProvider : ContentProvider() {
override fun unregisterDataSetObserver(dataSetObserver: DataSetObserver) {} override fun unregisterDataSetObserver(dataSetObserver: DataSetObserver) {}
override fun setNotificationUri(contentResolver: ContentResolver, uri: Uri) {} override fun setNotificationUri(contentResolver: ContentResolver, uri: Uri) {}
override fun getNotificationUri(): Uri? { override fun getNotificationUri() = null as Uri?
return null
}
override fun getWantsAllOnMoveCalls(): Boolean { override fun getWantsAllOnMoveCalls() = false
return false
}
override fun setExtras(bundle: Bundle) {} override fun setExtras(bundle: Bundle) {}
override fun getExtras(): Bundle? { override fun getExtras() = null as Bundle?
return null
}
override fun respond(bundle: Bundle): Bundle? { override fun respond(bundle: Bundle) = null as Bundle?
return null
}
} }
} }

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

Loading…
Cancel
Save