delete anko:anko-sdk27-coroutines

pull/840/head
gedoor 4 years ago
parent ca6b4ced1d
commit a03eba41d7
  1. 13
      app/build.gradle
  2. 2
      app/src/main/java/io/legado/app/App.kt
  3. 29
      app/src/main/java/io/legado/app/base/BaseViewModel.kt
  4. 6
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  5. 6
      app/src/main/java/io/legado/app/help/IntentHelp.kt
  6. 4
      app/src/main/java/io/legado/app/help/LauncherIconHelp.kt
  7. 6
      app/src/main/java/io/legado/app/help/SourceHelp.kt
  8. 4
      app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt
  9. 7
      app/src/main/java/io/legado/app/help/storage/BookWebDav.kt
  10. 28
      app/src/main/java/io/legado/app/help/storage/ImportOldData.kt
  11. 3
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  12. 4
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  13. 10
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  14. 4
      app/src/main/java/io/legado/app/service/CacheBookService.kt
  15. 4
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  16. 6
      app/src/main/java/io/legado/app/service/DownloadService.kt
  17. 12
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  18. 4
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  19. 7
      app/src/main/java/io/legado/app/service/WebService.kt
  20. 4
      app/src/main/java/io/legado/app/service/help/CheckSource.kt
  21. 4
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  22. 4
      app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
  23. 5
      app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt
  24. 4
      app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt
  25. 4
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt
  26. 6
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  27. 4
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
  28. 4
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt
  29. 5
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  30. 19
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  31. 4
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt
  32. 10
      app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt
  33. 6
      app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt
  34. 4
      app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt
  35. 7
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt
  36. 6
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  37. 4
      app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt
  38. 6
      app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt
  39. 8
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  40. 28
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  41. 16
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  42. 8
      app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt
  43. 10
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  44. 6
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  45. 4
      app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt
  46. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  47. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  48. 39
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  49. 17
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  50. 10
      app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt
  51. 4
      app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt
  52. 26
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  53. 4
      app/src/main/java/io/legado/app/ui/book/read/config/ChineseConverter.kt
  54. 20
      app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt
  55. 4
      app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt
  56. 22
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  57. 21
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  58. 14
      app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt
  59. 4
      app/src/main/java/io/legado/app/ui/book/read/config/TextFontWeightConverter.kt
  60. 23
      app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt
  61. 12
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  62. 7
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  63. 4
      app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt
  64. 8
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  65. 6
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  66. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  67. 11
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  68. 4
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt
  69. 4
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt
  70. 4
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  71. 8
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  72. 5
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  73. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  74. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt
  75. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt
  76. 7
      app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt
  77. 4
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt
  78. 8
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt
  79. 11
      app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt
  80. 4
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  81. 14
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  82. 10
      app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt
  83. 4
      app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt
  84. 4
      app/src/main/java/io/legado/app/ui/filepicker/adapter/FileAdapter.kt
  85. 4
      app/src/main/java/io/legado/app/ui/filepicker/adapter/PathAdapter.kt
  86. 4
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  87. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  88. 10
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
  89. 7
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt
  90. 7
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt
  91. 9
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  92. 7
      app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt
  93. 4
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  94. 6
      app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt
  95. 3
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  96. 8
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt
  97. 14
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt
  98. 7
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  99. 10
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt
  100. 10
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt
  101. Some files were not shown because too many files have changed in this diff Show More

@ -125,17 +125,21 @@ dependencies {
implementation 'com.google.firebase:firebase-crashlytics-ktx:17.3.0' implementation 'com.google.firebase:firebase-crashlytics-ktx:17.3.0'
//androidX //androidX
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.media:media:1.2.1' implementation 'androidx.core:core-ktx:1.3.2'
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.preference:preference-ktx:1.1.1'
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'
implementation 'androidx.media:media:1.2.1'
implementation 'com.google.android.material:material:1.2.1' implementation 'com.google.android.material:material:1.2.1'
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"
//lifecycle //lifecycle
def lifecycle_version = '2.2.0' def lifecycle_version = '2.2.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
@ -150,11 +154,6 @@ dependencies {
//paging //paging
implementation 'androidx.paging:paging-runtime-ktx:2.1.2' implementation 'androidx.paging:paging-runtime-ktx:2.1.2'
//anko
def anko_version = '0.10.8'
implementation "org.jetbrains.anko:anko-sdk27:$anko_version"
implementation "org.jetbrains.anko:anko-sdk27-coroutines:$anko_version"
//liveEventBus //liveEventBus
implementation 'com.jeremyliao:live-event-bus-x:1.5.7' implementation 'com.jeremyliao:live-event-bus-x:1.5.7'

@ -18,8 +18,8 @@ import io.legado.app.data.AppDatabase
import io.legado.app.help.* import io.legado.app.help.*
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.utils.LanguageUtils import io.legado.app.utils.LanguageUtils
import io.legado.app.utils.defaultSharedPreferences
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import org.jetbrains.anko.defaultSharedPreferences
import rxhttp.wrapper.param.RxHttp import rxhttp.wrapper.param.RxHttp
@Suppress("DEPRECATION") @Suppress("DEPRECATION")

@ -6,15 +6,13 @@ import androidx.annotation.CallSuper
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import io.legado.app.App import io.legado.app.App
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.toastOnUI
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.toast
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@Suppress("unused") @Suppress("unused")
open class BaseViewModel(application: Application) : AndroidViewModel(application), open class BaseViewModel(application: Application) : AndroidViewModel(application),
CoroutineScope by MainScope(), CoroutineScope by MainScope() {
AnkoLogger {
val context: Context by lazy { this.getApplication<App>() } val context: Context by lazy { this.getApplication<App>() }
@ -40,27 +38,12 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio
cancel() cancel()
} }
open fun toast(message: Int) { open fun toastOnUI(message: Int) {
launch { context.toastOnUI(message)
context.toast(message)
}
} }
open fun toast(message: CharSequence?) { open fun toastOnUI(message: CharSequence?) {
launch { context.toastOnUI(message ?: toString())
context.toast(message ?: toString())
}
} }
open fun longToast(message: Int) {
launch {
context.toast(message)
}
}
open fun longToast(message: CharSequence?) {
launch {
context.toast(message ?: toString())
}
}
} }

@ -4,9 +4,9 @@ import com.hankcs.hanlp.HanLP
import io.legado.app.App import io.legado.app.App
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.toastOnUI
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.toast
class ContentProcessor(private val bookName: String, private val bookOrigin: String) { class ContentProcessor(private val bookName: String, private val bookOrigin: String) {
@ -40,7 +40,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
} }
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
App.INSTANCE.toast("${item.name}替换出错") App.INSTANCE.toastOnUI("${item.name}替换出错")
} }
} }
} }
@ -57,7 +57,7 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
} }
} catch (e: Exception) { } catch (e: Exception) {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
App.INSTANCE.toast("简繁转换出错") App.INSTANCE.toastOnUI("简繁转换出错")
} }
} }
} }

@ -5,7 +5,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import io.legado.app.R import io.legado.app.R
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
@Suppress("unused") @Suppress("unused")
object IntentHelp { object IntentHelp {
@ -19,7 +19,7 @@ object IntentHelp {
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent) context.startActivity(intent)
}.onFailure { }.onFailure {
context.toast(R.string.tip_cannot_jump_setting_page) context.toastOnUI(R.string.tip_cannot_jump_setting_page)
} }
} }
@ -30,7 +30,7 @@ object IntentHelp {
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent) context.startActivity(intent)
}.onFailure { }.onFailure {
context.toast("无法打开设置") context.toastOnUI("无法打开设置")
} }
} }

