From b324df70953a1e39c4206559cfc1158760214f55 Mon Sep 17 00:00:00 2001 From: 1552980358 <1552980358@qq.com> Date: Wed, 9 Sep 2020 10:08:00 +0800 Subject: [PATCH 1/4] Support JDK14 Signed-off-by: 1552980358 <1552980358@qq.com> --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 372426236..c1e56316f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME 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 From ab38641a9d418428e57661b3d4180a13f4e928dc Mon Sep 17 00:00:00 2001 From: 1552980358 <1552980358@qq.com> Date: Wed, 9 Sep 2020 10:21:27 +0800 Subject: [PATCH 2/4] ReaderProvider.kt: Modify initial process of `sMatcher` Signed-off-by: 1552980358 <1552980358@qq.com> --- .../java/io/legado/app/api/ReaderProvider.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 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 d7802f235..a8cbf9f16 100644 --- a/app/src/main/java/io/legado/app/api/ReaderProvider.kt +++ b/app/src/main/java/io/legado/app/api/ReaderProvider.kt @@ -29,18 +29,19 @@ class ReaderProvider : ContentProvider() { private val postBodyKey = "json" private val sMatcher by lazy { - val uriMatcher = UriMatcher(UriMatcher.NO_MATCH) - val authority = "${context?.applicationInfo?.packageName}.readerProvider" - uriMatcher.addURI(authority, "source/insert", RequestCode.saveSource.ordinal) - uriMatcher.addURI(authority, "sources/insert", RequestCode.saveSources.ordinal) - uriMatcher.addURI(authority, "book/insert", RequestCode.saveBook.ordinal) - uriMatcher.addURI(authority, "sources/delete", RequestCode.deleteSources.ordinal) - uriMatcher.addURI(authority, "source/query", RequestCode.getSource.ordinal) - uriMatcher.addURI(authority, "sources/query", RequestCode.getSources.ordinal) - uriMatcher.addURI(authority, "books/query", RequestCode.getBookshelf.ordinal) - uriMatcher.addURI(authority, "book/chapter/query", RequestCode.getChapterList.ordinal) - uriMatcher.addURI(authority, "book/content/query", RequestCode.getBookContent.ordinal) - return@lazy uriMatcher + 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, "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/chapter/query", RequestCode.getChapterList.ordinal) + addURI(authority, "book/content/query", RequestCode.getBookContent.ordinal) + } + } } override fun onCreate(): Boolean { From 54aef7bf4d1a2c28be607109bff031a30556a006 Mon Sep 17 00:00:00 2001 From: 1552980358 <1552980358@qq.com> Date: Wed, 9 Sep 2020 10:22:40 +0800 Subject: [PATCH 3/4] ReaderProvider.kt: Modify `RequestCode` enum entry name with Uppercase Signed-off-by: 1552980358 <1552980358@qq.com> --- .../java/io/legado/app/api/ReaderProvider.kt | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 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 a8cbf9f16..9ee3d068c 100644 --- a/app/src/main/java/io/legado/app/api/ReaderProvider.kt +++ b/app/src/main/java/io/legado/app/api/ReaderProvider.kt @@ -24,22 +24,22 @@ import java.util.* */ class ReaderProvider : ContentProvider() { 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 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, "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/chapter/query", RequestCode.getChapterList.ordinal) - addURI(authority, "book/content/query", RequestCode.getBookContent.ordinal) + addURI(authority, "source/insert", RequestCode.SaveSource.ordinal) + addURI(authority, "sources/insert", RequestCode.SaveSources.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/chapter/query", RequestCode.GetChapterList.ordinal) + addURI(authority, "book/content/query", RequestCode.GetBookContent.ordinal) } } } @@ -55,7 +55,7 @@ class ReaderProvider : ContentProvider() { ): Int { if (sMatcher.match(uri) < 0) return -1 when (RequestCode.values()[sMatcher.match(uri)]) { - RequestCode.deleteSources -> SourceController.deleteSources(selection) + RequestCode.DeleteSources -> SourceController.deleteSources(selection) else -> throw IllegalStateException( "Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name ) @@ -70,13 +70,13 @@ 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.SaveSource -> values?.let { SourceController.saveSource(values.getAsString(postBodyKey)) } - RequestCode.saveBook -> values?.let { + RequestCode.SaveBook -> values?.let { BookshelfController.saveBook(values.getAsString(postBodyKey)) } - RequestCode.saveSources -> values?.let { + RequestCode.SaveSources -> values?.let { SourceController.saveSources(values.getAsString(postBodyKey)) } else -> throw IllegalStateException( @@ -98,11 +98,11 @@ class ReaderProvider : ContentProvider() { map["index"] = arrayListOf(it) } return if (sMatcher.match(uri) < 0) null else when (RequestCode.values()[sMatcher.match(uri)]) { - RequestCode.getSource -> SimpleCursor(SourceController.getSource(map)) - RequestCode.getSources -> SimpleCursor(SourceController.sources) - RequestCode.getBookshelf -> SimpleCursor(BookshelfController.bookshelf) - RequestCode.getBookContent -> SimpleCursor(BookshelfController.getBookContent(map)) - RequestCode.getChapterList -> SimpleCursor(BookshelfController.getChapterList(map)) + RequestCode.GetSource -> SimpleCursor(SourceController.getSource(map)) + RequestCode.GetSources -> SimpleCursor(SourceController.sources) + RequestCode.GetBookshelf -> SimpleCursor(BookshelfController.bookshelf) + RequestCode.GetBookContent -> SimpleCursor(BookshelfController.getBookContent(map)) + RequestCode.GetChapterList -> SimpleCursor(BookshelfController.getChapterList(map)) else -> throw IllegalStateException( "Unexpected value: " + RequestCode.values()[sMatcher.match(uri)].name ) From 1d945a7368c05a6242da1f58b1c704a6742ea174 Mon Sep 17 00:00:00 2001 From: 1552980358 <1552980358@qq.com> Date: Wed, 9 Sep 2020 10:29:15 +0800 Subject: [PATCH 4/4] ReaderProvider.kt: Modify functions with assigning style Signed-off-by: 1552980358 <1552980358@qq.com> --- .../java/io/legado/app/api/ReaderProvider.kt | 140 +++++------------- 1 file changed, 37 insertions(+), 103 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 9ee3d068c..fcf50aa9c 100644 --- a/app/src/main/java/io/legado/app/api/ReaderProvider.kt +++ b/app/src/main/java/io/legado/app/api/ReaderProvider.kt @@ -44,9 +44,7 @@ class ReaderProvider : ContentProvider() { } } - override fun onCreate(): Boolean { - return false - } + override fun onCreate() = false override fun delete( uri: Uri, @@ -63,9 +61,7 @@ class ReaderProvider : ContentProvider() { return 0 } - override fun getType(uri: Uri): String? { - throw UnsupportedOperationException("Not yet implemented") - } + override fun getType(uri: Uri) = throw UnsupportedOperationException("Not yet implemented") override fun insert(uri: Uri, values: ContentValues?): Uri? { if (sMatcher.match(uri) < 0) return null @@ -112,9 +108,8 @@ class ReaderProvider : ContentProvider() { override fun update( uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array? - ): Int { - throw UnsupportedOperationException("Not yet implemented") - } + ) = throw UnsupportedOperationException("Not yet implemented") + /** * Simple inner class to deliver json callback data. @@ -125,82 +120,46 @@ class ReaderProvider : ContentProvider() { private val mData: String = Gson().toJson(data) - override fun getCount(): Int { - return 1 - } + override fun getCount() = 1 - override fun getPosition(): Int { - return 0 - } + override fun getPosition() = 0 - override fun move(i: Int): Boolean { - return true - } + override fun move(i: Int) = true - override fun moveToPosition(i: Int): Boolean { - return true - } + override fun moveToPosition(i: Int) = true - override fun moveToFirst(): Boolean { - return true - } + override fun moveToFirst() = true - override fun moveToLast(): Boolean { - return true - } + override fun moveToLast() = true - override fun moveToNext(): Boolean { - return true - } + override fun moveToNext() = true - override fun moveToPrevious(): Boolean { - return true - } + override fun moveToPrevious() = true - override fun isFirst(): Boolean { - return true - } + override fun isFirst() = true - override fun isLast(): Boolean { - return true - } + override fun isLast() = true - override fun isBeforeFirst(): Boolean { - return false - } + override fun isBeforeFirst() = true - override fun isAfterLast(): Boolean { - return false - } + override fun isAfterLast() = true - override fun getColumnIndex(s: String): Int { - return 0 - } + override fun getColumnIndex(s: String) = 0 @Throws(IllegalArgumentException::class) override fun getColumnIndexOrThrow(s: String): Int { throw UnsupportedOperationException("Not yet implemented") } - override fun getColumnName(i: Int): String? { - return null - } + override fun getColumnName(i: Int) = null as String? - override fun getColumnNames(): Array { - return arrayOf() - } + override fun getColumnNames() = arrayOf() - override fun getColumnCount(): Int { - return 0 - } + override fun getColumnCount() = 0 - override fun getBlob(i: Int): ByteArray { - return ByteArray(0) - } + override fun getBlob(i: Int) = ByteArray(0) - override fun getString(i: Int): String { - return mData - } + override fun getString(i: Int) = mData override fun copyStringToBuffer( i: Int, @@ -208,43 +167,26 @@ class ReaderProvider : ContentProvider() { ) { } - override fun getShort(i: Int): Short { - return 0 - } + override fun getShort(i: Int) = 0.toShort() + - override fun getInt(i: Int): Int { - return 0 - } + override fun getInt(i: Int) = 0 - override fun getLong(i: Int): Long { - return 0 - } + override fun getLong(i: Int) = 0L - override fun getFloat(i: Int): Float { - return 0f - } + override fun getFloat(i: Int) = 0F - override fun getDouble(i: Int): Double { - return 0.0 - } + override fun getDouble(i: Int) = 0.toDouble() - override fun getType(i: Int): Int { - return 0 - } + override fun getType(i: Int) = 0 - override fun isNull(i: Int): Boolean { - return false - } + override fun isNull(i: Int) = false override fun deactivate() {} - override fun requery(): Boolean { - return false - } + override fun requery() = false override fun close() {} - override fun isClosed(): Boolean { - return false - } + override fun isClosed() = false override fun registerContentObserver(contentObserver: ContentObserver) {} override fun unregisterContentObserver(contentObserver: ContentObserver) {} @@ -252,22 +194,14 @@ class ReaderProvider : ContentProvider() { override fun unregisterDataSetObserver(dataSetObserver: DataSetObserver) {} override fun setNotificationUri(contentResolver: ContentResolver, uri: Uri) {} - override fun getNotificationUri(): Uri? { - return null - } + override fun getNotificationUri() = null as Uri? - override fun getWantsAllOnMoveCalls(): Boolean { - return false - } + override fun getWantsAllOnMoveCalls() = false override fun setExtras(bundle: Bundle) {} - override fun getExtras(): Bundle? { - return null - } - - override fun respond(bundle: Bundle): Bundle? { - return null - } + override fun getExtras() = null as Bundle? + + override fun respond(bundle: Bundle) = null as Bundle? } } \ No newline at end of file