From 0fac54d28aac896e838c07a5fc30ba2dc4eb7be9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 4 Feb 2021 16:33:44 +0800 Subject: [PATCH] delete anko --- app/build.gradle | 7 ++- .../app/base/adapter/DiffRecyclerAdapter.kt | 7 ++- .../app/base/adapter/RecyclerAdapter.kt | 7 ++- .../io/legado/app/help/permission/Request.kt | 40 ++++++++---- .../java/io/legado/app/help/storage/Backup.kt | 1 - .../io/legado/app/help/storage/Restore.kt | 1 - .../io/legado/app/lib/dialogs/AlertBuilder.kt | 34 ++++------ .../app/lib/dialogs/AndroidAlertBuilder.kt | 62 +++++++++---------- .../legado/app/lib/dialogs/AndroidDialogs.kt | 10 ++- .../app/lib/dialogs/AndroidSelectors.kt | 4 +- .../java/io/legado/app/lib/dialogs/Dialogs.kt | 8 +-- .../io/legado/app/lib/dialogs/Selectors.kt | 2 +- .../app/receiver/SharedReceiverActivity.kt | 10 ++- .../io/legado/app/service/DownloadService.kt | 2 +- .../app/service/HttpReadAloudService.kt | 12 ++-- .../java/io/legado/app/service/WebService.kt | 6 +- .../io/legado/app/service/help/ReadBook.kt | 4 +- .../io/legado/app/ui/about/AboutActivity.kt | 2 +- .../io/legado/app/ui/about/DonateFragment.kt | 4 +- .../legado/app/ui/about/ReadRecordActivity.kt | 2 +- .../ui/association/FileAssociationActivity.kt | 3 +- .../ui/association/ImportBookSourceDialog.kt | 4 +- .../ui/association/ImportRssSourceDialog.kt | 4 +- .../legado/app/ui/audio/AudioPlayActivity.kt | 14 ++--- .../book/changesource/ChangeSourceAdapter.kt | 4 +- .../ui/book/explore/ExploreShowActivity.kt | 11 ++-- .../app/ui/book/group/GroupManageDialog.kt | 4 +- .../app/ui/book/group/GroupSelectDialog.kt | 4 +- .../app/ui/book/info/BookInfoActivity.kt | 50 ++++++++------- .../app/ui/book/read/ReadBookActivity.kt | 42 +++++++------ .../app/ui/book/read/ReadBookBaseActivity.kt | 8 +-- .../io/legado/app/ui/book/read/ReadMenu.kt | 4 +- .../legado/app/ui/book/read/TextActionMenu.kt | 1 - .../ui/book/read/config/BgTextConfigDialog.kt | 4 +- .../ui/book/read/config/ReadStyleDialog.kt | 5 +- .../ui/book/read/config/SpeakEngineDialog.kt | 2 +- .../app/ui/book/read/config/TocRegexDialog.kt | 4 +- .../app/ui/book/search/HistoryKeyAdapter.kt | 8 +-- .../app/ui/book/search/SearchActivity.kt | 18 +++--- .../source/debug/BookSourceDebugActivity.kt | 2 +- .../source/edit/BookSourceEditActivity.kt | 18 +++--- .../book/source/manage/BookSourceActivity.kt | 26 +++++--- .../book/source/manage/BookSourceViewModel.kt | 9 ++- .../book/source/manage/GroupManageDialog.kt | 4 +- .../legado/app/ui/book/toc/BookmarkAdapter.kt | 4 +- .../app/ui/book/toc/BookmarkFragment.kt | 4 +- .../app/ui/config/OtherConfigFragment.kt | 2 +- .../app/ui/config/ThemeConfigFragment.kt | 2 +- .../legado/app/ui/config/ThemeListDialog.kt | 2 - .../ui/main/bookshelf/BookshelfFragment.kt | 27 ++++---- .../main/bookshelf/books/BooksAdapterGrid.kt | 4 +- .../main/bookshelf/books/BooksAdapterList.kt | 4 +- .../ui/main/bookshelf/books/BooksFragment.kt | 20 +++--- .../app/ui/main/explore/ExploreAdapter.kt | 4 +- .../app/ui/main/explore/ExploreFragment.kt | 14 +++-- .../io/legado/app/ui/main/my/MyFragment.kt | 18 +++--- .../io/legado/app/ui/main/rss/RssAdapter.kt | 4 +- .../io/legado/app/ui/main/rss/RssFragment.kt | 16 +++-- .../app/ui/replace/GroupManageDialog.kt | 6 +- .../app/ui/replace/ReplaceRuleActivity.kt | 16 +++-- .../ui/replace/edit/ReplaceEditActivity.kt | 6 +- .../app/ui/rss/article/RssArticlesFragment.kt | 10 +-- .../app/ui/rss/article/RssSortActivity.kt | 7 ++- .../ui/rss/favorites/RssFavoritesActivity.kt | 12 ++-- .../legado/app/ui/rss/read/ReadRssActivity.kt | 2 +- .../rss/source/edit/RssSourceEditActivity.kt | 10 +-- .../ui/rss/source/manage/RssSourceActivity.kt | 20 +++--- .../ui/rss/subscription/RuleSubActivity.kt | 16 +++-- .../legado/app/ui/welcome/WelcomeActivity.kt | 2 +- .../legado/app/ui/widget/prefs/Preference.kt | 4 +- .../io/legado/app/utils/ActivityExtensions.kt | 8 +++ .../io/legado/app/utils/ContextExtensions.kt | 33 +++++++--- .../io/legado/app/utils/FragmentExtensions.kt | 32 ++++------ .../io/legado/app/utils/GsonExtensions.kt | 15 ++--- .../java/io/legado/app/utils/MainHandler.kt | 37 +++++++++++ .../main/java/io/legado/app/utils/Toasts.kt | 5 +- 76 files changed, 466 insertions(+), 378 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/MainHandler.kt diff --git a/app/build.gradle b/app/build.gradle index 4bbc6084c..c01677c0c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -130,6 +130,7 @@ dependencies { implementation "androidx.activity:activity-ktx:1.1.0" implementation "androidx.fragment:fragment-ktx:1.2.5" implementation 'androidx.preference:preference-ktx:1.1.1' + implementation "androidx.collection:collection-ktx:1.1.0" implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' @@ -138,7 +139,11 @@ dependencies { implementation 'com.google.android:flexbox:1.1.0' implementation 'com.google.code.gson:gson:2.8.6' - implementation "org.jetbrains.anko:anko-sdk27:0.10.8" + //Splitties + def splitties_version = '2.1.1' + implementation("com.louiscad.splitties:splitties-appctx:$splitties_version") + implementation("com.louiscad.splitties:splitties-systemservices:$splitties_version") + implementation("com.louiscad.splitties:splitties-views:$splitties_version") //lifecycle def lifecycle_version = '2.2.0' diff --git a/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt index 60d3600ed..2575ea067 100644 --- a/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding +import splitties.views.onLongClick /** * Created by Invincible on 2017/12/15. @@ -130,10 +131,10 @@ abstract class DiffRecyclerAdapter(protected val context } if (itemLongClickListener != null) { - holder.itemView.setOnLongClickListener { + holder.itemView.onLongClick { getItem(holder.layoutPosition)?.let { - itemLongClickListener?.invoke(holder, it) ?: true - } ?: true + itemLongClickListener?.invoke(holder, it) + } } } diff --git a/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt index 0d6e3b668..11dd17f8c 100644 --- a/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding +import splitties.views.onLongClick import java.util.* /** @@ -351,10 +352,10 @@ abstract class RecyclerAdapter(protected val context: Co } if (itemLongClickListener != null) { - holder.itemView.setOnLongClickListener { + holder.itemView.onLongClick { getItem(holder.layoutPosition)?.let { - itemLongClickListener?.invoke(holder, it) ?: true - } ?: true + itemLongClickListener?.invoke(holder, it) + } } } diff --git a/app/src/main/java/io/legado/app/help/permission/Request.kt b/app/src/main/java/io/legado/app/help/permission/Request.kt index f7ed0293a..7a26f521f 100644 --- a/app/src/main/java/io/legado/app/help/permission/Request.kt +++ b/app/src/main/java/io/legado/app/help/permission/Request.kt @@ -9,7 +9,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import io.legado.app.R -import org.jetbrains.anko.startActivity +import io.legado.app.utils.startActivity import java.util.* internal class Request : OnRequestPermissionsResultCallback { @@ -77,20 +77,26 @@ internal class Request : OnRequestPermissionsResultCallback { if (deniedPermissions == null) { onPermissionsGranted(requestCode) } else { - val rationale = if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale + val rationale = + if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale if (rationale != null) { - showSettingDialog(rationale) { onPermissionsDenied(requestCode, deniedPermissions) } + showSettingDialog(rationale) { + onPermissionsDenied( + requestCode, + deniedPermissions + ) + } } else { onPermissionsDenied(requestCode, deniedPermissions) } } } else { if (deniedPermissions != null) { - source?.context?.startActivity( - PermissionActivity.KEY_INPUT_REQUEST_TYPE to TYPE_REQUEST_PERMISSION, - PermissionActivity.KEY_INPUT_PERMISSIONS_CODE to requestCode, - PermissionActivity.KEY_INPUT_PERMISSIONS to deniedPermissions - ) + source?.context?.startActivity { + putExtra(PermissionActivity.KEY_INPUT_REQUEST_TYPE, TYPE_REQUEST_PERMISSION) + putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS_CODE, requestCode) + putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions) + } } else { onPermissionsGranted(requestCode) } @@ -132,9 +138,12 @@ internal class Request : OnRequestPermissionsResultCallback { .setTitle(R.string.dialog_title) .setMessage(rationale) .setPositiveButton(R.string.dialog_setting) { _, _ -> - it.startActivity( - PermissionActivity.KEY_INPUT_REQUEST_TYPE to TYPE_REQUEST_SETTING - ) + it.startActivity { + putExtra( + PermissionActivity.KEY_INPUT_REQUEST_TYPE, + TYPE_REQUEST_SETTING + ) + } } .setNegativeButton(R.string.dialog_cancel) { _, _ -> cancel() } .show() @@ -160,10 +169,15 @@ internal class Request : OnRequestPermissionsResultCallback { RequestPlugins.sResultCallback?.onPermissionsDenied(requestCode, deniedPermissions) } - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray + ) { val deniedPermissions = getDeniedPermissions(permissions) if (deniedPermissions != null) { - val rationale = if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale + val rationale = + if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale if (rationale != null) { showSettingDialog(rationale) { onPermissionsDenied(requestCode, deniedPermissions) } } else { diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 3aa43ecf3..7a72d655d 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -12,7 +12,6 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.withContext -import org.jetbrains.anko.defaultSharedPreferences import java.io.File import java.util.concurrent.TimeUnit diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 217c9e143..59896f64e 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -23,7 +23,6 @@ import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.withContext -import org.jetbrains.anko.defaultSharedPreferences import java.io.File object Restore { 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 6a245e5fb..5dab676bb 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 @@ -11,40 +11,28 @@ 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 @SuppressLint("SupportAnnotationUsage") interface AlertBuilder { val ctx: Context - var title: CharSequence - @Deprecated(NO_GETTER, level = ERROR) get + fun setTitle(title: CharSequence) - var titleResource: Int - @Deprecated(NO_GETTER, level = ERROR) get + fun setTitle(titleResource: Int) - var message: CharSequence - @Deprecated(NO_GETTER, level = ERROR) get + fun setMessage(message: CharSequence) - var messageResource: Int - @Deprecated(NO_GETTER, level = ERROR) get + fun setMessage(messageResource: Int) - var icon: Drawable - @Deprecated(NO_GETTER, level = ERROR) get + fun setIcon(icon: Drawable) - @setparam:DrawableRes - var iconResource: Int - @Deprecated(NO_GETTER, level = ERROR) get + fun setIcon(@DrawableRes iconResource: Int) - var customTitle: View - @Deprecated(NO_GETTER, level = ERROR) get + fun setCustomTitle(customTitle: View) - var customView: View - @Deprecated(NO_GETTER, level = ERROR) get + fun setCustomView(customView: View) - var isCancelable: Boolean - @Deprecated(NO_GETTER, level = ERROR) get + fun setCancelable(isCancelable: Boolean) fun positiveButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) fun positiveButton( @@ -97,11 +85,11 @@ interface AlertBuilder { fun customTitle(view: () -> View) { - customTitle = view() + setCustomTitle(view()) } fun customView(view: () -> View) { - customView = view() + setCustomView(view()) } fun okButton(handler: ((dialog: DialogInterface) -> Unit)? = null) = diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt b/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt index cf53eac12..47cb3432b 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt @@ -7,48 +7,45 @@ import android.view.KeyEvent import android.view.View import androidx.appcompat.app.AlertDialog import io.legado.app.utils.applyTint -import org.jetbrains.anko.internals.AnkoInternals -import org.jetbrains.anko.internals.AnkoInternals.NO_GETTER -import kotlin.DeprecationLevel.ERROR internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder { private val builder = AlertDialog.Builder(ctx) - override var title: CharSequence - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setTitle(value) } + override fun setTitle(title: CharSequence) { + builder.setTitle(title) + } - override var titleResource: Int - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setTitle(value) } + override fun setTitle(titleResource: Int) { + builder.setTitle(titleResource) + } - override var message: CharSequence - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setMessage(value) } + override fun setMessage(message: CharSequence) { + builder.setMessage(message) + } - override var messageResource: Int - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setMessage(value) } + override fun setMessage(messageResource: Int) { + builder.setMessage(messageResource) + } - override var icon: Drawable - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setIcon(value) } + override fun setIcon(icon: Drawable) { + builder.setIcon(icon) + } - override var iconResource: Int - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setIcon(value) } + override fun setIcon(iconResource: Int) { + builder.setIcon(iconResource) + } - override var customTitle: View - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setCustomTitle(value) } + override fun setCustomTitle(customTitle: View) { + builder.setCustomTitle(customTitle) + } - override var customView: View - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setView(value) } + override fun setCustomView(customView: View) { + builder.setView(customView) + } - override var isCancelable: Boolean - @Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() - set(value) { builder.setCancelable(value) } + override fun setCancelable(isCancelable: Boolean) { + builder.setCancelable(isCancelable) + } override fun onCancelled(handler: (DialogInterface) -> Unit) { builder.setOnCancelListener(handler) @@ -58,7 +55,10 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder Unit)?) { + override fun positiveButton( + buttonText: String, + onClicked: ((dialog: DialogInterface) -> Unit)? + ) { builder.setPositiveButton(buttonText) { dialog, _ -> onClicked?.invoke(dialog) } } diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt b/app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt index 233bbfe7d..d99ec1e7b 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt @@ -7,7 +7,6 @@ import android.content.Context import android.content.DialogInterface import androidx.appcompat.app.AlertDialog import androidx.fragment.app.Fragment -import org.jetbrains.anko.AnkoContext inline fun Fragment.alert( title: CharSequence? = null, @@ -22,10 +21,10 @@ fun Context.alert( ): AlertBuilder { return AndroidAlertBuilder(this).apply { if (title != null) { - this.title = title + this.setTitle(title) } if (message != null) { - this.message = message + this.setMessage(message) } if (init != null) init() } @@ -44,17 +43,16 @@ fun Context.alert( ): AlertBuilder { return AndroidAlertBuilder(this).apply { if (titleResource != null) { - this.titleResource = titleResource + this.setTitle(titleResource) } if (messageResource != null) { - this.messageResource = messageResource + this.setMessage(messageResource) } if (init != null) init() } } -inline fun AnkoContext<*>.alert(noinline init: AlertBuilder.() -> Unit) = ctx.alert(init) inline fun Fragment.alert(noinline init: AlertBuilder.() -> Unit) = requireContext().alert(init) fun Context.alert(init: AlertBuilder.() -> Unit): AlertBuilder = diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt b/app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt index fd6570240..6033879de 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt @@ -35,7 +35,7 @@ fun Context.selector( ) { with(AndroidAlertBuilder(this)) { if (title != null) { - this.title = title + this.setTitle(title) } items(items, onClick) show() @@ -49,7 +49,7 @@ fun Context.selector( ) { with(AndroidAlertBuilder(this)) { if (titleSource != null) { - this.title = getString(titleSource) + this.setTitle(titleSource) } items(items, onClick) show() diff --git a/app/src/main/java/io/legado/app/lib/dialogs/Dialogs.kt b/app/src/main/java/io/legado/app/lib/dialogs/Dialogs.kt index fb3729465..0abcc36c0 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/Dialogs.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/Dialogs.kt @@ -23,10 +23,10 @@ fun Context.alert( ): AlertBuilder { return factory(this).apply { if (title != null) { - this.title = title + this.setTitle(title) } if (message != null) { - this.message = message + this.setMessage(message) } if (init != null) init() } @@ -47,10 +47,10 @@ fun Context.alert( ): AlertBuilder { return factory(this).apply { if (titleResource != null) { - this.titleResource = titleResource + this.setTitle(titleResource) } if (messageResource != null) { - this.messageResource = messageResource + this.setMessage(messageResource) } if (init != null) init() } diff --git a/app/src/main/java/io/legado/app/lib/dialogs/Selectors.kt b/app/src/main/java/io/legado/app/lib/dialogs/Selectors.kt index 87a35cf76..c74535955 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/Selectors.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/Selectors.kt @@ -21,7 +21,7 @@ fun Context.selector( ) { with(factory(this)) { if (title != null) { - this.title = title + this.setTitle(title) } items(items, onClick) show() diff --git a/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt b/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt index e6b78f0f5..6d76736d5 100644 --- a/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt +++ b/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt @@ -6,7 +6,7 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.main.MainActivity -import org.jetbrains.anko.startActivity +import io.legado.app.utils.startActivity class SharedReceiverActivity : AppCompatActivity() { @@ -22,7 +22,9 @@ class SharedReceiverActivity : AppCompatActivity() { if (Intent.ACTION_SEND == intent.action && intent.type == receivingType) { intent.getStringExtra(Intent.EXTRA_TEXT)?.let { if (openUrl(it)) { - startActivity(Pair("key", it)) + startActivity { + putExtra("key", it) + } } } } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M @@ -31,7 +33,9 @@ class SharedReceiverActivity : AppCompatActivity() { ) { intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let { if (openUrl(it)) { - startActivity(Pair("key", it)) + startActivity { + putExtra("key", it) + } } } } diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 4b3f11b6f..134ca55eb 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -19,9 +19,9 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.IntentAction import io.legado.app.help.IntentHelp import io.legado.app.utils.RealPathUtil -import io.legado.app.utils.downloadManager import io.legado.app.utils.msg import io.legado.app.utils.toastOnUi +import splitties.systemservices.downloadManager import java.io.File diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 562e80ce0..8ad7b1420 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -13,8 +13,6 @@ import io.legado.app.service.help.ReadBook import io.legado.app.utils.* import kotlinx.coroutines.ensureActive import kotlinx.coroutines.isActive -import org.jetbrains.anko.collections.forEachWithIndex -import org.jetbrains.anko.runOnUiThread import java.io.File import java.io.FileDescriptor import java.io.FileInputStream @@ -80,10 +78,10 @@ class HttpReadAloudService : BaseReadAloudService(), task = execute { removeCacheFile() ReadAloud.httpTTS?.let { - contentList.forEachWithIndex { index, item -> + contentList.forEachIndexed { index, item -> if (isActive) { val fileName = - md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), item) + md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), item) if (hasSpeakFile(fileName)) { //已经下载好的语音缓存 if (index == nowSpeak) { @@ -119,17 +117,17 @@ class HttpReadAloudService : BaseReadAloudService(), } } catch (e: SocketTimeoutException) { removeSpeakCacheFile(fileName) - runOnUiThread { toastOnUi("tts接口超时,尝试重新获取") } + toastOnUi("tts接口超时,尝试重新获取") downloadAudio() } catch (e: ConnectException) { removeSpeakCacheFile(fileName) - runOnUiThread { toastOnUi("网络错误") } + toastOnUi("网络错误") } catch (e: IOException) { val file = getSpeakFileAsMd5(fileName) if (file.exists()) { FileUtils.deleteFile(file.absolutePath) } - runOnUiThread { toastOnUi("tts文件解析错误") } + toastOnUi("tts文件解析错误") } catch (e: Exception) { removeSpeakCacheFile(fileName) } diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 441a718de..da350a90a 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -10,13 +10,9 @@ import io.legado.app.constant.EventBus import io.legado.app.constant.IntentAction import io.legado.app.constant.PreferKey import io.legado.app.help.IntentHelp -import io.legado.app.utils.NetworkUtils -import io.legado.app.utils.getPrefInt -import io.legado.app.utils.postEvent -import io.legado.app.utils.toastOnUi +import io.legado.app.utils.* import io.legado.app.web.HttpServer import io.legado.app.web.WebSocketServer -import org.jetbrains.anko.startService import java.io.IOException class WebService : BaseService() { diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 88440d47c..c6f3f9281 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -14,12 +14,12 @@ import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ImageProvider +import io.legado.app.utils.msg import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import org.jetbrains.anko.getStackTraceString @Suppress("MemberVisibilityCanBePrivate") @@ -437,7 +437,7 @@ object ReadBook { } }.onError { it.printStackTrace() - App.INSTANCE.toastOnUi("ChapterProvider ERROR:\n${it.getStackTraceString()}") + App.INSTANCE.toastOnUi("ChapterProvider ERROR:\n${it.msg}") }.onSuccess { success?.invoke() } diff --git a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt index f6c9088de..2c669aacd 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt @@ -12,7 +12,7 @@ import io.legado.app.databinding.ActivityAboutBinding import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.utils.openUrl -import org.jetbrains.anko.share +import io.legado.app.utils.share class AboutActivity : BaseActivity() { diff --git a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt index b716c8f05..29da08d54 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt @@ -8,9 +8,9 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.utils.ACache +import io.legado.app.utils.longToastOnUi import io.legado.app.utils.openUrl import io.legado.app.utils.sendToClip -import org.jetbrains.anko.longToast class DonateFragment : PreferenceFragmentCompat() { @@ -42,7 +42,7 @@ class DonateFragment : PreferenceFragmentCompat() { private fun getZfbHb(context: Context) { requireContext().sendToClip("537954522") - context.longToast("高级功能已开启\n红包码已复制\n支付宝首页搜索“537954522” 立即领红包") + context.longToastOnUi("高级功能已开启\n红包码已复制\n支付宝首页搜索“537954522” 立即领红包") try { val packageManager = context.applicationContext.packageManager val intent = packageManager.getLaunchIntentForPackage("com.eg.android.AlipayGphone")!! diff --git a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt index 8ee502735..4d128ecb9 100644 --- a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt @@ -121,7 +121,7 @@ class ReadRecordActivity : BaseActivity() { private fun sureDelAlert(item: ReadRecordShow) { alert(R.string.delete) { - message = getString(R.string.sure_del_any, item.bookName) + setMessage(getString(R.string.sure_del_any, item.bookName)) okButton { App.db.readRecordDao.deleteByName(item.bookName) initData() diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index 02506cccc..67aec440f 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -7,10 +7,9 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Theme import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.ui.main.MainActivity +import io.legado.app.utils.startActivity import io.legado.app.utils.toastOnUi -import org.jetbrains.anko.startActivity - class FileAssociationActivity : VMBaseActivity( diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt index 27c90b97f..88b2c7438 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt @@ -96,7 +96,9 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList editView.setFilterValues(groups.toList()) editView.dropDownHeight = 180.dp } - customView = alertBinding.root + customView { + alertBinding.root + } okButton { alertBinding.editView.text?.toString()?.let { group -> viewModel.groupName = group diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index 38d4ecfcf..47a4e083c 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -96,7 +96,9 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe editView.setFilterValues(groups.toList()) editView.dropDownHeight = 180.dp } - customView = alertBinding.root + customView { + alertBinding.root + } okButton { alertBinding.editView.text?.toString()?.let { group -> viewModel.groupName = group diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index 38f9e338c..a210aeb99 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -29,7 +29,7 @@ import io.legado.app.ui.book.toc.ChapterListActivity import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* -import org.jetbrains.anko.startActivityForResult +import splitties.views.onLongClick import java.util.* /** @@ -82,9 +82,8 @@ class AudioPlayActivity : binding.fabPlayStop.setOnClickListener { playButton() } - binding.fabPlayStop.setOnLongClickListener { + binding.fabPlayStop.onLongClick { AudioPlay.stop(this@AudioPlayActivity) - true } binding.ivSkipNext.setOnClickListener { AudioPlay.next(this@AudioPlayActivity) @@ -108,10 +107,9 @@ class AudioPlayActivity : }) binding.ivChapter.setOnClickListener { AudioPlay.book?.let { - startActivityForResult( - requestCodeChapter, - Pair("bookUrl", it.bookUrl) - ) + startActivityForResult(requestCodeChapter) { + putExtra("bookUrl", it.bookUrl) + } } } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { @@ -165,7 +163,7 @@ class AudioPlayActivity : AudioPlay.book?.let { if (!AudioPlay.inBookshelf) { alert(title = getString(R.string.add_to_shelf)) { - message = getString(R.string.check_add_bookshelf, it.name) + setMessage(getString(R.string.check_add_bookshelf, it.name)) okButton { AudioPlay.inBookshelf = true setResult(Activity.RESULT_OK) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 32b3fc8ce..70196a543 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -13,6 +13,7 @@ import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.ItemChangeSourceBinding import io.legado.app.utils.invisible import io.legado.app.utils.visible +import splitties.views.onLongClick class ChangeSourceAdapter(context: Context, val callBack: CallBack) : @@ -68,9 +69,8 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) : callBack.changeTo(it) } } - holder.itemView.setOnLongClickListener { + holder.itemView.onLongClick { showMenu(holder.itemView, getItem(holder.layoutPosition)) - true } } diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt index f4ce03bd3..95f1a12bc 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt @@ -12,8 +12,7 @@ import io.legado.app.databinding.ViewLoadMoreBinding import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.widget.recycler.LoadMoreView import io.legado.app.ui.widget.recycler.VerticalDivider - -import org.jetbrains.anko.startActivity +import io.legado.app.utils.startActivity class ExploreShowActivity : VMBaseActivity(), ExploreShowAdapter.CallBack { @@ -88,9 +87,9 @@ class ExploreShowActivity : VMBaseActivity( - Pair("name", book.name), - Pair("author", book.author) - ) + startActivity { + putExtra("name", book.name) + putExtra("author", book.author) + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 84ef201bf..7d1d5597b 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -99,7 +99,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { editView.setHint(R.string.group_name) } - customView = alertBinding.root + customView { alertBinding.root } yesButton { alertBinding.editView.text?.toString()?.let { if (it.isNotBlank()) { @@ -123,7 +123,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener deleteGroup(bookGroup) } } - customView = alertBinding.root + customView { alertBinding.root } yesButton { alertBinding.editView.text?.toString()?.let { viewModel.upGroup(bookGroup.copy(groupName = it)) diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 40aa03b6b..fcd7648be 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -122,7 +122,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { editView.setHint(R.string.group_name) } - customView = alertBinding.root + customView { alertBinding.root } yesButton { alertBinding.editView.text?.toString()?.let { if (it.isNotBlank()) { @@ -141,7 +141,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener editView.setHint(R.string.group_name) editView.setText(bookGroup.groupName) } - customView = alertBinding.root + customView { alertBinding.root } yesButton { alertBinding.editView.text?.toString()?.let { viewModel.upGroup(bookGroup.copy(groupName = it)) 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 6018f4531..f5e4c9ff8 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 @@ -38,8 +38,6 @@ import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.toc.ChapterListActivity import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.utils.* -import org.jetbrains.anko.startActivity -import org.jetbrains.anko.startActivityForResult class BookInfoActivity : @@ -86,9 +84,10 @@ class BookInfoActivity : if (viewModel.inBookshelf) { viewModel.bookData.value?.let { startActivityForResult( - requestCodeInfoEdit, - Pair("bookUrl", it.bookUrl) - ) + requestCodeInfoEdit + ) { + putExtra("bookUrl", it.bookUrl) + } } } else { toastOnUi(R.string.after_add_bookshelf) @@ -227,7 +226,9 @@ class BookInfoActivity : } tvOrigin.setOnClickListener { viewModel.bookData.value?.let { - startActivity(Pair("data", it.origin)) + startActivity { + putExtra("data", it.origin) + } } } tvChangeSource.setOnClickListener { @@ -252,10 +253,14 @@ class BookInfoActivity : } } tvAuthor.setOnClickListener { - startActivity(Pair("key", viewModel.bookData.value?.author)) + startActivity { + putExtra("key", viewModel.bookData.value?.author) + } } tvName.setOnClickListener { - startActivity(Pair("key", viewModel.bookData.value?.name)) + startActivity { + putExtra("key", viewModel.bookData.value?.name) + } } } @@ -274,7 +279,7 @@ class BookInfoActivity : setPadding(16.dp, 0, 16.dp, 0) addView(checkBox) } - customView = view + customView { view } positiveButton(R.string.yes) { viewModel.delBook(checkBox.isChecked) { finish() @@ -297,9 +302,10 @@ class BookInfoActivity : } viewModel.bookData.value?.let { startActivityForResult( - requestCodeChapterList, - Pair("bookUrl", it.bookUrl) - ) + requestCodeChapterList + ) { + putExtra("bookUrl", it.bookUrl) + } } } @@ -320,16 +326,18 @@ class BookInfoActivity : private fun startReadActivity(book: Book) { when (book.type) { BookType.audio -> startActivityForResult( - requestCodeRead, - Pair("bookUrl", book.bookUrl), - Pair("inBookshelf", viewModel.inBookshelf) - ) + requestCodeRead + ) { + putExtra("bookUrl", book.bookUrl) + putExtra("inBookshelf", viewModel.inBookshelf) + } else -> startActivityForResult( - requestCodeRead, - Pair("bookUrl", book.bookUrl), - Pair("inBookshelf", viewModel.inBookshelf), - Pair("key", IntentDataHelp.putData(book)) - ) + requestCodeRead + ) { + putExtra("bookUrl", book.bookUrl) + putExtra("inBookshelf", viewModel.inBookshelf) + putExtra("key", IntentDataHelp.putData(book)) + } } } 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 c514bdd14..4def37e81 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 @@ -53,8 +53,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import org.jetbrains.anko.startActivity -import org.jetbrains.anko.startActivityForResult class ReadBookActivity : ReadBookBaseActivity(), View.OnTouchListener, @@ -234,7 +232,10 @@ class ReadBookActivity : ReadBookBaseActivity(), binding.readView.upPageAnim() } R.id.menu_book_info -> ReadBook.book?.let { - startActivity(Pair("name", it.name), Pair("author", it.author)) + startActivity { + putExtra("name", it.name) + putExtra("author", it.author) + } } R.id.menu_toc_regex -> TocRegexDialog.show( supportFragmentManager, @@ -657,9 +658,10 @@ class ReadBookActivity : ReadBookBaseActivity(), override fun openSourceEditActivity() { ReadBook.webBook?.let { startActivityForResult( - requestCodeEditSource, - Pair("data", it.bookSource.bookSourceUrl) - ) + requestCodeEditSource + ) { + putExtra("data", it.bookSource.bookSourceUrl) + } } } @@ -676,9 +678,10 @@ class ReadBookActivity : ReadBookBaseActivity(), override fun openChapterList() { ReadBook.book?.let { startActivityForResult( - requestCodeChapterList, - Pair("bookUrl", it.bookUrl) - ) + requestCodeChapterList + ) { + putExtra("bookUrl", it.bookUrl) + } } } @@ -688,10 +691,11 @@ class ReadBookActivity : ReadBookBaseActivity(), override fun openSearchActivity(searchWord: String?) { ReadBook.book?.let { startActivityForResult( - requestCodeSearchResult, - Pair("bookUrl", it.bookUrl), - Pair("searchWord", searchWord ?: viewModel.searchContentQuery) - ) + requestCodeSearchResult + ) { + putExtra("bookUrl", it.bookUrl) + putExtra("searchWord", searchWord ?: viewModel.searchContentQuery) + } } } @@ -719,10 +723,10 @@ class ReadBookActivity : ReadBookBaseActivity(), override fun showLogin() { ReadBook.webBook?.bookSource?.let { - startActivity( - Pair("sourceUrl", it.bookSourceUrl), - Pair("loginUrl", it.loginUrl) - ) + startActivity { + putExtra("sourceUrl", it.bookSourceUrl) + putExtra("loginUrl", it.loginUrl) + } } } @@ -774,7 +778,7 @@ class ReadBookActivity : ReadBookBaseActivity(), private fun sureSyncProgress(progress: BookProgress) { alert(R.string.get_book_progress) { - message = getString(R.string.current_progress_exceeds_cloud) + setMessage(R.string.current_progress_exceeds_cloud) okButton { ReadBook.setProgress(progress) } @@ -845,7 +849,7 @@ class ReadBookActivity : ReadBookBaseActivity(), ReadBook.book?.let { if (!ReadBook.inBookshelf) { alert(title = getString(R.string.add_to_shelf)) { - message = getString(R.string.check_add_bookshelf, it.name) + setMessage(getString(R.string.check_add_bookshelf, it.name)) okButton { ReadBook.inBookshelf = true setResult(Activity.RESULT_OK) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt index b61a8972f..c97146db2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt @@ -187,7 +187,7 @@ abstract class ReadBookBaseActivity : editStart.setText((book.durChapterIndex + 1).toString()) editEnd.setText(book.totalChapterNum.toString()) } - customView = alertBinding.root + customView { alertBinding.root } yesButton { alertBinding.run { val start = editStart.text?.toString()?.toInt() ?: 0 @@ -203,12 +203,12 @@ abstract class ReadBookBaseActivity : @SuppressLint("InflateParams") fun showBookMark(bookmark: Bookmark) { alert(title = getString(R.string.bookmark_add)) { - message = bookmark.chapterName + setMessage(bookmark.chapterName) val alertBinding = DialogBookmarkBinding.inflate(layoutInflater).apply { editBookText.setText(bookmark.bookText) editView.setText(bookmark.content) } - customView = alertBinding.root + customView { alertBinding.root } yesButton { alertBinding.apply { Coroutine.async { @@ -231,7 +231,7 @@ abstract class ReadBookBaseActivity : editView.setFilterValues(charsets) editView.setText(ReadBook.book?.charset) } - customView = alertBinding.root + customView { alertBinding.root } okButton { alertBinding.editView.text?.toString()?.let { ReadBook.setCharset(it) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 85bedf3e1..8d7f37a33 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -21,6 +21,7 @@ import io.legado.app.lib.theme.* import io.legado.app.service.help.ReadBook import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* +import splitties.views.onLongClick /** * 阅读界面菜单 @@ -210,9 +211,8 @@ class ReadMenu @JvmOverloads constructor( callBack.onClickReadAloud() } } - llReadAloud.setOnLongClickListener { + llReadAloud.onLongClick { runMenuOut { callBack.showReadAloudDialog() } - true } //界面 llFont.setOnClickListener { diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index 416b69132..29373ae37 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -25,7 +25,6 @@ import io.legado.app.databinding.ItemTextBinding import io.legado.app.databinding.PopupActionMenuBinding import io.legado.app.service.BaseReadAloudService import io.legado.app.utils.* -import org.jetbrains.anko.share import java.util.* @SuppressLint("RestrictedApi") diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index ca489c093..771ae2873 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -123,7 +123,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { editView.setText(ReadBookConfig.durConfig.name) } - customView = alertBinding.root + customView { alertBinding.root } okButton { alertBinding.editView.text?.toString()?.let { binding.tvName.text = it @@ -278,7 +278,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { private fun importNetConfigAlert() { alert("输入地址") { val alertBinding = DialogEditTextBinding.inflate(layoutInflater) - customView = alertBinding.root + customView { alertBinding.root } okButton { alertBinding.editView.text?.toString()?.let { url -> importNetConfig(url) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 18f244259..d92394e14 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -24,6 +24,7 @@ import io.legado.app.utils.dp import io.legado.app.utils.getIndexById import io.legado.app.utils.postEvent import io.legado.app.utils.viewbindingdelegate.viewBinding +import splitties.views.onLongClick class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { private val binding by viewBinding(DialogReadBookStyleBinding::bind) @@ -237,11 +238,9 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { changeBg(holder.layoutPosition) } } - ivStyle.setOnLongClickListener { + ivStyle.onLongClick(ivStyle.isInView) { if (ivStyle.isInView) { showBgTextConfig(holder.layoutPosition) - } else { - false } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index bb40914d2..83524fd5e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -110,7 +110,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener val alertBinding = DialogHttpTtsEditBinding.inflate(layoutInflater) alertBinding.tvName.setText(httpTTS.name) alertBinding.tvUrl.setText(httpTTS.url) - customView = alertBinding.root + customView { alertBinding.root } cancelButton() okButton { alertBinding.apply { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index ed531176f..62acc0753 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -147,7 +147,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { aCache.put(importTocRuleKey, cacheUrls.joinToString(",")) } } - customView = alertBinding.root + customView { alertBinding.root } okButton { val text = alertBinding.editView.text?.toString() text?.let { @@ -175,7 +175,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { tvRuleName.setText(tocRule.name) tvRuleRegex.setText(tocRule.rule) } - customView = alertBinding.root + customView { alertBinding.root } okButton { alertBinding.apply { tocRule.name = tvRuleName.text.toString() diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index 223081a8b..b8f76f38c 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -10,6 +10,7 @@ import io.legado.app.ui.widget.anima.explosion_field.ExplosionField import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import splitties.views.onLongClick class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : RecyclerAdapter(activity) { @@ -38,16 +39,13 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : callBack.searchHistory(it.word) } } - setOnLongClickListener { - it?.let { - explosionField.explode(it, true) - } + onLongClick { + explosionField.explode(this, true) getItem(holder.layoutPosition)?.let { GlobalScope.launch(IO) { App.db.searchKeywordDao.delete(it) } } - true } } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 033f3a4d1..57b95fb45 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -30,8 +30,6 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.startActivity - class SearchActivity : VMBaseActivity(), BookAdapter.CallBack, HistoryKeyAdapter.CallBack, @@ -333,10 +331,10 @@ class SearchActivity : VMBaseActivity searchBook?.let { - startActivity( - Pair("name", it.name), - Pair("author", it.author) - ) + startActivity { + putExtra("name", it.name) + putExtra("author", it.author) + } } } } @@ -345,10 +343,10 @@ class SearchActivity : VMBaseActivity( - Pair("name", book.name), - Pair("author", book.author) - ) + startActivity { + putExtra("name", book.name) + putExtra("author", book.author) + } } /** diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index d98786edc..fb11c3cfd 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -14,10 +14,10 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.widget.dialog.TextDialog +import io.legado.app.utils.startActivityForResult import io.legado.app.utils.toastOnUi import kotlinx.coroutines.launch -import org.jetbrains.anko.startActivityForResult class BookSourceDebugActivity : VMBaseActivity() { diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 88db0b9f9..b8d5ca594 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -21,6 +21,7 @@ import io.legado.app.data.entities.rule.* import io.legado.app.databinding.ActivityBookSourceEditBinding import io.legado.app.help.LocalConfig import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.book.source.debug.BookSourceDebugActivity @@ -31,7 +32,6 @@ import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* -import org.jetbrains.anko.* import kotlin.math.abs class BookSourceEditActivity : @@ -90,7 +90,9 @@ class BookSourceEditActivity : R.id.menu_debug_source -> getSource().let { source -> if (checkSource(source)) { viewModel.save(source) { - startActivity(Pair("key", source.bookSourceUrl)) + startActivity { + putExtra("key", source.bookSourceUrl) + } } } } @@ -108,10 +110,10 @@ class BookSourceEditActivity : if (it.loginUrl.isNullOrEmpty()) { toastOnUi(R.string.source_no_login) } else { - startActivity( - Pair("sourceUrl", it.bookSourceUrl), - Pair("loginUrl", it.loginUrl) - ) + startActivity { + putExtra("sourceUrl", it.bookSourceUrl) + putExtra("loginUrl", it.loginUrl) + } } } } @@ -145,7 +147,7 @@ class BookSourceEditActivity : val source = getSource() if (!source.equal(viewModel.bookSource ?: BookSource())) { alert(R.string.exit) { - messageResource = R.string.exit_no_save + setMessage(R.string.exit_no_save) positiveButton(R.string.yes) negativeButton(R.string.no) { super.finish() @@ -449,7 +451,7 @@ class BookSourceEditActivity : val rect = Rect() // 获取当前页面窗口的显示范围 window.decorView.getWindowVisibleDisplayFrame(rect) - val screenHeight = this@BookSourceEditActivity.displayMetrics.heightPixels + val screenHeight = this@BookSourceEditActivity.getSize().heightPixels val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 val preShowing = mIsSoftKeyBoardShowing if (abs(keyboardHeight) > screenHeight / 5) { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 35b7ab175..ebdd3b9ce 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -39,8 +39,6 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* -import org.jetbrains.anko.startActivity -import org.jetbrains.anko.startActivityForResult import java.io.File class BookSourceActivity : VMBaseActivity(), @@ -304,7 +302,7 @@ class BookSourceActivity : VMBaseActivity(Pair("source", it)) + startActivity { + putExtra("source", it) + } } } cancelButton() @@ -443,7 +443,9 @@ class BookSourceActivity : VMBaseActivity(Pair("data", bookSource.bookSourceUrl)) + startActivity { + putExtra("data", bookSource.bookSourceUrl) + } } override fun upOrder() { @@ -463,7 +465,9 @@ class BookSourceActivity : VMBaseActivity if (resultCode == RESULT_OK) { data?.getStringExtra("result")?.let { - startActivity("source" to it) + startActivity { + putExtra("source", it) + } } } importRequestCode -> if (resultCode == Activity.RESULT_OK) { @@ -471,7 +475,9 @@ class BookSourceActivity : VMBaseActivity("dataKey" to dataKey) + startActivity { + putExtra("dataKey", dataKey) + } } } catch (e: Exception) { toastOnUi("readTextError:${e.localizedMessage}") diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index e8bf52ec8..fdbd6f16a 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -11,7 +11,6 @@ import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppPattern import io.legado.app.data.entities.BookSource import io.legado.app.utils.* -import org.jetbrains.anko.longToast import java.io.File class BookSourceViewModel(application: Application) : BaseViewModel(application) { @@ -144,9 +143,9 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) FileUtils.createFileIfNotExist(file, "exportBookSource.json") .writeText(json) }.onSuccess { - context.longToast("成功导出至\n${file.absolutePath}") + context.longToastOnUi("成功导出至\n${file.absolutePath}") }.onError { - context.longToast("导出失败\n${it.localizedMessage}") + context.longToastOnUi("导出失败\n${it.localizedMessage}") } } @@ -157,9 +156,9 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) doc.createFile("", "exportBookSource.json") ?.writeText(context, json) }.onSuccess { - context.longToast("成功导出至\n${doc.uri.path}") + context.longToastOnUi("成功导出至\n${doc.uri.path}") }.onError { - context.longToast("导出失败\n${it.localizedMessage}") + context.longToastOnUi("导出失败\n${it.localizedMessage}") } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 4958d8a3d..56e344fe4 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -86,7 +86,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { alert(title = getString(R.string.add_group)) { val alertBinding = DialogEditTextBinding.inflate(layoutInflater) alertBinding.editView.setHint(R.string.group_name) - customView = alertBinding.root + customView { alertBinding.root } yesButton { alertBinding.editView.text?.toString()?.let { if (it.isNotBlank()) { @@ -103,7 +103,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { alert(title = getString(R.string.group_edit)) { val alertBinding = DialogEditTextBinding.inflate(layoutInflater) alertBinding.editView.setHint(R.string.group_name) - customView = alertBinding.root + customView { alertBinding.root } yesButton { viewModel.upGroup(group, alertBinding.editView.text?.toString()) } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt index f6fc46bf8..8300aa3da 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt @@ -7,6 +7,7 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import io.legado.app.data.entities.Bookmark import io.legado.app.databinding.ItemBookmarkBinding +import splitties.views.onLongClick class BookmarkAdapter(val callback: Callback) : PagedListAdapter(DIFF_CALLBACK) { @@ -46,9 +47,8 @@ class BookmarkAdapter(val callback: Callback) : PagedListAdapter(R.layout.fragment_ @SuppressLint("InflateParams") override fun onLongClick(bookmark: Bookmark) { requireContext().alert(R.string.bookmark) { - message = bookmark.chapterName + setMessage(bookmark.chapterName) val alertBinding = DialogBookmarkBinding.inflate(layoutInflater).apply { editBookText.setText(bookmark.bookText) editView.setText(bookmark.content) } - customView = alertBinding.root + customView { alertBinding.root } yesButton { alertBinding.apply { Coroutine.async { diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 3c226c8c6..1e1179ab9 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -156,7 +156,7 @@ class OtherConfigFragment : BasePreferenceFragment(), alert("UserAgent") { val alertBinding = DialogEditTextBinding.inflate(layoutInflater) alertBinding.editView.setText(AppConfig.userAgent) - customView = alertBinding.root + customView { alertBinding.root } okButton { val userAgent = alertBinding.editView.text?.toString() if (userAgent.isNullOrBlank()) { diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 4450905e5..3ecbd9eaa 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -225,7 +225,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), private fun saveThemeAlert(key: String) { alert(R.string.theme_name) { val alertBinding = DialogEditTextBinding.inflate(layoutInflater) - customView = alertBinding.root + customView { alertBinding.root } okButton { alertBinding.editView.text?.toString()?.let { themeName -> when (key) { diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index 3aadc8b25..358b16613 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -20,8 +20,6 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.share - class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private val binding by viewBinding(DialogRecyclerViewBinding::bind) private lateinit var adapter: Adapter diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index ab47477dc..3187f0daa 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -35,7 +35,6 @@ import io.legado.app.ui.main.MainViewModel import io.legado.app.ui.main.bookshelf.books.BooksFragment import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.share /** * 书架界面 @@ -81,14 +80,14 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b .show(childFragmentManager, "groupManageDialog") R.id.menu_add_local -> startActivity() R.id.menu_add_url -> addBookByUrl() - R.id.menu_arrange_bookshelf -> startActivity( - Pair("groupId", selectedGroup.groupId), - Pair("groupName", selectedGroup.groupName) - ) - R.id.menu_download -> startActivity( - Pair("groupId", selectedGroup.groupId), - Pair("groupName", selectedGroup.groupName) - ) + R.id.menu_arrange_bookshelf -> startActivity { + putExtra("groupId", selectedGroup.groupId) + putExtra("groupName", selectedGroup.groupName) + } + R.id.menu_download -> startActivity { + putExtra("groupId", selectedGroup.groupId) + putExtra("groupName", selectedGroup.groupName) + } R.id.menu_export_bookshelf -> { val fragment = fragmentMap[selectedGroup.groupId] viewModel.exportBookshelf(fragment?.getBooks()) { @@ -124,7 +123,9 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b } override fun onQueryTextSubmit(query: String?): Boolean { - startActivity(Pair("key", query)) + startActivity { + putExtra("key", query) + } return false } @@ -164,7 +165,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b rgLayout.checkByIndex(bookshelfLayout) rgSort.checkByIndex(bookshelfSort) } - customView = alertBinding.root + customView { alertBinding.root } okButton { alertBinding.apply { var changed = false @@ -189,7 +190,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b private fun addBookByUrl() { alert(titleResource = R.string.add_book_url) { val alertBinding = DialogEditTextBinding.inflate(layoutInflater) - customView = alertBinding.root + customView { alertBinding.root } okButton { alertBinding.editView.text?.toString()?.let { viewModel.addBookByUrl(it) @@ -220,7 +221,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { editView.hint = "url/json" } - customView = alertBinding.root + customView { alertBinding.root } okButton { alertBinding.editView.text?.toString()?.let { viewModel.importBookshelf(it, selectedGroup.groupId) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt index 41e72a1d3..f8897ca9e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt @@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book import io.legado.app.databinding.ItemBookshelfGridBinding import io.legado.app.lib.theme.ATH import io.legado.app.utils.invisible +import splitties.views.onLongClick class BooksAdapterGrid(context: Context, private val callBack: CallBack) : BaseBooksAdapter(context) { @@ -59,11 +60,10 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) : } } - setOnLongClickListener { + onLongClick { getItem(holder.layoutPosition)?.let { callBack.openBookInfo(it) } - true } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt index b70b6c3e3..343ba19fd 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt @@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book import io.legado.app.databinding.ItemBookshelfListBinding import io.legado.app.lib.theme.ATH import io.legado.app.utils.invisible +import splitties.views.onLongClick class BooksAdapterList(context: Context, private val callBack: CallBack) : BaseBooksAdapter(context) { @@ -65,11 +66,10 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : } } - setOnLongClickListener { + onLongClick { getItem(holder.layoutPosition)?.let { callBack.openBookInfo(it) } - true } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 09fd306a4..7fffc6ff9 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -144,19 +144,21 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), override fun open(book: Book) { when (book.type) { BookType.audio -> - startActivity(Pair("bookUrl", book.bookUrl)) - else -> startActivity( - Pair("bookUrl", book.bookUrl), - Pair("key", IntentDataHelp.putData(book)) - ) + startActivity { + putExtra("bookUrl", book.bookUrl) + } + else -> startActivity { + putExtra("bookUrl", book.bookUrl) + putExtra("key", IntentDataHelp.putData(book)) + } } } override fun openBookInfo(book: Book) { - startActivity( - Pair("name", book.name), - Pair("author", book.author) - ) + startActivity { + putExtra("name", book.name) + putExtra("author", book.author) + } } override fun isUpdate(bookUrl: String): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index d5058a288..4a57df08d 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -19,6 +19,7 @@ import io.legado.app.utils.dp import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.coroutines.CoroutineScope +import splitties.views.onLongClick class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : RecyclerAdapter(context) { @@ -104,9 +105,8 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca notifyItemChanged(position, false) } } - llTitle.setOnLongClickListener { + llTitle.onLongClick { showMenu(llTitle, holder.layoutPosition) - true } } } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 56cf3a4d9..6ff32cdb3 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -151,15 +151,17 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo } override fun openExplore(sourceUrl: String, title: String, exploreUrl: String) { - startActivity( - Pair("exploreName", title), - Pair("sourceUrl", sourceUrl), - Pair("exploreUrl", exploreUrl) - ) + startActivity { + putExtra("exploreName", title) + putExtra("sourceUrl", sourceUrl) + putExtra("exploreUrl", exploreUrl) + } } override fun editSource(sourceUrl: String) { - startActivity(Pair("data", sourceUrl)) + startActivity { + putExtra("data", sourceUrl) + } } override fun toTop(source: BookSource) { diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index ce6065e27..42c4416e1 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -135,15 +135,15 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FilePickerDialog.C when (preference?.key) { "bookSourceManage" -> startActivity() "replaceManage" -> startActivity() - "setting" -> startActivity( - Pair("configType", ConfigViewModel.TYPE_CONFIG) - ) - "web_dav_setting" -> startActivity( - Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG) - ) - "theme_setting" -> startActivity( - Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG) - ) + "setting" -> startActivity { + putExtra("configType", ConfigViewModel.TYPE_CONFIG) + } + "web_dav_setting" -> startActivity { + putExtra("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG) + } + "theme_setting" -> startActivity { + putExtra("configType", ConfigViewModel.TYPE_THEME_CONFIG) + } "readRecord" -> startActivity() "donate" -> startActivity() "about" -> startActivity() diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt index dbe75836d..1af9bdb9b 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -10,6 +10,7 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.entities.RssSource import io.legado.app.databinding.ItemRssBinding import io.legado.app.help.ImageLoader +import splitties.views.onLongClick class RssAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context) { @@ -41,11 +42,10 @@ class RssAdapter(context: Context, val callBack: CallBack) : callBack.openRss(it) } } - root.setOnLongClickListener { + root.onLongClick { getItemByLayoutPosition(holder.layoutPosition)?.let { showMenu(ivIcon, it) } - true } } } diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 8e185fd57..3829a545c 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -144,12 +144,14 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), override fun openRss(rssSource: RssSource) { if (rssSource.singleUrl) { - startActivity( - Pair("title", rssSource.sourceName), - Pair("origin", rssSource.sourceUrl) - ) + startActivity { + putExtra("title", rssSource.sourceName) + putExtra("origin", rssSource.sourceUrl) + } } else { - startActivity(Pair("url", rssSource.sourceUrl)) + startActivity { + putExtra("url", rssSource.sourceUrl) + } } } @@ -158,7 +160,9 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), } override fun edit(rssSource: RssSource) { - startActivity(Pair("data", rssSource.sourceUrl)) + startActivity { + putExtra("data", rssSource.sourceUrl) + } } override fun del(rssSource: RssSource) { diff --git a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt index a589a84db..80bcbf47f 100644 --- a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt @@ -101,11 +101,11 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { @SuppressLint("InflateParams") private fun editGroup(group: String) { alert(title = getString(R.string.group_edit)) { - val alertBinding = DialogEditTextBinding.inflate(layoutInflater) - customView = alertBinding.apply { + val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { editView.hint = "分组名称" editView.setText(group) - }.root + } + customView { alertBinding.root } yesButton { viewModel.upGroup(group, alertBinding.editView.text?.toString()) } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index f7b32f174..c9a334d6b 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -38,8 +38,6 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* -import org.jetbrains.anko.startActivity -import org.jetbrains.anko.startActivityForResult import java.io.File /** @@ -229,7 +227,7 @@ class ReplaceRuleActivity : VMBaseActivity("source" to it) + startActivity { + putExtra("source", it) + } } } cancelButton() @@ -266,7 +266,9 @@ class ReplaceRuleActivity : VMBaseActivity("dataKey" to dataKey) + startActivity { + putExtra("dataKey", dataKey) + } } }.onFailure { toastOnUi("readTextError:${it.localizedMessage}") @@ -275,7 +277,9 @@ class ReplaceRuleActivity : VMBaseActivity if (resultCode == Activity.RESULT_OK) { data?.getStringExtra("result")?.let { - startActivity("source" to it) + startActivity { + putExtra("source", it) + } } } exportRequestCode -> if (resultCode == RESULT_OK) { diff --git a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt index ca92187f7..e4349c296 100644 --- a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt @@ -17,13 +17,13 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.data.entities.ReplaceRule import io.legado.app.databinding.ActivityReplaceEditBinding +import io.legado.app.lib.dialogs.selector import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.dialog.TextDialog +import io.legado.app.utils.getSize import io.legado.app.utils.postEvent import io.legado.app.utils.toastOnUi -import org.jetbrains.anko.displayMetrics -import org.jetbrains.anko.selector import kotlin.math.abs /** @@ -171,7 +171,7 @@ class ReplaceEditActivity : val rect = Rect() // 获取当前页面窗口的显示范围 window.decorView.getWindowVisibleDisplayFrame(rect) - val screenHeight = this.displayMetrics.heightPixels + val screenHeight = this.getSize().heightPixels val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 val preShowing = mIsSoftKeyBoardShowing if (abs(keyboardHeight) > screenHeight / 5) { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt index b50873ebc..ec53cdb47 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt @@ -125,10 +125,10 @@ class RssArticlesFragment : VMBaseFragment(R.layout.fragme override fun readRss(rssArticle: RssArticle) { activityViewModel.read(rssArticle) - startActivity( - Pair("title", rssArticle.title), - Pair("origin", rssArticle.origin), - Pair("link", rssArticle.link) - ) + startActivity { + putExtra("title", rssArticle.title) + putExtra("origin", rssArticle.origin) + putExtra("link", rssArticle.link) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt index 2dcc2d5b8..46d3480d7 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt @@ -13,10 +13,9 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.databinding.ActivityRssArtivlesBinding import io.legado.app.ui.rss.source.edit.RssSourceEditActivity - import io.legado.app.utils.gone +import io.legado.app.utils.startActivityForResult import io.legado.app.utils.visible -import org.jetbrains.anko.startActivityForResult class RssSortActivity : VMBaseActivity() { @@ -50,7 +49,9 @@ class RssSortActivity : VMBaseActivity viewModel.rssSource?.sourceUrl?.let { - startActivityForResult(editSource, Pair("data", it)) + startActivityForResult(editSource) { + putExtra("data", it) + } } R.id.menu_clear -> { viewModel.url?.let { diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt index 99d9f47a1..9871c2eae 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt @@ -9,7 +9,7 @@ import io.legado.app.data.entities.RssStar import io.legado.app.databinding.ActivityRssFavoritesBinding import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.widget.recycler.VerticalDivider -import org.jetbrains.anko.startActivity +import io.legado.app.utils.startActivity class RssFavoritesActivity : BaseActivity(), @@ -45,10 +45,10 @@ class RssFavoritesActivity : BaseActivity(), } override fun readRss(rssStar: RssStar) { - startActivity( - Pair("title", rssStar.title), - Pair("origin", rssStar.origin), - Pair("link", rssStar.link) - ) + startActivity { + putExtra("title", rssStar.title) + putExtra("origin", rssStar.origin) + putExtra("link", rssStar.link) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index ae843eaeb..b72b3b1a8 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -26,8 +26,8 @@ import io.legado.app.ui.filepicker.FilePickerDialog import io.legado.app.utils.* import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils -import org.jetbrains.anko.share import org.jsoup.Jsoup +import splitties.systemservices.downloadManager class ReadRssActivity : VMBaseActivity(false), diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 98f128fba..39a288da2 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -18,13 +18,13 @@ import io.legado.app.data.entities.RssSource import io.legado.app.databinding.ActivityRssSourceEditBinding import io.legado.app.help.LocalConfig import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* -import org.jetbrains.anko.* import kotlin.math.abs class RssSourceEditActivity : @@ -63,7 +63,7 @@ class RssSourceEditActivity : val source = getRssSource() if (!source.equal(viewModel.rssSource)) { alert(R.string.exit) { - messageResource = R.string.exit_no_save + setMessage(R.string.exit_no_save) positiveButton(R.string.yes) negativeButton(R.string.no) { super.finish() @@ -100,7 +100,9 @@ class RssSourceEditActivity : val source = getRssSource() if (checkSource(source)) { viewModel.save(source) { - startActivity(Pair("key", source.sourceUrl)) + startActivity { + putExtra("key", source.sourceUrl) + } } } } @@ -249,7 +251,7 @@ class RssSourceEditActivity : val rect = Rect() // 获取当前页面窗口的显示范围 window.decorView.getWindowVisibleDisplayFrame(rect) - val screenHeight = this@RssSourceEditActivity.displayMetrics.heightPixels + val screenHeight = this@RssSourceEditActivity.getSize().heightPixels val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 val preShowing = mIsSoftKeyBoardShowing if (abs(keyboardHeight) > screenHeight / 5) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 1e4a0ea44..5faac92a5 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -35,8 +35,6 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* -import org.jetbrains.anko.startActivity -import org.jetbrains.anko.startActivityForResult import java.io.File @@ -245,7 +243,7 @@ class RssSourceActivity : VMBaseActivity("source" to it) + startActivity { + putExtra("source", it) + } } } cancelButton() @@ -268,7 +268,9 @@ class RssSourceActivity : VMBaseActivity("dataKey" to dataKey) + startActivity { + putExtra("dataKey", dataKey) + } } }.onFailure { toastOnUi("readTextError:${it.localizedMessage}") @@ -277,7 +279,9 @@ class RssSourceActivity : VMBaseActivity if (resultCode == RESULT_OK) { data?.getStringExtra("result")?.let { - startActivity("source" to it) + startActivity { + putExtra("source", it) + } } } exportRequestCode -> if (resultCode == RESULT_OK) { @@ -301,7 +305,9 @@ class RssSourceActivity : VMBaseActivity(Pair("data", source.sourceUrl)) + startActivity { + putExtra("data", source.sourceUrl) + } } override fun update(vararg source: RssSource) { diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt index 67d9cabc2..997579f65 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt @@ -17,9 +17,9 @@ import io.legado.app.ui.association.ImportBookSourceActivity import io.legado.app.ui.association.ImportReplaceRuleActivity import io.legado.app.ui.association.ImportRssSourceActivity import io.legado.app.ui.widget.recycler.ItemTouchCallback +import io.legado.app.utils.startActivity import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch -import org.jetbrains.anko.startActivity /** * 规则订阅界面 @@ -74,13 +74,19 @@ class RuleSubActivity : BaseActivity(), override fun openSubscription(ruleSub: RuleSub) { when (ruleSub.type) { 0 -> { - startActivity("source" to ruleSub.url) + startActivity { + putExtra("source", ruleSub.url) + } } 1 -> { - startActivity("source" to ruleSub.url) + startActivity { + putExtra("source", ruleSub.url) + } } 2 -> { - startActivity("source" to ruleSub.url) + startActivity { + putExtra("source", ruleSub.url) + } } } } @@ -92,7 +98,7 @@ class RuleSubActivity : BaseActivity(), etName.setText(ruleSub.name) etUrl.setText(ruleSub.url) } - customView = alertBinding.root + customView { alertBinding.root } okButton { ruleSub.type = alertBinding.spType.selectedItemPosition ruleSub.name = alertBinding.etName.text?.toString() ?: "" diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index 49fd459fd..eb01ad30e 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -14,7 +14,7 @@ import io.legado.app.lib.theme.accentColor import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainActivity import io.legado.app.utils.getPrefBoolean -import org.jetbrains.anko.startActivity +import io.legado.app.utils.startActivity import java.util.concurrent.TimeUnit open class WelcomeActivity : BaseActivity() { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt index 3de75300c..baea502b3 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt @@ -17,6 +17,7 @@ import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.utils.ColorUtils +import splitties.views.onLongClick import kotlin.math.roundToInt class Preference(context: Context, attrs: AttributeSet) : @@ -115,9 +116,8 @@ class Preference(context: Context, attrs: AttributeSet) : isBottomBackground = isBottomBackground ) super.onBindViewHolder(holder) - holder?.itemView?.setOnLongClickListener { + holder?.itemView?.onLongClick { onLongClick?.invoke() - true } } diff --git a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt index df4bae769..37a46f74c 100644 --- a/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ActivityExtensions.kt @@ -1,12 +1,20 @@ package io.legado.app.utils import android.app.Activity +import android.content.Intent import android.os.Build import android.util.DisplayMetrics import android.view.WindowInsets import android.view.WindowMetrics +inline fun Activity.startActivityForResult( + requestCode: Int, + configIntent: Intent.() -> Unit = {} +) { + startActivityForResult(Intent(this, A::class.java).apply(configIntent), requestCode) +} + fun Activity.getSize(): DisplayMetrics { val displayMetrics = DisplayMetrics() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 6b31409ac..911e695c8 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -3,14 +3,14 @@ package io.legado.app.utils import android.annotation.SuppressLint -import android.app.DownloadManager +import android.app.Activity +import android.app.Service import android.content.* import android.content.pm.PackageManager import android.content.res.ColorStateList import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.drawable.Drawable -import android.net.ConnectivityManager import android.net.Uri import android.os.BatteryManager import android.provider.Settings @@ -24,16 +24,16 @@ import androidx.core.content.edit import androidx.preference.PreferenceManager import io.legado.app.BuildConfig import io.legado.app.R -import org.jetbrains.anko.longToast -import org.jetbrains.anko.runOnUiThread import java.io.File import java.io.FileOutputStream -val Context.downloadManager - get() = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager +inline fun Context.startActivity(configIntent: Intent.() -> Unit = {}) { + startActivity(Intent(this, A::class.java).apply(configIntent)) +} -val Context.connectivityManager - get() = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager +inline fun Context.startService(configIntent: Intent.() -> Unit = {}) { + startService(Intent(this, T::class.java).apply(configIntent)) +} fun Context.toastOnUi(message: Int) { runOnUiThread { @@ -135,6 +135,21 @@ val Context.navigationBarHeight: Int return resources.getDimensionPixelSize(resourceId) } +fun Context.share(text: String) { + share(getString(R.string.share), text) +} + +fun Context.share(title: String, text: String) { + kotlin.runCatching { + val intent = Intent(Intent.ACTION_SEND) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + intent.putExtra(Intent.EXTRA_SUBJECT, title) + intent.putExtra(Intent.EXTRA_TEXT, text) + intent.type = "text/plain" + startActivity(Intent.createChooser(intent, title)) + } +} + @SuppressLint("SetWorldReadable") fun Context.shareWithQr(title: String, text: String) { val bitmap = QRCodeUtils.createQRCode(text) @@ -170,7 +185,7 @@ fun Context.sendToClip(text: String) { val clipData = ClipData.newPlainText(null, text) clipboard?.let { clipboard.setPrimaryClip(clipData) - longToast(R.string.copy_complete) + longToastOnUi(R.string.copy_complete) } } diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index c74ba5a0d..5a086cf29 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -3,7 +3,6 @@ package io.legado.app.utils import android.app.Activity -import android.app.Service import android.content.Intent import android.content.res.ColorStateList import android.graphics.drawable.Drawable @@ -11,12 +10,10 @@ import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.edit import androidx.fragment.app.Fragment -import org.jetbrains.anko.defaultSharedPreferences -import org.jetbrains.anko.internals.AnkoInternals +import splitties.systemservices.connectivityManager @Suppress("DEPRECATION") -fun Fragment.isOnline() = - requireContext().connectivityManager.activeNetworkInfo?.isConnected == true +fun Fragment.isOnline() = connectivityManager.activeNetworkInfo?.isConnected == true fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = requireContext().defaultSharedPreferences.getBoolean(key, defValue) @@ -62,22 +59,15 @@ fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id) -inline fun Fragment.startActivity(vararg params: Pair) = - AnkoInternals.internalStartActivity(requireActivity(), T::class.java, params) +inline fun Fragment.startActivity( + configIntent: Intent.() -> Unit = {} +) { + startActivity(Intent(requireContext(), T::class.java).apply(configIntent)) +} inline fun Fragment.startActivityForResult( requestCode: Int, - vararg params: Pair -) = startActivityForResult( - AnkoInternals.createIntent(requireActivity(), T::class.java, params), - requestCode -) - -inline fun Fragment.startService(vararg params: Pair) = - AnkoInternals.internalStartService(requireActivity(), T::class.java, params) - -inline fun Fragment.stopService(vararg params: Pair) = - AnkoInternals.internalStopService(requireActivity(), T::class.java, params) - -inline fun Fragment.intentFor(vararg params: Pair): Intent = - AnkoInternals.createIntent(requireActivity(), T::class.java, params) \ No newline at end of file + configIntent: Intent.() -> Unit = {} +) { + startActivityForResult(Intent(requireContext(), T::class.java).apply(configIntent), requestCode) +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/GsonExtensions.kt b/app/src/main/java/io/legado/app/utils/GsonExtensions.kt index b29b4e2b4..db32ca60a 100644 --- a/app/src/main/java/io/legado/app/utils/GsonExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/GsonExtensions.kt @@ -3,7 +3,6 @@ package io.legado.app.utils import com.google.gson.* import com.google.gson.internal.LinkedTreeMap import com.google.gson.reflect.TypeToken -import org.jetbrains.anko.attempt import java.lang.reflect.ParameterizedType import java.lang.reflect.Type import kotlin.math.ceil @@ -24,17 +23,15 @@ val GSON: Gson by lazy { inline fun genericType(): Type = object : TypeToken() {}.type inline fun Gson.fromJsonObject(json: String?): T? {//可转成任意类型 - return attempt { - val result: T? = fromJson(json, genericType()) - result - }.value + return kotlin.runCatching { + fromJson(json, genericType()) as? T + }.getOrNull() } inline fun Gson.fromJsonArray(json: String?): List? { - return attempt { - val result: List? = fromJson(json, ParameterizedTypeImpl(T::class.java)) - result - }.value + return kotlin.runCatching { + fromJson(json, ParameterizedTypeImpl(T::class.java)) as? List + }.getOrNull() } class ParameterizedTypeImpl(private val clazz: Class<*>) : ParameterizedType { diff --git a/app/src/main/java/io/legado/app/utils/MainHandler.kt b/app/src/main/java/io/legado/app/utils/MainHandler.kt new file mode 100644 index 000000000..c7bfac683 --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/MainHandler.kt @@ -0,0 +1,37 @@ +package io.legado.app.utils + +import android.os.Build.VERSION.SDK_INT +import android.os.Handler +import android.os.Looper + +/** This main looper cache avoids synchronization overhead when accessed repeatedly. */ +@JvmField +val mainLooper: Looper = Looper.getMainLooper()!! + +@JvmField +val mainThread: Thread = mainLooper.thread + +val isMainThread: Boolean inline get() = mainThread === Thread.currentThread() + +@PublishedApi +internal val currentThread: Any? + inline get() = Thread.currentThread() + +@JvmField +val mainHandler: Handler = if (SDK_INT >= 28) Handler.createAsync(mainLooper) else try { + Handler::class.java.getDeclaredConstructor( + Looper::class.java, + Handler.Callback::class.java, + Boolean::class.javaPrimitiveType // async + ).newInstance(mainLooper, null, true) +} catch (ignored: NoSuchMethodException) { + Handler(mainLooper) // Hidden constructor absent. Fall back to non-async constructor. +} + +fun runOnUiThread(f: () -> Unit) { + if (isMainThread) { + f() + } else { + mainHandler.post(f) + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/Toasts.kt b/app/src/main/java/io/legado/app/utils/Toasts.kt index b0fea3e38..c98f3561c 100644 --- a/app/src/main/java/io/legado/app/utils/Toasts.kt +++ b/app/src/main/java/io/legado/app/utils/Toasts.kt @@ -4,7 +4,6 @@ package io.legado.app.utils import android.widget.Toast import androidx.fragment.app.Fragment -import org.jetbrains.anko.longToast /** @@ -26,11 +25,11 @@ fun Fragment.toastOnUi(message: CharSequence) = requireActivity().toastOnUi(mess * * @param message the message text resource. */ -fun Fragment.longToast(message: Int) = requireActivity().longToast(message) +fun Fragment.longToast(message: Int) = requireContext().longToastOnUi(message) /** * Display the simple Toast message with the [Toast.LENGTH_LONG] duration. * * @param message the message text. */ -fun Fragment.longToast(message: CharSequence) = requireActivity().longToast(message) +fun Fragment.longToast(message: CharSequence) = requireContext().longToastOnUi(message)