@ -6,7 +6,7 @@ import android.os.Build
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.ui.welcome.* import io.legado.app.ui.welcome.*
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
/** /**
* Created by GKF on 2018/2/27. * Created by GKF on 2018/2/27.
@ -26,7 +26,7 @@ object LauncherIconHelp {
fun changeIcon(icon: String?) { fun changeIcon(icon: String?) {
if (icon.isNullOrEmpty()) return if (icon.isNullOrEmpty()) return
if (Build.VERSION.SDK_INT < 26) { if (Build.VERSION.SDK_INT < 26) {
App.INSTANCE.toast(R.string.change_icon_error) App.INSTANCE.toastOnUI(R.string.change_icon_error)
return return
} }
var hasEnabled = false var hasEnabled = false

@ -8,7 +8,7 @@ import io.legado.app.data.entities.RssSource
import io.legado.app.utils.EncoderUtils import io.legado.app.utils.EncoderUtils
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
object SourceHelp { object SourceHelp {
@ -26,7 +26,7 @@ object SourceHelp {
rssSources.forEach { rssSource -> rssSources.forEach { rssSource ->
if (is18Plus(rssSource.sourceUrl)) { if (is18Plus(rssSource.sourceUrl)) {
handler.post { handler.post {
App.INSTANCE.toast("${rssSource.sourceName}是18+网址,禁止导入.") App.INSTANCE.toastOnUI("${rssSource.sourceName}是18+网址,禁止导入.")
} }
} else { } else {
App.db.rssSourceDao.insert(rssSource) App.db.rssSourceDao.insert(rssSource)
@ -38,7 +38,7 @@ object SourceHelp {
bookSources.forEach { bookSource -> bookSources.forEach { bookSource ->
if (is18Plus(bookSource.bookSourceUrl)) { if (is18Plus(bookSource.bookSourceUrl)) {
handler.post { handler.post {
App.INSTANCE.toast("${bookSource.bookSourceName}是18+网址,禁止导入.") App.INSTANCE.toastOnUI("${bookSource.bookSourceName}是18+网址,禁止导入.")
} }
} else { } else {
App.db.bookSourceDao.insert(bookSource) App.db.bookSourceDao.insert(bookSource)

@ -8,7 +8,7 @@ import android.view.KeyEvent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import io.legado.app.R import io.legado.app.R
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
class PermissionActivity : AppCompatActivity() { class PermissionActivity : AppCompatActivity() {
@ -32,7 +32,7 @@ class PermissionActivity : AppCompatActivity() {
settingIntent.data = Uri.fromParts("package", packageName, null) settingIntent.data = Uri.fromParts("package", packageName, null)
startActivityForResult(settingIntent, Request.TYPE_REQUEST_SETTING) startActivityForResult(settingIntent, Request.TYPE_REQUEST_SETTING)
} catch (e: Exception) { } catch (e: Exception) {
toast(R.string.tip_cannot_jump_setting_page) toastOnUI(R.string.tip_cannot_jump_setting_page)
finish() finish()
} }

@ -16,7 +16,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.toast
import java.io.File import java.io.File
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@ -80,7 +79,7 @@ object BookWebDav {
Coroutine.async { Coroutine.async {
restoreWebDav(names[index]) restoreWebDav(names[index])
}.onError { }.onError {
App.INSTANCE.toast("WebDavError:${it.localizedMessage}") App.INSTANCE.toastOnUI("WebDavError:${it.localizedMessage}")
} }
} }
} }
@ -118,7 +117,7 @@ object BookWebDav {
} }
} catch (e: Exception) { } catch (e: Exception) {
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
App.INSTANCE.toast("WebDav\n${e.localizedMessage}") App.INSTANCE.toastOnUI("WebDav\n${e.localizedMessage}")
} }
} }
} }
@ -139,7 +138,7 @@ object BookWebDav {
} }
} catch (e: Exception) { } catch (e: Exception) {
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
App.INSTANCE.toast("WebDav导出\n${e.localizedMessage}") App.INSTANCE.toastOnUI("WebDav导出\n${e.localizedMessage}")
} }
} }
} }

@ -8,7 +8,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.utils.DocumentUtils import io.legado.app.utils.DocumentUtils
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import io.legado.app.utils.isContentScheme import io.legado.app.utils.isContentScheme
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
import java.io.File import java.io.File
object ImportOldData { object ImportOldData {
@ -21,28 +21,28 @@ object ImportOldData {
kotlin.runCatching { kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json -> DocumentUtils.readText(context, doc.uri)?.let { json ->
val importCount = importOldBookshelf(json) val importCount = importOldBookshelf(json)
context.toast("成功导入书籍${importCount}") context.toastOnUI("成功导入书籍${importCount}")
} }
}.onFailure { }.onFailure {
context.toast("导入书籍失败\n${it.localizedMessage}") context.toastOnUI("导入书籍失败\n${it.localizedMessage}")
} }
"myBookSource.json" -> "myBookSource.json" ->
kotlin.runCatching { kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json -> DocumentUtils.readText(context, doc.uri)?.let { json ->
val importCount = importOldSource(json) val importCount = importOldSource(json)
context.toast("成功导入书源${importCount}") context.toastOnUI("成功导入书源${importCount}")
} }
}.onFailure { }.onFailure {
context.toast("导入源失败\n${it.localizedMessage}") context.toastOnUI("导入源失败\n${it.localizedMessage}")
} }
"myBookReplaceRule.json" -> "myBookReplaceRule.json" ->
kotlin.runCatching { kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json -> DocumentUtils.readText(context, doc.uri)?.let { json ->
val importCount = importOldReplaceRule(json) val importCount = importOldReplaceRule(json)
context.toast("成功导入替换规则${importCount}") context.toastOnUI("成功导入替换规则${importCount}")
} }
}.onFailure { }.onFailure {
context.toast("导入替换规则失败\n${it.localizedMessage}") context.toastOnUI("导入替换规则失败\n${it.localizedMessage}")
} }
} }
} }
@ -54,9 +54,9 @@ object ImportOldData {
FileUtils.createFileIfNotExist(file, "myBookShelf.json") FileUtils.createFileIfNotExist(file, "myBookShelf.json")
val json = shelfFile.readText() val json = shelfFile.readText()
val importCount = importOldBookshelf(json) val importCount = importOldBookshelf(json)
context.toast("成功导入书籍${importCount}") context.toastOnUI("成功导入书籍${importCount}")
}.onFailure { }.onFailure {
context.toast("导入书籍失败\n${it.localizedMessage}") context.toastOnUI("导入书籍失败\n${it.localizedMessage}")
} }
kotlin.runCatching {// Book source kotlin.runCatching {// Book source
@ -64,9 +64,9 @@ object ImportOldData {
FileUtils.getFile(file, "myBookSource.json") FileUtils.getFile(file, "myBookSource.json")
val json = sourceFile.readText() val json = sourceFile.readText()
val importCount = importOldSource(json) val importCount = importOldSource(json)
context.toast("成功导入书源${importCount}") context.toastOnUI("成功导入书源${importCount}")
}.onFailure { }.onFailure {
context.toast("导入源失败\n${it.localizedMessage}") context.toastOnUI("导入源失败\n${it.localizedMessage}")
} }
kotlin.runCatching {// Replace rules kotlin.runCatching {// Replace rules
@ -74,12 +74,12 @@ object ImportOldData {
if (ruleFile.exists()) { if (ruleFile.exists()) {
val json = ruleFile.readText() val json = ruleFile.readText()
val importCount = importOldReplaceRule(json) val importCount = importOldReplaceRule(json)
context.toast("成功导入替换规则${importCount}") context.toastOnUI("成功导入替换规则${importCount}")
} else { } else {
context.toast("未找到替换规则") context.toastOnUI("未找到替换规则")
} }
}.onFailure { }.onFailure {
context.toast("导入替换规则失败\n${it.localizedMessage}") context.toastOnUI("导入替换规则失败\n${it.localizedMessage}")
} }
} }
} }

@ -24,7 +24,6 @@ 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 org.jetbrains.anko.defaultSharedPreferences
import org.jetbrains.anko.toast
import java.io.File import java.io.File
object Restore { object Restore {
@ -224,7 +223,7 @@ object Restore {
ReadBook.loadContent(resetPageOffset = false) ReadBook.loadContent(resetPageOffset = false)
} }
withContext(Main) { withContext(Main) {
App.INSTANCE.toast(R.string.restore_success) App.INSTANCE.toastOnUI(R.string.restore_success)
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
LauncherIconHelp.changeIcon(App.INSTANCE.getPrefString(PreferKey.launcherIcon)) LauncherIconHelp.changeIcon(App.INSTANCE.getPrefString(PreferKey.launcherIcon))
} }

@ -24,8 +24,6 @@ import io.legado.app.help.AppConfig
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dp
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import org.jetbrains.anko.backgroundColor
/** /**
* @author Karim Abou Zeid (kabouzeid) * @author Karim Abou Zeid (kabouzeid)
@ -272,7 +270,7 @@ object ATH {
fun applyBackgroundTint(view: View?) { fun applyBackgroundTint(view: View?) {
view?.apply { view?.apply {
if (background == null) { if (background == null) {
backgroundColor = context.backgroundColor setBackgroundColor(context.backgroundColor)
} else { } else {
setBackgroundTint(this, context.backgroundColor) setBackgroundTint(this, context.backgroundColor)
} }

@ -31,10 +31,10 @@ import io.legado.app.receiver.MediaButtonReceiver
import io.legado.app.service.help.AudioPlay import io.legado.app.service.help.AudioPlay
import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.ui.audio.AudioPlayActivity
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUI
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.toast
class AudioPlayService : BaseService(), class AudioPlayService : BaseService(),
@ -133,7 +133,7 @@ class AudioPlayService : BaseService(),
}.onFailure { }.onFailure {
it.printStackTrace() it.printStackTrace()
launch { launch {
toast("$url ${it.localizedMessage}") toastOnUI("$url ${it.localizedMessage}")
stopSelf() stopSelf()
} }
} }
@ -219,7 +219,7 @@ class AudioPlayService : BaseService(),
if (!mediaPlayer.isPlaying) { if (!mediaPlayer.isPlaying) {
AudioPlay.status = Status.STOP AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP) postEvent(EventBus.AUDIO_STATE, Status.STOP)
launch { toast("error: $what $extra $url") } launch { toastOnUI("error: $what $extra $url") }
} }
return true return true
} }
@ -274,7 +274,7 @@ class AudioPlayService : BaseService(),
.onSuccess { content -> .onSuccess { content ->
if (content.isEmpty()) { if (content.isEmpty()) {
withContext(Main) { withContext(Main) {
toast("未获取到资源链接") toastOnUI("未获取到资源链接")
} }
} else { } else {
contentLoadFinish(chapter, content) contentLoadFinish(chapter, content)
@ -286,7 +286,7 @@ class AudioPlayService : BaseService(),
} }
} else { } else {
removeLoading(chapter.index) removeLoading(chapter.index)
toast("book or source is null") toastOnUI("book or source is null")
} }
} }
} }

@ -20,9 +20,9 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.help.CacheBook import io.legado.app.service.help.CacheBook
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUI
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import org.jetbrains.anko.toast
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.CopyOnWriteArraySet
import java.util.concurrent.Executors import java.util.concurrent.Executors
@ -128,7 +128,7 @@ class CacheBookService : BaseService() {
if (downloadMap.containsKey(bookUrl)) { if (downloadMap.containsKey(bookUrl)) {
notificationContent = getString(R.string.already_in_download) notificationContent = getString(R.string.already_in_download)
upNotification() upNotification()
toast(notificationContent) toastOnUI(notificationContent)
return return
} }
downloadCount[bookUrl] = DownloadCount() downloadCount[bookUrl] = DownloadCount()

@ -16,8 +16,8 @@ import io.legado.app.model.webBook.WebBook
import io.legado.app.service.help.CheckSource import io.legado.app.service.help.CheckSource
import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUI
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import org.jetbrains.anko.toast
import java.util.concurrent.Executors import java.util.concurrent.Executors
import kotlin.math.min import kotlin.math.min
@ -70,7 +70,7 @@ class CheckSourceService : BaseService() {
private fun check(ids: List<String>) { private fun check(ids: List<String>) {
if (allIds.isNotEmpty()) { if (allIds.isNotEmpty()) {
toast("已有书源在校验,等完成后再试") toastOnUI("已有书源在校验,等完成后再试")
return return
} }
tasks.clear() tasks.clear()

@ -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 org.jetbrains.anko.downloadManager import io.legado.app.utils.toastOnUI
import org.jetbrains.anko.toast
import java.io.File import java.io.File
@ -149,7 +149,7 @@ class DownloadService : BaseService() {
try { try {
startActivity(intent) startActivity(intent)
} catch (e: Exception) { } catch (e: Exception) {
toast(e.msg) toastOnUI(e.msg)
} }
} }
} }

@ -10,15 +10,11 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadAloud
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.utils.FileUtils import io.legado.app.utils.*
import io.legado.app.utils.LogUtils
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.postEvent
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.collections.forEachWithIndex
import org.jetbrains.anko.runOnUiThread import org.jetbrains.anko.runOnUiThread
import org.jetbrains.anko.toast
import java.io.File import java.io.File
import java.io.FileDescriptor import java.io.FileDescriptor
import java.io.FileInputStream import java.io.FileInputStream
@ -123,17 +119,17 @@ class HttpReadAloudService : BaseReadAloudService(),
} }
} catch (e: SocketTimeoutException) { } catch (e: SocketTimeoutException) {
removeSpeakCacheFile(fileName) removeSpeakCacheFile(fileName)
runOnUiThread { toast("tts接口超时,尝试重新获取") } runOnUiThread { toastOnUI("tts接口超时,尝试重新获取") }
downloadAudio() downloadAudio()
} catch (e: ConnectException) { } catch (e: ConnectException) {
removeSpeakCacheFile(fileName) removeSpeakCacheFile(fileName)
runOnUiThread { toast("网络错误") } runOnUiThread { 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 { toast("tts文件解析错误") } runOnUiThread { toastOnUI("tts文件解析错误") }
} catch (e: Exception) { } catch (e: Exception) {
removeSpeakCacheFile(fileName) removeSpeakCacheFile(fileName)
} }

@ -13,8 +13,8 @@ import io.legado.app.help.MediaHelp
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUI
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.toast
import java.util.* import java.util.*
class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener {
@ -64,7 +64,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
} }
} else { } else {
launch { launch {
toast(R.string.tts_init_failed) toastOnUI(R.string.tts_init_failed)
} }
} }
} }

@ -13,11 +13,10 @@ import io.legado.app.help.IntentHelp
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.postEvent 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 kotlinx.coroutines.launch
import org.jetbrains.anko.startService import org.jetbrains.anko.startService
import org.jetbrains.anko.toast
import java.io.IOException import java.io.IOException
class WebService : BaseService() { class WebService : BaseService() {
@ -92,11 +91,9 @@ class WebService : BaseService() {
notificationContent = hostAddress notificationContent = hostAddress
upNotification() upNotification()
} catch (e: IOException) { } catch (e: IOException) {
launch { toastOnUI(e.localizedMessage ?: "")
toast(e.localizedMessage ?: "")
stopSelf() stopSelf()
} }
}
} else { } else {
stopSelf() stopSelf()
} }

@ -6,14 +6,14 @@ import io.legado.app.R
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.service.CheckSourceService import io.legado.app.service.CheckSourceService
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
object CheckSource { object CheckSource {
var keyword = "我的" var keyword = "我的"
fun start(context: Context, sources: List<BookSource>) { fun start(context: Context, sources: List<BookSource>) {
if (sources.isEmpty()) { if (sources.isEmpty()) {
context.toast(R.string.non_select) context.toastOnUI(R.string.non_select)
return return
} }
val selectedIds: ArrayList<String> = arrayListOf() val selectedIds: ArrayList<String> = arrayListOf()

@ -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.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 import org.jetbrains.anko.getStackTraceString
import org.jetbrains.anko.toast
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
@ -437,7 +437,7 @@ object ReadBook {
} }
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()
App.INSTANCE.toast("ChapterProvider ERROR:\n${it.getStackTraceString()}") App.INSTANCE.toastOnUI("ChapterProvider ERROR:\n${it.getStackTraceString()}")
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
} }

@ -15,7 +15,7 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.openUrl import io.legado.app.utils.openUrl
import io.legado.app.utils.sendMail import io.legado.app.utils.sendMail
import io.legado.app.utils.sendToClip import io.legado.app.utils.sendToClip
import io.legado.app.utils.toast import io.legado.app.utils.toastOnUI
class AboutFragment : PreferenceFragmentCompat() { class AboutFragment : PreferenceFragmentCompat() {
@ -105,7 +105,7 @@ class AboutFragment : PreferenceFragmentCompat() {
startActivity(intent) startActivity(intent)
return true return true
}.onFailure { }.onFailure {
toast("添加失败,请手动添加") toastOnUI("添加失败,请手动添加")
} }
return false return false
} }

@ -19,7 +19,6 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.sdk27.coroutines.onClick
import java.util.* import java.util.*
class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() { class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
@ -59,7 +58,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
readRecord.tvBookName.setText(R.string.all_read_time) readRecord.tvBookName.setText(R.string.all_read_time)
adapter = RecordAdapter(this@ReadRecordActivity) adapter = RecordAdapter(this@ReadRecordActivity)
recyclerView.adapter = adapter recyclerView.adapter = adapter
readRecord.tvRemove.onClick { readRecord.tvRemove.setOnClickListener {
alert(R.string.delete, R.string.sure_del) { alert(R.string.delete, R.string.sure_del) {
okButton { okButton {
App.db.readRecordDao.clear() App.db.readRecordDao.clear()
@ -112,7 +111,7 @@ class ReadRecordActivity : BaseActivity<ActivityReadRecordBinding>() {
override fun registerListener(holder: ItemViewHolder, binding: ItemReadRecordBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemReadRecordBinding) {
binding.apply { binding.apply {
tvRemove.onClick { tvRemove.setOnClickListener {
getItem(holder.layoutPosition)?.let { item -> getItem(holder.layoutPosition)?.let { item ->
sureDelAlert(item) sureDelAlert(item)
} }

@ -7,8 +7,8 @@ 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.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.toastOnUI
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
class FileAssociationActivity : class FileAssociationActivity :
@ -27,7 +27,7 @@ class FileAssociationActivity :
binding.rotateLoading.show() binding.rotateLoading.show()
viewModel.errorLiveData.observe(this, { viewModel.errorLiveData.observe(this, {
binding.rotateLoading.hide() binding.rotateLoading.hide()
toast(it) toastOnUI(it)
finish() finish()
}) })
viewModel.successLiveData.observe(this, { viewModel.successLiveData.observe(this, {

@ -8,7 +8,7 @@ import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
class ImportBookSourceActivity : class ImportBookSourceActivity :
@ -66,7 +66,7 @@ class ImportBookSourceActivity :
} }
else -> { else -> {
binding.rotateLoading.hide() binding.rotateLoading.hide()
toast(R.string.wrong_format) toastOnUI(R.string.wrong_format)
finish() finish()
} }
} }

@ -25,7 +25,7 @@ import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
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.sdk27.coroutines.onClick
/** /**
* 导入书源弹出窗口 * 导入书源弹出窗口
@ -62,11 +62,11 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
adapter.setItems(viewModel.allSources) adapter.setItems(viewModel.allSources)
binding.tvCancel.visible() binding.tvCancel.visible()
binding.tvCancel.onClick { binding.tvCancel.setOnClickListener {
dismiss() dismiss()
} }
binding.tvOk.visible() binding.tvOk.visible()
binding.tvOk.onClick { binding.tvOk.setOnClickListener {
viewModel.importSelect { viewModel.importSelect {
dismiss() dismiss()
} }

@ -9,7 +9,7 @@ import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
class ImportReplaceRuleActivity : class ImportReplaceRuleActivity :
VMBaseActivity<ActivityTranslucenceBinding, ImportReplaceRuleViewModel>( VMBaseActivity<ActivityTranslucenceBinding, ImportReplaceRuleViewModel>(
@ -66,7 +66,7 @@ class ImportReplaceRuleActivity :
} }
else -> { else -> {
binding.rotateLoading.hide() binding.rotateLoading.hide()
toast("格式不对") toastOnUI("格式不对")
finish() finish()
} }
} }

@ -8,7 +8,7 @@ import io.legado.app.databinding.ActivityTranslucenceBinding
import io.legado.app.help.IntentDataHelp import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
class ImportRssSourceActivity : class ImportRssSourceActivity :
VMBaseActivity<ActivityTranslucenceBinding, ImportRssSourceViewModel>( VMBaseActivity<ActivityTranslucenceBinding, ImportRssSourceViewModel>(
@ -65,7 +65,7 @@ class ImportRssSourceActivity :
} }
else -> { else -> {
binding.rotateLoading.hide() binding.rotateLoading.hide()
toast(R.string.wrong_format) toastOnUI(R.string.wrong_format)
finish() finish()
} }
} }

@ -25,7 +25,6 @@ import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
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.sdk27.coroutines.onClick
/** /**
* 导入rss源弹出窗口 * 导入rss源弹出窗口
@ -62,11 +61,11 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
adapter.setItems(viewModel.allSources) adapter.setItems(viewModel.allSources)
binding.tvCancel.visible() binding.tvCancel.visible()
binding.tvCancel.onClick { binding.tvCancel.setOnClickListener {
dismiss() dismiss()
} }
binding.tvOk.visible() binding.tvOk.visible()
binding.tvOk.onClick { binding.tvOk.setOnClickListener {
viewModel.importSelect { viewModel.importSelect {
dismiss() dismiss()
} }

@ -28,8 +28,6 @@ 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.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import java.util.* import java.util.*
@ -80,16 +78,17 @@ class AudioPlayActivity :
} }
private fun initView() { private fun initView() {
binding.fabPlayStop.onClick { binding.fabPlayStop.setOnClickListener {
playButton() playButton()
} }
binding.fabPlayStop.onLongClick(returnValue = true) { binding.fabPlayStop.setOnLongClickListener {
AudioPlay.stop(this@AudioPlayActivity) AudioPlay.stop(this@AudioPlayActivity)
true
} }
binding.ivSkipNext.onClick { binding.ivSkipNext.setOnClickListener {
AudioPlay.next(this@AudioPlayActivity) AudioPlay.next(this@AudioPlayActivity)
} }
binding.ivSkipPrevious.onClick { binding.ivSkipPrevious.setOnClickListener {
AudioPlay.prev(this@AudioPlayActivity) AudioPlay.prev(this@AudioPlayActivity)
} }
binding.playerProgress.setOnSeekBarChangeListener(object : SeekBarChangeListener { binding.playerProgress.setOnSeekBarChangeListener(object : SeekBarChangeListener {
@ -106,7 +105,7 @@ class AudioPlayActivity :
AudioPlay.adjustProgress(this@AudioPlayActivity, seekBar.progress) AudioPlay.adjustProgress(this@AudioPlayActivity, seekBar.progress)
} }
}) })
binding.ivChapter.onClick { binding.ivChapter.setOnClickListener {
AudioPlay.book?.let { AudioPlay.book?.let {
startActivityForResult<ChapterListActivity>( startActivityForResult<ChapterListActivity>(
requestCodeChapter, requestCodeChapter,
@ -118,13 +117,13 @@ class AudioPlayActivity :
binding.ivFastRewind.invisible() binding.ivFastRewind.invisible()
binding.ivFastForward.invisible() binding.ivFastForward.invisible()
} }
binding.ivFastForward.onClick { binding.ivFastForward.setOnClickListener {
AudioPlay.adjustSpeed(this@AudioPlayActivity, 0.1f) AudioPlay.adjustSpeed(this@AudioPlayActivity, 0.1f)
} }
binding.ivFastRewind.onClick { binding.ivFastRewind.setOnClickListener {
AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f) AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f)
} }
binding.ivTimer.onClick { binding.ivTimer.setOnClickListener {
AudioPlay.addTimer(this@AudioPlayActivity) AudioPlay.addTimer(this@AudioPlayActivity)
} }
} }

@ -75,10 +75,10 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
} }
AudioPlay.upDurChapter(book) AudioPlay.upDurChapter(book)
} else { } else {
toast(R.string.error_load_toc) toastOnUI(R.string.error_load_toc)
} }
}?.onError { }?.onError {
toast(R.string.error_load_toc) toastOnUI(R.string.error_load_toc)
} }
} }
} }

@ -13,8 +13,6 @@ import io.legado.app.databinding.ItemArrangeBookBinding
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper 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 org.jetbrains.anko.backgroundColor
import org.jetbrains.anko.sdk27.coroutines.onClick
import java.util.* import java.util.*
class ArrangeBookAdapter(context: Context, val callBack: CallBack) : class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
@ -40,7 +38,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
binding.apply { binding.apply {
root.backgroundColor = context.backgroundColor root.setBackgroundColor(context.backgroundColor)
tvName.text = item.name tvName.text = item.name
tvAuthor.text = item.author tvAuthor.text = item.author
tvAuthor.visibility = if (item.author.isEmpty()) View.GONE else View.VISIBLE tvAuthor.visibility = if (item.author.isEmpty()) View.GONE else View.VISIBLE
@ -65,7 +63,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
} }
} }
} }
root.onClick { root.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
checkbox.isChecked = !checkbox.isChecked checkbox.isChecked = !checkbox.isChecked
if (checkbox.isChecked) { if (checkbox.isChecked) {
@ -76,12 +74,12 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) :
callBack.upSelectCount() callBack.upSelectCount()
} }
} }
tvDelete.onClick { tvDelete.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.deleteBook(it) callBack.deleteBook(it)
} }
} }
tvGroup.onClick { tvGroup.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
actionItem = it actionItem = it
callBack.selectGroup(groupRequestCode, it.group) callBack.selectGroup(groupRequestCode, it.group)

@ -10,7 +10,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.ItemDownloadBinding import io.legado.app.databinding.ItemDownloadBinding
import io.legado.app.service.help.CacheBook import io.legado.app.service.help.CacheBook
import org.jetbrains.anko.sdk27.coroutines.onClick
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.CopyOnWriteArraySet
@ -54,7 +54,7 @@ class CacheAdapter(context: Context, private val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemDownloadBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemDownloadBinding) {
with(binding) { with(binding) {
ivDownload.onClick { ivDownload.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
if (downloadMap?.containsKey(it.bookUrl) == true) { if (downloadMap?.containsKey(it.bookUrl) == true) {
CacheBook.remove(context, it.bookUrl) CacheBook.remove(context, it.bookUrl)
@ -63,7 +63,7 @@ class CacheAdapter(context: Context, private val callBack: CallBack) :
} }
} }
} }
tvExport.onClick { tvExport.setOnClickListener {
callBack.export(holder.layoutPosition) callBack.export(holder.layoutPosition)
} }
} }

@ -7,7 +7,7 @@ import io.legado.app.base.adapter.DiffRecyclerAdapter
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.databinding.ItemCoverBinding import io.legado.app.databinding.ItemCoverBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class CoverAdapter(context: Context, val callBack: CallBack) : class CoverAdapter(context: Context, val callBack: CallBack) :
DiffRecyclerAdapter<SearchBook, ItemCoverBinding>(context) { DiffRecyclerAdapter<SearchBook, ItemCoverBinding>(context) {
@ -41,7 +41,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemCoverBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemCoverBinding) {
holder.itemView.apply { holder.itemView.apply {
onClick { setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.changeTo(it.coverUrl ?: "") callBack.changeTo(it.coverUrl ?: "")
} }

@ -13,8 +13,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick
class ChangeSourceAdapter(context: Context, val callBack: CallBack) : class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
@ -65,13 +63,14 @@ class ChangeSourceAdapter(context: Context, val callBack: CallBack) :
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemChangeSourceBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemChangeSourceBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.changeTo(it) callBack.changeTo(it)
} }
} }
holder.itemView.onLongClick(returnValue = true) { holder.itemView.setOnLongClickListener {
showMenu(holder.itemView, getItem(holder.layoutPosition)) showMenu(holder.itemView, getItem(holder.layoutPosition))
true
} }
} }

@ -6,7 +6,6 @@ import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
@ -21,7 +20,6 @@ import io.legado.app.utils.getPrefString
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.ExecutorCoroutineDispatcher import kotlinx.coroutines.ExecutorCoroutineDispatcher
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import org.jetbrains.anko.debug
import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.CopyOnWriteArraySet
import java.util.concurrent.Executors import java.util.concurrent.Executors
@ -173,7 +171,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
searchFinish(searchBook) searchFinish(searchBook)
} }
}.onError { }.onError {
debug { context.getString(R.string.error_get_book_info) } it.printStackTrace()
} }
} }
@ -186,7 +184,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
searchFinish(searchBook) searchFinish(searchBook)
} }
}.onError { }.onError {
debug { context.getString(R.string.error_get_chapter_list) } it.printStackTrace()
} }
} }

@ -10,7 +10,7 @@ import io.legado.app.data.entities.SearchBook
import io.legado.app.databinding.ItemSearchBinding import io.legado.app.databinding.ItemSearchBinding
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 org.jetbrains.anko.sdk27.coroutines.onClick
class ExploreShowAdapter(context: Context, val callBack: CallBack) : class ExploreShowAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<SearchBook, ItemSearchBinding>(context) { RecyclerAdapter<SearchBook, ItemSearchBinding>(context) {
@ -51,7 +51,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.showBookInfo(it.toBook()) callBack.showBookInfo(it.toBook())
} }

@ -28,7 +28,7 @@ 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 io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: GroupViewModel private lateinit var viewModel: GroupViewModel
@ -68,7 +68,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView) ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView)
binding.tvOk.setTextColor(requireContext().accentColor) binding.tvOk.setTextColor(requireContext().accentColor)
binding.tvOk.visible() binding.tvOk.visible()
binding.tvOk.onClick { dismiss() } binding.tvOk.setOnClickListener { dismiss() }
} }
private fun initData() { private fun initData() {
@ -164,7 +164,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun registerListener(holder: ItemViewHolder, binding: ItemBookGroupManageBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemBookGroupManageBinding) {
with(binding) { with(binding) {
tvEdit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } } tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } }
swShow.setOnCheckedChangeListener { buttonView, isChecked -> swShow.setOnCheckedChangeListener { buttonView, isChecked ->
if (buttonView.isPressed) { if (buttonView.isPressed) {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {

@ -32,7 +32,7 @@ import io.legado.app.utils.getSize
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.requestInputMethod import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
@ -95,9 +95,9 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
val itemTouchCallback = ItemTouchCallback(adapter) val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = true itemTouchCallback.isCanDrag = true
ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView) ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView)
binding.tvCancel.onClick { dismiss() } binding.tvCancel.setOnClickListener { dismiss() }
binding.tvOk.setTextColor(requireContext().accentColor) binding.tvOk.setTextColor(requireContext().accentColor)
binding.tvOk.onClick { binding.tvOk.setOnClickListener {
callBack?.upGroup(requestCode, groupId) callBack?.upGroup(requestCode, groupId)
dismiss() dismiss()
} }
@ -187,7 +187,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
} }
} }
} }
tvEdit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } } tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } }
} }
} }

@ -37,10 +37,8 @@ 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.sdk27.coroutines.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
class BookInfoActivity : class BookInfoActivity :
@ -92,7 +90,7 @@ class BookInfoActivity :
) )
} }
} else { } else {
toast(R.string.after_add_bookshelf) toastOnUI(R.string.after_add_bookshelf)
} }
} }
R.id.menu_share_it -> { R.id.menu_share_it -> {
@ -113,7 +111,7 @@ class BookInfoActivity :
} }
R.id.menu_copy_url -> viewModel.bookData.value?.bookUrl?.let { R.id.menu_copy_url -> viewModel.bookData.value?.bookUrl?.let {
sendToClip(it) sendToClip(it)
} ?: toast(R.string.no_book) } ?: toastOnUI(R.string.no_book)
R.id.menu_can_update -> { R.id.menu_can_update -> {
if (viewModel.inBookshelf) { if (viewModel.inBookshelf) {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
@ -121,7 +119,7 @@ class BookInfoActivity :
viewModel.saveBook() viewModel.saveBook()
} }
} else { } else {
toast(R.string.after_add_bookshelf) toastOnUI(R.string.after_add_bookshelf)
} }
} }
R.id.menu_clear_cache -> viewModel.clearCache() R.id.menu_clear_cache -> viewModel.clearCache()
@ -207,17 +205,17 @@ class BookInfoActivity :
} }
private fun initOnClick() = with(binding) { private fun initOnClick() = with(binding) {
ivCover.onClick { ivCover.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) ChangeCoverDialog.show(supportFragmentManager, it.name, it.author)
} }
} }
tvRead.onClick { tvRead.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
readBook(it) readBook(it)
} }
} }
tvShelf.onClick { tvShelf.setOnClickListener {
if (viewModel.inBookshelf) { if (viewModel.inBookshelf) {
deleteBook() deleteBook()
} else { } else {
@ -226,17 +224,17 @@ class BookInfoActivity :
} }
} }
} }
tvOrigin.onClick { tvOrigin.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
startActivity<BookSourceEditActivity>(Pair("data", it.origin)) startActivity<BookSourceEditActivity>(Pair("data", it.origin))
} }
} }
tvChangeSource.onClick { tvChangeSource.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) ChangeSourceDialog.show(supportFragmentManager, it.name, it.author)
} }
} }
tvTocView.onClick { tvTocView.setOnClickListener {
if (!viewModel.inBookshelf) { if (!viewModel.inBookshelf) {
viewModel.saveBook { viewModel.saveBook {
viewModel.saveChapterList { viewModel.saveChapterList {
@ -247,15 +245,15 @@ class BookInfoActivity :
openChapterList() openChapterList()
} }
} }
tvChangeGroup.onClick { tvChangeGroup.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
GroupSelectDialog.show(supportFragmentManager, it.group) GroupSelectDialog.show(supportFragmentManager, it.group)
} }
} }
tvAuthor.onClick { tvAuthor.setOnClickListener {
startActivity<SearchActivity>(Pair("key", viewModel.bookData.value?.author)) startActivity<SearchActivity>(Pair("key", viewModel.bookData.value?.author))
} }
tvName.onClick { tvName.setOnClickListener {
startActivity<SearchActivity>(Pair("key", viewModel.bookData.value?.name)) startActivity<SearchActivity>(Pair("key", viewModel.bookData.value?.name))
} }
} }
@ -293,7 +291,7 @@ class BookInfoActivity :
private fun openChapterList() { private fun openChapterList() {
if (viewModel.chapterListData.value.isNullOrEmpty()) { if (viewModel.chapterListData.value.isNullOrEmpty()) {
toast(R.string.chapter_list_empty) toastOnUI(R.string.chapter_list_empty)
return return
} }
viewModel.bookData.value?.let { viewModel.bookData.value?.let {

@ -65,11 +65,11 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} }
loadChapter(it, changeDruChapterIndex) loadChapter(it, changeDruChapterIndex)
}.onError { }.onError {
toast(R.string.error_get_book_info) toastOnUI(R.string.error_get_book_info)
} }
} ?: let { } ?: let {
chapterListData.postValue(null) chapterListData.postValue(null)
toast(R.string.error_no_source) toastOnUI(R.string.error_no_source)
} }
} }
} }
@ -101,19 +101,19 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
changeDruChapterIndex(it) changeDruChapterIndex(it)
} }
} else { } else {
toast(R.string.chapter_list_empty) toastOnUI(R.string.chapter_list_empty)
} }
}.onError { }.onError {
chapterListData.postValue(null) chapterListData.postValue(null)
toast(R.string.error_get_chapter_list) toastOnUI(R.string.error_get_chapter_list)
} }
} ?: let { } ?: let {
chapterListData.postValue(null) chapterListData.postValue(null)
toast(R.string.error_no_source) toastOnUI(R.string.error_no_source)
} }
} }
}.onError { }.onError {
toast("LoadTocError:${it.localizedMessage}") toastOnUI("LoadTocError:${it.localizedMessage}")
} }
} }
@ -238,9 +238,9 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
BookHelp.clearCache(bookData.value!!) BookHelp.clearCache(bookData.value!!)
}.onSuccess { }.onSuccess {
toast(R.string.clear_cache_success) toastOnUI(R.string.clear_cache_success)
}.onError { }.onError {
toast(it.stackTraceToString()) toastOnUI(it.stackTraceToString())
} }
} }

@ -8,8 +8,8 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.ItemChapterListBinding import io.legado.app.databinding.ItemChapterListBinding
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import org.jetbrains.anko.sdk27.coroutines.onClick import io.legado.app.utils.getCompatColor
import org.jetbrains.anko.textColorResource
class ChapterListAdapter(context: Context, var callBack: CallBack) : class ChapterListAdapter(context: Context, var callBack: CallBack) :
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) { RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
@ -29,7 +29,7 @@ class ChapterListAdapter(context: Context, var callBack: CallBack) :
if (item.index == callBack.durChapterIndex()) { if (item.index == callBack.durChapterIndex()) {
tvChapterName.setTextColor(context.accentColor) tvChapterName.setTextColor(context.accentColor)
} else { } else {
tvChapterName.textColorResource = R.color.secondaryText tvChapterName.setTextColor(context.getCompatColor(R.color.secondaryText))
} }
} }
@ -37,7 +37,7 @@ class ChapterListAdapter(context: Context, var callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) {
holder.itemView.apply { holder.itemView.apply {
this.onClick { this.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.openChapter(it) callBack.openChapter(it)
} }

@ -15,8 +15,6 @@ import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.ui.book.changecover.ChangeCoverDialog import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.toast
import java.io.File import java.io.File
class BookInfoEditActivity : class BookInfoEditActivity :
@ -55,15 +53,15 @@ class BookInfoEditActivity :
} }
private fun initEvent() = with(binding) { private fun initEvent() = with(binding) {
tvChangeCover.onClick { tvChangeCover.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) ChangeCoverDialog.show(supportFragmentManager, it.name, it.author)
} }
} }
tvSelectCover.onClick { tvSelectCover.setOnClickListener {
selectImage() selectImage()
} }
tvRefreshCover.onClick { tvRefreshCover.setOnClickListener {
viewModel.book?.customCoverUrl = tieCoverUrl.text?.toString() viewModel.book?.customCoverUrl = tieCoverUrl.text?.toString()
upCover() upCover()
} }
@ -121,7 +119,7 @@ class BookInfoEditActivity :
}.getOrNull()?.let { byteArray -> }.getOrNull()?.let { byteArray ->
file.writeBytes(byteArray) file.writeBytes(byteArray)
coverChangeTo(file.absolutePath) coverChangeTo(file.absolutePath)
} ?: toast("获取文件出错") } ?: toastOnUI("获取文件出错")
} }
} else { } else {
PermissionsCompat.Builder(this) PermissionsCompat.Builder(this)

@ -28,8 +28,6 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.toast
import java.io.File import java.io.File
import java.util.* import java.util.*
@ -112,7 +110,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
} }
private fun initEvent() { private fun initEvent() {
binding.tvGoBack.onClick { binding.tvGoBack.setOnClickListener {
goBackDir() goBackDir()
} }
} }
@ -253,7 +251,7 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
} ?: let { } ?: let {
val lastPath = AppConfig.importBookPath val lastPath = AppConfig.importBookPath
if (lastPath.isNullOrEmpty()) { if (lastPath.isNullOrEmpty()) {
toast(R.string.empty_msg_import_book) toastOnUI(R.string.empty_msg_import_book)
} else { } else {
adapter.clearItems() adapter.clearItems()
val file = File(path) val file = File(path)

@ -9,7 +9,7 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.databinding.ItemImportBookBinding import io.legado.app.databinding.ItemImportBookBinding
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.sdk27.coroutines.onClick
class ImportBookAdapter(context: Context, val callBack: CallBack) : class ImportBookAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<DocItem, ItemImportBookBinding>(context) { RecyclerAdapter<DocItem, ItemImportBookBinding>(context) {
@ -62,7 +62,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemImportBookBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemImportBookBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
if (it.isDir) { if (it.isDir) {
callBack.nextDoc(it.uri) callBack.nextDoc(it.uri)

@ -55,7 +55,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
class ReadBookActivity : ReadBookBaseActivity(), class ReadBookActivity : ReadBookBaseActivity(),
View.OnTouchListener, View.OnTouchListener,
@ -347,7 +346,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
) { ) {
if (BaseReadAloudService.isPlay()) { if (BaseReadAloudService.isPlay()) {
ReadAloud.pause(this) ReadAloud.pause(this)
toast(R.string.read_aloud_pause) toastOnUI(R.string.read_aloud_pause)
return true return true
} }
if (isAutoPage) { if (isAutoPage) {
@ -453,7 +452,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
R.id.menu_bookmark -> binding.readView.curPage.let { R.id.menu_bookmark -> binding.readView.curPage.let {
val bookmark = it.createBookmark() val bookmark = it.createBookmark()
if (bookmark == null) { if (bookmark == null) {
toast(R.string.create_bookmark_error) toastOnUI(R.string.create_bookmark_error)
} else { } else {
showBookMark(bookmark) showBookMark(bookmark)
} }

@ -226,7 +226,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
}.onStart { }.onStart {
ReadBook.upMsg(context.getString(R.string.source_auto_changing)) ReadBook.upMsg(context.getString(R.string.source_auto_changing))
}.onError { }.onError {
toast(it.msg) toastOnUI(it.msg)
}.onFinally { }.onFinally {
ReadBook.upMsg(null) ReadBook.upMsg(null)
} }

@ -21,8 +21,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick
/** /**
* 阅读界面菜单 * 阅读界面菜单
@ -83,8 +81,8 @@ class ReadMenu @JvmOverloads constructor(
tvFont.setTextColor(textColor) tvFont.setTextColor(textColor)
ivSetting.setColorFilter(textColor) ivSetting.setColorFilter(textColor)
tvSetting.setTextColor(textColor) tvSetting.setTextColor(textColor)
vwBg.onClick { } vwBg.setOnClickListener { }
vwNavigationBar.onClick { } vwNavigationBar.setOnClickListener { }
seekBrightness.progress = context.getPrefInt("brightness", 100) seekBrightness.progress = context.getPrefInt("brightness", 100)
} }
@ -135,16 +133,16 @@ class ReadMenu @JvmOverloads constructor(
} }
private fun bindEvent() = with(binding) { private fun bindEvent() = with(binding) {
tvChapterName.onClick { tvChapterName.setOnClickListener {
callBack.openSourceEditActivity() callBack.openSourceEditActivity()
} }
tvChapterUrl.onClick { tvChapterUrl.setOnClickListener {
context.openUrl(binding.tvChapterUrl.text.toString()) context.openUrl(binding.tvChapterUrl.text.toString())
} }
tvLogin.onClick { tvLogin.setOnClickListener {
callBack.showLogin() callBack.showLogin()
} }
ivBrightnessAuto.onClick { ivBrightnessAuto.setOnClickListener {
context.putPrefBoolean("brightnessAuto", !brightnessAuto()) context.putPrefBoolean("brightnessAuto", !brightnessAuto())
upBrightnessState() upBrightnessState()
} }
@ -171,59 +169,60 @@ class ReadMenu @JvmOverloads constructor(
}) })
//搜索 //搜索
fabSearch.onClick { fabSearch.setOnClickListener {
runMenuOut { runMenuOut {
callBack.openSearchActivity(null) callBack.openSearchActivity(null)
} }
} }
//自动翻页 //自动翻页
fabAutoPage.onClick { fabAutoPage.setOnClickListener {
runMenuOut { runMenuOut {
callBack.autoPage() callBack.autoPage()
} }
} }
//替换 //替换
fabReplaceRule.onClick { callBack.openReplaceRule() } fabReplaceRule.setOnClickListener { callBack.openReplaceRule() }
//夜间模式 //夜间模式
fabNightTheme.onClick { fabNightTheme.setOnClickListener {
AppConfig.isNightTheme = !AppConfig.isNightTheme AppConfig.isNightTheme = !AppConfig.isNightTheme
App.INSTANCE.applyDayNight() App.INSTANCE.applyDayNight()
} }
//上一章 //上一章
tvPre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
//下一章 //下一章
tvNext.onClick { ReadBook.moveToNextChapter(true) } tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) }
//目录 //目录
llCatalog.onClick { llCatalog.setOnClickListener {
runMenuOut { runMenuOut {
callBack.openChapterList() callBack.openChapterList()
} }
} }
//朗读 //朗读
llReadAloud.onClick { llReadAloud.setOnClickListener {
runMenuOut { runMenuOut {
callBack.onClickReadAloud() callBack.onClickReadAloud()
} }
} }
llReadAloud.onLongClick(returnValue = true) { llReadAloud.setOnLongClickListener {
runMenuOut { callBack.showReadAloudDialog() } runMenuOut { callBack.showReadAloudDialog() }
true
} }
//界面 //界面
llFont.onClick { llFont.setOnClickListener {
runMenuOut { runMenuOut {
callBack.showReadStyle() callBack.showReadStyle()
} }
} }
//设置 //设置
llSetting.onClick { llSetting.setOnClickListener {
runMenuOut { runMenuOut {
callBack.showMoreSetting() callBack.showMoreSetting()
} }
@ -241,7 +240,7 @@ class ReadMenu @JvmOverloads constructor(
} }
override fun onAnimationEnd(animation: Animation) { override fun onAnimationEnd(animation: Animation) {
binding.vwMenuBg.onClick { runMenuOut() } binding.vwMenuBg.setOnClickListener { runMenuOut() }
binding.vwNavigationBar.layoutParams = binding.vwNavigationBar.layoutParams.apply { binding.vwNavigationBar.layoutParams = binding.vwNavigationBar.layoutParams.apply {
height = activity!!.navigationBarHeight height = activity!!.navigationBarHeight
} }

@ -24,13 +24,8 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.databinding.ItemTextBinding 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.gone import io.legado.app.utils.*
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.sendToClip
import io.legado.app.utils.visible
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.share import org.jetbrains.anko.share
import org.jetbrains.anko.toast
import java.util.* import java.util.*
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
@ -73,7 +68,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
if (moreMenu.size() > 0) { if (moreMenu.size() > 0) {
ivMenuMore.visible() ivMenuMore.visible()
} }
ivMenuMore.onClick { ivMenuMore.setOnClickListener {
if (recyclerView.isVisible) { if (recyclerView.isVisible) {
ivMenuMore.setImageResource(R.drawable.ic_arrow_back) ivMenuMore.setImageResource(R.drawable.ic_arrow_back)
adapter.setItems(moreMenu.visibleItems) adapter.setItems(moreMenu.visibleItems)
@ -107,7 +102,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
if (!callBack.onMenuItemSelected(it.itemId)) { if (!callBack.onMenuItemSelected(it.itemId)) {
onMenuItemSelected(it) onMenuItemSelected(it)
@ -124,7 +119,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
R.id.menu_share_str -> context.share(callBack.selectedText) R.id.menu_share_str -> context.share(callBack.selectedText)
R.id.menu_aloud -> { R.id.menu_aloud -> {
if (BaseReadAloudService.isRun) { if (BaseReadAloudService.isRun) {
context.toast(R.string.alouding_disable) context.toastOnUI(R.string.alouding_disable)
return return
} }
readAloud(callBack.selectedText) readAloud(callBack.selectedText)
@ -143,7 +138,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
context.startActivity(intent) context.startActivity(intent)
}.onFailure { }.onFailure {
it.printStackTrace() it.printStackTrace()
context.toast(it.localizedMessage ?: "ERROR") context.toastOnUI(it.localizedMessage ?: "ERROR")
} }
} }
else -> item.intent?.let { else -> item.intent?.let {
@ -219,7 +214,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
).intent = createProcessTextIntentForResolveInfo(resolveInfo) ).intent = createProcessTextIntentForResolveInfo(resolveInfo)
} }
}.onFailure { }.onFailure {
context.toast("获取文字操作菜单出错:${it.localizedMessage}") context.toastOnUI("获取文字操作菜单出错:${it.localizedMessage}")
} }
} }

@ -16,7 +16,7 @@ import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class AutoReadDialog : BaseDialogFragment() { class AutoReadDialog : BaseDialogFragment() {
var callBack: CallBack? = null var callBack: CallBack? = null
@ -94,12 +94,12 @@ class AutoReadDialog : BaseDialogFragment() {
} }
private fun initEvent() { private fun initEvent() {
binding.llMainMenu.onClick { callBack?.showMenuBar(); dismiss() } binding.llMainMenu.setOnClickListener { callBack?.showMenuBar(); dismiss() }
binding.llSetting.onClick { binding.llSetting.setOnClickListener {
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog")
} }
binding.llCatalog.onClick { callBack?.openChapterList() } binding.llCatalog.setOnClickListener { callBack?.openChapterList() }
binding.llAutoPageStop.onClick { binding.llAutoPageStop.setOnClickListener {
callBack?.autoPageStop() callBack?.autoPageStop()
dismiss() dismiss()
} }

@ -9,7 +9,7 @@ import io.legado.app.databinding.ItemBgImageBinding
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import org.jetbrains.anko.sdk27.coroutines.onClick
import java.io.File import java.io.File
class BgAdapter(context: Context, val textColor: Int) : class BgAdapter(context: Context, val textColor: Int) :
@ -39,7 +39,7 @@ class BgAdapter(context: Context, val textColor: Int) :
override fun registerListener(holder: ItemViewHolder, binding: ItemBgImageBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemBgImageBinding) {
holder.itemView.apply { holder.itemView.apply {
this.onClick { this.setOnClickListener {
getItemByLayoutPosition(holder.layoutPosition)?.let { getItemByLayoutPosition(holder.layoutPosition)?.let {
ReadBookConfig.durConfig.setCurBg(1, it) ReadBookConfig.durConfig.setCurBg(1, it)
ReadBookConfig.upBg() ReadBookConfig.upBg()

@ -28,8 +28,6 @@ import io.legado.app.ui.filepicker.FilePicker
import io.legado.app.ui.filepicker.FilePickerDialog import io.legado.app.ui.filepicker.FilePickerDialog
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.sdk27.coroutines.onCheckedChange
import org.jetbrains.anko.sdk27.coroutines.onClick
import rxhttp.wrapper.param.RxHttp import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toByteArray import rxhttp.wrapper.param.toByteArray
import java.io.File import java.io.File
@ -110,7 +108,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
tvName.text = getString(R.string.select_image) tvName.text = getString(R.string.select_image)
ivBg.setImageResource(R.drawable.ic_image) ivBg.setImageResource(R.drawable.ic_image)
ivBg.setColorFilter(primaryTextColor) ivBg.setColorFilter(primaryTextColor)
root.onClick { selectImage() } root.setOnClickListener { selectImage() }
} }
} }
requireContext().assets.list("bg")?.let { requireContext().assets.list("bg")?.let {
@ -120,7 +118,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
private fun initEvent() = with(ReadBookConfig.durConfig) { private fun initEvent() = with(ReadBookConfig.durConfig) {
binding.ivEdit.onClick { binding.ivEdit.setOnClickListener {
alert(R.string.style_name) { alert(R.string.style_name) {
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setText(ReadBookConfig.durConfig.name) editView.setText(ReadBookConfig.durConfig.name)
@ -135,13 +133,13 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
cancelButton() cancelButton()
}.show() }.show()
} }
binding.swDarkStatusIcon.onCheckedChange { buttonView, isChecked -> binding.swDarkStatusIcon.setOnCheckedChangeListener { buttonView, isChecked ->
if (buttonView?.isPressed == true) { if (buttonView?.isPressed == true) {
setCurStatusIconDark(isChecked) setCurStatusIconDark(isChecked)
(activity as? ReadBookActivity)?.upSystemUiVisibility() (activity as? ReadBookActivity)?.upSystemUiVisibility()
} }
} }
binding.tvTextColor.onClick { binding.tvTextColor.setOnClickListener {
ColorPickerDialog.newBuilder() ColorPickerDialog.newBuilder()
.setColor(curTextColor()) .setColor(curTextColor())
.setShowAlphaSlider(false) .setShowAlphaSlider(false)
@ -149,7 +147,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
.setDialogId(TEXT_COLOR) .setDialogId(TEXT_COLOR)
.show(requireActivity()) .show(requireActivity())
} }
binding.tvBgColor.onClick { binding.tvBgColor.setOnClickListener {
val bgColor = val bgColor =
if (curBgType() == 0) Color.parseColor(curBgStr()) if (curBgType() == 0) Color.parseColor(curBgStr())
else Color.parseColor("#015A86") else Color.parseColor("#015A86")
@ -160,7 +158,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
.setDialogId(BG_COLOR) .setDialogId(BG_COLOR)
.show(requireActivity()) .show(requireActivity())
} }
binding.ivImport.onClick { binding.ivImport.setOnClickListener {
val importFormNet = "网络导入" val importFormNet = "网络导入"
val otherActions = arrayListOf(importFormNet) val otherActions = arrayListOf(importFormNet)
FilePicker.selectFile( FilePicker.selectFile(
@ -175,19 +173,19 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
} }
} }
} }
binding.ivExport.onClick { binding.ivExport.setOnClickListener {
FilePicker.selectFolder( FilePicker.selectFolder(
this@BgTextConfigDialog, this@BgTextConfigDialog,
requestCodeExport, requestCodeExport,
title = getString(R.string.export_str) title = getString(R.string.export_str)
) )
} }
binding.ivDelete.onClick { binding.ivDelete.setOnClickListener {
if (ReadBookConfig.deleteDur()) { if (ReadBookConfig.deleteDur()) {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
dismiss() dismiss()
} else { } else {
toast("数量已是最少,不能删除.") toastOnUI("数量已是最少,不能删除.")
} }
} }
} }
@ -269,7 +267,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
} }
} }
}.onSuccess { }.onSuccess {
toast("导出成功, 文件名为 $exportFileName") toastOnUI("导出成功, 文件名为 $exportFileName")
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()
longToast("导出失败:${it.localizedMessage}") longToast("导出失败:${it.localizedMessage}")
@ -365,7 +363,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
ReadBookConfig.durConfig = config ReadBookConfig.durConfig = config
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
}.onSuccess { }.onSuccess {
toast("导入成功") toastOnUI("导入成功")
}.onError { }.onError {
it.printStackTrace() it.printStackTrace()
longToast("导入失败:${it.localizedMessage}") longToast("导入失败:${it.localizedMessage}")
@ -406,7 +404,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
ReadBookConfig.durConfig.setCurBg(2, file.absolutePath) ReadBookConfig.durConfig.setCurBg(2, file.absolutePath)
ReadBookConfig.upBg() ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)
} ?: toast("获取文件出错") } ?: toastOnUI("获取文件出错")
} }
} else { } else {
PermissionsCompat.Builder(this) PermissionsCompat.Builder(this)

@ -10,7 +10,7 @@ import io.legado.app.help.AppConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.widget.text.StrokeTextView import io.legado.app.ui.widget.text.StrokeTextView
import org.jetbrains.anko.sdk27.coroutines.onClick
class ChineseConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(context, attrs) { class ChineseConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(context, attrs) {
@ -23,7 +23,7 @@ class ChineseConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(
if (!isInEditMode) { if (!isInEditMode) {
upUi(AppConfig.chineseConverterType) upUi(AppConfig.chineseConverterType)
} }
onClick { setOnClickListener {
selectType() selectType()
} }
} }

@ -16,7 +16,7 @@ import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.putPrefInt import io.legado.app.utils.putPrefInt
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class ClickActionConfigDialog : BaseDialogFragment() { class ClickActionConfigDialog : BaseDialogFragment() {
private val binding by viewBinding(DialogClickActionConfigBinding::bind) private val binding by viewBinding(DialogClickActionConfigBinding::bind)
@ -68,52 +68,52 @@ class ClickActionConfigDialog : BaseDialogFragment() {
} }
private fun initViewEvent() { private fun initViewEvent() {
binding.ivClose.onClick { binding.ivClose.setOnClickListener {
dismiss() dismiss()
} }
binding.tvTopLeft.onClick { binding.tvTopLeft.setOnClickListener {
selectAction { action -> selectAction { action ->
putPrefInt(PreferKey.clickActionTL, action) putPrefInt(PreferKey.clickActionTL, action)
(it as? TextView)?.text = actions[action] (it as? TextView)?.text = actions[action]
} }
} }
binding.tvTopCenter.onClick { binding.tvTopCenter.setOnClickListener {
selectAction { action -> selectAction { action ->
putPrefInt(PreferKey.clickActionTC, action) putPrefInt(PreferKey.clickActionTC, action)
(it as? TextView)?.text = actions[action] (it as? TextView)?.text = actions[action]
} }
} }
binding.tvTopRight.onClick { binding.tvTopRight.setOnClickListener {
selectAction { action -> selectAction { action ->
putPrefInt(PreferKey.clickActionTR, action) putPrefInt(PreferKey.clickActionTR, action)
(it as? TextView)?.text = actions[action] (it as? TextView)?.text = actions[action]
} }
} }
binding.tvMiddleLeft.onClick { binding.tvMiddleLeft.setOnClickListener {
selectAction { action -> selectAction { action ->
putPrefInt(PreferKey.clickActionML, action) putPrefInt(PreferKey.clickActionML, action)
(it as? TextView)?.text = actions[action] (it as? TextView)?.text = actions[action]
} }
} }
binding.tvMiddleRight.onClick { binding.tvMiddleRight.setOnClickListener {
selectAction { action -> selectAction { action ->
putPrefInt(PreferKey.clickActionMR, action) putPrefInt(PreferKey.clickActionMR, action)
(it as? TextView)?.text = actions[action] (it as? TextView)?.text = actions[action]
} }
} }
binding.tvBottomLeft.onClick { binding.tvBottomLeft.setOnClickListener {
selectAction { action -> selectAction { action ->
putPrefInt(PreferKey.clickActionBL, action) putPrefInt(PreferKey.clickActionBL, action)
(it as? TextView)?.text = actions[action] (it as? TextView)?.text = actions[action]
} }
} }
binding.tvBottomCenter.onClick { binding.tvBottomCenter.setOnClickListener {
selectAction { action -> selectAction { action ->
putPrefInt(PreferKey.clickActionBC, action) putPrefInt(PreferKey.clickActionBC, action)
(it as? TextView)?.text = actions[action] (it as? TextView)?.text = actions[action]
} }
} }
binding.tvBottomRight.onClick { binding.tvBottomRight.setOnClickListener {
selectAction { action -> selectAction { action ->
putPrefInt(PreferKey.clickActionBR, action) putPrefInt(PreferKey.clickActionBR, action)
(it as? TextView)?.text = actions[action] (it as? TextView)?.text = actions[action]

@ -10,7 +10,7 @@ import io.legado.app.lib.theme.backgroundColor
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.hideSoftInput import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.putPrefString import io.legado.app.utils.putPrefString
import org.jetbrains.anko.sdk27.coroutines.onClick
class PageKeyDialog(context: Context) : Dialog(context, R.style.AppTheme_AlertDialog) { class PageKeyDialog(context: Context) : Dialog(context, R.style.AppTheme_AlertDialog) {
@ -21,7 +21,7 @@ class PageKeyDialog(context: Context) : Dialog(context, R.style.AppTheme_AlertDi
binding.contentView.setBackgroundColor(context.backgroundColor) binding.contentView.setBackgroundColor(context.backgroundColor)
binding.etPrev.setText(context.getPrefString(PreferKey.prevKeys)) binding.etPrev.setText(context.getPrefString(PreferKey.prevKeys))
binding.etNext.setText(context.getPrefString(PreferKey.nextKeys)) binding.etNext.setText(context.getPrefString(PreferKey.nextKeys))
binding.tvOk.onClick { binding.tvOk.setOnClickListener {
context.putPrefString(PreferKey.prevKeys, binding.etPrev.text?.toString()) context.putPrefString(PreferKey.prevKeys, binding.etPrev.text?.toString())
context.putPrefString(PreferKey.nextKeys, binding.etNext.text?.toString()) context.putPrefString(PreferKey.nextKeys, binding.etNext.text?.toString())
dismiss() dismiss()

@ -21,7 +21,7 @@ import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import io.legado.app.utils.putPrefBoolean import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class ReadAloudDialog : BaseDialogFragment() { class ReadAloudDialog : BaseDialogFragment() {
private var callBack: CallBack? = null private var callBack: CallBack? = null
@ -122,18 +122,18 @@ class ReadAloudDialog : BaseDialogFragment() {
} }
private fun initEvent() = with(binding) { private fun initEvent() = with(binding) {
llMainMenu.onClick { callBack?.showMenuBar(); dismiss() } llMainMenu.setOnClickListener { callBack?.showMenuBar(); dismiss() }
llSetting.onClick { llSetting.setOnClickListener {
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog")
} }
tvPre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
tvNext.onClick { ReadBook.moveToNextChapter(true) } tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) }
ivStop.onClick { ReadAloud.stop(requireContext()); dismiss() } ivStop.setOnClickListener { ReadAloud.stop(requireContext()); dismiss() }
ivPlayPause.onClick { callBack?.onClickReadAloud() } ivPlayPause.setOnClickListener { callBack?.onClickReadAloud() }
ivPlayPrev.onClick { ReadAloud.prevParagraph(requireContext()) } ivPlayPrev.setOnClickListener { ReadAloud.prevParagraph(requireContext()) }
ivPlayNext.onClick { ReadAloud.nextParagraph(requireContext()) } ivPlayNext.setOnClickListener { ReadAloud.nextParagraph(requireContext()) }
llCatalog.onClick { callBack?.openChapterList() } llCatalog.setOnClickListener { callBack?.openChapterList() }
llToBackstage.onClick { callBack?.finish() } llToBackstage.setOnClickListener { callBack?.finish() }
} }
private fun upPlayState() { private fun upPlayState() {

@ -24,9 +24,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onCheckedChange
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.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)
@ -93,7 +90,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
ivStyle.setColorFilter(textColor) ivStyle.setColorFilter(textColor)
ivStyle.borderColor = textColor ivStyle.borderColor = textColor
ivStyle.setImageResource(R.drawable.ic_add) ivStyle.setImageResource(R.drawable.ic_add)
root.onClick { root.setOnClickListener {
ReadBookConfig.configList.add(ReadBookConfig.Config()) ReadBookConfig.configList.add(ReadBookConfig.Config())
showBgTextConfig(ReadBookConfig.configList.lastIndex) showBgTextConfig(ReadBookConfig.configList.lastIndex)
} }
@ -114,10 +111,10 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
textFontWeightConverter.onChanged { textFontWeightConverter.onChanged {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
tvTextFont.onClick { tvTextFont.setOnClickListener {
FontSelectDialog().show(childFragmentManager, "fontSelectDialog") FontSelectDialog().show(childFragmentManager, "fontSelectDialog")
} }
tvTextIndent.onClick { tvTextIndent.setOnClickListener {
selector( selector(
title = getString(R.string.text_indent), title = getString(R.string.text_indent),
items = resources.getStringArray(R.array.indent).toList() items = resources.getStringArray(R.array.indent).toList()
@ -126,14 +123,14 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
tvPadding.onClick { tvPadding.setOnClickListener {
dismiss() dismiss()
callBack?.showPaddingConfig() callBack?.showPaddingConfig()
} }
tvTip.onClick { tvTip.setOnClickListener {
TipConfigDialog().show(childFragmentManager, "tipConfigDialog") TipConfigDialog().show(childFragmentManager, "tipConfigDialog")
} }
rgPageAnim.onCheckedChange { _, checkedId -> rgPageAnim.setOnCheckedChangeListener { _, checkedId ->
ReadBook.book?.setPageAnim(-1) ReadBook.book?.setPageAnim(-1)
ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId) ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId)
callBack?.upPageAnim() callBack?.upPageAnim()
@ -235,14 +232,16 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack {
override fun registerListener(holder: ItemViewHolder, binding: ItemReadStyleBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemReadStyleBinding) {
binding.apply { binding.apply {
ivStyle.onClick { ivStyle.setOnClickListener {
if (ivStyle.isInView) { if (ivStyle.isInView) {
changeBg(holder.layoutPosition) changeBg(holder.layoutPosition)
} }
} }
ivStyle.onLongClick(returnValue = ivStyle.isInView) { ivStyle.setOnLongClickListener {
if (ivStyle.isInView) { if (ivStyle.isInView) {
showBgTextConfig(holder.layoutPosition) showBgTextConfig(holder.layoutPosition)
} else {
false
} }
} }
} }

@ -27,7 +27,7 @@ import io.legado.app.service.help.ReadAloud
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 io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val binding by viewBinding(DialogRecyclerViewBinding::bind)
@ -66,17 +66,17 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
recyclerView.adapter = adapter recyclerView.adapter = adapter
tvFooterLeft.setText(R.string.local_tts) tvFooterLeft.setText(R.string.local_tts)
tvFooterLeft.visible() tvFooterLeft.visible()
tvFooterLeft.onClick { tvFooterLeft.setOnClickListener {
removePref(PreferKey.speakEngine) removePref(PreferKey.speakEngine)
dismiss() dismiss()
} }
tvOk.visible() tvOk.visible()
tvOk.onClick { tvOk.setOnClickListener {
putPrefLong(PreferKey.speakEngine, engineId) putPrefLong(PreferKey.speakEngine, engineId)
dismiss() dismiss()
} }
tvCancel.visible() tvCancel.visible()
tvCancel.onClick { tvCancel.setOnClickListener {
dismiss() dismiss()
} }
} }
@ -150,16 +150,16 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener
override fun registerListener(holder: ItemViewHolder, binding: ItemHttpTtsBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemHttpTtsBinding) {
binding.apply { binding.apply {
cbName.onClick { cbName.setOnClickListener {
getItem(holder.layoutPosition)?.let { httpTTS -> getItem(holder.layoutPosition)?.let { httpTTS ->
engineId = httpTTS.id engineId = httpTTS.id
notifyItemRangeChanged(0, itemCount) notifyItemRangeChanged(0, itemCount)
} }
} }
ivEdit.onClick { ivEdit.setOnClickListener {
editHttpTTS(getItem(holder.layoutPosition)) editHttpTTS(getItem(holder.layoutPosition))
} }
ivMenuDelete.onClick { ivMenuDelete.setOnClickListener {
getItem(holder.layoutPosition)?.let { httpTTS -> getItem(holder.layoutPosition)?.let { httpTTS ->
App.db.httpTTSDao.delete(httpTTS) App.db.httpTTSDao.delete(httpTTS)
} }

@ -10,7 +10,7 @@ import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.widget.text.StrokeTextView import io.legado.app.ui.widget.text.StrokeTextView
import org.jetbrains.anko.sdk27.coroutines.onClick
class TextFontWeightConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(context, attrs) { class TextFontWeightConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(context, attrs) {
@ -23,7 +23,7 @@ class TextFontWeightConverter(context: Context, attrs: AttributeSet?) : StrokeTe
if (!isInEditMode) { if (!isInEditMode) {
upUi(ReadBookConfig.textBold) upUi(ReadBookConfig.textBold)
} }
onClick { setOnClickListener {
selectType() selectType()
} }
} }

@ -14,8 +14,7 @@ import io.legado.app.help.ReadTipConfig
import io.legado.app.lib.dialogs.selector import io.legado.app.lib.dialogs.selector
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.sdk27.coroutines.onCheckedChange
import org.jetbrains.anko.sdk27.coroutines.onClick
class TipConfigDialog : BaseDialogFragment() { class TipConfigDialog : BaseDialogFragment() {
@ -76,7 +75,7 @@ class TipConfigDialog : BaseDialogFragment() {
} }
private fun initEvent() = with(binding) { private fun initEvent() = with(binding) {
rgTitleMode.onCheckedChange { _, checkedId -> rgTitleMode.setOnCheckedChangeListener { _, checkedId ->
ReadBookConfig.titleMode = rgTitleMode.getIndexById(checkedId) ReadBookConfig.titleMode = rgTitleMode.getIndexById(checkedId)
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
@ -92,21 +91,21 @@ class TipConfigDialog : BaseDialogFragment() {
ReadBookConfig.titleBottomSpacing = it ReadBookConfig.titleBottomSpacing = it
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
llHeaderShow.onClick { llHeaderShow.setOnClickListener {
selector(items = ReadTipConfig.headerModes.values.toList()) { _, i -> selector(items = ReadTipConfig.headerModes.values.toList()) { _, i ->
ReadTipConfig.headerMode = ReadTipConfig.headerModes.keys.toList()[i] ReadTipConfig.headerMode = ReadTipConfig.headerModes.keys.toList()[i]
tvHeaderShow.text = ReadTipConfig.headerModes[ReadTipConfig.headerMode] tvHeaderShow.text = ReadTipConfig.headerModes[ReadTipConfig.headerMode]
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
llFooterShow.onClick { llFooterShow.setOnClickListener {
selector(items = ReadTipConfig.footerModes.values.toList()) { _, i -> selector(items = ReadTipConfig.footerModes.values.toList()) { _, i ->
ReadTipConfig.footerMode = ReadTipConfig.footerModes.keys.toList()[i] ReadTipConfig.footerMode = ReadTipConfig.footerModes.keys.toList()[i]
tvFooterShow.text = ReadTipConfig.footerModes[ReadTipConfig.footerMode] tvFooterShow.text = ReadTipConfig.footerModes[ReadTipConfig.footerMode]
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
llHeaderLeft.onClick { llHeaderLeft.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i -> selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i) clearRepeat(i)
ReadTipConfig.tipHeaderLeft = i ReadTipConfig.tipHeaderLeft = i
@ -114,7 +113,7 @@ class TipConfigDialog : BaseDialogFragment() {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
llHeaderMiddle.onClick { llHeaderMiddle.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i -> selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i) clearRepeat(i)
ReadTipConfig.tipHeaderMiddle = i ReadTipConfig.tipHeaderMiddle = i
@ -122,7 +121,7 @@ class TipConfigDialog : BaseDialogFragment() {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
llHeaderRight.onClick { llHeaderRight.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i -> selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i) clearRepeat(i)
ReadTipConfig.tipHeaderRight = i ReadTipConfig.tipHeaderRight = i
@ -130,7 +129,7 @@ class TipConfigDialog : BaseDialogFragment() {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
llFooterLeft.onClick { llFooterLeft.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i -> selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i) clearRepeat(i)
ReadTipConfig.tipFooterLeft = i ReadTipConfig.tipFooterLeft = i
@ -138,7 +137,7 @@ class TipConfigDialog : BaseDialogFragment() {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
llFooterMiddle.onClick { llFooterMiddle.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i -> selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i) clearRepeat(i)
ReadTipConfig.tipFooterMiddle = i ReadTipConfig.tipFooterMiddle = i
@ -146,7 +145,7 @@ class TipConfigDialog : BaseDialogFragment() {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
llFooterRight.onClick { llFooterRight.setOnClickListener {
selector(items = ReadTipConfig.tips) { _, i -> selector(items = ReadTipConfig.tips) { _, i ->
clearRepeat(i) clearRepeat(i)
ReadTipConfig.tipFooterRight = i ReadTipConfig.tipFooterRight = i
@ -154,7 +153,7 @@ class TipConfigDialog : BaseDialogFragment() {
postEvent(EventBus.UP_CONFIG, true) postEvent(EventBus.UP_CONFIG, true)
} }
} }
llTipColor.onClick { llTipColor.setOnClickListener {
selector(items = arrayListOf("跟随正文", "自定义")) { _, i -> selector(items = arrayListOf("跟随正文", "自定义")) { _, i ->
when (i) { when (i) {
0 -> { 0 -> {

@ -33,7 +33,7 @@ import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.sdk27.coroutines.onClick
import java.util.* import java.util.*
class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
@ -79,16 +79,16 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
val itemTouchCallback = ItemTouchCallback(adapter) val itemTouchCallback = ItemTouchCallback(adapter)
itemTouchCallback.isCanDrag = true itemTouchCallback.isCanDrag = true
ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recyclerView) ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recyclerView)
tvCancel.onClick { tvCancel.setOnClickListener {
dismiss() dismiss()
} }
tvOk.onClick { tvOk.setOnClickListener {
adapter.getItems().forEach { tocRule -> adapter.getItems().forEach { tocRule ->
if (selectedName == tocRule.name) { if (selectedName == tocRule.name) {
val callBack = activity as? CallBack val callBack = activity as? CallBack
callBack?.onTocRegexDialogResult(tocRule.rule) callBack?.onTocRegexDialogResult(tocRule.rule)
dismiss() dismiss()
return@onClick return@setOnClickListener
} }
} }
} }
@ -231,10 +231,10 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
} }
} }
} }
ivEdit.onClick { ivEdit.setOnClickListener {
editRule(getItem(holder.layoutPosition)) editRule(getItem(holder.layoutPosition))
} }
ivDelete.onClick { ivDelete.setOnClickListener {
getItem(holder.layoutPosition)?.let { item -> getItem(holder.layoutPosition)?.let { item ->
launch(IO) { launch(IO) {
App.db.txtTocRule.delete(item) App.db.txtTocRule.delete(item)

@ -20,7 +20,6 @@ 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.widget.BatteryView import io.legado.app.ui.widget.BatteryView
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.topPadding
import java.util.* import java.util.*
/** /**
@ -97,9 +96,9 @@ class PageView(context: Context) : FrameLayout(context) {
/** /**
* 显示状态栏时隐藏header * 显示状态栏时隐藏header
*/ */
fun upStatusBar() { fun upStatusBar() = with(binding.vwStatusBar) {
binding.vwStatusBar.topPadding = context.statusBarHeight setPadding(paddingLeft, context.statusBarHeight, paddingRight, paddingBottom)
binding.vwStatusBar.isGone = isGone =
ReadBookConfig.hideStatusBar || (activity as? BaseActivity<*>)?.isInMultiWindow == true ReadBookConfig.hideStatusBar || (activity as? BaseActivity<*>)?.isInMultiWindow == true
} }

