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.fragment:fragment-ktx:1.2.5"
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation "androidx.collection:collection-ktx:1.1.0"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
@ -138,7 +139,11 @@ dependencies {
implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation "org.jetbrains.anko:anko-sdk27:0.10.8"
//Splitties
def splitties_version = '2.1.1'
implementation("com.louiscad.splitties:splitties-appctx:$splitties_version")
implementation("com.louiscad.splitties:splitties-systemservices:$splitties_version")
implementation("com.louiscad.splitties:splitties-views:$splitties_version")
//lifecycle
def lifecycle_version = '2.2.0'

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -30,8 +30,6 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.jetbrains.anko.startActivity
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
BookAdapter.CallBack,
HistoryKeyAdapter.CallBack,
@ -333,10 +331,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
override fun showBookInfo(name: String, author: String) {
viewModel.getSearchBook(name, author) { searchBook ->
searchBook?.let {
startActivity<BookInfoActivity>(
Pair("name", it.name),
Pair("author", it.author)
)
startActivity<BookInfoActivity> {
putExtra("name", it.name)
putExtra("author", it.author)
}
}
}
}
@ -345,10 +343,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
* 显示书籍详情
*/
override fun showBookInfo(book: Book) {
startActivity<BookInfoActivity>(
Pair("name", book.name),
Pair("author", book.author)
)
startActivity<BookInfoActivity> {
putExtra("name", book.name)
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.ui.qrcode.QrCodeActivity
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.startActivityForResult
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivityForResult
class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() {

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

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

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

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

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

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

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

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

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

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

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

@ -144,19 +144,21 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
override fun open(book: Book) {
when (book.type) {
BookType.audio ->
startActivity<AudioPlayActivity>(Pair("bookUrl", book.bookUrl))
else -> startActivity<ReadBookActivity>(
Pair("bookUrl", book.bookUrl),
Pair("key", IntentDataHelp.putData(book))
)
startActivity<AudioPlayActivity> {
putExtra("bookUrl", book.bookUrl)
}
else -> startActivity<ReadBookActivity> {
putExtra("bookUrl", book.bookUrl)
putExtra("key", IntentDataHelp.putData(book))
}
}
}
override fun openBookInfo(book: Book) {
startActivity<BookInfoActivity>(
Pair("name", book.name),
Pair("author", book.author)
)
startActivity<BookInfoActivity> {
putExtra("name", book.name)
putExtra("author", book.author)
}
}
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.visible
import kotlinx.coroutines.CoroutineScope
import splitties.views.onLongClick
class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) :
RecyclerAdapter<BookSource, ItemFindBookBinding>(context) {
@ -104,9 +105,8 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
notifyItemChanged(position, false)
}
}
llTitle.setOnLongClickListener {
llTitle.onLongClick {
showMenu(llTitle, holder.layoutPosition)
true
}
}
}

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

@ -135,15 +135,15 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FilePickerDialog.C
when (preference?.key) {
"bookSourceManage" -> startActivity<BookSourceActivity>()
"replaceManage" -> startActivity<ReplaceRuleActivity>()
"setting" -> startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_CONFIG)
)
"web_dav_setting" -> startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG)
)
"theme_setting" -> startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG)
)
"setting" -> startActivity<ConfigActivity> {
putExtra("configType", ConfigViewModel.TYPE_CONFIG)
}
"web_dav_setting" -> startActivity<ConfigActivity> {
putExtra("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG)
}
"theme_setting" -> startActivity<ConfigActivity> {
putExtra("configType", ConfigViewModel.TYPE_THEME_CONFIG)
}
"readRecord" -> startActivity<ReadRecordActivity>()
"donate" -> startActivity<DonateActivity>()
"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.databinding.ItemRssBinding
import io.legado.app.help.ImageLoader
import splitties.views.onLongClick
class RssAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<RssSource, ItemRssBinding>(context) {
@ -41,11 +42,10 @@ class RssAdapter(context: Context, val callBack: CallBack) :
callBack.openRss(it)
}
}
root.setOnLongClickListener {
root.onLongClick {
getItemByLayoutPosition(holder.layoutPosition)?.let {
showMenu(ivIcon, it)
}
true
}
}
}

