delete anko

pull/840/head
gedoor 4 years ago
parent 440edccdc4
commit 0fac54d28a
  1. 7
      app/build.gradle
  2. 7
      app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt
  3. 7
      app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt
  4. 38
      app/src/main/java/io/legado/app/help/permission/Request.kt
  5. 1
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  6. 1
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  7. 34
      app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt
  8. 62
      app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt
  9. 10
      app/src/main/java/io/legado/app/lib/dialogs/AndroidDialogs.kt
  10. 4
      app/src/main/java/io/legado/app/lib/dialogs/AndroidSelectors.kt
  11. 8
      app/src/main/java/io/legado/app/lib/dialogs/Dialogs.kt
  12. 2
      app/src/main/java/io/legado/app/lib/dialogs/Selectors.kt
  13. 10
      app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt
  14. 2
      app/src/main/java/io/legado/app/service/DownloadService.kt
  15. 10
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  16. 6
      app/src/main/java/io/legado/app/service/WebService.kt
  17. 4
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  18. 2
      app/src/main/java/io/legado/app/ui/about/AboutActivity.kt
  19. 4
      app/src/main/java/io/legado/app/ui/about/DonateFragment.kt
  20. 2
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  21. 3
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  22. 4
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  23. 4
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  24. 14
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  25. 4
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt
  26. 11
      app/src/main/java/io/legado/app/ui/book/explore/ExploreShowActivity.kt
  27. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  28. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  29. 50
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  30. 42
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  31. 8
      app/src/main/java/io/legado/app/ui/book/read/ReadBookBaseActivity.kt
  32. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  33. 1
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  34. 4
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  35. 5
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  36. 2
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  37. 4
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  38. 8
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  39. 18
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  40. 2
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt
  41. 18
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  42. 26
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  43. 9
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  44. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  45. 4
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt
  46. 4
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt
  47. 2
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  48. 2
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  49. 2
      app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt
  50. 27
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  51. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt
  52. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt
  53. 20
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt
  54. 4
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  55. 14
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  56. 18
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  57. 4
      app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt
  58. 16
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  59. 6
      app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt
  60. 16
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  61. 6
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  62. 10
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt
  63. 7
      app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt
  64. 12
      app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt
  65. 2
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  66. 10
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  67. 20
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  68. 16
      app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubActivity.kt
  69. 2
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt
  70. 4
      app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt
  71. 8
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt
  72. 33
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  73. 32
      app/src/main/java/io/legado/app/utils/FragmentExtensions.kt
  74. 15
      app/src/main/java/io/legado/app/utils/GsonExtensions.kt
  75. 37
      app/src/main/java/io/legado/app/utils/MainHandler.kt
  76. 5
      app/src/main/java/io/legado/app/utils/Toasts.kt