@ -6,7 +6,7 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.databinding.ItemFilletTextBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class BookAdapter(context: Context, val callBack: CallBack) : class BookAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<Book, ItemFilletTextBinding>(context) { RecyclerAdapter<Book, ItemFilletTextBinding>(context) {
@ -28,7 +28,7 @@ class BookAdapter(context: Context, val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) {
holder.itemView.apply { holder.itemView.apply {
onClick { setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.showBookInfo(it) callBack.showBookInfo(it)
} }

@ -10,9 +10,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick
class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
RecyclerAdapter<SearchKeyword, ItemFilletTextBinding>(activity) { RecyclerAdapter<SearchKeyword, ItemFilletTextBinding>(activity) {
@ -36,12 +33,12 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) {
holder.itemView.apply { holder.itemView.apply {
onClick { setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.searchHistory(it.word) callBack.searchHistory(it.word)
} }
} }
onLongClick(returnValue = true) { setOnLongClickListener {
it?.let { it?.let {
explosionField.explode(it, true) explosionField.explode(it, true)
} }
@ -50,6 +47,7 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
App.db.searchKeywordDao.delete(it) App.db.searchKeywordDao.delete(it)
} }
} }
true
} }
} }
} }

@ -28,7 +28,7 @@ import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO 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.sdk27.coroutines.onClick
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(), class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
@ -184,11 +184,11 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
.setDefaultColor(accentColor) .setDefaultColor(accentColor)
.setPressedColor(ColorUtils.darkenColor(accentColor)) .setPressedColor(ColorUtils.darkenColor(accentColor))
.create() .create()
binding.fbStop.onClick { binding.fbStop.setOnClickListener {
viewModel.stop() viewModel.stop()
binding.refreshProgressBar.isAutoLoading = false binding.refreshProgressBar.isAutoLoading = false
} }
binding.tvClearHistory.onClick { viewModel.clearHistory() } binding.tvClearHistory.setOnClickListener { viewModel.clearHistory() }
} }
private fun initLiveData() { private fun initLiveData() {

@ -11,7 +11,7 @@ import io.legado.app.data.entities.SearchBook
import io.legado.app.databinding.ItemSearchBinding import io.legado.app.databinding.ItemSearchBinding
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 org.jetbrains.anko.sdk27.coroutines.onClick
class SearchAdapter(context: Context, val callBack: CallBack) : class SearchAdapter(context: Context, val callBack: CallBack) :
DiffRecyclerAdapter<SearchBook, ItemSearchBinding>(context) { DiffRecyclerAdapter<SearchBook, ItemSearchBinding>(context) {
@ -66,7 +66,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) {
binding.root.onClick { binding.root.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.showBookInfo(it.name, it.author) callBack.showBookInfo(it.name, it.author)
} }

@ -26,7 +26,7 @@ import io.legado.app.utils.observeEvent
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.sdk27.coroutines.onClick
class SearchContentActivity : class SearchContentActivity :
VMBaseActivity<ActivitySearchContentBinding, SearchContentViewModel>(), VMBaseActivity<ActivitySearchContentBinding, SearchContentViewModel>(),
@ -92,8 +92,13 @@ class SearchContentActivity :
} }
private fun initView() { private fun initView() {
binding.ivSearchContentTop.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } binding.ivSearchContentTop.setOnClickListener {
binding.ivSearchContentBottom.onClick { mLayoutManager.scrollToPositionWithOffset(
0,
0
)
}
binding.ivSearchContentBottom.setOnClickListener {
if (adapter.itemCount > 0) { if (adapter.itemCount > 0) {
mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0) mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0)
} }

@ -9,7 +9,7 @@ import io.legado.app.databinding.ItemSearchListBinding
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.hexString import io.legado.app.utils.hexString
import org.jetbrains.anko.sdk27.coroutines.onClick
class SearchContentAdapter(context: Context, val callback: Callback) : class SearchContentAdapter(context: Context, val callback: Callback) :
RecyclerAdapter<SearchResult, ItemSearchListBinding>(context) { RecyclerAdapter<SearchResult, ItemSearchListBinding>(context) {
@ -38,7 +38,7 @@ class SearchContentAdapter(context: Context, val callback: Callback) :
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemSearchListBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemSearchListBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callback.openSearchResult(it) callback.openSearchResult(it)
} }

@ -14,9 +14,9 @@ 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.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.toastOnUI
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() { class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookSourceDebugModel>() {
@ -83,7 +83,7 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
viewModel.startDebug(key, { viewModel.startDebug(key, {
binding.rotateLoading.show() binding.rotateLoading.show()
}, { }, {
toast("未获取到书源") toastOnUI("未获取到书源")
}) })
} }

@ -105,7 +105,7 @@ class BookSourceEditActivity :
R.id.menu_login -> getSource().let { R.id.menu_login -> getSource().let {
if (checkSource(it)) { if (checkSource(it)) {
if (it.loginUrl.isNullOrEmpty()) { if (it.loginUrl.isNullOrEmpty()) {
toast(R.string.source_no_login) toastOnUI(R.string.source_no_login)
} else { } else {
startActivity<SourceLogin>( startActivity<SourceLogin>(
Pair("sourceUrl", it.bookSourceUrl), Pair("sourceUrl", it.bookSourceUrl),
@ -357,7 +357,7 @@ class BookSourceEditActivity :
private fun checkSource(source: BookSource): Boolean { private fun checkSource(source: BookSource): Boolean {
if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) { if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) {
toast(R.string.non_null_name_url) toastOnUI(R.string.non_null_name_url)
return false return false
} }
return true return true

@ -45,7 +45,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
}.onError { }.onError {
toast(it.localizedMessage) toastOnUI(it.localizedMessage)
it.printStackTrace() it.printStackTrace()
} }
} }
@ -58,13 +58,13 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
} }
source source
}.onError { }.onError {
toast(it.localizedMessage) toastOnUI(it.localizedMessage)
it.printStackTrace() it.printStackTrace()
}.onSuccess { }.onSuccess {
if (it != null) { if (it != null) {
onSuccess(it) onSuccess(it)
} else { } else {
toast("格式不对") toastOnUI("格式不对")
} }
} }
} }
@ -76,7 +76,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
finally.invoke(it) finally.invoke(it)
} }
}.onError { }.onError {
toast(it.localizedMessage ?: "Error") toastOnUI(it.localizedMessage ?: "Error")
} }
} }
} }