@ -144,12 +144,14 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
override fun openRss(rssSource: RssSource) {
if (rssSource.singleUrl) {
startActivity<ReadRssActivity>(
Pair("title", rssSource.sourceName),
Pair("origin", rssSource.sourceUrl)
)
startActivity<ReadRssActivity> {
putExtra("title", rssSource.sourceName)
putExtra("origin", rssSource.sourceUrl)
}
} 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) {
startActivity<RssSourceEditActivity>(Pair("data", rssSource.sourceUrl))
startActivity<RssSourceEditActivity> {
putExtra("data", rssSource.sourceUrl)
}
}
override fun del(rssSource: RssSource) {

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

@ -38,8 +38,6 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import java.io.File
/**
@ -229,7 +227,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
}
customView = alertBinding.root
customView { alertBinding.root }
okButton {
val text = alertBinding.editView.text?.toString()
text?.let {
@ -237,7 +235,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
startActivity<ImportReplaceRuleActivity>("source" to it)
startActivity<ImportReplaceRuleActivity> {
putExtra("source", it)
}
}
}
cancelButton()
@ -266,7 +266,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
kotlin.runCatching {
uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it)
startActivity<ImportReplaceRuleActivity>("dataKey" to dataKey)
startActivity<ImportReplaceRuleActivity> {
putExtra("dataKey", dataKey)
}
}
}.onFailure {
toastOnUi("readTextError:${it.localizedMessage}")
@ -275,7 +277,9 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
}
importRequestCodeQr -> if (resultCode == Activity.RESULT_OK) {
data?.getStringExtra("result")?.let {
startActivity<ImportReplaceRuleActivity>("source" to it)
startActivity<ImportReplaceRuleActivity> {
putExtra("source", it)
}
}
}
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.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceEditBinding
import io.legado.app.lib.dialogs.selector
import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.getSize
import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUi
import org.jetbrains.anko.displayMetrics
import org.jetbrains.anko.selector
import kotlin.math.abs
/**
@ -171,7 +171,7 @@ class ReplaceEditActivity :
val rect = Rect()
// 获取当前页面窗口的显示范围
window.decorView.getWindowVisibleDisplayFrame(rect)
val screenHeight = this.displayMetrics.heightPixels
val screenHeight = this.getSize().heightPixels
val keyboardHeight = screenHeight - rect.bottom // 输入法的高度
val preShowing = mIsSoftKeyBoardShowing
if (abs(keyboardHeight) > screenHeight / 5) {

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

@ -13,10 +13,9 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityRssArtivlesBinding
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.utils.gone
import io.legado.app.utils.startActivityForResult
import io.legado.app.utils.visible
import org.jetbrains.anko.startActivityForResult
class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewModel>() {
@ -50,7 +49,9 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
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 -> {
viewModel.url?.let {

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

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

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

@ -35,8 +35,6 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import java.io.File
@ -245,7 +243,7 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
}
customView = alertBinding.root
customView { alertBinding.root }
okButton {
val text = alertBinding.editView.text?.toString()
text?.let {
@ -253,7 +251,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
cacheUrls.add(0, it)
aCache.put(importRecordKey, cacheUrls.joinToString(","))
}
startActivity<ImportRssSourceActivity>("source" to it)
startActivity<ImportRssSourceActivity> {
putExtra("source", it)
}
}
}
cancelButton()
@ -268,7 +268,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
kotlin.runCatching {
uri.readText(this)?.let {
val dataKey = IntentDataHelp.putData(it)
startActivity<ImportRssSourceActivity>("dataKey" to dataKey)
startActivity<ImportRssSourceActivity> {
putExtra("dataKey", dataKey)
}
}
}.onFailure {
toastOnUi("readTextError:${it.localizedMessage}")
@ -277,7 +279,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
}
qrRequestCode -> if (resultCode == RESULT_OK) {
data?.getStringExtra("result")?.let {
startActivity<ImportRssSourceActivity>("source" to it)
startActivity<ImportRssSourceActivity> {
putExtra("source", it)
}
}
}
exportRequestCode -> if (resultCode == RESULT_OK) {
@ -301,7 +305,9 @@ class RssSourceActivity : VMBaseActivity<ActivityRssSourceBinding, RssSourceView
}
override fun edit(source: RssSource) {
startActivity<RssSourceEditActivity>(Pair("data", source.sourceUrl))
startActivity<RssSourceEditActivity> {
putExtra("data", source.sourceUrl)
}
}
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.ImportRssSourceActivity
import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.utils.startActivity
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity
/**
* 规则订阅界面
@ -74,13 +74,19 @@ class RuleSubActivity : BaseActivity<ActivityRuleSubBinding>(),
override fun openSubscription(ruleSub: RuleSub) {
when (ruleSub.type) {
0 -> {
startActivity<ImportBookSourceActivity>("source" to ruleSub.url)
startActivity<ImportBookSourceActivity> {
putExtra("source", ruleSub.url)
}
}
1 -> {
startActivity<ImportRssSourceActivity>("source" to ruleSub.url)
startActivity<ImportRssSourceActivity> {
putExtra("source", ruleSub.url)
}
}
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)
etUrl.setText(ruleSub.url)
}
customView = alertBinding.root
customView { alertBinding.root }
okButton {
ruleSub.type = alertBinding.spType.selectedItemPosition
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.main.MainActivity
import io.legado.app.utils.getPrefBoolean
import org.jetbrains.anko.startActivity
import io.legado.app.utils.startActivity
import java.util.concurrent.TimeUnit
open class WelcomeActivity : BaseActivity<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.getSecondaryTextColor
import io.legado.app.utils.ColorUtils
import splitties.views.onLongClick
import kotlin.math.roundToInt
class Preference(context: Context, attrs: AttributeSet) :
@ -115,9 +116,8 @@ class Preference(context: Context, attrs: AttributeSet) :
isBottomBackground = isBottomBackground
)
super.onBindViewHolder(holder)
holder?.itemView?.setOnLongClickListener {
holder?.itemView?.onLongClick {
onLongClick?.invoke()
true
}
}

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

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

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

@ -3,7 +3,6 @@ package io.legado.app.utils
import com.google.gson.*
import com.google.gson.internal.LinkedTreeMap
import com.google.gson.reflect.TypeToken
import org.jetbrains.anko.attempt
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import kotlin.math.ceil
@ -24,17 +23,15 @@ val GSON: Gson by lazy {
inline fun <reified T> genericType(): Type = object : TypeToken<T>() {}.type
inline fun <reified T> Gson.fromJsonObject(json: String?): T? {//可转成任意类型
return attempt {
val result: T? = fromJson(json, genericType<T>())
result
}.value
return kotlin.runCatching {
fromJson(json, genericType<T>()) as? T
}.getOrNull()
}
inline fun <reified T> Gson.fromJsonArray(json: String?): List<T>? {
return attempt {
val result: List<T>? = fromJson(json, ParameterizedTypeImpl(T::class.java))
result
}.value
return kotlin.runCatching {
fromJson(json, ParameterizedTypeImpl(T::class.java)) as? List<T>
}.getOrNull()
}
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 androidx.fragment.app.Fragment
import org.jetbrains.anko.longToast
/**
@ -26,11 +25,11 @@ fun Fragment.toastOnUi(message: CharSequence) = requireActivity().toastOnUi(mess
*
* @param message the message text resource.
*/
fun Fragment.longToast(message: Int) = requireActivity().longToast(message)
fun Fragment.longToast(message: Int) = requireContext().longToastOnUi(message)
/**
* Display the simple Toast message with the [Toast.LENGTH_LONG] duration.
*
* @param message the message text.
*/
fun Fragment.longToast(message: CharSequence) = requireActivity().longToast(message)
fun Fragment.longToast(message: CharSequence) = requireContext().longToastOnUi(message)

Loading…
Cancel
Save