@ -130,6 +130,7 @@ dependencies {
implementation "androidx.activity:activity-ktx:1.1.0" implementation "androidx.activity:activity-ktx:1.1.0"
implementation "androidx.fragment:fragment-ktx:1.2.5" implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation 'androidx.preference:preference-ktx:1.1.1' 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.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'androidx.viewpager2:viewpager2:1.0.0'
@ -138,7 +139,11 @@ dependencies {
implementation 'com.google.android:flexbox:1.1.0' implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6' 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 //lifecycle
def lifecycle_version = '2.2.0' def lifecycle_version = '2.2.0'

@ -8,6 +8,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import splitties.views.onLongClick
/** /**
* Created by Invincible on 2017/12/15. * Created by Invincible on 2017/12/15.
@ -130,10 +131,10 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context
} }
if (itemLongClickListener != null) { if (itemLongClickListener != null) {
holder.itemView.setOnLongClickListener { holder.itemView.onLongClick {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
itemLongClickListener?.invoke(holder, it) ?: true itemLongClickListener?.invoke(holder, it)
} ?: true }
} }
} }

@ -8,6 +8,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import splitties.views.onLongClick
import java.util.* import java.util.*
/** /**
@ -351,10 +352,10 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
} }
if (itemLongClickListener != null) { if (itemLongClickListener != null) {
holder.itemView.setOnLongClickListener { holder.itemView.onLongClick {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
itemLongClickListener?.invoke(holder, it) ?: true itemLongClickListener?.invoke(holder, it)
} ?: true }
} }
} }

@ -9,7 +9,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.R import io.legado.app.R
import org.jetbrains.anko.startActivity import io.legado.app.utils.startActivity
import java.util.* import java.util.*
internal class Request : OnRequestPermissionsResultCallback { internal class Request : OnRequestPermissionsResultCallback {
@ -77,20 +77,26 @@ internal class Request : OnRequestPermissionsResultCallback {
if (deniedPermissions == null) { if (deniedPermissions == null) {
onPermissionsGranted(requestCode) onPermissionsGranted(requestCode)
} else { } 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) { if (rationale != null) {
showSettingDialog(rationale) { onPermissionsDenied(requestCode, deniedPermissions) } showSettingDialog(rationale) {
onPermissionsDenied(
requestCode,
deniedPermissions
)
}
} else { } else {
onPermissionsDenied(requestCode, deniedPermissions) onPermissionsDenied(requestCode, deniedPermissions)
} }
} }
} else { } else {
if (deniedPermissions != null) { if (deniedPermissions != null) {
source?.context?.startActivity<PermissionActivity>( source?.context?.startActivity<PermissionActivity> {
PermissionActivity.KEY_INPUT_REQUEST_TYPE to TYPE_REQUEST_PERMISSION, putExtra(PermissionActivity.KEY_INPUT_REQUEST_TYPE, TYPE_REQUEST_PERMISSION)
PermissionActivity.KEY_INPUT_PERMISSIONS_CODE to requestCode, putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS_CODE, requestCode)
PermissionActivity.KEY_INPUT_PERMISSIONS to deniedPermissions putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
) }
} else { } else {
onPermissionsGranted(requestCode) onPermissionsGranted(requestCode)
} }
@ -132,10 +138,13 @@ internal class Request : OnRequestPermissionsResultCallback {
.setTitle(R.string.dialog_title) .setTitle(R.string.dialog_title)
.setMessage(rationale) .setMessage(rationale)
.setPositiveButton(R.string.dialog_setting) { _, _ -> .setPositiveButton(R.string.dialog_setting) { _, _ ->
it.startActivity<PermissionActivity>( it.startActivity<PermissionActivity> {
PermissionActivity.KEY_INPUT_REQUEST_TYPE to TYPE_REQUEST_SETTING putExtra(
PermissionActivity.KEY_INPUT_REQUEST_TYPE,
TYPE_REQUEST_SETTING
) )
} }
}
.setNegativeButton(R.string.dialog_cancel) { _, _ -> cancel() } .setNegativeButton(R.string.dialog_cancel) { _, _ -> cancel() }
.show() .show()
} }
@ -160,10 +169,15 @@ internal class Request : OnRequestPermissionsResultCallback {
RequestPlugins.sResultCallback?.onPermissionsDenied(requestCode, deniedPermissions) RequestPlugins.sResultCallback?.onPermissionsDenied(requestCode, deniedPermissions)
} }
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
) {
val deniedPermissions = getDeniedPermissions(permissions) val deniedPermissions = getDeniedPermissions(permissions)
if (deniedPermissions != null) { 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) { if (rationale != null) {
showSettingDialog(rationale) { onPermissionsDenied(requestCode, deniedPermissions) } showSettingDialog(rationale) { onPermissionsDenied(requestCode, deniedPermissions) }
} else { } else {

@ -12,7 +12,6 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.defaultSharedPreferences
import java.io.File import java.io.File
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit

@ -23,7 +23,6 @@ import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.defaultSharedPreferences
import java.io.File import java.io.File
object Restore { object Restore {

@ -11,40 +11,28 @@ import android.view.View
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import io.legado.app.R import io.legado.app.R
import org.jetbrains.anko.internals.AnkoInternals.NO_GETTER
import kotlin.DeprecationLevel.ERROR
@SuppressLint("SupportAnnotationUsage") @SuppressLint("SupportAnnotationUsage")
interface AlertBuilder<out D : DialogInterface> { interface AlertBuilder<out D : DialogInterface> {
val ctx: Context val ctx: Context
var title: CharSequence fun setTitle(title: CharSequence)
@Deprecated(NO_GETTER, level = ERROR) get
var titleResource: Int fun setTitle(titleResource: Int)
@Deprecated(NO_GETTER, level = ERROR) get
var message: CharSequence fun setMessage(message: CharSequence)
@Deprecated(NO_GETTER, level = ERROR) get
var messageResource: Int fun setMessage(messageResource: Int)
@Deprecated(NO_GETTER, level = ERROR) get
var icon: Drawable fun setIcon(icon: Drawable)
@Deprecated(NO_GETTER, level = ERROR) get
@setparam:DrawableRes fun setIcon(@DrawableRes iconResource: Int)
var iconResource: Int
@Deprecated(NO_GETTER, level = ERROR) get
var customTitle: View fun setCustomTitle(customTitle: View)
@Deprecated(NO_GETTER, level = ERROR) get
var customView: View fun setCustomView(customView: View)
@Deprecated(NO_GETTER, level = ERROR) get
var isCancelable: Boolean fun setCancelable(isCancelable: Boolean)
@Deprecated(NO_GETTER, level = ERROR) get
fun positiveButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) fun positiveButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null)
fun positiveButton( fun positiveButton(
@ -97,11 +85,11 @@ interface AlertBuilder<out D : DialogInterface> {
fun customTitle(view: () -> View) { fun customTitle(view: () -> View) {
customTitle = view() setCustomTitle(view())
} }
fun customView(view: () -> View) { fun customView(view: () -> View) {
customView = view() setCustomView(view())
} }
fun okButton(handler: ((dialog: DialogInterface) -> Unit)? = null) = fun okButton(handler: ((dialog: DialogInterface) -> Unit)? = null) =

@ -7,48 +7,45 @@ import android.view.KeyEvent
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import io.legado.app.utils.applyTint 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<AlertDialog> { internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<AlertDialog> {
private val builder = AlertDialog.Builder(ctx) private val builder = AlertDialog.Builder(ctx)
override var title: CharSequence override fun setTitle(title: CharSequence) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setTitle(title)
set(value) { builder.setTitle(value) } }
override var titleResource: Int override fun setTitle(titleResource: Int) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setTitle(titleResource)
set(value) { builder.setTitle(value) } }
override var message: CharSequence override fun setMessage(message: CharSequence) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setMessage(message)
set(value) { builder.setMessage(value) } }
override var messageResource: Int override fun setMessage(messageResource: Int) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setMessage(messageResource)
set(value) { builder.setMessage(value) } }
override var icon: Drawable override fun setIcon(icon: Drawable) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setIcon(icon)
set(value) { builder.setIcon(value) } }
override var iconResource: Int override fun setIcon(iconResource: Int) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setIcon(iconResource)
set(value) { builder.setIcon(value) } }
override var customTitle: View override fun setCustomTitle(customTitle: View) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setCustomTitle(customTitle)
set(value) { builder.setCustomTitle(value) } }
override var customView: View override fun setCustomView(customView: View) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setView(customView)
set(value) { builder.setView(value) } }
override var isCancelable: Boolean override fun setCancelable(isCancelable: Boolean) {
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() builder.setCancelable(isCancelable)
set(value) { builder.setCancelable(value) } }
override fun onCancelled(handler: (DialogInterface) -> Unit) { override fun onCancelled(handler: (DialogInterface) -> Unit) {
builder.setOnCancelListener(handler) builder.setOnCancelListener(handler)
@ -58,7 +55,10 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
builder.setOnKeyListener(handler) builder.setOnKeyListener(handler)
} }
override fun positiveButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)?) { override fun positiveButton(
buttonText: String,
onClicked: ((dialog: DialogInterface) -> Unit)?
) {
builder.setPositiveButton(buttonText) { dialog, _ -> onClicked?.invoke(dialog) } builder.setPositiveButton(buttonText) { dialog, _ -> onClicked?.invoke(dialog) }
} }

@ -7,7 +7,6 @@ import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import org.jetbrains.anko.AnkoContext
inline fun Fragment.alert( inline fun Fragment.alert(
title: CharSequence? = null, title: CharSequence? = null,
@ -22,10 +21,10 @@ fun Context.alert(
): AlertBuilder<AlertDialog> { ): AlertBuilder<AlertDialog> {
return AndroidAlertBuilder(this).apply { return AndroidAlertBuilder(this).apply {
if (title != null) { if (title != null) {
this.title = title this.setTitle(title)
} }
if (message != null) { if (message != null) {
this.message = message this.setMessage(message)
} }
if (init != null) init() if (init != null) init()
} }
@ -44,17 +43,16 @@ fun Context.alert(
): AlertBuilder<AlertDialog> { ): AlertBuilder<AlertDialog> {
return AndroidAlertBuilder(this).apply { return AndroidAlertBuilder(this).apply {
if (titleResource != null) { if (titleResource != null) {
this.titleResource = titleResource this.setTitle(titleResource)
} }
if (messageResource != null) { if (messageResource != null) {
this.messageResource = messageResource this.setMessage(messageResource)
} }
if (init != null) init() if (init != null) init()
} }
} }
inline fun AnkoContext<*>.alert(noinline init: AlertBuilder<DialogInterface>.() -> Unit) = ctx.alert(init)
inline fun Fragment.alert(noinline init: AlertBuilder<DialogInterface>.() -> Unit) = requireContext().alert(init) inline fun Fragment.alert(noinline init: AlertBuilder<DialogInterface>.() -> Unit) = requireContext().alert(init)
fun Context.alert(init: AlertBuilder<AlertDialog>.() -> Unit): AlertBuilder<AlertDialog> = fun Context.alert(init: AlertBuilder<AlertDialog>.() -> Unit): AlertBuilder<AlertDialog> =

@ -35,7 +35,7 @@ fun Context.selector(
) { ) {
with(AndroidAlertBuilder(this)) { with(AndroidAlertBuilder(this)) {
if (title != null) { if (title != null) {
this.title = title this.setTitle(title)
} }
items(items, onClick) items(items, onClick)
show() show()
@ -49,7 +49,7 @@ fun Context.selector(
) { ) {
with(AndroidAlertBuilder(this)) { with(AndroidAlertBuilder(this)) {
if (titleSource != null) { if (titleSource != null) {
this.title = getString(titleSource) this.setTitle(titleSource)
} }
items(items, onClick) items(items, onClick)
show() show()

@ -23,10 +23,10 @@ fun <D : DialogInterface> Context.alert(
): AlertBuilder<D> { ): AlertBuilder<D> {
return factory(this).apply { return factory(this).apply {
if (title != null) { if (title != null) {
this.title = title this.setTitle(title)
} }
if (message != null) { if (message != null) {
this.message = message this.setMessage(message)
} }
if (init != null) init() if (init != null) init()
} }
@ -47,10 +47,10 @@ fun <D : DialogInterface> Context.alert(
): AlertBuilder<D> { ): AlertBuilder<D> {
return factory(this).apply { return factory(this).apply {
if (titleResource != null) { if (titleResource != null) {
this.titleResource = titleResource this.setTitle(titleResource)
} }
if (messageResource != null) { if (messageResource != null) {
this.messageResource = messageResource this.setMessage(messageResource)
} }
if (init != null) init() if (init != null) init()
} }

@ -21,7 +21,7 @@ fun <D : DialogInterface> Context.selector(
) { ) {
with(factory(this)) { with(factory(this)) {
if (title != null) { if (title != null) {
this.title = title this.setTitle(title)
} }
items(items, onClick) items(items, onClick)
show() show()

@ -6,7 +6,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.main.MainActivity import io.legado.app.ui.main.MainActivity
import org.jetbrains.anko.startActivity import io.legado.app.utils.startActivity
class SharedReceiverActivity : AppCompatActivity() { class SharedReceiverActivity : AppCompatActivity() {
@ -22,7 +22,9 @@ class SharedReceiverActivity : AppCompatActivity() {
if (Intent.ACTION_SEND == intent.action && intent.type == receivingType) { if (Intent.ACTION_SEND == intent.action && intent.type == receivingType) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
if (openUrl(it)) { if (openUrl(it)) {
startActivity<SearchActivity>(Pair("key", it)) startActivity<SearchActivity> {
putExtra("key", it)
}
} }
} }
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
@ -31,7 +33,9 @@ class SharedReceiverActivity : AppCompatActivity() {
) { ) {
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let { intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let {
if (openUrl(it)) { if (openUrl(it)) {
startActivity<SearchActivity>(Pair("key", it)) startActivity<SearchActivity> {
putExtra("key", it)
}
} }
} }
} }

@ -19,9 +19,9 @@ import io.legado.app.constant.AppConst
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.utils.RealPathUtil import io.legado.app.utils.RealPathUtil
import io.legado.app.utils.downloadManager
import io.legado.app.utils.msg import io.legado.app.utils.msg
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import splitties.systemservices.downloadManager
import java.io.File import java.io.File

@ -13,8 +13,6 @@ import io.legado.app.service.help.ReadBook
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.ensureActive import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import org.jetbrains.anko.collections.forEachWithIndex
import org.jetbrains.anko.runOnUiThread
import java.io.File import java.io.File
import java.io.FileDescriptor import java.io.FileDescriptor
import java.io.FileInputStream import java.io.FileInputStream
@ -80,7 +78,7 @@ class HttpReadAloudService : BaseReadAloudService(),
task = execute { task = execute {
removeCacheFile() removeCacheFile()
ReadAloud.httpTTS?.let { ReadAloud.httpTTS?.let {
contentList.forEachWithIndex { index, item -> contentList.forEachIndexed { index, item ->
if (isActive) { if (isActive) {
val fileName = val fileName =
md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), item) md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), item)
@ -119,17 +117,17 @@ class HttpReadAloudService : BaseReadAloudService(),
} }
} catch (e: SocketTimeoutException) { } catch (e: SocketTimeoutException) {
removeSpeakCacheFile(fileName) removeSpeakCacheFile(fileName)
runOnUiThread { toastOnUi("tts接口超时,尝试重新获取") } toastOnUi("tts接口超时,尝试重新获取")
downloadAudio() downloadAudio()
} catch (e: ConnectException) { } catch (e: ConnectException) {
removeSpeakCacheFile(fileName) removeSpeakCacheFile(fileName)
runOnUiThread { toastOnUi("网络错误") } toastOnUi("网络错误")
} catch (e: IOException) { } catch (e: IOException) {
val file = getSpeakFileAsMd5(fileName) val file = getSpeakFileAsMd5(fileName)
if (file.exists()) { if (file.exists()) {
FileUtils.deleteFile(file.absolutePath) FileUtils.deleteFile(file.absolutePath)
} }
runOnUiThread { toastOnUi("tts文件解析错误") } toastOnUi("tts文件解析错误")
} catch (e: Exception) { } catch (e: Exception) {
removeSpeakCacheFile(fileName) removeSpeakCacheFile(fileName)
} }

@ -10,13 +10,9 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.*
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUi
import io.legado.app.web.HttpServer import io.legado.app.web.HttpServer
import io.legado.app.web.WebSocketServer import io.legado.app.web.WebSocketServer
import org.jetbrains.anko.startService
import java.io.IOException import java.io.IOException
class WebService : BaseService() { class WebService : BaseService() {

@ -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.entities.TextPage
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.msg
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.getStackTraceString
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
@ -437,7 +437,7 @@ object ReadBook {
} }
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()
App.INSTANCE.toastOnUi("ChapterProvider ERROR:\n${it.getStackTraceString()}") App.INSTANCE.toastOnUi("ChapterProvider ERROR:\n${it.msg}")
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
} }

@ -12,7 +12,7 @@ import io.legado.app.databinding.ActivityAboutBinding
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.openUrl import io.legado.app.utils.openUrl
import org.jetbrains.anko.share import io.legado.app.utils.share
class AboutActivity : BaseActivity<ActivityAboutBinding>() { class AboutActivity : BaseActivity<ActivityAboutBinding>() {

@ -8,9 +8,9 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.ACache import io.legado.app.utils.ACache
import io.legado.app.utils.longToastOnUi
import io.legado.app.utils.openUrl import io.legado.app.utils.openUrl
import io.legado.app.utils.sendToClip import io.legado.app.utils.sendToClip
import org.jetbrains.anko.longToast
class DonateFragment : PreferenceFragmentCompat() { class DonateFragment : PreferenceFragmentCompat() {
@ -42,7 +42,7 @@ class DonateFragment : PreferenceFragmentCompat() {
private fun getZfbHb(context: Context) { private fun getZfbHb(context: Context) {
requireContext().sendToClip("537954522") requireContext().sendToClip("537954522")
context.longToast("高级功能已开启\n红包码已复制\n支付宝首页搜索“537954522” 立即领红包") context.longToastOnUi("高级功能已开启\n红包码已复制\n支付宝首页搜索“537954522” 立即领红包")
try { try {
val packageManager = context.applicationContext.packageManager val packageManager = context.applicationContext.packageManager
val intent = packageManager.getLaunchIntentForPackage("com.eg.android.AlipayGphone")!! val intent = packageManager.getLaunchIntentForPackage("com.eg.android.AlipayGphone")!!

@ -121,7 +121,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
private fun sureDelAlert(item: ReadRecordShow) { private fun sureDelAlert(item: ReadRecordShow) {
alert(R.string.delete) { alert(R.string.delete) {
message = getString(R.string.sure_del_any, item.bookName) setMessage(getString(R.string.sure_del_any, item.bookName))
okButton { okButton {
App.db.readRecordDao.deleteByName(item.bookName) App.db.readRecordDao.deleteByName(item.bookName)
initData() initData()

@ -7,10 +7,9 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.ui.main.MainActivity import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import org.jetbrains.anko.startActivity
class FileAssociationActivity : class FileAssociationActivity :
VMBaseActivity<ActivityTranslucenceBinding, FileAssociationViewModel>( VMBaseActivity<ActivityTranslucenceBinding, FileAssociationViewModel>(

@ -96,7 +96,9 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dp
} }
customView = alertBinding.root customView {
alertBinding.root
}
okButton { okButton {
alertBinding.editView.text?.toString()?.let { group -> alertBinding.editView.text?.toString()?.let { group ->
viewModel.groupName = group viewModel.groupName = group

@ -96,7 +96,9 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dp
} }
customView = alertBinding.root customView {
alertBinding.root
}
okButton { okButton {
alertBinding.editView.text?.toString()?.let { group -> alertBinding.editView.text?.toString()?.let { group ->
viewModel.groupName = group viewModel.groupName = group

@ -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.image.CoverImageView
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.startActivityForResult import splitties.views.onLongClick
import java.util.* import java.util.*
/** /**
@ -82,9 +82,8 @@ class AudioPlayActivity :
binding.fabPlayStop.setOnClickListener { binding.fabPlayStop.setOnClickListener {
playButton() playButton()
} }
binding.fabPlayStop.setOnLongClickListener { binding.fabPlayStop.onLongClick {
AudioPlay.stop(this@AudioPlayActivity) AudioPlay.stop(this@AudioPlayActivity)
true
} }
binding.ivSkipNext.setOnClickListener { binding.ivSkipNext.setOnClickListener {
AudioPlay.next(this@AudioPlayActivity) AudioPlay.next(this@AudioPlayActivity)
@ -108,10 +107,9 @@ class AudioPlayActivity :
}) })
binding.ivChapter.setOnClickListener { binding.ivChapter.setOnClickListener {
AudioPlay.book?.let { AudioPlay.book?.let {
startActivityForResult<ChapterListActivity>( startActivityForResult<ChapterListActivity>(requestCodeChapter) {
requestCodeChapter, putExtra("bookUrl", it.bookUrl)
Pair("bookUrl", it.bookUrl) }
)
} }
} }
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@ -165,7 +163,7 @@ class AudioPlayActivity :
AudioPlay.book?.let { AudioPlay.book?.let {
if (!AudioPlay.inBookshelf) { if (!AudioPlay.inBookshelf) {
alert(title = getString(R.string.add_to_shelf)) { 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 { okButton {
AudioPlay.inBookshelf = true AudioPlay.inBookshelf = true
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)

@ -13,6 +13,7 @@ import io.legado.app.data.entities.SearchBook
import io.legado.app.databinding.ItemChangeSourceBinding import io.legado.app.databinding.ItemChangeSourceBinding
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import io.legado.app.utils.visible import io.legado.app.utils.visible
import splitties.views.onLongClick
class ChangeSourceAdapter(context: Context, val callBack: CallBack) : class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
@ -68,9 +69,8 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
callBack.changeTo(it) callBack.changeTo(it)
} }
} }
holder.itemView.setOnLongClickListener { holder.itemView.onLongClick {
showMenu(holder.itemView, getItem(holder.layoutPosition)) showMenu(holder.itemView, getItem(holder.layoutPosition))
true
} }
} }

@ -12,8 +12,7 @@ import io.legado.app.databinding.ViewLoadMoreBinding
import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.widget.recycler.LoadMoreView import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.startActivity
import org.jetbrains.anko.startActivity
class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreShowViewModel>(), class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreShowViewModel>(),
ExploreShowAdapter.CallBack { ExploreShowAdapter.CallBack {
@ -88,9 +87,9 @@ class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreSh
} }
override fun showBookInfo(book: Book) { override fun showBookInfo(book: Book) {
startActivity<BookInfoActivity>( startActivity<BookInfoActivity> {
Pair("name", book.name), putExtra("name", book.name)
Pair("author", book.author) putExtra("author", book.author)
) }
} }
} }

@ -99,7 +99,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setHint(R.string.group_name) editView.setHint(R.string.group_name)
} }
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
if (it.isNotBlank()) { if (it.isNotBlank()) {
@ -123,7 +123,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
deleteGroup(bookGroup) deleteGroup(bookGroup)
} }
} }
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
viewModel.upGroup(bookGroup.copy(groupName = it)) viewModel.upGroup(bookGroup.copy(groupName = it))

@ -122,7 +122,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setHint(R.string.group_name) editView.setHint(R.string.group_name)
} }
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
if (it.isNotBlank()) { if (it.isNotBlank()) {
@ -141,7 +141,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
editView.setHint(R.string.group_name) editView.setHint(R.string.group_name)
editView.setText(bookGroup.groupName) editView.setText(bookGroup.groupName)
} }
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
viewModel.upGroup(bookGroup.copy(groupName = it)) viewModel.upGroup(bookGroup.copy(groupName = it))

@ -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.book.toc.ChapterListActivity
import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.image.CoverImageView
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
class BookInfoActivity : class BookInfoActivity :
@ -86,9 +84,10 @@ class BookInfoActivity :
if (viewModel.inBookshelf) { if (viewModel.inBookshelf) {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
startActivityForResult<BookInfoEditActivity>( startActivityForResult<BookInfoEditActivity>(
requestCodeInfoEdit, requestCodeInfoEdit
Pair("bookUrl", it.bookUrl) ) {
) putExtra("bookUrl", it.bookUrl)
}
} }
} else { } else {
toastOnUi(R.string.after_add_bookshelf) toastOnUi(R.string.after_add_bookshelf)
@ -227,7 +226,9 @@ class BookInfoActivity :
} }
tvOrigin.setOnClickListener { tvOrigin.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
startActivity<BookSourceEditActivity>(Pair("data", it.origin)) startActivity<BookSourceEditActivity> {
putExtra("data", it.origin)
}
} }
} }
tvChangeSource.setOnClickListener { tvChangeSource.setOnClickListener {
@ -252,10 +253,14 @@ class BookInfoActivity :
} }
} }
tvAuthor.setOnClickListener { tvAuthor.setOnClickListener {
startActivity<SearchActivity>(Pair("key", viewModel.bookData.value?.author)) startActivity<SearchActivity> {
putExtra("key", viewModel.bookData.value?.author)
}
} }
tvName.setOnClickListener { tvName.setOnClickListener {
startActivity<SearchActivity>(Pair("key", viewModel.bookData.value?.name)) startActivity<SearchActivity> {
putExtra("key", viewModel.bookData.value?.name)
}
} }
} }
@ -274,7 +279,7 @@ class BookInfoActivity :
setPadding(16.dp, 0, 16.dp, 0) setPadding(16.dp, 0, 16.dp, 0)
addView(checkBox) addView(checkBox)
} }
customView = view customView { view }
positiveButton(R.string.yes) { positiveButton(R.string.yes) {
viewModel.delBook(checkBox.isChecked) { viewModel.delBook(checkBox.isChecked) {
finish() finish()
@ -297,9 +302,10 @@ class BookInfoActivity :
} }
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
startActivityForResult<ChapterListActivity>( startActivityForResult<ChapterListActivity>(
requestCodeChapterList, requestCodeChapterList
Pair("bookUrl", it.bookUrl) ) {
) putExtra("bookUrl", it.bookUrl)
}
} }
} }
@ -320,16 +326,18 @@ class BookInfoActivity :
private fun startReadActivity(book: Book) { private fun startReadActivity(book: Book) {
when (book.type) { when (book.type) {
BookType.audio -> startActivityForResult<AudioPlayActivity>( BookType.audio -> startActivityForResult<AudioPlayActivity>(
requestCodeRead, requestCodeRead
Pair("bookUrl", book.bookUrl), ) {
Pair("inBookshelf", viewModel.inBookshelf) putExtra("bookUrl", book.bookUrl)
) putExtra("inBookshelf", viewModel.inBookshelf)
}
else -> startActivityForResult<ReadBookActivity>( else -> startActivityForResult<ReadBookActivity>(
requestCodeRead, requestCodeRead
Pair("bookUrl", book.bookUrl), ) {
Pair("inBookshelf", viewModel.inBookshelf), putExtra("bookUrl", book.bookUrl)
Pair("key", IntentDataHelp.putData(book)) putExtra("inBookshelf", viewModel.inBookshelf)
) putExtra("key", IntentDataHelp.putData(book))
}
} }
} }

@ -53,8 +53,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
class ReadBookActivity : ReadBookBaseActivity(), class ReadBookActivity : ReadBookBaseActivity(),
View.OnTouchListener, View.OnTouchListener,
@ -234,7 +232,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
binding.readView.upPageAnim() binding.readView.upPageAnim()
} }
R.id.menu_book_info -> ReadBook.book?.let { R.id.menu_book_info -> ReadBook.book?.let {
startActivity<BookInfoActivity>(Pair("name", it.name), Pair("author", it.author)) startActivity<BookInfoActivity> {
putExtra("name", it.name)
putExtra("author", it.author)
}
} }
R.id.menu_toc_regex -> TocRegexDialog.show( R.id.menu_toc_regex -> TocRegexDialog.show(
supportFragmentManager, supportFragmentManager,
@ -657,9 +658,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun openSourceEditActivity() { override fun openSourceEditActivity() {
ReadBook.webBook?.let { ReadBook.webBook?.let {
startActivityForResult<BookSourceEditActivity>( startActivityForResult<BookSourceEditActivity>(
requestCodeEditSource, requestCodeEditSource
Pair("data", it.bookSource.bookSourceUrl) ) {
) putExtra("data", it.bookSource.bookSourceUrl)
}
} }
} }
@ -676,9 +678,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun openChapterList() { override fun openChapterList() {
ReadBook.book?.let { ReadBook.book?.let {
startActivityForResult<ChapterListActivity>( startActivityForResult<ChapterListActivity>(
requestCodeChapterList, requestCodeChapterList
Pair("bookUrl", it.bookUrl) ) {
) putExtra("bookUrl", it.bookUrl)
}
} }
} }
@ -688,10 +691,11 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun openSearchActivity(searchWord: String?) { override fun openSearchActivity(searchWord: String?) {
ReadBook.book?.let { ReadBook.book?.let {
startActivityForResult<SearchContentActivity>( startActivityForResult<SearchContentActivity>(
requestCodeSearchResult, requestCodeSearchResult
Pair("bookUrl", it.bookUrl), ) {
Pair("searchWord", searchWord ?: viewModel.searchContentQuery) putExtra("bookUrl", it.bookUrl)
) putExtra("searchWord", searchWord ?: viewModel.searchContentQuery)
}
} }
} }
@ -719,10 +723,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
override fun showLogin() { override fun showLogin() {
ReadBook.webBook?.bookSource?.let { ReadBook.webBook?.bookSource?.let {
startActivity<SourceLogin>( startActivity<SourceLogin> {
Pair("sourceUrl", it.bookSourceUrl), putExtra("sourceUrl", it.bookSourceUrl)
Pair("loginUrl", it.loginUrl) putExtra("loginUrl", it.loginUrl)
) }
} }
} }
@ -774,7 +778,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
private fun sureSyncProgress(progress: BookProgress) { private fun sureSyncProgress(progress: BookProgress) {
alert(R.string.get_book_progress) { alert(R.string.get_book_progress) {
message = getString(R.string.current_progress_exceeds_cloud) setMessage(R.string.current_progress_exceeds_cloud)
okButton { okButton {
ReadBook.setProgress(progress) ReadBook.setProgress(progress)
} }
@ -845,7 +849,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
ReadBook.book?.let { ReadBook.book?.let {
if (!ReadBook.inBookshelf) { if (!ReadBook.inBookshelf) {
alert(title = getString(R.string.add_to_shelf)) { 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 { okButton {
ReadBook.inBookshelf = true ReadBook.inBookshelf = true
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)

@ -187,7 +187,7 @@ abstract class ReadBookBaseActivity :
editStart.setText((book.durChapterIndex + 1).toString()) editStart.setText((book.durChapterIndex + 1).toString())
editEnd.setText(book.totalChapterNum.toString()) editEnd.setText(book.totalChapterNum.toString())
} }
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
alertBinding.run { alertBinding.run {
val start = editStart.text?.toString()?.toInt() ?: 0 val start = editStart.text?.toString()?.toInt() ?: 0
@ -203,12 +203,12 @@ abstract class ReadBookBaseActivity :
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
fun showBookMark(bookmark: Bookmark) { fun showBookMark(bookmark: Bookmark) {
alert(title = getString(R.string.bookmark_add)) { alert(title = getString(R.string.bookmark_add)) {
message = bookmark.chapterName setMessage(bookmark.chapterName)
val alertBinding = DialogBookmarkBinding.inflate(layoutInflater).apply { val alertBinding = DialogBookmarkBinding.inflate(layoutInflater).apply {
editBookText.setText(bookmark.bookText) editBookText.setText(bookmark.bookText)
editView.setText(bookmark.content) editView.setText(bookmark.content)
} }
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
alertBinding.apply { alertBinding.apply {
Coroutine.async { Coroutine.async {
@ -231,7 +231,7 @@ abstract class ReadBookBaseActivity :
editView.setFilterValues(charsets) editView.setFilterValues(charsets)
editView.setText(ReadBook.book?.charset) editView.setText(ReadBook.book?.charset)
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
ReadBook.setCharset(it) ReadBook.setCharset(it)

@ -21,6 +21,7 @@ import io.legado.app.lib.theme.*
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.* import io.legado.app.utils.*
import splitties.views.onLongClick
/** /**
* 阅读界面菜单 * 阅读界面菜单
@ -210,9 +211,8 @@ class ReadMenu @JvmOverloads constructor(
callBack.onClickReadAloud() callBack.onClickReadAloud()
} }
} }
llReadAloud.setOnLongClickListener { llReadAloud.onLongClick {
runMenuOut { callBack.showReadAloudDialog() } runMenuOut { callBack.showReadAloudDialog() }
true
} }
//界面 //界面
llFont.setOnClickListener { llFont.setOnClickListener {

@ -25,7 +25,6 @@ import io.legado.app.databinding.ItemTextBinding
import io.legado.app.databinding.PopupActionMenuBinding import io.legado.app.databinding.PopupActionMenuBinding
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.share
import java.util.* import java.util.*
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")

@ -123,7 +123,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setText(ReadBookConfig.durConfig.name) editView.setText(ReadBookConfig.durConfig.name)
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
binding.tvName.text = it binding.tvName.text = it
@ -278,7 +278,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
private fun importNetConfigAlert() { private fun importNetConfigAlert() {
alert("输入地址") { alert("输入地址") {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater) val alertBinding = DialogEditTextBinding.inflate(layoutInflater)
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { url -> alertBinding.editView.text?.toString()?.let { url ->
importNetConfig(url) importNetConfig(url)

@ -24,6 +24,7 @@ import io.legado.app.utils.dp
import io.legado.app.utils.getIndexById import io.legado.app.utils.getIndexById
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import splitties.views.onLongClick
class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
private val binding by viewBinding(DialogReadBookStyleBinding::bind) private val binding by viewBinding(DialogReadBookStyleBinding::bind)
@ -237,11 +238,9 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
changeBg(holder.layoutPosition) changeBg(holder.layoutPosition)
} }
} }
ivStyle.setOnLongClickListener { ivStyle.onLongClick(ivStyle.isInView) {
if (ivStyle.isInView) { if (ivStyle.isInView) {
showBgTextConfig(holder.layoutPosition) showBgTextConfig(holder.layoutPosition)
} else {
false
} }
} }
} }

@ -110,7 +110,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
val alertBinding = DialogHttpTtsEditBinding.inflate(layoutInflater) val alertBinding = DialogHttpTtsEditBinding.inflate(layoutInflater)
alertBinding.tvName.setText(httpTTS.name) alertBinding.tvName.setText(httpTTS.name)
alertBinding.tvUrl.setText(httpTTS.url) alertBinding.tvUrl.setText(httpTTS.url)
customView = alertBinding.root customView { alertBinding.root }
cancelButton() cancelButton()
okButton { okButton {
alertBinding.apply { alertBinding.apply {

@ -147,7 +147,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
aCache.put(importTocRuleKey, cacheUrls.joinToString(",")) aCache.put(importTocRuleKey, cacheUrls.joinToString(","))
} }
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
val text = alertBinding.editView.text?.toString() val text = alertBinding.editView.text?.toString()
text?.let { text?.let {
@ -175,7 +175,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
tvRuleName.setText(tocRule.name) tvRuleName.setText(tocRule.name)
tvRuleRegex.setText(tocRule.rule) tvRuleRegex.setText(tocRule.rule)
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.apply { alertBinding.apply {
tocRule.name = tvRuleName.text.toString() tocRule.name = tvRuleName.text.toString()

@ -10,6 +10,7 @@ import io.legado.app.ui.widget.anima.explosion_field.ExplosionField
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import splitties.views.onLongClick
class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
RecyclerAdapter<SearchKeyword, ItemFilletTextBinding>(activity) { RecyclerAdapter<SearchKeyword, ItemFilletTextBinding>(activity) {
@ -38,16 +39,13 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
callBack.searchHistory(it.word) callBack.searchHistory(it.word)
} }
} }
setOnLongClickListener { onLongClick {
it?.let { explosionField.explode(this, true)
explosionField.explode(it, true)
}
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
GlobalScope.launch(IO) { GlobalScope.launch(IO) {
App.db.searchKeywordDao.delete(it) App.db.searchKeywordDao.delete(it)
} }
} }
true
} }
} }
} }

@ -30,8 +30,6 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.startActivity
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(), class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
BookAdapter.CallBack, BookAdapter.CallBack,
HistoryKeyAdapter.CallBack, HistoryKeyAdapter.CallBack,
@ -333,10 +331,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
override fun showBookInfo(name: String, author: String) { override fun showBookInfo(name: String, author: String) {
viewModel.getSearchBook(name, author) { searchBook -> viewModel.getSearchBook(name, author) { searchBook ->
searchBook?.let { searchBook?.let {
startActivity<BookInfoActivity>( startActivity<BookInfoActivity> {
Pair("name", it.name), putExtra("name", it.name)
Pair("author", it.author) putExtra("author", it.author)
) }
} }
} }
} }
@ -345,10 +343,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
* 显示书籍详情 * 显示书籍详情
*/ */
override fun showBookInfo(book: Book) { override fun showBookInfo(book: Book) {
startActivity<BookInfoActivity>( startActivity<BookInfoActivity> {
Pair("name", book.name), putExtra("name", book.name)
Pair("author", book.author) putExtra("author", book.author)
) }
} }
/** /**

@ -14,10 +14,10 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.startActivityForResult
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivityForResult
class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() { class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() {

@ -21,6 +21,7 @@ import io.legado.app.data.entities.rule.*
import io.legado.app.databinding.ActivityBookSourceEditBinding import io.legado.app.databinding.ActivityBookSourceEditBinding
import io.legado.app.help.LocalConfig import io.legado.app.help.LocalConfig
import io.legado.app.lib.dialogs.alert 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.ATH
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity 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.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.*
import kotlin.math.abs import kotlin.math.abs
class BookSourceEditActivity : class BookSourceEditActivity :
@ -90,7 +90,9 @@ class BookSourceEditActivity :
R.id.menu_debug_source -> getSource().let { source -> R.id.menu_debug_source -> getSource().let { source ->
if (checkSource(source)) { if (checkSource(source)) {
viewModel.save(source) { viewModel.save(source) {
startActivity<BookSourceDebugActivity>(Pair("key", source.bookSourceUrl)) startActivity<BookSourceDebugActivity> {
putExtra("key", source.bookSourceUrl)
}
} }
} }
} }
@ -108,10 +110,10 @@ class BookSourceEditActivity :
if (it.loginUrl.isNullOrEmpty()) { if (it.loginUrl.isNullOrEmpty()) {
toastOnUi(R.string.source_no_login) toastOnUi(R.string.source_no_login)
} else { } else {
startActivity<SourceLogin>( startActivity<SourceLogin> {
Pair("sourceUrl", it.bookSourceUrl), putExtra("sourceUrl", it.bookSourceUrl)
Pair("loginUrl", it.loginUrl) putExtra("loginUrl", it.loginUrl)
) }
} }
} }
} }
@ -145,7 +147,7 @@ class BookSourceEditActivity :
val source = getSource() val source = getSource()
if (!source.equal(viewModel.bookSource ?: BookSource())) { if (!source.equal(viewModel.bookSource ?: BookSource())) {
alert(R.string.exit) { alert(R.string.exit) {
messageResource = R.string.exit_no_save setMessage(R.string.exit_no_save)
positiveButton(R.string.yes) positiveButton(R.string.yes)
negativeButton(R.string.no) { negativeButton(R.string.no) {
super.finish() super.finish()
@ -449,7 +451,7 @@ class BookSourceEditActivity :
val rect = Rect() val rect = Rect()
// 获取当前页面窗口的显示范围 // 获取当前页面窗口的显示范围
window.decorView.getWindowVisibleDisplayFrame(rect) window.decorView.getWindowVisibleDisplayFrame(rect)
val screenHeight = this@BookSourceEditActivity.displayMetrics.heightPixels val screenHeight = this@BookSourceEditActivity.getSize().heightPixels
val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
val preShowing = mIsSoftKeyBoardShowing val preShowing = mIsSoftKeyBoardShowing
if (abs(keyboardHeight) > screenHeight / 5) { if (abs(keyboardHeight) > screenHeight / 5) {

@ -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.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import java.io.File import java.io.File
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(), class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
@ -304,7 +302,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setText(CheckSource.keyword) editView.setText(CheckSource.keyword)
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
@ -325,7 +323,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dp
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
@ -345,7 +343,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dp
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
@ -381,7 +379,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
val text = alertBinding.editView.text?.toString() val text = alertBinding.editView.text?.toString()
text?.let { text?.let {
@ -389,7 +387,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
startActivity<ImportBookSourceActivity>(Pair("source", it)) startActivity<ImportBookSourceActivity> {
putExtra("source", it)
}
} }
} }
cancelButton() cancelButton()
@ -443,7 +443,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
override fun edit(bookSource: BookSource) { override fun edit(bookSource: BookSource) {
startActivity<BookSourceEditActivity>(Pair("data", bookSource.bookSourceUrl)) startActivity<BookSourceEditActivity> {
putExtra("data", bookSource.bookSourceUrl)
}
} }
override fun upOrder() { override fun upOrder() {
@ -463,7 +465,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
when (requestCode) { when (requestCode) {
qrRequestCode -> if (resultCode == RESULT_OK) { qrRequestCode -> if (resultCode == RESULT_OK) {
data?.getStringExtra("result")?.let { data?.getStringExtra("result")?.let {
startActivity<ImportBookSourceActivity>("source" to it) startActivity<ImportBookSourceActivity> {
putExtra("source", it)
}
} }
} }
importRequestCode -> if (resultCode == Activity.RESULT_OK) { importRequestCode -> if (resultCode == Activity.RESULT_OK) {
@ -471,7 +475,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
try { try {
uri.readText(this)?.let { uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it) val dataKey = IntentDataHelp.putData(it)
startActivity<ImportBookSourceActivity>("dataKey" to dataKey) startActivity<ImportBookSourceActivity> {
putExtra("dataKey", dataKey)
}
} }
} catch (e: Exception) { } catch (e: Exception) {
toastOnUi("readTextError:${e.localizedMessage}") toastOnUi("readTextError:${e.localizedMessage}")

@ -11,7 +11,6 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.longToast
import java.io.File import java.io.File
class BookSourceViewModel(application: Application) : BaseViewModel(application) { class BookSourceViewModel(application: Application) : BaseViewModel(application) {
@ -144,9 +143,9 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
FileUtils.createFileIfNotExist(file, "exportBookSource.json") FileUtils.createFileIfNotExist(file, "exportBookSource.json")
.writeText(json) .writeText(json)
}.onSuccess { }.onSuccess {
context.longToast("成功导出至\n${file.absolutePath}") context.longToastOnUi("成功导出至\n${file.absolutePath}")
}.onError { }.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") doc.createFile("", "exportBookSource.json")
?.writeText(context, json) ?.writeText(context, json)
}.onSuccess { }.onSuccess {
context.longToast("成功导出至\n${doc.uri.path}") context.longToastOnUi("成功导出至\n${doc.uri.path}")
}.onError { }.onError {
context.longToast("导出失败\n${it.localizedMessage}") context.longToastOnUi("导出失败\n${it.localizedMessage}")
} }
} }

@ -86,7 +86,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
alert(title = getString(R.string.add_group)) { alert(title = getString(R.string.add_group)) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater) val alertBinding = DialogEditTextBinding.inflate(layoutInflater)
alertBinding.editView.setHint(R.string.group_name) alertBinding.editView.setHint(R.string.group_name)
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
if (it.isNotBlank()) { if (it.isNotBlank()) {
@ -103,7 +103,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
alert(title = getString(R.string.group_edit)) { alert(title = getString(R.string.group_edit)) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater) val alertBinding = DialogEditTextBinding.inflate(layoutInflater)
alertBinding.editView.setHint(R.string.group_name) alertBinding.editView.setHint(R.string.group_name)
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
viewModel.upGroup(group, alertBinding.editView.text?.toString()) viewModel.upGroup(group, alertBinding.editView.text?.toString())
} }

@ -7,6 +7,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.data.entities.Bookmark import io.legado.app.data.entities.Bookmark
import io.legado.app.databinding.ItemBookmarkBinding import io.legado.app.databinding.ItemBookmarkBinding
import splitties.views.onLongClick
class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>(DIFF_CALLBACK) { class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -46,9 +47,8 @@ class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, Bookm
itemView.setOnClickListener { itemView.setOnClickListener {
callback?.onClick(bookmark) callback?.onClick(bookmark)
} }
itemView.setOnLongClickListener { itemView.onLongClick {
callback?.onLongClick(bookmark) callback?.onLongClick(bookmark)
true
} }
} }
} }

@ -85,12 +85,12 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
override fun onLongClick(bookmark: Bookmark) { override fun onLongClick(bookmark: Bookmark) {
requireContext().alert(R.string.bookmark) { requireContext().alert(R.string.bookmark) {
message = bookmark.chapterName setMessage(bookmark.chapterName)
val alertBinding = DialogBookmarkBinding.inflate(layoutInflater).apply { val alertBinding = DialogBookmarkBinding.inflate(layoutInflater).apply {
editBookText.setText(bookmark.bookText) editBookText.setText(bookmark.bookText)
editView.setText(bookmark.content) editView.setText(bookmark.content)
} }
customView = alertBinding.root customView { alertBinding.root }
yesButton { yesButton {
alertBinding.apply { alertBinding.apply {
Coroutine.async { Coroutine.async {

@ -156,7 +156,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
alert("UserAgent") { alert("UserAgent") {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater) val alertBinding = DialogEditTextBinding.inflate(layoutInflater)
alertBinding.editView.setText(AppConfig.userAgent) alertBinding.editView.setText(AppConfig.userAgent)
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
val userAgent = alertBinding.editView.text?.toString() val userAgent = alertBinding.editView.text?.toString()
if (userAgent.isNullOrBlank()) { if (userAgent.isNullOrBlank()) {

@ -225,7 +225,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
private fun saveThemeAlert(key: String) { private fun saveThemeAlert(key: String) {
alert(R.string.theme_name) { alert(R.string.theme_name) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater) val alertBinding = DialogEditTextBinding.inflate(layoutInflater)
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { themeName -> alertBinding.editView.text?.toString()?.let { themeName ->
when (key) { when (key) {

@ -20,8 +20,6 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.share
class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private lateinit var adapter: Adapter private lateinit var adapter: Adapter

@ -35,7 +35,6 @@ import io.legado.app.ui.main.MainViewModel
import io.legado.app.ui.main.bookshelf.books.BooksFragment import io.legado.app.ui.main.bookshelf.books.BooksFragment
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.share
/** /**
* 书架界面 * 书架界面
@ -81,14 +80,14 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
.show(childFragmentManager, "groupManageDialog") .show(childFragmentManager, "groupManageDialog")
R.id.menu_add_local -> startActivity<ImportBookActivity>() R.id.menu_add_local -> startActivity<ImportBookActivity>()
R.id.menu_add_url -> addBookByUrl() R.id.menu_add_url -> addBookByUrl()
R.id.menu_arrange_bookshelf -> startActivity<ArrangeBookActivity>( R.id.menu_arrange_bookshelf -> startActivity<ArrangeBookActivity> {
Pair("groupId", selectedGroup.groupId), putExtra("groupId", selectedGroup.groupId)
Pair("groupName", selectedGroup.groupName) putExtra("groupName", selectedGroup.groupName)
) }
R.id.menu_download -> startActivity<CacheActivity>( R.id.menu_download -> startActivity<CacheActivity> {
Pair("groupId", selectedGroup.groupId), putExtra("groupId", selectedGroup.groupId)
Pair("groupName", selectedGroup.groupName) putExtra("groupName", selectedGroup.groupName)
) }
R.id.menu_export_bookshelf -> { R.id.menu_export_bookshelf -> {
val fragment = fragmentMap[selectedGroup.groupId] val fragment = fragmentMap[selectedGroup.groupId]
viewModel.exportBookshelf(fragment?.getBooks()) { viewModel.exportBookshelf(fragment?.getBooks()) {
@ -124,7 +123,9 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
} }
override fun onQueryTextSubmit(query: String?): Boolean { override fun onQueryTextSubmit(query: String?): Boolean {
startActivity<SearchActivity>(Pair("key", query)) startActivity<SearchActivity> {
putExtra("key", query)
}
return false return false
} }
@ -164,7 +165,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
rgLayout.checkByIndex(bookshelfLayout) rgLayout.checkByIndex(bookshelfLayout)
rgSort.checkByIndex(bookshelfSort) rgSort.checkByIndex(bookshelfSort)
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.apply { alertBinding.apply {
var changed = false var changed = false
@ -189,7 +190,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
private fun addBookByUrl() { private fun addBookByUrl() {
alert(titleResource = R.string.add_book_url) { alert(titleResource = R.string.add_book_url) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater) val alertBinding = DialogEditTextBinding.inflate(layoutInflater)
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
viewModel.addBookByUrl(it) viewModel.addBookByUrl(it)
@ -220,7 +221,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.hint = "url/json" editView.hint = "url/json"
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
alertBinding.editView.text?.toString()?.let { alertBinding.editView.text?.toString()?.let {
viewModel.importBookshelf(it, selectedGroup.groupId) viewModel.importBookshelf(it, selectedGroup.groupId)

@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.databinding.ItemBookshelfGridBinding import io.legado.app.databinding.ItemBookshelfGridBinding
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import splitties.views.onLongClick
class BooksAdapterGrid(context: Context, private val callBack: CallBack) : class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
BaseBooksAdapter<ItemBookshelfGridBinding>(context) { BaseBooksAdapter<ItemBookshelfGridBinding>(context) {
@ -59,11 +60,10 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
} }
} }
setOnLongClickListener { onLongClick {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.openBookInfo(it) callBack.openBookInfo(it)
} }
true
} }
} }
} }

@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.databinding.ItemBookshelfListBinding import io.legado.app.databinding.ItemBookshelfListBinding
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import splitties.views.onLongClick
class BooksAdapterList(context: Context, private val callBack: CallBack) : class BooksAdapterList(context: Context, private val callBack: CallBack) :
BaseBooksAdapter<ItemBookshelfListBinding>(context) { BaseBooksAdapter<ItemBookshelfListBinding>(context) {
@ -65,11 +66,10 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
} }
} }
setOnLongClickListener { onLongClick {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.openBookInfo(it) callBack.openBookInfo(it)
} }
true
} }
} }
} }

@ -144,19 +144,21 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
override fun open(book: Book) { override fun open(book: Book) {
when (book.type) { when (book.type) {
BookType.audio -> BookType.audio ->
startActivity<AudioPlayActivity>(Pair("bookUrl", book.bookUrl)) startActivity<AudioPlayActivity> {
else -> startActivity<ReadBookActivity>( putExtra("bookUrl", book.bookUrl)
Pair("bookUrl", book.bookUrl), }
Pair("key", IntentDataHelp.putData(book)) else -> startActivity<ReadBookActivity> {
) putExtra("bookUrl", book.bookUrl)
putExtra("key", IntentDataHelp.putData(book))
}
} }
} }
override fun openBookInfo(book: Book) { override fun openBookInfo(book: Book) {
startActivity<BookInfoActivity>( startActivity<BookInfoActivity> {
Pair("name", book.name), putExtra("name", book.name)
Pair("author", book.author) putExtra("author", book.author)
) }
} }
override fun isUpdate(bookUrl: String): Boolean { override fun isUpdate(bookUrl: String): Boolean {

@ -19,6 +19,7 @@ import io.legado.app.utils.dp
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.visible import io.legado.app.utils.visible
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import splitties.views.onLongClick
class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) :
RecyclerAdapter<BookSource, ItemFindBookBinding>(context) { RecyclerAdapter<BookSource, ItemFindBookBinding>(context) {
@ -104,9 +105,8 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
notifyItemChanged(position, false) notifyItemChanged(position, false)
} }
} }
llTitle.setOnLongClickListener { llTitle.onLongClick {
showMenu(llTitle, holder.layoutPosition) showMenu(llTitle, holder.layoutPosition)
true
} }
} }
} }

@ -151,15 +151,17 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
} }
override fun openExplore(sourceUrl: String, title: String, exploreUrl: String) { override fun openExplore(sourceUrl: String, title: String, exploreUrl: String) {
startActivity<ExploreShowActivity>( startActivity<ExploreShowActivity> {
Pair("exploreName", title), putExtra("exploreName", title)
Pair("sourceUrl", sourceUrl), putExtra("sourceUrl", sourceUrl)
Pair("exploreUrl", exploreUrl) putExtra("exploreUrl", exploreUrl)
) }
} }
override fun editSource(sourceUrl: String) { override fun editSource(sourceUrl: String) {
startActivity<BookSourceEditActivity>(Pair("data", sourceUrl)) startActivity<BookSourceEditActivity> {
putExtra("data", sourceUrl)
}
} }
override fun toTop(source: BookSource) { override fun toTop(source: BookSource) {

@ -135,15 +135,15 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FilePickerDialog.C
when (preference?.key) { when (preference?.key) {
"bookSourceManage" -> startActivity<BookSourceActivity>() "bookSourceManage" -> startActivity<BookSourceActivity>()
"replaceManage" -> startActivity<ReplaceRuleActivity>() "replaceManage" -> startActivity<ReplaceRuleActivity>()
"setting" -> startActivity<ConfigActivity>( "setting" -> startActivity<ConfigActivity> {
Pair("configType", ConfigViewModel.TYPE_CONFIG) putExtra("configType", ConfigViewModel.TYPE_CONFIG)
) }
"web_dav_setting" -> startActivity<ConfigActivity>( "web_dav_setting" -> startActivity<ConfigActivity> {
Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG) putExtra("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG)
) }
"theme_setting" -> startActivity<ConfigActivity>( "theme_setting" -> startActivity<ConfigActivity> {
Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG) putExtra("configType", ConfigViewModel.TYPE_THEME_CONFIG)
) }
"readRecord" -> startActivity<ReadRecordActivity>() "readRecord" -> startActivity<ReadRecordActivity>()
"donate" -> startActivity<DonateActivity>() "donate" -> startActivity<DonateActivity>()
"about" -> startActivity<AboutActivity>() "about" -> startActivity<AboutActivity>()

@ -10,6 +10,7 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.ItemRssBinding import io.legado.app.databinding.ItemRssBinding
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import splitties.views.onLongClick
class RssAdapter(context: Context, val callBack: CallBack) : class RssAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<RssSource, ItemRssBinding>(context) { RecyclerAdapter<RssSource, ItemRssBinding>(context) {
@ -41,11 +42,10 @@ class RssAdapter(context: Context, val callBack: CallBack) :
callBack.openRss(it) callBack.openRss(it)
} }
} }
root.setOnLongClickListener { root.onLongClick {
getItemByLayoutPosition(holder.layoutPosition)?.let { getItemByLayoutPosition(holder.layoutPosition)?.let {
showMenu(ivIcon, it) showMenu(ivIcon, it)
} }
true
} }
} }
} }

@ -144,12 +144,14 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
override fun openRss(rssSource: RssSource) { override fun openRss(rssSource: RssSource) {
if (rssSource.singleUrl) { if (rssSource.singleUrl) {
startActivity<ReadRssActivity>( startActivity<ReadRssActivity> {
Pair("title", rssSource.sourceName), putExtra("title", rssSource.sourceName)
Pair("origin", rssSource.sourceUrl) putExtra("origin", rssSource.sourceUrl)
) }
} else { } else {
startActivity<RssSortActivity>(Pair("url", rssSource.sourceUrl)) startActivity<RssSortActivity> {
putExtra("url", rssSource.sourceUrl)
}
} }
} }
@ -158,7 +160,9 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
} }
override fun edit(rssSource: RssSource) { override fun edit(rssSource: RssSource) {
startActivity<RssSourceEditActivity>(Pair("data", rssSource.sourceUrl)) startActivity<RssSourceEditActivity> {
putExtra("data", rssSource.sourceUrl)
}
} }
override fun del(rssSource: RssSource) { override fun del(rssSource: RssSource) {

@ -101,11 +101,11 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
private fun editGroup(group: String) { private fun editGroup(group: String) {
alert(title = getString(R.string.group_edit)) { alert(title = getString(R.string.group_edit)) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater) val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
customView = alertBinding.apply {
editView.hint = "分组名称" editView.hint = "分组名称"
editView.setText(group) editView.setText(group)
}.root }
customView { alertBinding.root }
yesButton { yesButton {
viewModel.upGroup(group, alertBinding.editView.text?.toString()) viewModel.upGroup(group, alertBinding.editView.text?.toString())
} }

@ -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.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import java.io.File import java.io.File
/** /**
@ -229,7 +227,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
val text = alertBinding.editView.text?.toString() val text = alertBinding.editView.text?.toString()
text?.let { text?.let {
@ -237,7 +235,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
startActivity<ImportReplaceRuleActivity>("source" to it) startActivity<ImportReplaceRuleActivity> {
putExtra("source", it)
}
} }
} }
cancelButton() cancelButton()
@ -266,7 +266,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
kotlin.runCatching { kotlin.runCatching {
uri.readText(this)?.let { uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it) val dataKey = IntentDataHelp.putData(it)
startActivity<ImportReplaceRuleActivity>("dataKey" to dataKey) startActivity<ImportReplaceRuleActivity> {
putExtra("dataKey", dataKey)
}
} }
}.onFailure { }.onFailure {
toastOnUi("readTextError:${it.localizedMessage}") toastOnUi("readTextError:${it.localizedMessage}")
@ -275,7 +277,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
} }
importRequestCodeQr -> if (resultCode == Activity.RESULT_OK) { importRequestCodeQr -> if (resultCode == Activity.RESULT_OK) {
data?.getStringExtra("result")?.let { data?.getStringExtra("result")?.let {
startActivity<ImportReplaceRuleActivity>("source" to it) startActivity<ImportReplaceRuleActivity> {
putExtra("source", it)
}
} }
} }
exportRequestCode -> if (resultCode == RESULT_OK) { exportRequestCode -> if (resultCode == RESULT_OK) {

@ -17,13 +17,13 @@ import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceEditBinding 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.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog 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.postEvent
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import org.jetbrains.anko.displayMetrics
import org.jetbrains.anko.selector
import kotlin.math.abs import kotlin.math.abs
/** /**
@ -171,7 +171,7 @@ class ReplaceEditActivity :
val rect = Rect() val rect = Rect()
// 获取当前页面窗口的显示范围 // 获取当前页面窗口的显示范围
window.decorView.getWindowVisibleDisplayFrame(rect) window.decorView.getWindowVisibleDisplayFrame(rect)
val screenHeight = this.displayMetrics.heightPixels val screenHeight = this.getSize().heightPixels
val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
val preShowing = mIsSoftKeyBoardShowing val preShowing = mIsSoftKeyBoardShowing
if (abs(keyboardHeight) > screenHeight / 5) { if (abs(keyboardHeight) > screenHeight / 5) {

@ -125,10 +125,10 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme
override fun readRss(rssArticle: RssArticle) { override fun readRss(rssArticle: RssArticle) {
activityViewModel.read(rssArticle) activityViewModel.read(rssArticle)
startActivity<ReadRssActivity>( startActivity<ReadRssActivity> {
Pair("title", rssArticle.title), putExtra("title", rssArticle.title)
Pair("origin", rssArticle.origin), putExtra("origin", rssArticle.origin)
Pair("link", rssArticle.link) putExtra("link", rssArticle.link)
) }
} }
} }

@ -13,10 +13,9 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityRssArtivlesBinding import io.legado.app.databinding.ActivityRssArtivlesBinding
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.startActivityForResult
import io.legado.app.utils.visible import io.legado.app.utils.visible
import org.jetbrains.anko.startActivityForResult
class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewModel>() { class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewModel>() {
@ -50,7 +49,9 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_edit_source -> viewModel.rssSource?.sourceUrl?.let { R.id.menu_edit_source -> viewModel.rssSource?.sourceUrl?.let {
startActivityForResult<RssSourceEditActivity>(editSource, Pair("data", it)) startActivityForResult<RssSourceEditActivity>(editSource) {
putExtra("data", it)
}
} }
R.id.menu_clear -> { R.id.menu_clear -> {
viewModel.url?.let { viewModel.url?.let {

@ -9,7 +9,7 @@ import io.legado.app.data.entities.RssStar
import io.legado.app.databinding.ActivityRssFavoritesBinding import io.legado.app.databinding.ActivityRssFavoritesBinding
import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.rss.read.ReadRssActivity
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import org.jetbrains.anko.startActivity import io.legado.app.utils.startActivity
class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>(), class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>(),
@ -45,10 +45,10 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>(),
} }
override fun readRss(rssStar: RssStar) { override fun readRss(rssStar: RssStar) {
startActivity<ReadRssActivity>( startActivity<ReadRssActivity> {
Pair("title", rssStar.title), putExtra("title", rssStar.title)
Pair("origin", rssStar.origin), putExtra("origin", rssStar.origin)
Pair("link", rssStar.link) putExtra("link", rssStar.link)
) }
} }
} }

@ -26,8 +26,8 @@ import io.legado.app.ui.filepicker.FilePickerDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.apache.commons.text.StringEscapeUtils import org.apache.commons.text.StringEscapeUtils
import org.jetbrains.anko.share
import org.jsoup.Jsoup import org.jsoup.Jsoup
import splitties.systemservices.downloadManager
class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>(false), class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>(false),

@ -18,13 +18,13 @@ import io.legado.app.data.entities.RssSource
import io.legado.app.databinding.ActivityRssSourceEditBinding import io.legado.app.databinding.ActivityRssSourceEditBinding
import io.legado.app.help.LocalConfig import io.legado.app.help.LocalConfig
import io.legado.app.lib.dialogs.alert 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.ATH
import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity
import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.*
import kotlin.math.abs import kotlin.math.abs
class RssSourceEditActivity : class RssSourceEditActivity :
@ -63,7 +63,7 @@ class RssSourceEditActivity :
val source = getRssSource() val source = getRssSource()
if (!source.equal(viewModel.rssSource)) { if (!source.equal(viewModel.rssSource)) {
alert(R.string.exit) { alert(R.string.exit) {
messageResource = R.string.exit_no_save setMessage(R.string.exit_no_save)
positiveButton(R.string.yes) positiveButton(R.string.yes)
negativeButton(R.string.no) { negativeButton(R.string.no) {
super.finish() super.finish()
@ -100,7 +100,9 @@ class RssSourceEditActivity :
val source = getRssSource() val source = getRssSource()
if (checkSource(source)) { if (checkSource(source)) {
viewModel.save(source) { viewModel.save(source) {
startActivity<RssSourceDebugActivity>(Pair("key", source.sourceUrl)) startActivity<RssSourceDebugActivity> {
putExtra("key", source.sourceUrl)
}
} }
} }
} }
@ -249,7 +251,7 @@ class RssSourceEditActivity :
val rect = Rect() val rect = Rect()
// 获取当前页面窗口的显示范围 // 获取当前页面窗口的显示范围
window.decorView.getWindowVisibleDisplayFrame(rect) window.decorView.getWindowVisibleDisplayFrame(rect)
val screenHeight = this@RssSourceEditActivity.displayMetrics.heightPixels val screenHeight = this@RssSourceEditActivity.getSize().heightPixels
val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
val preShowing = mIsSoftKeyBoardShowing val preShowing = mIsSoftKeyBoardShowing
if (abs(keyboardHeight) > screenHeight / 5) { if (abs(keyboardHeight) > screenHeight / 5) {

@ -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.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import java.io.File import java.io.File
@ -245,7 +243,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
val text = alertBinding.editView.text?.toString() val text = alertBinding.editView.text?.toString()
text?.let { text?.let {
@ -253,7 +251,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
cacheUrls.add(0, it) cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(",")) aCache.put(importRecordKey, cacheUrls.joinToString(","))
} }
startActivity<ImportRssSourceActivity>("source" to it) startActivity<ImportRssSourceActivity> {
putExtra("source", it)
}
} }
} }
cancelButton() cancelButton()
@ -268,7 +268,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
kotlin.runCatching { kotlin.runCatching {
uri.readText(this)?.let { uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it) val dataKey = IntentDataHelp.putData(it)
startActivity<ImportRssSourceActivity>("dataKey" to dataKey) startActivity<ImportRssSourceActivity> {
putExtra("dataKey", dataKey)
}
} }
}.onFailure { }.onFailure {
toastOnUi("readTextError:${it.localizedMessage}") toastOnUi("readTextError:${it.localizedMessage}")
@ -277,7 +279,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
} }
qrRequestCode -> if (resultCode == RESULT_OK) { qrRequestCode -> if (resultCode == RESULT_OK) {
data?.getStringExtra("result")?.let { data?.getStringExtra("result")?.let {
startActivity<ImportRssSourceActivity>("source" to it) startActivity<ImportRssSourceActivity> {
putExtra("source", it)
}
} }
} }
exportRequestCode -> if (resultCode == RESULT_OK) { exportRequestCode -> if (resultCode == RESULT_OK) {
@ -301,7 +305,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
} }
override fun edit(source: RssSource) { override fun edit(source: RssSource) {
startActivity<RssSourceEditActivity>(Pair("data", source.sourceUrl)) startActivity<RssSourceEditActivity> {
putExtra("data", source.sourceUrl)
}
} }
override fun update(vararg source: RssSource) { override fun update(vararg source: RssSource) {

@ -17,9 +17,9 @@ import io.legado.app.ui.association.ImportBookSourceActivity
import io.legado.app.ui.association.ImportReplaceRuleActivity import io.legado.app.ui.association.ImportReplaceRuleActivity
import io.legado.app.ui.association.ImportRssSourceActivity import io.legado.app.ui.association.ImportRssSourceActivity
import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.startActivity
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity
/** /**
* 规则订阅界面 * 规则订阅界面
@ -74,13 +74,19 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun openSubscription(ruleSub: RuleSub) { override fun openSubscription(ruleSub: RuleSub) {
when (ruleSub.type) { when (ruleSub.type) {
0 -> { 0 -> {
startActivity<ImportBookSourceActivity>("source" to ruleSub.url) startActivity<ImportBookSourceActivity> {
putExtra("source", ruleSub.url)
}
} }
1 -> { 1 -> {
startActivity<ImportRssSourceActivity>("source" to ruleSub.url) startActivity<ImportRssSourceActivity> {
putExtra("source", ruleSub.url)
}
} }
2 -> { 2 -> {
startActivity<ImportReplaceRuleActivity>("source" to ruleSub.url) startActivity<ImportReplaceRuleActivity> {
putExtra("source", ruleSub.url)
}
} }
} }
} }
@ -92,7 +98,7 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
etName.setText(ruleSub.name) etName.setText(ruleSub.name)
etUrl.setText(ruleSub.url) etUrl.setText(ruleSub.url)
} }
customView = alertBinding.root customView { alertBinding.root }
okButton { okButton {
ruleSub.type = alertBinding.spType.selectedItemPosition ruleSub.type = alertBinding.spType.selectedItemPosition
ruleSub.name = alertBinding.etName.text?.toString() ?: "" ruleSub.name = alertBinding.etName.text?.toString() ?: ""

@ -14,7 +14,7 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.main.MainActivity import io.legado.app.ui.main.MainActivity
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import org.jetbrains.anko.startActivity import io.legado.app.utils.startActivity
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() { open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {

@ -17,6 +17,7 @@ import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import splitties.views.onLongClick
import kotlin.math.roundToInt import kotlin.math.roundToInt
class Preference(context: Context, attrs: AttributeSet) : class Preference(context: Context, attrs: AttributeSet) :
@ -115,9 +116,8 @@ class Preference(context: Context, attrs: AttributeSet) :
isBottomBackground = isBottomBackground isBottomBackground = isBottomBackground
) )
super.onBindViewHolder(holder) super.onBindViewHolder(holder)
holder?.itemView?.setOnLongClickListener { holder?.itemView?.onLongClick {
onLongClick?.invoke() onLongClick?.invoke()
true
} }
} }

@ -1,12 +1,20 @@
package io.legado.app.utils package io.legado.app.utils
import android.app.Activity import android.app.Activity
import android.content.Intent
import android.os.Build import android.os.Build
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.WindowInsets import android.view.WindowInsets
import android.view.WindowMetrics import android.view.WindowMetrics
inline fun <reified A : Activity> Activity.startActivityForResult(
requestCode: Int,
configIntent: Intent.() -> Unit = {}
) {
startActivityForResult(Intent(this, A::class.java).apply(configIntent), requestCode)
}
fun Activity.getSize(): DisplayMetrics { fun Activity.getSize(): DisplayMetrics {
val displayMetrics = DisplayMetrics() val displayMetrics = DisplayMetrics()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {

@ -3,14 +3,14 @@
package io.legado.app.utils package io.legado.app.utils
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.DownloadManager import android.app.Activity
import android.app.Service
import android.content.* import android.content.*
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.ConnectivityManager
import android.net.Uri import android.net.Uri
import android.os.BatteryManager import android.os.BatteryManager
import android.provider.Settings import android.provider.Settings
@ -24,16 +24,16 @@ import androidx.core.content.edit
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.R import io.legado.app.R
import org.jetbrains.anko.longToast
import org.jetbrains.anko.runOnUiThread
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
val Context.downloadManager inline fun <reified A : Activity> Context.startActivity(configIntent: Intent.() -> Unit = {}) {
get() = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager startActivity(Intent(this, A::class.java).apply(configIntent))
}
val Context.connectivityManager inline fun <reified T : Service> Context.startService(configIntent: Intent.() -> Unit = {}) {
get() = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager startService(Intent(this, T::class.java).apply(configIntent))
}
fun Context.toastOnUi(message: Int) { fun Context.toastOnUi(message: Int) {
runOnUiThread { runOnUiThread {
@ -135,6 +135,21 @@ val Context.navigationBarHeight: Int
return resources.getDimensionPixelSize(resourceId) 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") @SuppressLint("SetWorldReadable")
fun Context.shareWithQr(title: String, text: String) { fun Context.shareWithQr(title: String, text: String) {
val bitmap = QRCodeUtils.createQRCode(text) val bitmap = QRCodeUtils.createQRCode(text)
@ -170,7 +185,7 @@ fun Context.sendToClip(text: String) {
val clipData = ClipData.newPlainText(null, text) val clipData = ClipData.newPlainText(null, text)
clipboard?.let { clipboard?.let {
clipboard.setPrimaryClip(clipData) clipboard.setPrimaryClip(clipData)
longToast(R.string.copy_complete) longToastOnUi(R.string.copy_complete)
} }
} }

@ -3,7 +3,6 @@
package io.legado.app.utils package io.legado.app.utils
import android.app.Activity import android.app.Activity
import android.app.Service
import android.content.Intent import android.content.Intent
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
@ -11,12 +10,10 @@ import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.content.edit import androidx.core.content.edit
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import org.jetbrains.anko.defaultSharedPreferences import splitties.systemservices.connectivityManager
import org.jetbrains.anko.internals.AnkoInternals
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
fun Fragment.isOnline() = fun Fragment.isOnline() = connectivityManager.activeNetworkInfo?.isConnected == true
requireContext().connectivityManager.activeNetworkInfo?.isConnected == true
fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) =
requireContext().defaultSharedPreferences.getBoolean(key, defValue) requireContext().defaultSharedPreferences.getBoolean(key, defValue)
@ -62,22 +59,15 @@ fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? =
fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? =
requireContext().getCompatColorStateList(id) requireContext().getCompatColorStateList(id)
inline fun <reified T : Activity> Fragment.startActivity(vararg params: Pair<String, Any?>) = inline fun <reified T : Activity> Fragment.startActivity(
AnkoInternals.internalStartActivity(requireActivity(), T::class.java, params) configIntent: Intent.() -> Unit = {}
) {
startActivity(Intent(requireContext(), T::class.java).apply(configIntent))
}
inline fun <reified T : Activity> Fragment.startActivityForResult( inline fun <reified T : Activity> Fragment.startActivityForResult(
requestCode: Int, requestCode: Int,
vararg params: Pair<String, Any?> configIntent: Intent.() -> Unit = {}
) = startActivityForResult( ) {
AnkoInternals.createIntent(requireActivity(), T::class.java, params), startActivityForResult(Intent(requireContext(), T::class.java).apply(configIntent), requestCode)
requestCode }
)
inline fun <reified T : Service> Fragment.startService(vararg params: Pair<String, Any?>) =
AnkoInternals.internalStartService(requireActivity(), T::class.java, params)
inline fun <reified T : Service> Fragment.stopService(vararg params: Pair<String, Any?>) =
AnkoInternals.internalStopService(requireActivity(), T::class.java, params)
inline fun <reified T : Any> Fragment.intentFor(vararg params: Pair<String, Any?>): Intent =
AnkoInternals.createIntent(requireActivity(), T::class.java, params)

@ -3,7 +3,6 @@ package io.legado.app.utils
import com.google.gson.* import com.google.gson.*
import com.google.gson.internal.LinkedTreeMap import com.google.gson.internal.LinkedTreeMap
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import org.jetbrains.anko.attempt
import java.lang.reflect.ParameterizedType import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type import java.lang.reflect.Type
import kotlin.math.ceil import kotlin.math.ceil
@ -24,17 +23,15 @@ val GSON: Gson by lazy {
inline fun <reified T> genericType(): Type = object : TypeToken<T>() {}.type inline fun <reified T> genericType(): Type = object : TypeToken<T>() {}.type
inline fun <reified T> Gson.fromJsonObject(json: String?): T? {//可转成任意类型 inline fun <reified T> Gson.fromJsonObject(json: String?): T? {//可转成任意类型
return attempt { return kotlin.runCatching {
val result: T? = fromJson(json, genericType<T>()) fromJson(json, genericType<T>()) as? T
result }.getOrNull()
}.value
} }
inline fun <reified T> Gson.fromJsonArray(json: String?): List<T>? { inline fun <reified T> Gson.fromJsonArray(json: String?): List<T>? {
return attempt { return kotlin.runCatching {
val result: List<T>? = fromJson(json, ParameterizedTypeImpl(T::class.java)) fromJson(json, ParameterizedTypeImpl(T::class.java)) as? List<T>
result }.getOrNull()
}.value
} }
class ParameterizedTypeImpl(private val clazz: Class<*>) : ParameterizedType { class ParameterizedTypeImpl(private val clazz: Class<*>) : ParameterizedType {

@ -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)
}
}

@ -4,7 +4,6 @@ package io.legado.app.utils
import android.widget.Toast import android.widget.Toast
import androidx.fragment.app.Fragment 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. * @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. * Display the simple Toast message with the [Toast.LENGTH_LONG] duration.
* *
* @param message the message text. * @param message the message text.
*/ */
fun Fragment.longToast(message: CharSequence) = requireActivity().longToast(message) fun Fragment.longToast(message: CharSequence) = requireContext().longToastOnUi(message)

Loading…
Cancel
Save