@ -40,7 +40,6 @@ 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.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
import java.io.File import java.io.File
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(), class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
@ -412,7 +411,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
groups.map { group -> groups.map { group ->
if (group.contains("失效")) { if (group.contains("失效")) {
searchView.setQuery("失效", true) searchView.setQuery("失效", true)
toast("发现有失效书源,已为您自动筛选!") toastOnUI("发现有失效书源,已为您自动筛选!")
} }
} }
} }
@ -474,7 +473,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
startActivity<ImportBookSourceActivity>("dataKey" to dataKey) startActivity<ImportBookSourceActivity>("dataKey" to dataKey)
} }
} catch (e: Exception) { } catch (e: Exception) {
toast("readTextError:${e.localizedMessage}") toastOnUI("readTextError:${e.localizedMessage}")
} }
} }
} }

@ -20,7 +20,7 @@ import io.legado.app.ui.widget.recycler.DragSelectTouchHelper
import io.legado.app.ui.widget.recycler.ItemTouchCallback.Callback import io.legado.app.ui.widget.recycler.ItemTouchCallback.Callback
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 org.jetbrains.anko.sdk27.coroutines.onClick
class BookSourceAdapter(context: Context, val callBack: CallBack) : class BookSourceAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<BookSource, ItemBookSourceBinding>(context), RecyclerAdapter<BookSource, ItemBookSourceBinding>(context),
@ -132,12 +132,12 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
} }
} }
} }
ivEdit.onClick { ivEdit.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.edit(it) callBack.edit(it)
} }
} }
ivMenuMore.onClick { ivMenuMore.setOnClickListener {
showMenu(ivMenuMore, holder.layoutPosition) showMenu(ivMenuMore, holder.layoutPosition)
} }
} }

