From f3aaba87d3eb71dbe2f203aeb1003948aee41dcb Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 26 Oct 2020 10:08:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=88=86=E7=BB=84=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E5=88=86=E7=BB=84=E4=B9=A6=E7=B1=8D=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 ++-- app/src/main/assets/updateLog.md | 1 + .../java/io/legado/app/base/BaseActivity.kt | 21 +++++++------------ .../java/io/legado/app/help/ActivityHelp.kt | 2 +- .../io/legado/app/help/http/AjaxWebView.kt | 11 +++++----- .../app/help/permission/RequestManager.kt | 3 ++- .../io/legado/app/lib/dialogs/AlertBuilder.kt | 5 +++-- .../association/ImportBookSourceActivity.kt | 2 ++ .../app/ui/book/info/BookInfoActivity.kt | 4 ++-- .../app/ui/book/read/ReadBookActivity.kt | 3 ++- .../app/ui/book/search/SearchViewModel.kt | 3 ++- .../app/ui/book/toc/BookmarkFragment.kt | 7 ++----- .../io/legado/app/ui/login/SourceLogin.kt | 8 +++++-- .../io/legado/app/utils/ActivityExtensions.kt | 2 ++ 14 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/ActivityExtensions.kt diff --git a/app/build.gradle b/app/build.gradle index 9a931e753..ca951504e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,7 +18,7 @@ def version = "3." + releaseTime() def gitCommits = Integer.parseInt('git rev-list --count HEAD'.execute([], project.rootDir).text.trim()) android { - compileSdkVersion 29 + compileSdkVersion 30 signingConfigs { if (project.hasProperty("RELEASE_STORE_FILE")) { myConfig { @@ -34,7 +34,7 @@ android { defaultConfig { applicationId "io.legado.app" minSdkVersion 21 - targetSdkVersion 29 + targetSdkVersion 30 versionCode gitCommits versionName version testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 4b0715664..fed29cacf 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/10/25** * 点击书籍分组可显示书籍数量 +* 升级到SDK30 **2020/10/24** * 修复选择错误的bug diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index b1d3c76d9..7c5953584 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -100,24 +100,19 @@ abstract class BaseActivity( } ?: super.onCreateOptionsMenu(menu) } - override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { - menu?.let { - menu.applyOpenTint(this) - return super.onMenuOpened(featureId, menu) - } - return true + override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { + menu.applyOpenTint(this) + return super.onMenuOpened(featureId, menu) } open fun onCompatCreateOptionsMenu(menu: Menu) = super.onCreateOptionsMenu(menu) - final override fun onOptionsItemSelected(item: MenuItem?): Boolean { - item?.let { - if (it.itemId == android.R.id.home) { - supportFinishAfterTransition() - return true - } + final override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == android.R.id.home) { + supportFinishAfterTransition() + return true } - return item != null && onCompatOptionsItemSelected(item) + return onCompatOptionsItemSelected(item) } open fun onCompatOptionsItemSelected(item: MenuItem) = super.onOptionsItemSelected(item) diff --git a/app/src/main/java/io/legado/app/help/ActivityHelp.kt b/app/src/main/java/io/legado/app/help/ActivityHelp.kt index 9c9cb0175..b5e1dbe28 100644 --- a/app/src/main/java/io/legado/app/help/ActivityHelp.kt +++ b/app/src/main/java/io/legado/app/help/ActivityHelp.kt @@ -104,7 +104,7 @@ object ActivityHelp : Application.ActivityLifecycleCallbacks { remove(activity) } - override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) { + override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { } override fun onActivityStopped(activity: Activity) { diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt index a12816486..db6dc165b 100644 --- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt @@ -64,11 +64,12 @@ class AjaxWebView { webView.webViewClient = HtmlWebViewClient(params, handler) } when (params.requestMethod) { - RequestMethod.POST -> webView.postUrl(params.url, params.postData) - RequestMethod.GET -> webView.loadUrl( - params.url, - params.headerMap - ) + RequestMethod.POST -> params.postData?.let { + webView.postUrl(params.url, it) + } + RequestMethod.GET -> params.headerMap?.let { + webView.loadUrl(params.url, it) + } } return webView } diff --git a/app/src/main/java/io/legado/app/help/permission/RequestManager.kt b/app/src/main/java/io/legado/app/help/permission/RequestManager.kt index 18bedb800..eb28b9e6c 100644 --- a/app/src/main/java/io/legado/app/help/permission/RequestManager.kt +++ b/app/src/main/java/io/legado/app/help/permission/RequestManager.kt @@ -1,6 +1,7 @@ package io.legado.app.help.permission import android.os.Handler +import android.os.Looper import java.util.* internal object RequestManager : OnPermissionsResultCallback { @@ -8,7 +9,7 @@ internal object RequestManager : OnPermissionsResultCallback { private var requests: Stack? = null private var request: Request? = null - private val handler = Handler() + private val handler = Handler(Looper.getMainLooper()) private val requestRunnable = Runnable { request?.start() diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt b/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt index b1f0f494d..a938b3584 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt @@ -26,6 +26,7 @@ import android.view.KeyEvent import android.view.View import androidx.annotation.DrawableRes import androidx.annotation.StringRes +import io.legado.app.R import org.jetbrains.anko.internals.AnkoInternals.NO_GETTER import kotlin.DeprecationLevel.ERROR @@ -111,7 +112,7 @@ inline fun AlertBuilder<*>.cancelButton(noinline handler: ((dialog: DialogInterf negativeButton(android.R.string.cancel, handler) inline fun AlertBuilder<*>.yesButton(noinline handler: ((dialog: DialogInterface) -> Unit)? = null) = - positiveButton(android.R.string.yes, handler) + positiveButton(R.string.yes, handler) inline fun AlertBuilder<*>.noButton(noinline handler: ((dialog: DialogInterface) -> Unit)? = null) = - negativeButton(android.R.string.no, handler) \ No newline at end of file + negativeButton(R.string.no, handler) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt index c045d0e33..6ff87b095 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.association +import android.annotation.SuppressLint import android.content.Context import android.content.DialogInterface import android.os.Bundle @@ -169,6 +170,7 @@ class ImportBookSourceActivity : VMBaseActivity( tool_bar.inflateMenu(R.menu.import_source) } + @SuppressLint("InflateParams") override fun onMenuItemClick(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_new_group -> { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 9d64e43fe..2e4a696ea 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -114,8 +114,8 @@ class BookInfoActivity : return super.onCompatOptionsItemSelected(item) } - override fun onMenuOpened(featureId: Int, menu: Menu?): Boolean { - menu?.findItem(R.id.menu_can_update)?.isChecked = + override fun onMenuOpened(featureId: Int, menu: Menu): Boolean { + menu.findItem(R.id.menu_can_update)?.isChecked = viewModel.bookData.value?.canUpdate ?: true return super.onMenuOpened(featureId, menu) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 540bb2a05..6939d413f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Bundle import android.os.Handler +import android.os.Looper import android.view.* import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import androidx.core.view.get @@ -92,7 +93,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override val scope: CoroutineScope get() = this override val isInitFinish: Boolean get() = viewModel.isInitFinish override val isScroll: Boolean get() = page_view.isScroll - private val mHandler = Handler() + private val mHandler = Handler(Looper.getMainLooper()) private val keepScreenRunnable: Runnable = Runnable { ReadBookActivityHelp.keepScreenOn(window, false) } private val autoPageRunnable: Runnable = Runnable { autoPagePlus() } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 7d5b1858a..a28cfabf4 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.book.search import android.app.Application import android.os.Handler +import android.os.Looper import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel @@ -15,7 +16,7 @@ import kotlinx.coroutines.isActive class SearchViewModel(application: Application) : BaseViewModel(application), SearchBookModel.CallBack { - val handler = Handler() + val handler = Handler(Looper.getMainLooper()) private val searchBookModel = SearchBookModel(this, this) var isSearchLiveData = MutableLiveData() var searchBookLiveData = MutableLiveData>() diff --git a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt index 0f507640c..3b5682f5e 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.book.toc import android.annotation.SuppressLint import android.app.Activity import android.content.Intent -import android.os.AsyncTask import android.os.Bundle import android.view.View import android.widget.EditText @@ -102,10 +101,8 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ } yesButton { editText?.text?.toString()?.let { editContent -> - AsyncTask.execute { - bookmark.content = editContent - App.db.bookmarkDao().update(bookmark) - } + bookmark.content = editContent + App.db.bookmarkDao().update(bookmark) } } noButton() diff --git a/app/src/main/java/io/legado/app/ui/login/SourceLogin.kt b/app/src/main/java/io/legado/app/ui/login/SourceLogin.kt index 767545d38..dffe03695 100644 --- a/app/src/main/java/io/legado/app/ui/login/SourceLogin.kt +++ b/app/src/main/java/io/legado/app/ui/login/SourceLogin.kt @@ -55,7 +55,9 @@ class SourceLogin : BaseActivity(R.layout.activity_source_login) { super.onPageFinished(view, url) } } - web_view.loadUrl(loginUrl) + loginUrl?.let { + web_view.loadUrl(it) + } } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { @@ -69,7 +71,9 @@ class SourceLogin : BaseActivity(R.layout.activity_source_login) { if (!checking) { checking = true title_bar.snackbar(R.string.check_host_cookie) - web_view.loadUrl(sourceUrl) + loginUrl?.let { + web_view.loadUrl(it) + } } } } diff --git a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt new file mode 100644 index 000000000..656da42d1 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt @@ -0,0 +1,2 @@ +package io.legado.app.utils +