@ -181,7 +181,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application)
}.onSuccess { }.onSuccess {
success.invoke(it) success.invoke(it)
}.onError { }.onError {
toast(it.msg) toastOnUI(it.msg)
} }
} }

@ -24,7 +24,7 @@ import io.legado.app.lib.theme.primaryColor
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 io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: BookSourceViewModel private lateinit var viewModel: BookSourceViewModel
@ -129,12 +129,12 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
override fun registerListener(holder: ItemViewHolder, binding: ItemGroupManageBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemGroupManageBinding) {
binding.apply { binding.apply {
tvEdit.onClick { tvEdit.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
editGroup(it) editGroup(it)
} }
} }
tvDel.onClick { tvDel.setOnClickListener {
getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) }
} }
} }

@ -7,8 +7,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick
class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>(DIFF_CALLBACK) { class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -45,11 +43,12 @@ class BookmarkAdapter(val callback: Callback) : PagedListAdapter<Bookmark, Bookm
tvChapterName.text = bookmark.chapterName tvChapterName.text = bookmark.chapterName
tvBookText.text = bookmark.bookText tvBookText.text = bookmark.bookText
tvContent.text = bookmark.content tvContent.text = bookmark.content
itemView.onClick { itemView.setOnClickListener {
callback?.onClick(bookmark) callback?.onClick(bookmark)
} }
itemView.onLongClick(returnValue = true) { itemView.setOnLongClickListener {
callback?.onLongClick(bookmark) callback?.onLongClick(bookmark)
true
} }
} }
} }

@ -10,7 +10,7 @@ import io.legado.app.databinding.ItemChapterListBinding
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.visible import io.legado.app.utils.visible
import org.jetbrains.anko.sdk27.coroutines.onClick
class ChapterListAdapter(context: Context, val callback: Callback) : class ChapterListAdapter(context: Context, val callback: Callback) :
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) { RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
@ -49,7 +49,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callback.openChapter(it) callback.openChapter(it)
} }

@ -26,7 +26,7 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.jetbrains.anko.sdk27.coroutines.onClick
import kotlin.math.min import kotlin.math.min
class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list), class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list),
@ -63,13 +63,13 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
} }
private fun initView() = with(binding) { private fun initView() = with(binding) {
ivChapterTop.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } ivChapterTop.setOnClickListener { mLayoutManager.scrollToPositionWithOffset(0, 0) }
ivChapterBottom.onClick { ivChapterBottom.setOnClickListener {
if (adapter.itemCount > 0) { if (adapter.itemCount > 0) {
mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0) mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0)
} }
} }
tvCurrentChapterInfo.onClick { tvCurrentChapterInfo.setOnClickListener {
mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0)
} }
} }

@ -20,9 +20,8 @@ import io.legado.app.ui.filepicker.FilePicker
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.isContentScheme import io.legado.app.utils.isContentScheme
import io.legado.app.utils.longToast import io.legado.app.utils.longToast
import io.legado.app.utils.toast import io.legado.app.utils.toastOnUI
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import org.jetbrains.anko.toast
object BackupRestoreUi { object BackupRestoreUi {
private const val selectFolderRequestCode = 21 private const val selectFolderRequestCode = 21
@ -42,7 +41,7 @@ object BackupRestoreUi {
Coroutine.async { Coroutine.async {
Backup.backup(fragment.requireContext(), backupPath) Backup.backup(fragment.requireContext(), backupPath)
}.onSuccess { }.onSuccess {
fragment.toast(R.string.backup_success) fragment.toastOnUI(R.string.backup_success)
} }
} else { } else {
selectBackupFolder(fragment, backupSelectRequestCode) selectBackupFolder(fragment, backupSelectRequestCode)
@ -65,7 +64,7 @@ object BackupRestoreUi {
AppConfig.backupPath = path AppConfig.backupPath = path
Backup.backup(fragment.requireContext(), path) Backup.backup(fragment.requireContext(), path)
}.onSuccess { }.onSuccess {
fragment.toast(R.string.backup_success) fragment.toastOnUI(R.string.backup_success)
} }
} }
.request() .request()
@ -135,7 +134,7 @@ object BackupRestoreUi {
Coroutine.async { Coroutine.async {
Backup.backup(App.INSTANCE, uri.toString()) Backup.backup(App.INSTANCE, uri.toString())
}.onSuccess { }.onSuccess {
App.INSTANCE.toast(R.string.backup_success) App.INSTANCE.toastOnUI(R.string.backup_success)
} }
} else { } else {
uri.path?.let { path -> uri.path?.let { path ->
@ -143,7 +142,7 @@ object BackupRestoreUi {
Coroutine.async { Coroutine.async {
Backup.backup(App.INSTANCE, path) Backup.backup(App.INSTANCE, path)
}.onSuccess { }.onSuccess {
App.INSTANCE.toast(R.string.backup_success) App.INSTANCE.toastOnUI(R.string.backup_success)
} }
} }
} }

@ -177,7 +177,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
okButton { okButton {
BookHelp.clearCache() BookHelp.clearCache()
FileUtils.deleteFile(requireActivity().cacheDir.absolutePath) FileUtils.deleteFile(requireActivity().cacheDir.absolutePath)
toast(R.string.clear_cache_success) toastOnUI(R.string.clear_cache_success)
} }
noButton() noButton()
}.show() }.show()
@ -221,7 +221,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
file.writeBytes(byteArray) file.writeBytes(byteArray)
putPrefString(PreferKey.defaultCover, file.absolutePath) putPrefString(PreferKey.defaultCover, file.absolutePath)
CoverImageView.upDefaultCover() CoverImageView.upDefaultCover()
} ?: toast("获取文件出错") } ?: toastOnUI("获取文件出错")
} }
} else { } else {
PermissionsCompat.Builder(this) PermissionsCompat.Builder(this)

@ -60,7 +60,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
findPreference<ColorPreference>(PreferKey.cBackground)?.let { findPreference<ColorPreference>(PreferKey.cBackground)?.let {
it.onSaveColor = { color -> it.onSaveColor = { color ->
if (!ColorUtils.isColorLight(color)) { if (!ColorUtils.isColorLight(color)) {
toast(R.string.day_background_too_dark) toastOnUI(R.string.day_background_too_dark)
true true
} else { } else {
false false
@ -70,7 +70,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
findPreference<ColorPreference>(PreferKey.cNBackground)?.let { findPreference<ColorPreference>(PreferKey.cNBackground)?.let {
it.onSaveColor = { color -> it.onSaveColor = { color ->
if (ColorUtils.isColorLight(color)) { if (ColorUtils.isColorLight(color)) {
toast(R.string.night_background_too_light) toastOnUI(R.string.night_background_too_light)
true true
} else { } else {
false false
@ -84,11 +84,11 @@ class ThemeConfigFragment : BasePreferenceFragment(),
val textColor = getCompatColor(R.color.primaryText) val textColor = getCompatColor(R.color.primaryText)
when { when {
ColorUtils.getColorDifference(color, background) <= 60 -> { ColorUtils.getColorDifference(color, background) <= 60 -> {
toast(R.string.accent_background_diff) toastOnUI(R.string.accent_background_diff)
true true
} }
ColorUtils.getColorDifference(color, textColor) <= 60 -> { ColorUtils.getColorDifference(color, textColor) <= 60 -> {
toast(R.string.accent_text_diff) toastOnUI(R.string.accent_text_diff)
true true
} }
else -> false else -> false
@ -102,11 +102,11 @@ class ThemeConfigFragment : BasePreferenceFragment(),
val textColor = getCompatColor(R.color.primaryText) val textColor = getCompatColor(R.color.primaryText)
when { when {
ColorUtils.getColorDifference(color, background) <= 60 -> { ColorUtils.getColorDifference(color, background) <= 60 -> {
toast(R.string.accent_background_diff) toastOnUI(R.string.accent_background_diff)
true true
} }
ColorUtils.getColorDifference(color, textColor) <= 60 -> { ColorUtils.getColorDifference(color, textColor) <= 60 -> {
toast(R.string.accent_text_diff) toastOnUI(R.string.accent_text_diff)
true true
} }
else -> false else -> false
@ -277,7 +277,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
putPrefString(preferenceKey, file.absolutePath) putPrefString(preferenceKey, file.absolutePath)
upPreferenceSummary(preferenceKey, file.absolutePath) upPreferenceSummary(preferenceKey, file.absolutePath)
success() success()
} ?: toast("获取文件出错") } ?: toastOnUI("获取文件出错")
} }
} else { } else {
PermissionsCompat.Builder(this) PermissionsCompat.Builder(this)

@ -19,7 +19,7 @@ import io.legado.app.lib.theme.primaryColor
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 io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.share import org.jetbrains.anko.share
class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
@ -72,7 +72,7 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
if (ThemeConfig.addConfig(it)) { if (ThemeConfig.addConfig(it)) {
initData() initData()
} else { } else {
toast("格式不对,添加失败") toastOnUI("格式不对,添加失败")
} }
} }
} }
@ -115,13 +115,13 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
override fun registerListener(holder: ItemViewHolder, binding: ItemThemeConfigBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemThemeConfigBinding) {
binding.apply { binding.apply {
root.onClick { root.setOnClickListener {
ThemeConfig.applyConfig(context, ThemeConfig.configList[holder.layoutPosition]) ThemeConfig.applyConfig(context, ThemeConfig.configList[holder.layoutPosition])
} }
ivShare.onClick { ivShare.setOnClickListener {
share(holder.layoutPosition) share(holder.layoutPosition)
} }
ivDelete.onClick { ivDelete.setOnClickListener {
delete(holder.layoutPosition) delete(holder.layoutPosition)
} }
} }

@ -170,14 +170,14 @@ class FilePickerDialog : DialogFragment(),
} else { } else {
fileItem?.path?.let { path -> fileItem?.path?.let { path ->
if (mode == DIRECTORY) { if (mode == DIRECTORY) {
toast("这是文件夹选择,不能选择文件,点击右上角的确定选择文件夹") toastOnUI("这是文件夹选择,不能选择文件,点击右上角的确定选择文件夹")
} else if (allowExtensions.isNullOrEmpty() || } else if (allowExtensions.isNullOrEmpty() ||
allowExtensions?.contains(FileUtils.getExtension(path)) == true allowExtensions?.contains(FileUtils.getExtension(path)) == true
) { ) {
setData(path) setData(path)
dismiss() dismiss()
} else { } else {
toast("不能打开此文件") toastOnUI("不能打开此文件")
} }
} }
} }

@ -13,7 +13,7 @@ import io.legado.app.ui.filepicker.entity.FileItem
import io.legado.app.ui.filepicker.utils.ConvertUtils import io.legado.app.ui.filepicker.utils.ConvertUtils
import io.legado.app.ui.filepicker.utils.FilePickerIcon import io.legado.app.ui.filepicker.utils.FilePickerIcon
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import org.jetbrains.anko.sdk27.coroutines.onClick
import java.io.File import java.io.File
import java.util.* import java.util.*
@ -118,7 +118,7 @@ class FileAdapter(context: Context, val callBack: CallBack) :
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemFileFilepickerBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemFileFilepickerBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
callBack.onFileClick(holder.layoutPosition) callBack.onFileClick(holder.layoutPosition)
} }
} }

@ -8,7 +8,7 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.databinding.ItemPathFilepickerBinding import io.legado.app.databinding.ItemPathFilepickerBinding
import io.legado.app.ui.filepicker.utils.ConvertUtils import io.legado.app.ui.filepicker.utils.ConvertUtils
import io.legado.app.ui.filepicker.utils.FilePickerIcon import io.legado.app.ui.filepicker.utils.FilePickerIcon
import org.jetbrains.anko.sdk27.coroutines.onClick
import java.util.* import java.util.*
@ -61,7 +61,7 @@ class PathAdapter(context: Context, val callBack: CallBack) :
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemPathFilepickerBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemPathFilepickerBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
callBack.onPathClick(holder.layoutPosition) callBack.onPathClick(holder.layoutPosition)
} }
} }

@ -32,7 +32,7 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.hideSoftInput import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
import org.jetbrains.anko.toast import io.legado.app.utils.toastOnUI
class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(), class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
@ -144,7 +144,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
return true return true
} }
if (System.currentTimeMillis() - exitTime > 2000) { if (System.currentTimeMillis() - exitTime > 2000) {
toast(R.string.double_click_exit) toastOnUI(R.string.double_click_exit)
exitTime = System.currentTimeMillis() exitTime = System.currentTimeMillis()
} else { } else {
if (BaseReadAloudService.pause) { if (BaseReadAloudService.pause) {

@ -205,7 +205,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
override fun onTabReselected(tab: TabLayout.Tab) { override fun onTabReselected(tab: TabLayout.Tab) {
fragmentMap[selectedGroup.groupId]?.let { fragmentMap[selectedGroup.groupId]?.let {
toast("${selectedGroup.groupName}(${it.getBooksCount()})") toastOnUI("${selectedGroup.groupName}(${it.getBooksCount()})")
} }
} }

@ -57,12 +57,12 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
} }
}.onSuccess { }.onSuccess {
if (successCount > 0) { if (successCount > 0) {
toast(R.string.success) toastOnUI(R.string.success)
} else { } else {
toast("ERROR") toastOnUI("ERROR")
} }
}.onError { }.onError {
toast(it.localizedMessage ?: "ERROR") toastOnUI(it.localizedMessage ?: "ERROR")
} }
} }
@ -98,7 +98,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
} }
} }
}.onError { }.onError {
toast(it.localizedMessage ?: "ERROR") toastOnUI(it.localizedMessage ?: "ERROR")
} }
} }
@ -121,7 +121,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
} }
} }
}.onFinally { }.onFinally {
toast(R.string.success) toastOnUI(R.string.success)
} }
} }

@ -9,8 +9,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick
class BooksAdapterGrid(context: Context, private val callBack: CallBack) : class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
BaseBooksAdapter<ItemBookshelfGridBinding>(context) { BaseBooksAdapter<ItemBookshelfGridBinding>(context) {
@ -55,16 +53,17 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemBookshelfGridBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemBookshelfGridBinding) {
holder.itemView.apply { holder.itemView.apply {
onClick { setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.open(it) callBack.open(it)
} }
} }
onLongClick(returnValue = true) { setOnLongClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.openBookInfo(it) callBack.openBookInfo(it)
} }
true
} }
} }
} }

@ -9,8 +9,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick
class BooksAdapterList(context: Context, private val callBack: CallBack) : class BooksAdapterList(context: Context, private val callBack: CallBack) :
BaseBooksAdapter<ItemBookshelfListBinding>(context) { BaseBooksAdapter<ItemBookshelfListBinding>(context) {
@ -61,16 +59,17 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemBookshelfListBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemBookshelfListBinding) {
holder.itemView.apply { holder.itemView.apply {
onClick { setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.open(it) callBack.open(it)
} }
} }
onLongClick(returnValue = true) { setOnLongClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.openBookInfo(it) callBack.openBookInfo(it)
} }
true
} }
} }
} }

@ -19,8 +19,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.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) {
@ -68,7 +66,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
glChild.addView(tv.root) glChild.addView(tv.root)
tv.textView.text = kind.title tv.textView.text = kind.title
if (!kind.url.isNullOrEmpty()) { if (!kind.url.isNullOrEmpty()) {
tv.textView.onClick { tv.textView.setOnClickListener {
callBack.openExplore( callBack.openExplore(
item.bookSourceUrl, item.bookSourceUrl,
kind.title, kind.title,
@ -95,7 +93,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
override fun registerListener(holder: ItemViewHolder, binding: ItemFindBookBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemFindBookBinding) {
binding.apply { binding.apply {
llTitle.onClick { llTitle.setOnClickListener {
val position = holder.layoutPosition val position = holder.layoutPosition
val oldEx = exIndex val oldEx = exIndex
exIndex = if (exIndex == position) -1 else position exIndex = if (exIndex == position) -1 else position
@ -106,8 +104,9 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
notifyItemChanged(position, false) notifyItemChanged(position, false)
} }
} }
llTitle.onLongClick { llTitle.setOnLongClickListener {
showMenu(llTitle, holder.layoutPosition) showMenu(llTitle, holder.layoutPosition)
true
} }
} }
} }

@ -10,8 +10,6 @@ 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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.sdk27.coroutines.onLongClick
class RssAdapter(context: Context, val callBack: CallBack) : class RssAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<RssSource, ItemRssBinding>(context) { RecyclerAdapter<RssSource, ItemRssBinding>(context) {
@ -38,15 +36,16 @@ class RssAdapter(context: Context, val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemRssBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemRssBinding) {
binding.apply { binding.apply {
root.onClick { root.setOnClickListener {
getItemByLayoutPosition(holder.layoutPosition)?.let { getItemByLayoutPosition(holder.layoutPosition)?.let {
callBack.openRss(it) callBack.openRss(it)
} }
} }
root.onLongClick(returnValue = true) { root.setOnLongClickListener {
getItemByLayoutPosition(holder.layoutPosition)?.let { getItemByLayoutPosition(holder.layoutPosition)?.let {
showMenu(ivIcon, it) showMenu(ivIcon, it)
} }
true
} }
} }
} }

@ -28,7 +28,7 @@ import io.legado.app.utils.getViewModel
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
/** /**
* 订阅界面 * 订阅界面
@ -106,7 +106,7 @@ class RssFragment : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
ItemRssBinding.inflate(layoutInflater, it, false).apply { ItemRssBinding.inflate(layoutInflater, it, false).apply {
tvName.setText(R.string.rule_subscription) tvName.setText(R.string.rule_subscription)
ivIcon.setImageResource(R.drawable.image_legado) ivIcon.setImageResource(R.drawable.image_legado)
root.onClick { root.setOnClickListener {
startActivity<RuleSubActivity>() startActivity<RuleSubActivity>()
} }
} }

@ -24,7 +24,7 @@ import io.legado.app.lib.theme.primaryColor
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 io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import org.jetbrains.anko.sdk27.coroutines.onClick
class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: ReplaceRuleViewModel private lateinit var viewModel: ReplaceRuleViewModel
@ -134,13 +134,13 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
override fun registerListener(holder: ItemViewHolder, binding: ItemGroupManageBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemGroupManageBinding) {
binding.apply { binding.apply {
tvEdit.onClick { tvEdit.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
editGroup(it) editGroup(it)
} }
} }
tvDel.onClick { tvDel.setOnClickListener {
getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) }
} }
} }

@ -39,7 +39,6 @@ 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.startActivity
import org.jetbrains.anko.startActivityForResult import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast
import java.io.File import java.io.File
/** /**
@ -270,7 +269,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
startActivity<ImportReplaceRuleActivity>("dataKey" to dataKey) startActivity<ImportReplaceRuleActivity>("dataKey" to dataKey)
} }
}.onFailure { }.onFailure {
toast("readTextError:${it.localizedMessage}") toastOnUI("readTextError:${it.localizedMessage}")
} }
} }
} }

@ -16,7 +16,7 @@ import io.legado.app.databinding.ItemReplaceRuleBinding
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.widget.recycler.DragSelectTouchHelper 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 org.jetbrains.anko.sdk27.coroutines.onClick
import java.util.* import java.util.*
@ -147,12 +147,12 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
} }
} }
} }
ivEdit.onClick { ivEdit.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.edit(it) callBack.edit(it)
} }
} }
cbName.onClick { cbName.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
if (cbName.isChecked) { if (cbName.isChecked) {
selected.add(it) selected.add(it)
@ -162,7 +162,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) :
} }
callBack.upCountView() callBack.upCountView()
} }
ivMenuMore.onClick { ivMenuMore.setOnClickListener {
showMenu(ivMenuMore, holder.layoutPosition) showMenu(ivMenuMore, holder.layoutPosition)
} }
} }

@ -6,11 +6,7 @@ import androidx.documentfile.provider.DocumentFile
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.FileUtils import io.legado.app.utils.*
import io.legado.app.utils.GSON
import io.legado.app.utils.splitNotBlank
import io.legado.app.utils.writeText
import org.jetbrains.anko.toast
import java.io.File import java.io.File
class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) { class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) {
@ -83,9 +79,9 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
FileUtils.createFileIfNotExist(file, "exportReplaceRule.json") FileUtils.createFileIfNotExist(file, "exportReplaceRule.json")
.writeText(json) .writeText(json)
}.onSuccess { }.onSuccess {
context.toast("成功导出至\n${file.absolutePath}") context.toastOnUI("成功导出至\n${file.absolutePath}")
}.onError { }.onError {
context.toast("导出失败\n${it.localizedMessage}") context.toastOnUI("导出失败\n${it.localizedMessage}")
} }
} }
@ -96,9 +92,9 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application
doc.createFile("", "exportReplaceRule.json") doc.createFile("", "exportReplaceRule.json")
?.writeText(context, json) ?.writeText(context, json)
}.onSuccess { }.onSuccess {
context.toast("成功导出至\n${doc.uri.path}") context.toastOnUI("成功导出至\n${doc.uri.path}")
}.onError { }.onError {
context.toast("导出失败\n${it.localizedMessage}") context.toastOnUI("导出失败\n${it.localizedMessage}")
} }
} }

@ -20,10 +20,9 @@ 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.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUI
import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.displayMetrics
import org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.selector import org.jetbrains.anko.selector
import org.jetbrains.anko.toast
import kotlin.math.abs import kotlin.math.abs
/** /**
@ -68,7 +67,7 @@ class ReplaceEditActivity :
viewModel.initData(intent) { viewModel.initData(intent) {
upReplaceView(it) upReplaceView(it)
} }
binding.ivHelp.onClick { binding.ivHelp.setOnClickListener {
showRegexHelp() showRegexHelp()
} }
} }
@ -83,7 +82,7 @@ class ReplaceEditActivity :
R.id.menu_save -> { R.id.menu_save -> {
val rule = getReplaceRule() val rule = getReplaceRule()
if (!rule.isValid()) { if (!rule.isValid()) {
toast(R.string.replace_rule_invalid) toastOnUI(R.string.replace_rule_invalid)
} else { } else {
viewModel.save(rule) { viewModel.save(rule) {
postEvent(EventBus.REPLACE_RULE_SAVE, "") postEvent(EventBus.REPLACE_RULE_SAVE, "")

@ -12,10 +12,10 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssArticle
import io.legado.app.databinding.ItemRssArticleBinding import io.legado.app.databinding.ItemRssArticleBinding
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.utils.getCompatColor
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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.textColorResource
class RssArticlesAdapter(context: Context, callBack: CallBack) : class RssArticlesAdapter(context: Context, callBack: CallBack) :
BaseRssArticlesAdapter<ItemRssArticleBinding>(context, callBack) { BaseRssArticlesAdapter<ItemRssArticleBinding>(context, callBack) {
@ -67,15 +67,15 @@ class RssArticlesAdapter(context: Context, callBack: CallBack) :
}.into(imageView) }.into(imageView)
} }
if (item.read) { if (item.read) {
tvTitle.textColorResource = R.color.tv_text_summary tvTitle.setTextColor(context.getCompatColor(R.color.tv_text_summary))
} else { } else {
tvTitle.textColorResource = R.color.primaryText tvTitle.setTextColor(context.getCompatColor(R.color.primaryText))
} }
} }
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticleBinding) { override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticleBinding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.readRss(it) callBack.readRss(it)
} }

@ -12,10 +12,10 @@ import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssArticle
import io.legado.app.databinding.ItemRssArticle1Binding import io.legado.app.databinding.ItemRssArticle1Binding
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.utils.getCompatColor
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 org.jetbrains.anko.sdk27.coroutines.onClick
import org.jetbrains.anko.textColorResource
class RssArticlesAdapter1(context: Context, callBack: CallBack) : class RssArticlesAdapter1(context: Context, callBack: CallBack) :
BaseRssArticlesAdapter<ItemRssArticle1Binding>(context, callBack) { BaseRssArticlesAdapter<ItemRssArticle1Binding>(context, callBack) {
@ -67,15 +67,15 @@ class RssArticlesAdapter1(context: Context, callBack: CallBack) :
}.into(imageView) }.into(imageView)
} }
if (item.read) { if (item.read) {
tvTitle.textColorResource = R.color.tv_text_summary tvTitle.setTextColor(context.getCompatColor(R.color.tv_text_summary))
} else { } else {
tvTitle.textColorResource = R.color.primaryText tvTitle.setTextColor(context.getCompatColor(R.color.primaryText))
} }
} }
} }
override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticle1Binding) { override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticle1Binding) {
holder.itemView.onClick { holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
callBack.readRss(it) callBack.readRss(it)
} }

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save