diff --git a/app/build.gradle b/app/build.gradle index d1eddd583..4bbc6084c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -125,17 +125,21 @@ dependencies { implementation 'com.google.firebase:firebase-crashlytics-ktx:17.3.0' //androidX - implementation 'androidx.core:core-ktx:1.3.2' 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.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.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:flexbox:1.1.0' implementation 'com.google.code.gson:gson:2.8.6' + implementation "org.jetbrains.anko:anko-sdk27:0.10.8" + //lifecycle def lifecycle_version = '2.2.0' implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" @@ -150,11 +154,6 @@ dependencies { //paging 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 implementation 'com.jeremyliao:live-event-bus-x:1.5.7' diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 6b48a7499..2d8c162b5 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -18,8 +18,8 @@ import io.legado.app.data.AppDatabase import io.legado.app.help.* import io.legado.app.help.http.HttpHelper import io.legado.app.utils.LanguageUtils +import io.legado.app.utils.defaultSharedPreferences import io.legado.app.utils.postEvent -import org.jetbrains.anko.defaultSharedPreferences import rxhttp.wrapper.param.RxHttp @Suppress("DEPRECATION") diff --git a/app/src/main/java/io/legado/app/base/BaseViewModel.kt b/app/src/main/java/io/legado/app/base/BaseViewModel.kt index e5432e204..44ea2884b 100644 --- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt +++ b/app/src/main/java/io/legado/app/base/BaseViewModel.kt @@ -6,15 +6,13 @@ import androidx.annotation.CallSuper import androidx.lifecycle.AndroidViewModel import io.legado.app.App import io.legado.app.help.coroutine.Coroutine +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.* -import org.jetbrains.anko.AnkoLogger -import org.jetbrains.anko.toast import kotlin.coroutines.CoroutineContext @Suppress("unused") open class BaseViewModel(application: Application) : AndroidViewModel(application), - CoroutineScope by MainScope(), - AnkoLogger { + CoroutineScope by MainScope() { val context: Context by lazy { this.getApplication() } @@ -40,27 +38,12 @@ open class BaseViewModel(application: Application) : AndroidViewModel(applicatio cancel() } - open fun toast(message: Int) { - launch { - context.toast(message) - } + open fun toastOnUI(message: Int) { + context.toastOnUI(message) } - open fun toast(message: CharSequence?) { - launch { - context.toast(message ?: toString()) - } + open fun toastOnUI(message: CharSequence?) { + context.toastOnUI(message ?: toString()) } - open fun longToast(message: Int) { - launch { - context.toast(message) - } - } - - open fun longToast(message: CharSequence?) { - launch { - context.toast(message ?: toString()) - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index c3fa8624d..b3424ad46 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -4,9 +4,9 @@ import com.hankcs.hanlp.HanLP import io.legado.app.App import io.legado.app.data.entities.Book import io.legado.app.data.entities.ReplaceRule +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import org.jetbrains.anko.toast 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) { 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) { withContext(Dispatchers.Main) { - App.INSTANCE.toast("简繁转换出错") + App.INSTANCE.toastOnUI("简繁转换出错") } } } diff --git a/app/src/main/java/io/legado/app/help/IntentHelp.kt b/app/src/main/java/io/legado/app/help/IntentHelp.kt index 7524bed78..ac44e893c 100644 --- a/app/src/main/java/io/legado/app/help/IntentHelp.kt +++ b/app/src/main/java/io/legado/app/help/IntentHelp.kt @@ -5,7 +5,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import io.legado.app.R -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI @Suppress("unused") object IntentHelp { @@ -19,7 +19,7 @@ object IntentHelp { intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK context.startActivity(intent) }.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 context.startActivity(intent) }.onFailure { - context.toast("无法打开设置") + context.toastOnUI("无法打开设置") } } diff --git a/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt b/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt index 04723c21a..d149f4464 100644 --- a/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt +++ b/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt @@ -6,7 +6,7 @@ import android.os.Build import io.legado.app.App import io.legado.app.R import io.legado.app.ui.welcome.* -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI /** * Created by GKF on 2018/2/27. @@ -26,7 +26,7 @@ object LauncherIconHelp { fun changeIcon(icon: String?) { if (icon.isNullOrEmpty()) return if (Build.VERSION.SDK_INT < 26) { - App.INSTANCE.toast(R.string.change_icon_error) + App.INSTANCE.toastOnUI(R.string.change_icon_error) return } var hasEnabled = false diff --git a/app/src/main/java/io/legado/app/help/SourceHelp.kt b/app/src/main/java/io/legado/app/help/SourceHelp.kt index 02b20bf52..5783b371a 100644 --- a/app/src/main/java/io/legado/app/help/SourceHelp.kt +++ b/app/src/main/java/io/legado/app/help/SourceHelp.kt @@ -8,7 +8,7 @@ import io.legado.app.data.entities.RssSource import io.legado.app.utils.EncoderUtils import io.legado.app.utils.NetworkUtils import io.legado.app.utils.splitNotBlank -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI object SourceHelp { @@ -26,7 +26,7 @@ object SourceHelp { rssSources.forEach { rssSource -> if (is18Plus(rssSource.sourceUrl)) { handler.post { - App.INSTANCE.toast("${rssSource.sourceName}是18+网址,禁止导入.") + App.INSTANCE.toastOnUI("${rssSource.sourceName}是18+网址,禁止导入.") } } else { App.db.rssSourceDao.insert(rssSource) @@ -38,7 +38,7 @@ object SourceHelp { bookSources.forEach { bookSource -> if (is18Plus(bookSource.bookSourceUrl)) { handler.post { - App.INSTANCE.toast("${bookSource.bookSourceName}是18+网址,禁止导入.") + App.INSTANCE.toastOnUI("${bookSource.bookSourceName}是18+网址,禁止导入.") } } else { App.db.bookSourceDao.insert(bookSource) diff --git a/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt b/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt index 04722997b..dcee55e64 100644 --- a/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt +++ b/app/src/main/java/io/legado/app/help/permission/PermissionActivity.kt @@ -8,7 +8,7 @@ import android.view.KeyEvent import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import io.legado.app.R -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI class PermissionActivity : AppCompatActivity() { @@ -32,7 +32,7 @@ class PermissionActivity : AppCompatActivity() { settingIntent.data = Uri.fromParts("package", packageName, null) startActivityForResult(settingIntent, Request.TYPE_REQUEST_SETTING) } catch (e: Exception) { - toast(R.string.tip_cannot_jump_setting_page) + toastOnUI(R.string.tip_cannot_jump_setting_page) finish() } diff --git a/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt b/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt index f3b7310b4..77b5b0fad 100644 --- a/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt +++ b/app/src/main/java/io/legado/app/help/storage/BookWebDav.kt @@ -16,7 +16,6 @@ import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.withContext -import org.jetbrains.anko.toast import java.io.File import java.text.SimpleDateFormat import java.util.* @@ -80,7 +79,7 @@ object BookWebDav { Coroutine.async { restoreWebDav(names[index]) }.onError { - App.INSTANCE.toast("WebDavError:${it.localizedMessage}") + App.INSTANCE.toastOnUI("WebDavError:${it.localizedMessage}") } } } @@ -118,7 +117,7 @@ object BookWebDav { } } catch (e: Exception) { 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) { Handler(Looper.getMainLooper()).post { - App.INSTANCE.toast("WebDav导出\n${e.localizedMessage}") + App.INSTANCE.toastOnUI("WebDav导出\n${e.localizedMessage}") } } } diff --git a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt index 178f8369a..f6bbcef1e 100644 --- a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt +++ b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt @@ -8,7 +8,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils import io.legado.app.utils.isContentScheme -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI import java.io.File object ImportOldData { @@ -21,28 +21,28 @@ object ImportOldData { kotlin.runCatching { DocumentUtils.readText(context, doc.uri)?.let { json -> val importCount = importOldBookshelf(json) - context.toast("成功导入书籍${importCount}") + context.toastOnUI("成功导入书籍${importCount}") } }.onFailure { - context.toast("导入书籍失败\n${it.localizedMessage}") + context.toastOnUI("导入书籍失败\n${it.localizedMessage}") } "myBookSource.json" -> kotlin.runCatching { DocumentUtils.readText(context, doc.uri)?.let { json -> val importCount = importOldSource(json) - context.toast("成功导入书源${importCount}") + context.toastOnUI("成功导入书源${importCount}") } }.onFailure { - context.toast("导入源失败\n${it.localizedMessage}") + context.toastOnUI("导入源失败\n${it.localizedMessage}") } "myBookReplaceRule.json" -> kotlin.runCatching { DocumentUtils.readText(context, doc.uri)?.let { json -> val importCount = importOldReplaceRule(json) - context.toast("成功导入替换规则${importCount}") + context.toastOnUI("成功导入替换规则${importCount}") } }.onFailure { - context.toast("导入替换规则失败\n${it.localizedMessage}") + context.toastOnUI("导入替换规则失败\n${it.localizedMessage}") } } } @@ -54,9 +54,9 @@ object ImportOldData { FileUtils.createFileIfNotExist(file, "myBookShelf.json") val json = shelfFile.readText() val importCount = importOldBookshelf(json) - context.toast("成功导入书籍${importCount}") + context.toastOnUI("成功导入书籍${importCount}") }.onFailure { - context.toast("导入书籍失败\n${it.localizedMessage}") + context.toastOnUI("导入书籍失败\n${it.localizedMessage}") } kotlin.runCatching {// Book source @@ -64,9 +64,9 @@ object ImportOldData { FileUtils.getFile(file, "myBookSource.json") val json = sourceFile.readText() val importCount = importOldSource(json) - context.toast("成功导入书源${importCount}") + context.toastOnUI("成功导入书源${importCount}") }.onFailure { - context.toast("导入源失败\n${it.localizedMessage}") + context.toastOnUI("导入源失败\n${it.localizedMessage}") } kotlin.runCatching {// Replace rules @@ -74,12 +74,12 @@ object ImportOldData { if (ruleFile.exists()) { val json = ruleFile.readText() val importCount = importOldReplaceRule(json) - context.toast("成功导入替换规则${importCount}") + context.toastOnUI("成功导入替换规则${importCount}") } else { - context.toast("未找到替换规则") + context.toastOnUI("未找到替换规则") } }.onFailure { - context.toast("导入替换规则失败\n${it.localizedMessage}") + context.toastOnUI("导入替换规则失败\n${it.localizedMessage}") } } } diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 212152849..ac90d7f91 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -24,7 +24,6 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.withContext import org.jetbrains.anko.defaultSharedPreferences -import org.jetbrains.anko.toast import java.io.File object Restore { @@ -224,7 +223,7 @@ object Restore { ReadBook.loadContent(resetPageOffset = false) } withContext(Main) { - App.INSTANCE.toast(R.string.restore_success) + App.INSTANCE.toastOnUI(R.string.restore_success) if (!BuildConfig.DEBUG) { LauncherIconHelp.changeIcon(App.INSTANCE.getPrefString(PreferKey.launcherIcon)) } diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index f5274d09a..80568f748 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -24,8 +24,6 @@ import io.legado.app.help.AppConfig import io.legado.app.utils.ColorUtils import io.legado.app.utils.dp import io.legado.app.utils.getCompatColor -import org.jetbrains.anko.backgroundColor - /** * @author Karim Abou Zeid (kabouzeid) @@ -272,7 +270,7 @@ object ATH { fun applyBackgroundTint(view: View?) { view?.apply { if (background == null) { - backgroundColor = context.backgroundColor + setBackgroundColor(context.backgroundColor) } else { setBackgroundTint(this, context.backgroundColor) } diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index 805fdfc14..d350c4850 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -31,10 +31,10 @@ import io.legado.app.receiver.MediaButtonReceiver import io.legado.app.service.help.AudioPlay import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.utils.postEvent +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.toast class AudioPlayService : BaseService(), @@ -133,7 +133,7 @@ class AudioPlayService : BaseService(), }.onFailure { it.printStackTrace() launch { - toast("$url ${it.localizedMessage}") + toastOnUI("$url ${it.localizedMessage}") stopSelf() } } @@ -219,7 +219,7 @@ class AudioPlayService : BaseService(), if (!mediaPlayer.isPlaying) { AudioPlay.status = Status.STOP postEvent(EventBus.AUDIO_STATE, Status.STOP) - launch { toast("error: $what $extra $url") } + launch { toastOnUI("error: $what $extra $url") } } return true } @@ -274,7 +274,7 @@ class AudioPlayService : BaseService(), .onSuccess { content -> if (content.isEmpty()) { withContext(Main) { - toast("未获取到资源链接") + toastOnUI("未获取到资源链接") } } else { contentLoadFinish(chapter, content) @@ -286,7 +286,7 @@ class AudioPlayService : BaseService(), } } else { removeLoading(chapter.index) - toast("book or source is null") + toastOnUI("book or source is null") } } } diff --git a/app/src/main/java/io/legado/app/service/CacheBookService.kt b/app/src/main/java/io/legado/app/service/CacheBookService.kt index 06a6dea35..2454f6c4e 100644 --- a/app/src/main/java/io/legado/app/service/CacheBookService.kt +++ b/app/src/main/java/io/legado/app/service/CacheBookService.kt @@ -20,9 +20,9 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.webBook.WebBook import io.legado.app.service.help.CacheBook import io.legado.app.utils.postEvent +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.isActive -import org.jetbrains.anko.toast import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.Executors @@ -128,7 +128,7 @@ class CacheBookService : BaseService() { if (downloadMap.containsKey(bookUrl)) { notificationContent = getString(R.string.already_in_download) upNotification() - toast(notificationContent) + toastOnUI(notificationContent) return } downloadCount[bookUrl] = DownloadCount() diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index a803a2aa2..0af7bd698 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -16,8 +16,8 @@ import io.legado.app.model.webBook.WebBook import io.legado.app.service.help.CheckSource import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.utils.postEvent +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.asCoroutineDispatcher -import org.jetbrains.anko.toast import java.util.concurrent.Executors import kotlin.math.min @@ -70,7 +70,7 @@ class CheckSourceService : BaseService() { private fun check(ids: List) { if (allIds.isNotEmpty()) { - toast("已有书源在校验,等完成后再试") + toastOnUI("已有书源在校验,等完成后再试") return } tasks.clear() diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index fd21a079b..71b71b3f7 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -19,9 +19,9 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.IntentAction import io.legado.app.help.IntentHelp import io.legado.app.utils.RealPathUtil +import io.legado.app.utils.downloadManager import io.legado.app.utils.msg -import org.jetbrains.anko.downloadManager -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI import java.io.File @@ -149,7 +149,7 @@ class DownloadService : BaseService() { try { startActivity(intent) } catch (e: Exception) { - toast(e.msg) + toastOnUI(e.msg) } } } diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 5ad4a9b20..29bb84efb 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -10,15 +10,11 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook -import io.legado.app.utils.FileUtils -import io.legado.app.utils.LogUtils -import io.legado.app.utils.MD5Utils -import io.legado.app.utils.postEvent +import io.legado.app.utils.* import kotlinx.coroutines.ensureActive import kotlinx.coroutines.isActive import org.jetbrains.anko.collections.forEachWithIndex import org.jetbrains.anko.runOnUiThread -import org.jetbrains.anko.toast import java.io.File import java.io.FileDescriptor import java.io.FileInputStream @@ -123,17 +119,17 @@ class HttpReadAloudService : BaseReadAloudService(), } } catch (e: SocketTimeoutException) { removeSpeakCacheFile(fileName) - runOnUiThread { toast("tts接口超时,尝试重新获取") } + runOnUiThread { toastOnUI("tts接口超时,尝试重新获取") } downloadAudio() } catch (e: ConnectException) { removeSpeakCacheFile(fileName) - runOnUiThread { toast("网络错误") } + runOnUiThread { toastOnUI("网络错误") } } catch (e: IOException) { val file = getSpeakFileAsMd5(fileName) if (file.exists()) { FileUtils.deleteFile(file.absolutePath) } - runOnUiThread { toast("tts文件解析错误") } + runOnUiThread { toastOnUI("tts文件解析错误") } } catch (e: Exception) { removeSpeakCacheFile(fileName) } diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index d1341a4c3..170ea4af7 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -13,8 +13,8 @@ import io.legado.app.help.MediaHelp import io.legado.app.service.help.ReadBook import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.postEvent +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.launch -import org.jetbrains.anko.toast import java.util.* class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener { @@ -64,7 +64,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener } } else { launch { - toast(R.string.tts_init_failed) + toastOnUI(R.string.tts_init_failed) } } } diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 03bddff2c..23077b707 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -13,11 +13,10 @@ import io.legado.app.help.IntentHelp import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getPrefInt import io.legado.app.utils.postEvent +import io.legado.app.utils.toastOnUI import io.legado.app.web.HttpServer import io.legado.app.web.WebSocketServer -import kotlinx.coroutines.launch import org.jetbrains.anko.startService -import org.jetbrains.anko.toast import java.io.IOException class WebService : BaseService() { @@ -92,10 +91,8 @@ class WebService : BaseService() { notificationContent = hostAddress upNotification() } catch (e: IOException) { - launch { - toast(e.localizedMessage ?: "") - stopSelf() - } + toastOnUI(e.localizedMessage ?: "") + stopSelf() } } else { stopSelf() diff --git a/app/src/main/java/io/legado/app/service/help/CheckSource.kt b/app/src/main/java/io/legado/app/service/help/CheckSource.kt index d38e6c225..856202fba 100644 --- a/app/src/main/java/io/legado/app/service/help/CheckSource.kt +++ b/app/src/main/java/io/legado/app/service/help/CheckSource.kt @@ -6,14 +6,14 @@ import io.legado.app.R import io.legado.app.constant.IntentAction import io.legado.app.data.entities.BookSource import io.legado.app.service.CheckSourceService -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI object CheckSource { var keyword = "我的" fun start(context: Context, sources: List) { if (sources.isEmpty()) { - context.toast(R.string.non_select) + context.toastOnUI(R.string.non_select) return } val selectedIds: ArrayList = arrayListOf() diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 1a2d7b340..1ee12fe94 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -14,12 +14,12 @@ import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ImageProvider +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.jetbrains.anko.getStackTraceString -import org.jetbrains.anko.toast @Suppress("MemberVisibilityCanBePrivate") @@ -437,7 +437,7 @@ object ReadBook { } }.onError { it.printStackTrace() - App.INSTANCE.toast("ChapterProvider ERROR:\n${it.getStackTraceString()}") + App.INSTANCE.toastOnUI("ChapterProvider ERROR:\n${it.getStackTraceString()}") }.onSuccess { success?.invoke() } diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index 321ba268b..5f89f34aa 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -15,7 +15,7 @@ import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.openUrl import io.legado.app.utils.sendMail import io.legado.app.utils.sendToClip -import io.legado.app.utils.toast +import io.legado.app.utils.toastOnUI class AboutFragment : PreferenceFragmentCompat() { @@ -105,7 +105,7 @@ class AboutFragment : PreferenceFragmentCompat() { startActivity(intent) return true }.onFailure { - toast("添加失败,请手动添加") + toastOnUI("添加失败,请手动添加") } return false } diff --git a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt index 23ece585c..8ee502735 100644 --- a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt @@ -19,7 +19,6 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.sdk27.coroutines.onClick import java.util.* class ReadRecordActivity : BaseActivity() { @@ -59,7 +58,7 @@ class ReadRecordActivity : BaseActivity() { readRecord.tvBookName.setText(R.string.all_read_time) adapter = RecordAdapter(this@ReadRecordActivity) recyclerView.adapter = adapter - readRecord.tvRemove.onClick { + readRecord.tvRemove.setOnClickListener { alert(R.string.delete, R.string.sure_del) { okButton { App.db.readRecordDao.clear() @@ -112,7 +111,7 @@ class ReadRecordActivity : BaseActivity() { override fun registerListener(holder: ItemViewHolder, binding: ItemReadRecordBinding) { binding.apply { - tvRemove.onClick { + tvRemove.setOnClickListener { getItem(holder.layoutPosition)?.let { item -> sureDelAlert(item) } diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index a9f79def1..3269b22b1 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -7,8 +7,8 @@ import io.legado.app.constant.Theme import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.ui.main.MainActivity import io.legado.app.utils.getViewModel +import io.legado.app.utils.toastOnUI import org.jetbrains.anko.startActivity -import org.jetbrains.anko.toast class FileAssociationActivity : @@ -27,7 +27,7 @@ class FileAssociationActivity : binding.rotateLoading.show() viewModel.errorLiveData.observe(this, { binding.rotateLoading.hide() - toast(it) + toastOnUI(it) finish() }) viewModel.successLiveData.observe(this, { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt index f6e11de63..458a98933 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt @@ -8,7 +8,7 @@ import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.alert import io.legado.app.utils.getViewModel -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI class ImportBookSourceActivity : @@ -66,7 +66,7 @@ class ImportBookSourceActivity : } else -> { binding.rotateLoading.hide() - toast(R.string.wrong_format) + toastOnUI(R.string.wrong_format) finish() } } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt index 0915e306e..7899f5416 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt @@ -25,7 +25,7 @@ import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.utils.* 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 adapter.setItems(viewModel.allSources) binding.tvCancel.visible() - binding.tvCancel.onClick { + binding.tvCancel.setOnClickListener { dismiss() } binding.tvOk.visible() - binding.tvOk.onClick { + binding.tvOk.setOnClickListener { viewModel.importSelect { dismiss() } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt index 19e90b540..f7c9dc783 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt @@ -9,7 +9,7 @@ import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.alert import io.legado.app.utils.getViewModel -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI class ImportReplaceRuleActivity : VMBaseActivity( @@ -66,7 +66,7 @@ class ImportReplaceRuleActivity : } else -> { binding.rotateLoading.hide() - toast("格式不对") + toastOnUI("格式不对") finish() } } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt index 76e7bb2c7..928279d63 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt @@ -8,7 +8,7 @@ import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.alert import io.legado.app.utils.getViewModel -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI class ImportRssSourceActivity : VMBaseActivity( @@ -65,7 +65,7 @@ class ImportRssSourceActivity : } else -> { binding.rotateLoading.hide() - toast(R.string.wrong_format) + toastOnUI(R.string.wrong_format) finish() } } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index 0ae606794..6b7c211bb 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -25,7 +25,6 @@ import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick /** * 导入rss源弹出窗口 @@ -62,11 +61,11 @@ class ImportRssSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListe binding.recyclerView.adapter = adapter adapter.setItems(viewModel.allSources) binding.tvCancel.visible() - binding.tvCancel.onClick { + binding.tvCancel.setOnClickListener { dismiss() } binding.tvOk.visible() - binding.tvOk.onClick { + binding.tvOk.setOnClickListener { viewModel.importSelect { dismiss() } diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index f943878bf..f271c87ee 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -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.seekbar.SeekBarChangeListener 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 java.util.* @@ -80,16 +78,17 @@ class AudioPlayActivity : } private fun initView() { - binding.fabPlayStop.onClick { + binding.fabPlayStop.setOnClickListener { playButton() } - binding.fabPlayStop.onLongClick(returnValue = true) { + binding.fabPlayStop.setOnLongClickListener { AudioPlay.stop(this@AudioPlayActivity) + true } - binding.ivSkipNext.onClick { + binding.ivSkipNext.setOnClickListener { AudioPlay.next(this@AudioPlayActivity) } - binding.ivSkipPrevious.onClick { + binding.ivSkipPrevious.setOnClickListener { AudioPlay.prev(this@AudioPlayActivity) } binding.playerProgress.setOnSeekBarChangeListener(object : SeekBarChangeListener { @@ -106,7 +105,7 @@ class AudioPlayActivity : AudioPlay.adjustProgress(this@AudioPlayActivity, seekBar.progress) } }) - binding.ivChapter.onClick { + binding.ivChapter.setOnClickListener { AudioPlay.book?.let { startActivityForResult( requestCodeChapter, @@ -118,13 +117,13 @@ class AudioPlayActivity : binding.ivFastRewind.invisible() binding.ivFastForward.invisible() } - binding.ivFastForward.onClick { + binding.ivFastForward.setOnClickListener { AudioPlay.adjustSpeed(this@AudioPlayActivity, 0.1f) } - binding.ivFastRewind.onClick { + binding.ivFastRewind.setOnClickListener { AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f) } - binding.ivTimer.onClick { + binding.ivTimer.setOnClickListener { AudioPlay.addTimer(this@AudioPlayActivity) } } diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index 184663f3d..80680f82d 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -75,10 +75,10 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) } AudioPlay.upDurChapter(book) } else { - toast(R.string.error_load_toc) + toastOnUI(R.string.error_load_toc) } }?.onError { - toast(R.string.error_load_toc) + toastOnUI(R.string.error_load_toc) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 6ee3d54f9..00474109f 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -13,8 +13,6 @@ import io.legado.app.databinding.ItemArrangeBookBinding import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback -import org.jetbrains.anko.backgroundColor -import org.jetbrains.anko.sdk27.coroutines.onClick import java.util.* class ArrangeBookAdapter(context: Context, val callBack: CallBack) : @@ -40,7 +38,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : payloads: MutableList ) { binding.apply { - root.backgroundColor = context.backgroundColor + root.setBackgroundColor(context.backgroundColor) tvName.text = item.name tvAuthor.text = item.author 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 { checkbox.isChecked = !checkbox.isChecked if (checkbox.isChecked) { @@ -76,12 +74,12 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : callBack.upSelectCount() } } - tvDelete.onClick { + tvDelete.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.deleteBook(it) } } - tvGroup.onClick { + tvGroup.setOnClickListener { getItem(holder.layoutPosition)?.let { actionItem = it callBack.selectGroup(groupRequestCode, it.group) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt index 7916dcc46..96d20d3df 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt @@ -10,7 +10,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ItemDownloadBinding import io.legado.app.service.help.CacheBook -import org.jetbrains.anko.sdk27.coroutines.onClick + import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.CopyOnWriteArraySet @@ -54,7 +54,7 @@ class CacheAdapter(context: Context, private val callBack: CallBack) : override fun registerListener(holder: ItemViewHolder, binding: ItemDownloadBinding) { with(binding) { - ivDownload.onClick { + ivDownload.setOnClickListener { getItem(holder.layoutPosition)?.let { if (downloadMap?.containsKey(it.bookUrl) == true) { 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) } } diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt index 97b665e6e..0f75ed99f 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt @@ -7,7 +7,7 @@ import io.legado.app.base.adapter.DiffRecyclerAdapter import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.ItemCoverBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class CoverAdapter(context: Context, val callBack: CallBack) : DiffRecyclerAdapter(context) { @@ -41,7 +41,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) : override fun registerListener(holder: ItemViewHolder, binding: ItemCoverBinding) { holder.itemView.apply { - onClick { + setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.changeTo(it.coverUrl ?: "") } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index 4d238a245..32b3fc8ce 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -13,8 +13,6 @@ import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.ItemChangeSourceBinding import io.legado.app.utils.invisible import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.sdk27.coroutines.onLongClick 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) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.changeTo(it) } } - holder.itemView.onLongClick(returnValue = true) { + holder.itemView.setOnLongClickListener { showMenu(holder.itemView, getItem(holder.layoutPosition)) + true } } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 0c738d93e..842a84355 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -6,7 +6,6 @@ import android.os.Handler import android.os.Looper import androidx.lifecycle.MutableLiveData import io.legado.app.App -import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppPattern import io.legado.app.constant.PreferKey @@ -21,7 +20,6 @@ import io.legado.app.utils.getPrefString import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.ExecutorCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher -import org.jetbrains.anko.debug import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.Executors @@ -173,7 +171,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio searchFinish(searchBook) } }.onError { - debug { context.getString(R.string.error_get_book_info) } + it.printStackTrace() } } @@ -186,7 +184,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio searchFinish(searchBook) } }.onError { - debug { context.getString(R.string.error_get_chapter_list) } + it.printStackTrace() } } diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt index c25be5124..9c0e521b7 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowAdapter.kt @@ -10,7 +10,7 @@ import io.legado.app.data.entities.SearchBook import io.legado.app.databinding.ItemSearchBinding import io.legado.app.utils.gone import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick + class ExploreShowAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context) { @@ -51,7 +51,7 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) : } override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.showBookInfo(it.toBook()) } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 06b6efd37..2c64e7fe1 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -28,7 +28,7 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var viewModel: GroupViewModel @@ -68,7 +68,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView) binding.tvOk.setTextColor(requireContext().accentColor) binding.tvOk.visible() - binding.tvOk.onClick { dismiss() } + binding.tvOk.setOnClickListener { dismiss() } } private fun initData() { @@ -164,7 +164,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener override fun registerListener(holder: ItemViewHolder, binding: ItemBookGroupManageBinding) { with(binding) { - tvEdit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } } + tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } } swShow.setOnCheckedChangeListener { buttonView, isChecked -> if (buttonView.isPressed) { getItem(holder.layoutPosition)?.let { diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index ea039a9e9..9802f7aef 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -32,7 +32,7 @@ import io.legado.app.utils.getSize import io.legado.app.utils.getViewModel import io.legado.app.utils.requestInputMethod import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { @@ -95,9 +95,9 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = true ItemTouchHelper(itemTouchCallback).attachToRecyclerView(binding.recyclerView) - binding.tvCancel.onClick { dismiss() } + binding.tvCancel.setOnClickListener { dismiss() } binding.tvOk.setTextColor(requireContext().accentColor) - binding.tvOk.onClick { + binding.tvOk.setOnClickListener { callBack?.upGroup(requestCode, groupId) 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) } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index c992f2ad0..7e54a5111 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -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.widget.image.CoverImageView import io.legado.app.utils.* -import org.jetbrains.anko.sdk27.coroutines.onClick import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult -import org.jetbrains.anko.toast class BookInfoActivity : @@ -92,7 +90,7 @@ class BookInfoActivity : ) } } else { - toast(R.string.after_add_bookshelf) + toastOnUI(R.string.after_add_bookshelf) } } R.id.menu_share_it -> { @@ -113,7 +111,7 @@ class BookInfoActivity : } R.id.menu_copy_url -> viewModel.bookData.value?.bookUrl?.let { sendToClip(it) - } ?: toast(R.string.no_book) + } ?: toastOnUI(R.string.no_book) R.id.menu_can_update -> { if (viewModel.inBookshelf) { viewModel.bookData.value?.let { @@ -121,7 +119,7 @@ class BookInfoActivity : viewModel.saveBook() } } else { - toast(R.string.after_add_bookshelf) + toastOnUI(R.string.after_add_bookshelf) } } R.id.menu_clear_cache -> viewModel.clearCache() @@ -207,17 +205,17 @@ class BookInfoActivity : } private fun initOnClick() = with(binding) { - ivCover.onClick { + ivCover.setOnClickListener { viewModel.bookData.value?.let { ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) } } - tvRead.onClick { + tvRead.setOnClickListener { viewModel.bookData.value?.let { readBook(it) } } - tvShelf.onClick { + tvShelf.setOnClickListener { if (viewModel.inBookshelf) { deleteBook() } else { @@ -226,17 +224,17 @@ class BookInfoActivity : } } } - tvOrigin.onClick { + tvOrigin.setOnClickListener { viewModel.bookData.value?.let { startActivity(Pair("data", it.origin)) } } - tvChangeSource.onClick { + tvChangeSource.setOnClickListener { viewModel.bookData.value?.let { ChangeSourceDialog.show(supportFragmentManager, it.name, it.author) } } - tvTocView.onClick { + tvTocView.setOnClickListener { if (!viewModel.inBookshelf) { viewModel.saveBook { viewModel.saveChapterList { @@ -247,15 +245,15 @@ class BookInfoActivity : openChapterList() } } - tvChangeGroup.onClick { + tvChangeGroup.setOnClickListener { viewModel.bookData.value?.let { GroupSelectDialog.show(supportFragmentManager, it.group) } } - tvAuthor.onClick { + tvAuthor.setOnClickListener { startActivity(Pair("key", viewModel.bookData.value?.author)) } - tvName.onClick { + tvName.setOnClickListener { startActivity(Pair("key", viewModel.bookData.value?.name)) } } @@ -293,7 +291,7 @@ class BookInfoActivity : private fun openChapterList() { if (viewModel.chapterListData.value.isNullOrEmpty()) { - toast(R.string.chapter_list_empty) + toastOnUI(R.string.chapter_list_empty) return } viewModel.bookData.value?.let { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 21f2dd157..cb768d081 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -65,11 +65,11 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } loadChapter(it, changeDruChapterIndex) }.onError { - toast(R.string.error_get_book_info) + toastOnUI(R.string.error_get_book_info) } } ?: let { 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) } } else { - toast(R.string.chapter_list_empty) + toastOnUI(R.string.chapter_list_empty) } }.onError { chapterListData.postValue(null) - toast(R.string.error_get_chapter_list) + toastOnUI(R.string.error_get_chapter_list) } } ?: let { chapterListData.postValue(null) - toast(R.string.error_no_source) + toastOnUI(R.string.error_no_source) } } }.onError { - toast("LoadTocError:${it.localizedMessage}") + toastOnUI("LoadTocError:${it.localizedMessage}") } } @@ -238,9 +238,9 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { execute { BookHelp.clearCache(bookData.value!!) }.onSuccess { - toast(R.string.clear_cache_success) + toastOnUI(R.string.clear_cache_success) }.onError { - toast(it.stackTraceToString()) + toastOnUI(it.stackTraceToString()) } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt index 0f0160517..dde20e3e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/ChapterListAdapter.kt @@ -8,8 +8,8 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.entities.BookChapter import io.legado.app.databinding.ItemChapterListBinding import io.legado.app.lib.theme.accentColor -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.textColorResource +import io.legado.app.utils.getCompatColor + class ChapterListAdapter(context: Context, var callBack: CallBack) : RecyclerAdapter(context) { @@ -29,7 +29,7 @@ class ChapterListAdapter(context: Context, var callBack: CallBack) : if (item.index == callBack.durChapterIndex()) { tvChapterName.setTextColor(context.accentColor) } 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) { holder.itemView.apply { - this.onClick { + this.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.openChapter(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index e22184f2f..bd40994aa 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -15,8 +15,6 @@ import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.ui.book.changecover.ChangeCoverDialog import io.legado.app.utils.* -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.toast import java.io.File class BookInfoEditActivity : @@ -55,15 +53,15 @@ class BookInfoEditActivity : } private fun initEvent() = with(binding) { - tvChangeCover.onClick { + tvChangeCover.setOnClickListener { viewModel.bookData.value?.let { ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) } } - tvSelectCover.onClick { + tvSelectCover.setOnClickListener { selectImage() } - tvRefreshCover.onClick { + tvRefreshCover.setOnClickListener { viewModel.book?.customCoverUrl = tieCoverUrl.text?.toString() upCover() } @@ -121,7 +119,7 @@ class BookInfoEditActivity : }.getOrNull()?.let { byteArray -> file.writeBytes(byteArray) coverChangeTo(file.absolutePath) - } ?: toast("获取文件出错") + } ?: toastOnUI("获取文件出错") } } else { PermissionsCompat.Builder(this) diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index f3762a29c..ce921cebe 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -28,8 +28,6 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.toast import java.io.File import java.util.* @@ -112,7 +110,7 @@ class ImportBookActivity : VMBaseActivity(context) { @@ -62,7 +62,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : } override fun registerListener(holder: ItemViewHolder, binding: ItemImportBookBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { if (it.isDir) { callBack.nextDoc(it.uri) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 14482296a..ab738e2dc 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -55,7 +55,6 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult -import org.jetbrains.anko.toast class ReadBookActivity : ReadBookBaseActivity(), View.OnTouchListener, @@ -347,7 +346,7 @@ class ReadBookActivity : ReadBookBaseActivity(), ) { if (BaseReadAloudService.isPlay()) { ReadAloud.pause(this) - toast(R.string.read_aloud_pause) + toastOnUI(R.string.read_aloud_pause) return true } if (isAutoPage) { @@ -453,7 +452,7 @@ class ReadBookActivity : ReadBookBaseActivity(), R.id.menu_bookmark -> binding.readView.curPage.let { val bookmark = it.createBookmark() if (bookmark == null) { - toast(R.string.create_bookmark_error) + toastOnUI(R.string.create_bookmark_error) } else { showBookMark(bookmark) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index d73f96658..9174aa62d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -226,7 +226,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { }.onStart { ReadBook.upMsg(context.getString(R.string.source_auto_changing)) }.onError { - toast(it.msg) + toastOnUI(it.msg) }.onFinally { ReadBook.upMsg(null) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 2e28fbdb5..85bedf3e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -21,8 +21,6 @@ import io.legado.app.lib.theme.* import io.legado.app.service.help.ReadBook import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.sdk27.coroutines.onLongClick /** * 阅读界面菜单 @@ -83,8 +81,8 @@ class ReadMenu @JvmOverloads constructor( tvFont.setTextColor(textColor) ivSetting.setColorFilter(textColor) tvSetting.setTextColor(textColor) - vwBg.onClick { } - vwNavigationBar.onClick { } + vwBg.setOnClickListener { } + vwNavigationBar.setOnClickListener { } seekBrightness.progress = context.getPrefInt("brightness", 100) } @@ -135,16 +133,16 @@ class ReadMenu @JvmOverloads constructor( } private fun bindEvent() = with(binding) { - tvChapterName.onClick { + tvChapterName.setOnClickListener { callBack.openSourceEditActivity() } - tvChapterUrl.onClick { + tvChapterUrl.setOnClickListener { context.openUrl(binding.tvChapterUrl.text.toString()) } - tvLogin.onClick { + tvLogin.setOnClickListener { callBack.showLogin() } - ivBrightnessAuto.onClick { + ivBrightnessAuto.setOnClickListener { context.putPrefBoolean("brightnessAuto", !brightnessAuto()) upBrightnessState() } @@ -171,59 +169,60 @@ class ReadMenu @JvmOverloads constructor( }) //搜索 - fabSearch.onClick { + fabSearch.setOnClickListener { runMenuOut { callBack.openSearchActivity(null) } } //自动翻页 - fabAutoPage.onClick { + fabAutoPage.setOnClickListener { runMenuOut { callBack.autoPage() } } //替换 - fabReplaceRule.onClick { callBack.openReplaceRule() } + fabReplaceRule.setOnClickListener { callBack.openReplaceRule() } //夜间模式 - fabNightTheme.onClick { + fabNightTheme.setOnClickListener { AppConfig.isNightTheme = !AppConfig.isNightTheme 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 { callBack.openChapterList() } } //朗读 - llReadAloud.onClick { + llReadAloud.setOnClickListener { runMenuOut { callBack.onClickReadAloud() } } - llReadAloud.onLongClick(returnValue = true) { + llReadAloud.setOnLongClickListener { runMenuOut { callBack.showReadAloudDialog() } + true } //界面 - llFont.onClick { + llFont.setOnClickListener { runMenuOut { callBack.showReadStyle() } } //设置 - llSetting.onClick { + llSetting.setOnClickListener { runMenuOut { callBack.showMoreSetting() } @@ -241,7 +240,7 @@ class ReadMenu @JvmOverloads constructor( } override fun onAnimationEnd(animation: Animation) { - binding.vwMenuBg.onClick { runMenuOut() } + binding.vwMenuBg.setOnClickListener { runMenuOut() } binding.vwNavigationBar.layoutParams = binding.vwNavigationBar.layoutParams.apply { height = activity!!.navigationBarHeight } diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index 0dff7326c..2ebc2ea02 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -24,13 +24,8 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.databinding.ItemTextBinding import io.legado.app.databinding.PopupActionMenuBinding import io.legado.app.service.BaseReadAloudService -import io.legado.app.utils.gone -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 io.legado.app.utils.* import org.jetbrains.anko.share -import org.jetbrains.anko.toast import java.util.* @SuppressLint("RestrictedApi") @@ -73,7 +68,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac if (moreMenu.size() > 0) { ivMenuMore.visible() } - ivMenuMore.onClick { + ivMenuMore.setOnClickListener { if (recyclerView.isVisible) { ivMenuMore.setImageResource(R.drawable.ic_arrow_back) 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) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { if (!callBack.onMenuItemSelected(it.itemId)) { 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_aloud -> { if (BaseReadAloudService.isRun) { - context.toast(R.string.alouding_disable) + context.toastOnUI(R.string.alouding_disable) return } readAloud(callBack.selectedText) @@ -143,7 +138,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac context.startActivity(intent) }.onFailure { it.printStackTrace() - context.toast(it.localizedMessage ?: "ERROR") + context.toastOnUI(it.localizedMessage ?: "ERROR") } } else -> item.intent?.let { @@ -219,7 +214,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac ).intent = createProcessTextIntentForResolveInfo(resolveInfo) } }.onFailure { - context.toast("获取文字操作菜单出错:${it.localizedMessage}") + context.toastOnUI("获取文字操作菜单出错:${it.localizedMessage}") } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt index 2c1169529..a3b8db620 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt @@ -16,7 +16,7 @@ import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.ColorUtils import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class AutoReadDialog : BaseDialogFragment() { var callBack: CallBack? = null @@ -94,12 +94,12 @@ class AutoReadDialog : BaseDialogFragment() { } private fun initEvent() { - binding.llMainMenu.onClick { callBack?.showMenuBar(); dismiss() } - binding.llSetting.onClick { + binding.llMainMenu.setOnClickListener { callBack?.showMenuBar(); dismiss() } + binding.llSetting.setOnClickListener { ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") } - binding.llCatalog.onClick { callBack?.openChapterList() } - binding.llAutoPageStop.onClick { + binding.llCatalog.setOnClickListener { callBack?.openChapterList() } + binding.llAutoPageStop.setOnClickListener { callBack?.autoPageStop() dismiss() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt index 435083830..fd0d390e9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt @@ -9,7 +9,7 @@ import io.legado.app.databinding.ItemBgImageBinding import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.utils.postEvent -import org.jetbrains.anko.sdk27.coroutines.onClick + import java.io.File 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) { holder.itemView.apply { - this.onClick { + this.setOnClickListener { getItemByLayoutPosition(holder.layoutPosition)?.let { ReadBookConfig.durConfig.setCurBg(1, it) ReadBookConfig.upBg() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index c875ae76c..57fd4c59a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -28,8 +28,6 @@ import io.legado.app.ui.filepicker.FilePicker import io.legado.app.ui.filepicker.FilePickerDialog import io.legado.app.utils.* 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.toByteArray import java.io.File @@ -110,7 +108,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { tvName.text = getString(R.string.select_image) ivBg.setImageResource(R.drawable.ic_image) ivBg.setColorFilter(primaryTextColor) - root.onClick { selectImage() } + root.setOnClickListener { selectImage() } } } requireContext().assets.list("bg")?.let { @@ -120,7 +118,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { @SuppressLint("InflateParams") private fun initEvent() = with(ReadBookConfig.durConfig) { - binding.ivEdit.onClick { + binding.ivEdit.setOnClickListener { alert(R.string.style_name) { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { editView.setText(ReadBookConfig.durConfig.name) @@ -135,13 +133,13 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { cancelButton() }.show() } - binding.swDarkStatusIcon.onCheckedChange { buttonView, isChecked -> + binding.swDarkStatusIcon.setOnCheckedChangeListener { buttonView, isChecked -> if (buttonView?.isPressed == true) { setCurStatusIconDark(isChecked) (activity as? ReadBookActivity)?.upSystemUiVisibility() } } - binding.tvTextColor.onClick { + binding.tvTextColor.setOnClickListener { ColorPickerDialog.newBuilder() .setColor(curTextColor()) .setShowAlphaSlider(false) @@ -149,7 +147,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { .setDialogId(TEXT_COLOR) .show(requireActivity()) } - binding.tvBgColor.onClick { + binding.tvBgColor.setOnClickListener { val bgColor = if (curBgType() == 0) Color.parseColor(curBgStr()) else Color.parseColor("#015A86") @@ -160,7 +158,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { .setDialogId(BG_COLOR) .show(requireActivity()) } - binding.ivImport.onClick { + binding.ivImport.setOnClickListener { val importFormNet = "网络导入" val otherActions = arrayListOf(importFormNet) FilePicker.selectFile( @@ -175,19 +173,19 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { } } } - binding.ivExport.onClick { + binding.ivExport.setOnClickListener { FilePicker.selectFolder( this@BgTextConfigDialog, requestCodeExport, title = getString(R.string.export_str) ) } - binding.ivDelete.onClick { + binding.ivDelete.setOnClickListener { if (ReadBookConfig.deleteDur()) { postEvent(EventBus.UP_CONFIG, true) dismiss() } else { - toast("数量已是最少,不能删除.") + toastOnUI("数量已是最少,不能删除.") } } } @@ -269,7 +267,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { } } }.onSuccess { - toast("导出成功, 文件名为 $exportFileName") + toastOnUI("导出成功, 文件名为 $exportFileName") }.onError { it.printStackTrace() longToast("导出失败:${it.localizedMessage}") @@ -365,7 +363,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { ReadBookConfig.durConfig = config postEvent(EventBus.UP_CONFIG, true) }.onSuccess { - toast("导入成功") + toastOnUI("导入成功") }.onError { it.printStackTrace() longToast("导入失败:${it.localizedMessage}") @@ -406,7 +404,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack { ReadBookConfig.durConfig.setCurBg(2, file.absolutePath) ReadBookConfig.upBg() postEvent(EventBus.UP_CONFIG, false) - } ?: toast("获取文件出错") + } ?: toastOnUI("获取文件出错") } } else { PermissionsCompat.Builder(this) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ChineseConverter.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ChineseConverter.kt index 4b227a9e0..514e0a350 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ChineseConverter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ChineseConverter.kt @@ -10,7 +10,7 @@ import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.accentColor import io.legado.app.ui.widget.text.StrokeTextView -import org.jetbrains.anko.sdk27.coroutines.onClick + class ChineseConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(context, attrs) { @@ -23,7 +23,7 @@ class ChineseConverter(context: Context, attrs: AttributeSet?) : StrokeTextView( if (!isInEditMode) { upUi(AppConfig.chineseConverterType) } - onClick { + setOnClickListener { selectType() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt index 4f142a192..e9f79e26c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt @@ -16,7 +16,7 @@ import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.utils.getCompatColor import io.legado.app.utils.putPrefInt import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class ClickActionConfigDialog : BaseDialogFragment() { private val binding by viewBinding(DialogClickActionConfigBinding::bind) @@ -68,52 +68,52 @@ class ClickActionConfigDialog : BaseDialogFragment() { } private fun initViewEvent() { - binding.ivClose.onClick { + binding.ivClose.setOnClickListener { dismiss() } - binding.tvTopLeft.onClick { + binding.tvTopLeft.setOnClickListener { selectAction { action -> putPrefInt(PreferKey.clickActionTL, action) (it as? TextView)?.text = actions[action] } } - binding.tvTopCenter.onClick { + binding.tvTopCenter.setOnClickListener { selectAction { action -> putPrefInt(PreferKey.clickActionTC, action) (it as? TextView)?.text = actions[action] } } - binding.tvTopRight.onClick { + binding.tvTopRight.setOnClickListener { selectAction { action -> putPrefInt(PreferKey.clickActionTR, action) (it as? TextView)?.text = actions[action] } } - binding.tvMiddleLeft.onClick { + binding.tvMiddleLeft.setOnClickListener { selectAction { action -> putPrefInt(PreferKey.clickActionML, action) (it as? TextView)?.text = actions[action] } } - binding.tvMiddleRight.onClick { + binding.tvMiddleRight.setOnClickListener { selectAction { action -> putPrefInt(PreferKey.clickActionMR, action) (it as? TextView)?.text = actions[action] } } - binding.tvBottomLeft.onClick { + binding.tvBottomLeft.setOnClickListener { selectAction { action -> putPrefInt(PreferKey.clickActionBL, action) (it as? TextView)?.text = actions[action] } } - binding.tvBottomCenter.onClick { + binding.tvBottomCenter.setOnClickListener { selectAction { action -> putPrefInt(PreferKey.clickActionBC, action) (it as? TextView)?.text = actions[action] } } - binding.tvBottomRight.onClick { + binding.tvBottomRight.setOnClickListener { selectAction { action -> putPrefInt(PreferKey.clickActionBR, action) (it as? TextView)?.text = actions[action] diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt index 8994db56f..092134e77 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt @@ -10,7 +10,7 @@ import io.legado.app.lib.theme.backgroundColor import io.legado.app.utils.getPrefString import io.legado.app.utils.hideSoftInput import io.legado.app.utils.putPrefString -import org.jetbrains.anko.sdk27.coroutines.onClick + 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.etPrev.setText(context.getPrefString(PreferKey.prevKeys)) binding.etNext.setText(context.getPrefString(PreferKey.nextKeys)) - binding.tvOk.onClick { + binding.tvOk.setOnClickListener { context.putPrefString(PreferKey.prevKeys, binding.etPrev.text?.toString()) context.putPrefString(PreferKey.nextKeys, binding.etNext.text?.toString()) dismiss() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index 8a913a5c2..6b0391738 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -21,7 +21,7 @@ import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.observeEvent import io.legado.app.utils.putPrefBoolean import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class ReadAloudDialog : BaseDialogFragment() { private var callBack: CallBack? = null @@ -122,18 +122,18 @@ class ReadAloudDialog : BaseDialogFragment() { } private fun initEvent() = with(binding) { - llMainMenu.onClick { callBack?.showMenuBar(); dismiss() } - llSetting.onClick { + llMainMenu.setOnClickListener { callBack?.showMenuBar(); dismiss() } + llSetting.setOnClickListener { ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") } - tvPre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } - tvNext.onClick { ReadBook.moveToNextChapter(true) } - ivStop.onClick { ReadAloud.stop(requireContext()); dismiss() } - ivPlayPause.onClick { callBack?.onClickReadAloud() } - ivPlayPrev.onClick { ReadAloud.prevParagraph(requireContext()) } - ivPlayNext.onClick { ReadAloud.nextParagraph(requireContext()) } - llCatalog.onClick { callBack?.openChapterList() } - llToBackstage.onClick { callBack?.finish() } + tvPre.setOnClickListener { ReadBook.moveToPrevChapter(upContent = true, toLast = false) } + tvNext.setOnClickListener { ReadBook.moveToNextChapter(true) } + ivStop.setOnClickListener { ReadAloud.stop(requireContext()); dismiss() } + ivPlayPause.setOnClickListener { callBack?.onClickReadAloud() } + ivPlayPrev.setOnClickListener { ReadAloud.prevParagraph(requireContext()) } + ivPlayNext.setOnClickListener { ReadAloud.nextParagraph(requireContext()) } + llCatalog.setOnClickListener { callBack?.openChapterList() } + llToBackstage.setOnClickListener { callBack?.finish() } } private fun upPlayState() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index b1df7f52e..18f244259 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -24,9 +24,6 @@ import io.legado.app.utils.dp import io.legado.app.utils.getIndexById import io.legado.app.utils.postEvent import io.legado.app.utils.viewbindingdelegate.viewBinding -import 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 { private val binding by viewBinding(DialogReadBookStyleBinding::bind) @@ -93,7 +90,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { ivStyle.setColorFilter(textColor) ivStyle.borderColor = textColor ivStyle.setImageResource(R.drawable.ic_add) - root.onClick { + root.setOnClickListener { ReadBookConfig.configList.add(ReadBookConfig.Config()) showBgTextConfig(ReadBookConfig.configList.lastIndex) } @@ -114,10 +111,10 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { textFontWeightConverter.onChanged { postEvent(EventBus.UP_CONFIG, true) } - tvTextFont.onClick { + tvTextFont.setOnClickListener { FontSelectDialog().show(childFragmentManager, "fontSelectDialog") } - tvTextIndent.onClick { + tvTextIndent.setOnClickListener { selector( title = getString(R.string.text_indent), items = resources.getStringArray(R.array.indent).toList() @@ -126,14 +123,14 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { postEvent(EventBus.UP_CONFIG, true) } } - tvPadding.onClick { + tvPadding.setOnClickListener { dismiss() callBack?.showPaddingConfig() } - tvTip.onClick { + tvTip.setOnClickListener { TipConfigDialog().show(childFragmentManager, "tipConfigDialog") } - rgPageAnim.onCheckedChange { _, checkedId -> + rgPageAnim.setOnCheckedChangeListener { _, checkedId -> ReadBook.book?.setPageAnim(-1) ReadBookConfig.pageAnim = binding.rgPageAnim.getIndexById(checkedId) callBack?.upPageAnim() @@ -235,14 +232,16 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { override fun registerListener(holder: ItemViewHolder, binding: ItemReadStyleBinding) { binding.apply { - ivStyle.onClick { + ivStyle.setOnClickListener { if (ivStyle.isInView) { changeBg(holder.layoutPosition) } } - ivStyle.onLongClick(returnValue = ivStyle.isInView) { + ivStyle.setOnLongClickListener { if (ivStyle.isInView) { showBgTextConfig(holder.layoutPosition) + } else { + false } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index f5275b730..12099ab2f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -27,7 +27,7 @@ import io.legado.app.service.help.ReadAloud import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private val binding by viewBinding(DialogRecyclerViewBinding::bind) @@ -66,17 +66,17 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener recyclerView.adapter = adapter tvFooterLeft.setText(R.string.local_tts) tvFooterLeft.visible() - tvFooterLeft.onClick { + tvFooterLeft.setOnClickListener { removePref(PreferKey.speakEngine) dismiss() } tvOk.visible() - tvOk.onClick { + tvOk.setOnClickListener { putPrefLong(PreferKey.speakEngine, engineId) dismiss() } tvCancel.visible() - tvCancel.onClick { + tvCancel.setOnClickListener { dismiss() } } @@ -150,16 +150,16 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener override fun registerListener(holder: ItemViewHolder, binding: ItemHttpTtsBinding) { binding.apply { - cbName.onClick { + cbName.setOnClickListener { getItem(holder.layoutPosition)?.let { httpTTS -> engineId = httpTTS.id notifyItemRangeChanged(0, itemCount) } } - ivEdit.onClick { + ivEdit.setOnClickListener { editHttpTTS(getItem(holder.layoutPosition)) } - ivMenuDelete.onClick { + ivMenuDelete.setOnClickListener { getItem(holder.layoutPosition)?.let { httpTTS -> App.db.httpTTSDao.delete(httpTTS) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TextFontWeightConverter.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TextFontWeightConverter.kt index dd7f60227..832cff925 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TextFontWeightConverter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TextFontWeightConverter.kt @@ -10,7 +10,7 @@ import io.legado.app.help.ReadBookConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.accentColor import io.legado.app.ui.widget.text.StrokeTextView -import org.jetbrains.anko.sdk27.coroutines.onClick + class TextFontWeightConverter(context: Context, attrs: AttributeSet?) : StrokeTextView(context, attrs) { @@ -23,7 +23,7 @@ class TextFontWeightConverter(context: Context, attrs: AttributeSet?) : StrokeTe if (!isInEditMode) { upUi(ReadBookConfig.textBold) } - onClick { + setOnClickListener { selectType() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt index 7654ba733..8e0d74b74 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt @@ -14,8 +14,7 @@ import io.legado.app.help.ReadTipConfig import io.legado.app.lib.dialogs.selector import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onCheckedChange -import org.jetbrains.anko.sdk27.coroutines.onClick + class TipConfigDialog : BaseDialogFragment() { @@ -76,7 +75,7 @@ class TipConfigDialog : BaseDialogFragment() { } private fun initEvent() = with(binding) { - rgTitleMode.onCheckedChange { _, checkedId -> + rgTitleMode.setOnCheckedChangeListener { _, checkedId -> ReadBookConfig.titleMode = rgTitleMode.getIndexById(checkedId) postEvent(EventBus.UP_CONFIG, true) } @@ -92,21 +91,21 @@ class TipConfigDialog : BaseDialogFragment() { ReadBookConfig.titleBottomSpacing = it postEvent(EventBus.UP_CONFIG, true) } - llHeaderShow.onClick { + llHeaderShow.setOnClickListener { selector(items = ReadTipConfig.headerModes.values.toList()) { _, i -> ReadTipConfig.headerMode = ReadTipConfig.headerModes.keys.toList()[i] tvHeaderShow.text = ReadTipConfig.headerModes[ReadTipConfig.headerMode] postEvent(EventBus.UP_CONFIG, true) } } - llFooterShow.onClick { + llFooterShow.setOnClickListener { selector(items = ReadTipConfig.footerModes.values.toList()) { _, i -> ReadTipConfig.footerMode = ReadTipConfig.footerModes.keys.toList()[i] tvFooterShow.text = ReadTipConfig.footerModes[ReadTipConfig.footerMode] postEvent(EventBus.UP_CONFIG, true) } } - llHeaderLeft.onClick { + llHeaderLeft.setOnClickListener { selector(items = ReadTipConfig.tips) { _, i -> clearRepeat(i) ReadTipConfig.tipHeaderLeft = i @@ -114,7 +113,7 @@ class TipConfigDialog : BaseDialogFragment() { postEvent(EventBus.UP_CONFIG, true) } } - llHeaderMiddle.onClick { + llHeaderMiddle.setOnClickListener { selector(items = ReadTipConfig.tips) { _, i -> clearRepeat(i) ReadTipConfig.tipHeaderMiddle = i @@ -122,7 +121,7 @@ class TipConfigDialog : BaseDialogFragment() { postEvent(EventBus.UP_CONFIG, true) } } - llHeaderRight.onClick { + llHeaderRight.setOnClickListener { selector(items = ReadTipConfig.tips) { _, i -> clearRepeat(i) ReadTipConfig.tipHeaderRight = i @@ -130,7 +129,7 @@ class TipConfigDialog : BaseDialogFragment() { postEvent(EventBus.UP_CONFIG, true) } } - llFooterLeft.onClick { + llFooterLeft.setOnClickListener { selector(items = ReadTipConfig.tips) { _, i -> clearRepeat(i) ReadTipConfig.tipFooterLeft = i @@ -138,7 +137,7 @@ class TipConfigDialog : BaseDialogFragment() { postEvent(EventBus.UP_CONFIG, true) } } - llFooterMiddle.onClick { + llFooterMiddle.setOnClickListener { selector(items = ReadTipConfig.tips) { _, i -> clearRepeat(i) ReadTipConfig.tipFooterMiddle = i @@ -146,7 +145,7 @@ class TipConfigDialog : BaseDialogFragment() { postEvent(EventBus.UP_CONFIG, true) } } - llFooterRight.onClick { + llFooterRight.setOnClickListener { selector(items = ReadTipConfig.tips) { _, i -> clearRepeat(i) ReadTipConfig.tipFooterRight = i @@ -154,7 +153,7 @@ class TipConfigDialog : BaseDialogFragment() { postEvent(EventBus.UP_CONFIG, true) } } - llTipColor.onClick { + llTipColor.setOnClickListener { selector(items = arrayListOf("跟随正文", "自定义")) { _, i -> when (i) { 0 -> { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 9aad332f9..6030ba0de 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -33,7 +33,7 @@ import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch -import org.jetbrains.anko.sdk27.coroutines.onClick + import java.util.* class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { @@ -79,16 +79,16 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = true ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recyclerView) - tvCancel.onClick { + tvCancel.setOnClickListener { dismiss() } - tvOk.onClick { + tvOk.setOnClickListener { adapter.getItems().forEach { tocRule -> if (selectedName == tocRule.name) { val callBack = activity as? CallBack callBack?.onTocRegexDialogResult(tocRule.rule) dismiss() - return@onClick + return@setOnClickListener } } } @@ -231,10 +231,10 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } } } - ivEdit.onClick { + ivEdit.setOnClickListener { editRule(getItem(holder.layoutPosition)) } - ivDelete.onClick { + ivDelete.setOnClickListener { getItem(holder.layoutPosition)?.let { item -> launch(IO) { App.db.txtTocRule.delete(item) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index dbecc4b82..7b621735f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -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.widget.BatteryView import io.legado.app.utils.* -import org.jetbrains.anko.topPadding import java.util.* /** @@ -97,9 +96,9 @@ class PageView(context: Context) : FrameLayout(context) { /** * 显示状态栏时隐藏header */ - fun upStatusBar() { - binding.vwStatusBar.topPadding = context.statusBarHeight - binding.vwStatusBar.isGone = + fun upStatusBar() = with(binding.vwStatusBar) { + setPadding(paddingLeft, context.statusBarHeight, paddingRight, paddingBottom) + isGone = ReadBookConfig.hideStatusBar || (activity as? BaseActivity<*>)?.isInMultiWindow == true } diff --git a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt index e192f8428..40bcd0ed3 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt @@ -6,7 +6,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.entities.Book import io.legado.app.databinding.ItemFilletTextBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class BookAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context) { @@ -28,7 +28,7 @@ class BookAdapter(context: Context, val callBack: CallBack) : override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) { holder.itemView.apply { - onClick { + setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.showBookInfo(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index a2022c0d1..223081a8b 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -10,9 +10,6 @@ import io.legado.app.ui.widget.anima.explosion_field.ExplosionField import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.GlobalScope 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) : RecyclerAdapter(activity) { @@ -36,12 +33,12 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) { holder.itemView.apply { - onClick { + setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.searchHistory(it.word) } } - onLongClick(returnValue = true) { + setOnLongClickListener { it?.let { explosionField.explode(it, true) } @@ -50,6 +47,7 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : App.db.searchKeywordDao.delete(it) } } + true } } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 4f6a0bfbd..5cfce4116 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -28,7 +28,7 @@ import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.sdk27.coroutines.onClick + import org.jetbrains.anko.startActivity class SearchActivity : VMBaseActivity(), @@ -184,11 +184,11 @@ class SearchActivity : VMBaseActivity(context) { @@ -66,7 +66,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } override fun registerListener(holder: ItemViewHolder, binding: ItemSearchBinding) { - binding.root.onClick { + binding.root.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.showBookInfo(it.name, it.author) } diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt index 93401168a..cd1f04551 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt @@ -26,7 +26,7 @@ import io.legado.app.utils.observeEvent import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.sdk27.coroutines.onClick + class SearchContentActivity : VMBaseActivity(), @@ -92,8 +92,13 @@ class SearchContentActivity : } private fun initView() { - binding.ivSearchContentTop.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } - binding.ivSearchContentBottom.onClick { + binding.ivSearchContentTop.setOnClickListener { + mLayoutManager.scrollToPositionWithOffset( + 0, + 0 + ) + } + binding.ivSearchContentBottom.setOnClickListener { if (adapter.itemCount > 0) { mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0) } diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt index 9bacaa3d4..10a3502df 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt @@ -9,7 +9,7 @@ import io.legado.app.databinding.ItemSearchListBinding import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getCompatColor import io.legado.app.utils.hexString -import org.jetbrains.anko.sdk27.coroutines.onClick + class SearchContentAdapter(context: Context, val callback: Callback) : RecyclerAdapter(context) { @@ -38,7 +38,7 @@ class SearchContentAdapter(context: Context, val callback: Callback) : } override fun registerListener(holder: ItemViewHolder, binding: ItemSearchListBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callback.openSearchResult(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index 42b2e2ccd..9ff85ebc0 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -14,9 +14,9 @@ import io.legado.app.lib.theme.accentColor import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.getViewModel +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.launch import org.jetbrains.anko.startActivityForResult -import org.jetbrains.anko.toast class BookSourceDebugActivity : VMBaseActivity() { @@ -83,7 +83,7 @@ class BookSourceDebugActivity : VMBaseActivity getSource().let { if (checkSource(it)) { if (it.loginUrl.isNullOrEmpty()) { - toast(R.string.source_no_login) + toastOnUI(R.string.source_no_login) } else { startActivity( Pair("sourceUrl", it.bookSourceUrl), @@ -357,7 +357,7 @@ class BookSourceEditActivity : private fun checkSource(source: BookSource): Boolean { if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) { - toast(R.string.non_null_name_url) + toastOnUI(R.string.non_null_name_url) return false } return true diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index e1c7d4d2c..aba8afa5e 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -45,7 +45,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat }.onSuccess { success?.invoke() }.onError { - toast(it.localizedMessage) + toastOnUI(it.localizedMessage) it.printStackTrace() } } @@ -58,13 +58,13 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat } source }.onError { - toast(it.localizedMessage) + toastOnUI(it.localizedMessage) it.printStackTrace() }.onSuccess { if (it != null) { onSuccess(it) } else { - toast("格式不对") + toastOnUI("格式不对") } } } @@ -76,7 +76,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat finally.invoke(it) } }.onError { - toast(it.localizedMessage ?: "Error") + toastOnUI(it.localizedMessage ?: "Error") } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index aa78e4a5b..2ae2773c8 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -40,7 +40,6 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult -import org.jetbrains.anko.toast import java.io.File class BookSourceActivity : VMBaseActivity(), @@ -412,7 +411,7 @@ class BookSourceActivity : VMBaseActivity if (group.contains("失效")) { searchView.setQuery("失效", true) - toast("发现有失效书源,已为您自动筛选!") + toastOnUI("发现有失效书源,已为您自动筛选!") } } } @@ -474,7 +473,7 @@ class BookSourceActivity : VMBaseActivity("dataKey" to dataKey) } } catch (e: Exception) { - toast("readTextError:${e.localizedMessage}") + toastOnUI("readTextError:${e.localizedMessage}") } } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index 022a4e800..2b17c3189 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -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.utils.invisible import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick + class BookSourceAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context), @@ -132,12 +132,12 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } } } - ivEdit.onClick { + ivEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.edit(it) } } - ivMenuMore.onClick { + ivMenuMore.setOnClickListener { showMenu(ivMenuMore, holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 25094113f..8ef8cc50f 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -181,7 +181,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - toast(it.msg) + toastOnUI(it.msg) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 5085076f4..7e6696cd5 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -24,7 +24,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var viewModel: BookSourceViewModel @@ -129,12 +129,12 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { override fun registerListener(holder: ItemViewHolder, binding: ItemGroupManageBinding) { binding.apply { - tvEdit.onClick { + tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } } - tvDel.onClick { + tvDel.setOnClickListener { getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt index 5cea134ec..f6fc46bf8 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt @@ -7,8 +7,6 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import io.legado.app.data.entities.Bookmark 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(DIFF_CALLBACK) { @@ -45,11 +43,12 @@ class BookmarkAdapter(val callback: Callback) : PagedListAdapter(context) { @@ -49,7 +49,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : } override fun registerListener(holder: ItemViewHolder, binding: ItemChapterListBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callback.openChapter(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index eeb80791e..236afdf10 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -26,7 +26,7 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import org.jetbrains.anko.sdk27.coroutines.onClick + import kotlin.math.min class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list), @@ -63,13 +63,13 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } private fun initView() = with(binding) { - ivChapterTop.onClick { mLayoutManager.scrollToPositionWithOffset(0, 0) } - ivChapterBottom.onClick { + ivChapterTop.setOnClickListener { mLayoutManager.scrollToPositionWithOffset(0, 0) } + ivChapterBottom.setOnClickListener { if (adapter.itemCount > 0) { mLayoutManager.scrollToPositionWithOffset(adapter.itemCount - 1, 0) } } - tvCurrentChapterInfo.onClick { + tvCurrentChapterInfo.setOnClickListener { mLayoutManager.scrollToPositionWithOffset(durChapterIndex, 0) } } diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index 794271d3e..970267735 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -20,9 +20,8 @@ import io.legado.app.ui.filepicker.FilePicker import io.legado.app.utils.getPrefString import io.legado.app.utils.isContentScheme import io.legado.app.utils.longToast -import io.legado.app.utils.toast +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.Dispatchers.Main -import org.jetbrains.anko.toast object BackupRestoreUi { private const val selectFolderRequestCode = 21 @@ -42,7 +41,7 @@ object BackupRestoreUi { Coroutine.async { Backup.backup(fragment.requireContext(), backupPath) }.onSuccess { - fragment.toast(R.string.backup_success) + fragment.toastOnUI(R.string.backup_success) } } else { selectBackupFolder(fragment, backupSelectRequestCode) @@ -65,7 +64,7 @@ object BackupRestoreUi { AppConfig.backupPath = path Backup.backup(fragment.requireContext(), path) }.onSuccess { - fragment.toast(R.string.backup_success) + fragment.toastOnUI(R.string.backup_success) } } .request() @@ -135,7 +134,7 @@ object BackupRestoreUi { Coroutine.async { Backup.backup(App.INSTANCE, uri.toString()) }.onSuccess { - App.INSTANCE.toast(R.string.backup_success) + App.INSTANCE.toastOnUI(R.string.backup_success) } } else { uri.path?.let { path -> @@ -143,7 +142,7 @@ object BackupRestoreUi { Coroutine.async { Backup.backup(App.INSTANCE, path) }.onSuccess { - App.INSTANCE.toast(R.string.backup_success) + App.INSTANCE.toastOnUI(R.string.backup_success) } } } diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 42945d48f..06eadc149 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -177,7 +177,7 @@ class OtherConfigFragment : BasePreferenceFragment(), okButton { BookHelp.clearCache() FileUtils.deleteFile(requireActivity().cacheDir.absolutePath) - toast(R.string.clear_cache_success) + toastOnUI(R.string.clear_cache_success) } noButton() }.show() @@ -221,7 +221,7 @@ class OtherConfigFragment : BasePreferenceFragment(), file.writeBytes(byteArray) putPrefString(PreferKey.defaultCover, file.absolutePath) CoverImageView.upDefaultCover() - } ?: toast("获取文件出错") + } ?: toastOnUI("获取文件出错") } } else { PermissionsCompat.Builder(this) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index ce5cf3814..d4b88d855 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -60,7 +60,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), findPreference(PreferKey.cBackground)?.let { it.onSaveColor = { color -> if (!ColorUtils.isColorLight(color)) { - toast(R.string.day_background_too_dark) + toastOnUI(R.string.day_background_too_dark) true } else { false @@ -70,7 +70,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), findPreference(PreferKey.cNBackground)?.let { it.onSaveColor = { color -> if (ColorUtils.isColorLight(color)) { - toast(R.string.night_background_too_light) + toastOnUI(R.string.night_background_too_light) true } else { false @@ -84,11 +84,11 @@ class ThemeConfigFragment : BasePreferenceFragment(), val textColor = getCompatColor(R.color.primaryText) when { ColorUtils.getColorDifference(color, background) <= 60 -> { - toast(R.string.accent_background_diff) + toastOnUI(R.string.accent_background_diff) true } ColorUtils.getColorDifference(color, textColor) <= 60 -> { - toast(R.string.accent_text_diff) + toastOnUI(R.string.accent_text_diff) true } else -> false @@ -102,11 +102,11 @@ class ThemeConfigFragment : BasePreferenceFragment(), val textColor = getCompatColor(R.color.primaryText) when { ColorUtils.getColorDifference(color, background) <= 60 -> { - toast(R.string.accent_background_diff) + toastOnUI(R.string.accent_background_diff) true } ColorUtils.getColorDifference(color, textColor) <= 60 -> { - toast(R.string.accent_text_diff) + toastOnUI(R.string.accent_text_diff) true } else -> false @@ -277,7 +277,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), putPrefString(preferenceKey, file.absolutePath) upPreferenceSummary(preferenceKey, file.absolutePath) success() - } ?: toast("获取文件出错") + } ?: toastOnUI("获取文件出错") } } else { PermissionsCompat.Builder(this) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index 6939a2625..f6b722c1a 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -19,7 +19,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + import org.jetbrains.anko.share class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { @@ -72,7 +72,7 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { if (ThemeConfig.addConfig(it)) { initData() } else { - toast("格式不对,添加失败") + toastOnUI("格式不对,添加失败") } } } @@ -115,13 +115,13 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { override fun registerListener(holder: ItemViewHolder, binding: ItemThemeConfigBinding) { binding.apply { - root.onClick { + root.setOnClickListener { ThemeConfig.applyConfig(context, ThemeConfig.configList[holder.layoutPosition]) } - ivShare.onClick { + ivShare.setOnClickListener { share(holder.layoutPosition) } - ivDelete.onClick { + ivDelete.setOnClickListener { delete(holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt index 9c4d1358f..00e9a7f31 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt @@ -170,14 +170,14 @@ class FilePickerDialog : DialogFragment(), } else { fileItem?.path?.let { path -> if (mode == DIRECTORY) { - toast("这是文件夹选择,不能选择文件,点击右上角的确定选择文件夹") + toastOnUI("这是文件夹选择,不能选择文件,点击右上角的确定选择文件夹") } else if (allowExtensions.isNullOrEmpty() || allowExtensions?.contains(FileUtils.getExtension(path)) == true ) { setData(path) dismiss() } else { - toast("不能打开此文件") + toastOnUI("不能打开此文件") } } } diff --git a/app/src/main/java/io/legado/app/ui/filepicker/adapter/FileAdapter.kt b/app/src/main/java/io/legado/app/ui/filepicker/adapter/FileAdapter.kt index 8aee54788..e4bedec58 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/adapter/FileAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/adapter/FileAdapter.kt @@ -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.FilePickerIcon import io.legado.app.utils.FileUtils -import org.jetbrains.anko.sdk27.coroutines.onClick + import java.io.File import java.util.* @@ -118,7 +118,7 @@ class FileAdapter(context: Context, val callBack: CallBack) : } override fun registerListener(holder: ItemViewHolder, binding: ItemFileFilepickerBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { callBack.onFileClick(holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/filepicker/adapter/PathAdapter.kt b/app/src/main/java/io/legado/app/ui/filepicker/adapter/PathAdapter.kt index e3c911876..60ea3f648 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/adapter/PathAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/adapter/PathAdapter.kt @@ -8,7 +8,7 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.databinding.ItemPathFilepickerBinding import io.legado.app.ui.filepicker.utils.ConvertUtils import io.legado.app.ui.filepicker.utils.FilePickerIcon -import org.jetbrains.anko.sdk27.coroutines.onClick + import java.util.* @@ -61,7 +61,7 @@ class PathAdapter(context: Context, val callBack: CallBack) : } override fun registerListener(holder: ItemViewHolder, binding: ItemPathFilepickerBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { callBack.onPathClick(holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 4890d22da..964164b98 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -32,7 +32,7 @@ import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.getViewModel import io.legado.app.utils.hideSoftInput import io.legado.app.utils.observeEvent -import org.jetbrains.anko.toast +import io.legado.app.utils.toastOnUI class MainActivity : VMBaseActivity(), @@ -144,7 +144,7 @@ class MainActivity : VMBaseActivity(), return true } if (System.currentTimeMillis() - exitTime > 2000) { - toast(R.string.double_click_exit) + toastOnUI(R.string.double_click_exit) exitTime = System.currentTimeMillis() } else { if (BaseReadAloudService.pause) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index fd67e259b..83e23e3e8 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -205,7 +205,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b override fun onTabReselected(tab: TabLayout.Tab) { fragmentMap[selectedGroup.groupId]?.let { - toast("${selectedGroup.groupName}(${it.getBooksCount()})") + toastOnUI("${selectedGroup.groupName}(${it.getBooksCount()})") } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index e2e1b50e3..5f464c8ac 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -57,12 +57,12 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } }.onSuccess { if (successCount > 0) { - toast(R.string.success) + toastOnUI(R.string.success) } else { - toast("ERROR") + toastOnUI("ERROR") } }.onError { - toast(it.localizedMessage ?: "ERROR") + toastOnUI(it.localizedMessage ?: "ERROR") } } @@ -98,7 +98,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } }.onError { - toast(it.localizedMessage ?: "ERROR") + toastOnUI(it.localizedMessage ?: "ERROR") } } @@ -121,7 +121,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } } }.onFinally { - toast(R.string.success) + toastOnUI(R.string.success) } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt index 395bedafd..41e72a1d3 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt @@ -9,8 +9,6 @@ import io.legado.app.data.entities.Book import io.legado.app.databinding.ItemBookshelfGridBinding import io.legado.app.lib.theme.ATH import io.legado.app.utils.invisible -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.sdk27.coroutines.onLongClick class BooksAdapterGrid(context: Context, private val callBack: CallBack) : BaseBooksAdapter(context) { @@ -55,16 +53,17 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) : override fun registerListener(holder: ItemViewHolder, binding: ItemBookshelfGridBinding) { holder.itemView.apply { - onClick { + setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.open(it) } } - onLongClick(returnValue = true) { + setOnLongClickListener { getItem(holder.layoutPosition)?.let { callBack.openBookInfo(it) } + true } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt index a08ec13df..b70b6c3e3 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt @@ -9,8 +9,6 @@ import io.legado.app.data.entities.Book import io.legado.app.databinding.ItemBookshelfListBinding import io.legado.app.lib.theme.ATH import io.legado.app.utils.invisible -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.sdk27.coroutines.onLongClick class BooksAdapterList(context: Context, private val callBack: CallBack) : BaseBooksAdapter(context) { @@ -61,16 +59,17 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : override fun registerListener(holder: ItemViewHolder, binding: ItemBookshelfListBinding) { holder.itemView.apply { - onClick { + setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.open(it) } } - onLongClick(returnValue = true) { + setOnLongClickListener { getItem(holder.layoutPosition)?.let { callBack.openBookInfo(it) } + true } } } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 234616e99..d5058a288 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -19,8 +19,6 @@ import io.legado.app.utils.dp import io.legado.app.utils.gone import io.legado.app.utils.visible 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) : RecyclerAdapter(context) { @@ -68,7 +66,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca glChild.addView(tv.root) tv.textView.text = kind.title if (!kind.url.isNullOrEmpty()) { - tv.textView.onClick { + tv.textView.setOnClickListener { callBack.openExplore( item.bookSourceUrl, kind.title, @@ -95,7 +93,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca override fun registerListener(holder: ItemViewHolder, binding: ItemFindBookBinding) { binding.apply { - llTitle.onClick { + llTitle.setOnClickListener { val position = holder.layoutPosition val oldEx = exIndex exIndex = if (exIndex == position) -1 else position @@ -106,8 +104,9 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca notifyItemChanged(position, false) } } - llTitle.onLongClick { + llTitle.setOnLongClickListener { showMenu(llTitle, holder.layoutPosition) + true } } } diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt index d22f7328e..dbe75836d 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssAdapter.kt @@ -10,8 +10,6 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.entities.RssSource import io.legado.app.databinding.ItemRssBinding import io.legado.app.help.ImageLoader -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.sdk27.coroutines.onLongClick class RssAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context) { @@ -38,15 +36,16 @@ class RssAdapter(context: Context, val callBack: CallBack) : override fun registerListener(holder: ItemViewHolder, binding: ItemRssBinding) { binding.apply { - root.onClick { + root.setOnClickListener { getItemByLayoutPosition(holder.layoutPosition)?.let { callBack.openRss(it) } } - root.onLongClick(returnValue = true) { + root.setOnLongClickListener { getItemByLayoutPosition(holder.layoutPosition)?.let { showMenu(ivIcon, it) } + true } } } diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 20d94c924..62a777d37 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -28,7 +28,7 @@ import io.legado.app.utils.getViewModel import io.legado.app.utils.splitNotBlank import io.legado.app.utils.startActivity import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + /** * 订阅界面 @@ -106,7 +106,7 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), ItemRssBinding.inflate(layoutInflater, it, false).apply { tvName.setText(R.string.rule_subscription) ivIcon.setImageResource(R.drawable.image_legado) - root.onClick { + root.setOnClickListener { startActivity() } } diff --git a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt index a863681ce..28cfffae6 100644 --- a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt @@ -24,7 +24,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var viewModel: ReplaceRuleViewModel @@ -134,13 +134,13 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { override fun registerListener(holder: ItemViewHolder, binding: ItemGroupManageBinding) { binding.apply { - tvEdit.onClick { + tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } } - tvDel.onClick { + tvDel.setOnClickListener { getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } } } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 6563f3a5b..8d1cb0889 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -39,7 +39,6 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult -import org.jetbrains.anko.toast import java.io.File /** @@ -270,7 +269,7 @@ class ReplaceRuleActivity : VMBaseActivity("dataKey" to dataKey) } }.onFailure { - toast("readTextError:${it.localizedMessage}") + toastOnUI("readTextError:${it.localizedMessage}") } } } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt index 1ad90b2b2..f4e68d9a2 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt @@ -16,7 +16,7 @@ import io.legado.app.databinding.ItemReplaceRuleBinding import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback -import org.jetbrains.anko.sdk27.coroutines.onClick + import java.util.* @@ -147,12 +147,12 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } } } - ivEdit.onClick { + ivEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.edit(it) } } - cbName.onClick { + cbName.setOnClickListener { getItem(holder.layoutPosition)?.let { if (cbName.isChecked) { selected.add(it) @@ -162,7 +162,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } callBack.upCountView() } - ivMenuMore.onClick { + ivMenuMore.setOnClickListener { showMenu(ivMenuMore, holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt index 33e68f6c1..e93debb74 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt @@ -6,11 +6,7 @@ import androidx.documentfile.provider.DocumentFile import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.ReplaceRule -import io.legado.app.utils.FileUtils -import io.legado.app.utils.GSON -import io.legado.app.utils.splitNotBlank -import io.legado.app.utils.writeText -import org.jetbrains.anko.toast +import io.legado.app.utils.* import java.io.File class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) { @@ -83,9 +79,9 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application FileUtils.createFileIfNotExist(file, "exportReplaceRule.json") .writeText(json) }.onSuccess { - context.toast("成功导出至\n${file.absolutePath}") + context.toastOnUI("成功导出至\n${file.absolutePath}") }.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") ?.writeText(context, json) }.onSuccess { - context.toast("成功导出至\n${doc.uri.path}") + context.toastOnUI("成功导出至\n${doc.uri.path}") }.onError { - context.toast("导出失败\n${it.localizedMessage}") + context.toastOnUI("导出失败\n${it.localizedMessage}") } } diff --git a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt index 669945224..c9fe46b03 100644 --- a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt @@ -20,10 +20,9 @@ import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.getViewModel import io.legado.app.utils.postEvent +import io.legado.app.utils.toastOnUI import org.jetbrains.anko.displayMetrics -import org.jetbrains.anko.sdk27.coroutines.onClick import org.jetbrains.anko.selector -import org.jetbrains.anko.toast import kotlin.math.abs /** @@ -68,7 +67,7 @@ class ReplaceEditActivity : viewModel.initData(intent) { upReplaceView(it) } - binding.ivHelp.onClick { + binding.ivHelp.setOnClickListener { showRegexHelp() } } @@ -83,7 +82,7 @@ class ReplaceEditActivity : R.id.menu_save -> { val rule = getReplaceRule() if (!rule.isValid()) { - toast(R.string.replace_rule_invalid) + toastOnUI(R.string.replace_rule_invalid) } else { viewModel.save(rule) { postEvent(EventBus.REPLACE_RULE_SAVE, "") diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index 85ae70914..cabd5b51a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -12,10 +12,10 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.data.entities.RssArticle import io.legado.app.databinding.ItemRssArticleBinding import io.legado.app.help.ImageLoader +import io.legado.app.utils.getCompatColor import io.legado.app.utils.gone import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.textColorResource + class RssArticlesAdapter(context: Context, callBack: CallBack) : BaseRssArticlesAdapter(context, callBack) { @@ -67,15 +67,15 @@ class RssArticlesAdapter(context: Context, callBack: CallBack) : }.into(imageView) } if (item.read) { - tvTitle.textColorResource = R.color.tv_text_summary + tvTitle.setTextColor(context.getCompatColor(R.color.tv_text_summary)) } else { - tvTitle.textColorResource = R.color.primaryText + tvTitle.setTextColor(context.getCompatColor(R.color.primaryText)) } } } override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticleBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.readRss(it) } diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt index 4b1702bcd..2c8ff0d8f 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt @@ -12,10 +12,10 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.data.entities.RssArticle import io.legado.app.databinding.ItemRssArticle1Binding import io.legado.app.help.ImageLoader +import io.legado.app.utils.getCompatColor import io.legado.app.utils.gone import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.textColorResource + class RssArticlesAdapter1(context: Context, callBack: CallBack) : BaseRssArticlesAdapter(context, callBack) { @@ -67,15 +67,15 @@ class RssArticlesAdapter1(context: Context, callBack: CallBack) : }.into(imageView) } if (item.read) { - tvTitle.textColorResource = R.color.tv_text_summary + tvTitle.setTextColor(context.getCompatColor(R.color.tv_text_summary)) } else { - tvTitle.textColorResource = R.color.primaryText + tvTitle.setTextColor(context.getCompatColor(R.color.primaryText)) } } } override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticle1Binding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.readRss(it) } diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt index 5c53dd4ac..a82300afe 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt @@ -12,10 +12,10 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.data.entities.RssArticle import io.legado.app.databinding.ItemRssArticle2Binding import io.legado.app.help.ImageLoader +import io.legado.app.utils.getCompatColor import io.legado.app.utils.gone import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.textColorResource + class RssArticlesAdapter2(context: Context, callBack: CallBack) : BaseRssArticlesAdapter(context, callBack) { @@ -67,15 +67,15 @@ class RssArticlesAdapter2(context: Context, callBack: CallBack) : }.into(imageView) } if (item.read) { - tvTitle.textColorResource = R.color.tv_text_summary + tvTitle.setTextColor(context.getCompatColor(R.color.tv_text_summary)) } else { - tvTitle.textColorResource = R.color.primaryText + tvTitle.setTextColor(context.getCompatColor(R.color.primaryText)) } } } override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticle2Binding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.readRss(it) } diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 1196e2ebd..0f45b14b6 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -51,7 +51,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application }.onError { loadFinally.postValue(false) it.printStackTrace() - toast(it.localizedMessage) + toastOnUI(it.localizedMessage) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt index 64300c104..517c4bb27 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt @@ -14,7 +14,7 @@ import io.legado.app.databinding.ItemRssArticleBinding import io.legado.app.help.ImageLoader import io.legado.app.utils.gone import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick + class RssFavoritesAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context) { @@ -65,7 +65,7 @@ class RssFavoritesAdapter(context: Context, val callBack: CallBack) : } override fun registerListener(holder: ItemViewHolder, binding: ItemRssArticleBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.readRss(it) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index eb211f0eb..0a7498c08 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -25,7 +25,6 @@ import io.legado.app.ui.filepicker.FilePickerDialog import io.legado.app.utils.* import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils -import org.jetbrains.anko.downloadManager import org.jetbrains.anko.share import org.jsoup.Jsoup diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 452f8c87f..24aafe19d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -137,9 +137,9 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } } ?: throw Throwable("NULL") }.onError { - toast("保存图片失败:${it.localizedMessage}") + toastOnUI("保存图片失败:${it.localizedMessage}") }.onSuccess { - toast("保存成功") + toastOnUI("保存成功") } } @@ -186,7 +186,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), play() } else { launch { - toast(R.string.tts_init_failed) + toastOnUI(R.string.tts_init_failed) } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt index a57afe2a3..5b9560a39 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt @@ -9,8 +9,8 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getViewModel import io.legado.app.utils.gone +import io.legado.app.utils.toastOnUI import kotlinx.coroutines.launch -import org.jetbrains.anko.toast class RssSourceDebugActivity : VMBaseActivity() { @@ -56,7 +56,7 @@ class RssSourceDebugActivity : VMBaseActivity() it.map { group -> @@ -132,13 +132,13 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener override fun registerListener(holder: ItemViewHolder, binding: ItemGroupManageBinding) { binding.apply { - tvEdit.onClick { + tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } } - tvDel.onClick { + tvDel.setOnClickListener { getItem(holder.layoutPosition)?.let { viewModel.delGroup(it) } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 1e6156391..c8d1b608b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -36,7 +36,6 @@ import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.* import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivityForResult -import org.jetbrains.anko.toast import java.io.File @@ -271,7 +270,7 @@ class RssSourceActivity : VMBaseActivity("dataKey" to dataKey) } }.onFailure { - toast("readTextError:${it.localizedMessage}") + toastOnUI("readTextError:${it.localizedMessage}") } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index fe7d9803d..a0b8bdccf 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -16,7 +16,7 @@ import io.legado.app.databinding.ItemRssSourceBinding import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback -import org.jetbrains.anko.sdk27.coroutines.onClick + class RssSourceAdapter(context: Context, val callBack: CallBack) : RecyclerAdapter(context), @@ -113,12 +113,12 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : } } } - ivEdit.onClick { + ivEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.edit(it) } } - ivMenuMore.onClick { + ivMenuMore.setOnClickListener { showMenu(ivMenuMore, holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 7ff23307c..5a4ea13c3 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -11,7 +11,6 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssSource import io.legado.app.help.DefaultData import io.legado.app.utils.* -import org.jetbrains.anko.toast import java.io.File class RssSourceViewModel(application: Application) : BaseViewModel(application) { @@ -86,9 +85,9 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) FileUtils.createFileIfNotExist(file, "exportRssSource.json") .writeText(json) }.onSuccess { - context.toast("成功导出至\n${file.absolutePath}") + context.toastOnUI("成功导出至\n${file.absolutePath}") }.onError { - context.toast("导出失败\n${it.localizedMessage}") + context.toastOnUI("导出失败\n${it.localizedMessage}") } } @@ -99,9 +98,9 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) doc.createFile("", "exportRssSource.json") ?.writeText(context, json) }.onSuccess { - context.toast("成功导出至\n${doc.uri.path}") + context.toastOnUI("成功导出至\n${doc.uri.path}") }.onError { - context.toast("导出失败\n${it.localizedMessage}") + context.toastOnUI("导出失败\n${it.localizedMessage}") } } @@ -123,7 +122,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - toast(it.msg) + toastOnUI(it.msg) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt index 0173f4fca..2bb5560be 100644 --- a/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/subscription/RuleSubAdapter.kt @@ -11,7 +11,7 @@ import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.entities.RuleSub import io.legado.app.databinding.ItemRuleSubBinding import io.legado.app.ui.widget.recycler.ItemTouchCallback -import org.jetbrains.anko.sdk27.coroutines.onClick + class RuleSubAdapter(context: Context, val callBack: Callback) : RecyclerAdapter(context), @@ -31,13 +31,13 @@ class RuleSubAdapter(context: Context, val callBack: Callback) : } override fun registerListener(holder: ItemViewHolder, binding: ItemRuleSubBinding) { - binding.root.onClick { + binding.root.setOnClickListener { callBack.openSubscription(getItem(holder.layoutPosition)!!) } - binding.ivEdit.onClick { + binding.ivEdit.setOnClickListener { callBack.editSubscription(getItem(holder.layoutPosition)!!) } - binding.ivMenuMore.onClick { + binding.ivMenuMore.setOnClickListener { showMenu(binding.ivMenuMore, holder.layoutPosition) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt index 6db32a25b..441a1853b 100644 --- a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt @@ -12,7 +12,7 @@ import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.ColorUtils import io.legado.app.utils.progressAdd -import org.jetbrains.anko.sdk27.coroutines.onClick + class DetailSeekBar @JvmOverloads constructor( context: Context, @@ -51,11 +51,11 @@ class DetailSeekBar @JvmOverloads constructor( binding.ivSeekReduce.setColorFilter(textColor) binding.tvSeekValue.setTextColor(textColor) } - binding.ivSeekPlus.onClick { + binding.ivSeekPlus.setOnClickListener { binding.seekBar.progressAdd(1) onChanged?.invoke(binding.seekBar.progress) } - binding.ivSeekReduce.onClick { + binding.ivSeekReduce.setOnClickListener { binding.seekBar.progressAdd(-1) onChanged?.invoke(binding.seekBar.progress) } diff --git a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt index 6d9f99e50..e0fef5da0 100644 --- a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt +++ b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt @@ -10,7 +10,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.databinding.PopupKeyboardToolBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class KeyboardToolPop( @@ -59,7 +59,7 @@ class KeyboardToolPop( override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) { holder.itemView.apply { - onClick { + setOnClickListener { getItem(holder.layoutPosition)?.let { callBack?.sendText(it) } diff --git a/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt b/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt index 006db6941..c95a8e493 100644 --- a/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt @@ -14,7 +14,7 @@ import io.legado.app.help.AppConfig import io.legado.app.lib.theme.* import io.legado.app.utils.ColorUtils import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick + @Suppress("unused") class SelectActionBar @JvmOverloads constructor( @@ -41,9 +41,9 @@ class SelectActionBar @JvmOverloads constructor( callBack?.selectAll(isChecked) } } - binding.btnRevertSelection.onClick { callBack?.revertSelection() } - binding.btnSelectActionMain.onClick { callBack?.onClickMainAction() } - binding.ivMenuMore.onClick { selMenu?.show() } + binding.btnRevertSelection.setOnClickListener { callBack?.revertSelection() } + binding.btnSelectActionMain.setOnClickListener { callBack?.onClickMainAction() } + binding.ivMenuMore.setOnClickListener { selMenu?.show() } } fun setMainActionText(text: String) = with(binding) { diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 51a04f97d..593ee4c4c 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -17,9 +17,6 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.utils.activity import io.legado.app.utils.navigationBarHeight import io.legado.app.utils.statusBarHeight -import org.jetbrains.anko.backgroundColor -import org.jetbrains.anko.bottomPadding -import org.jetbrains.anko.topPadding @Suppress("unused") class TitleBar @JvmOverloads constructor( @@ -144,14 +141,14 @@ class TitleBar @JvmOverloads constructor( if (!isInEditMode) { if (a.getBoolean(R.styleable.TitleBar_fitStatusBar, true)) { - topPadding = context.statusBarHeight + setPadding(paddingLeft, context.statusBarHeight, paddingRight, paddingBottom) } if (a.getBoolean(R.styleable.TitleBar_fitNavigationBar, false)) { - bottomPadding = context.navigationBarHeight + setPadding(paddingLeft, paddingTop, paddingRight, context.navigationBarHeight) } - backgroundColor = context.primaryColor + setBackgroundColor(context.primaryColor) stateListAnimator = null elevation = if (AppConfig.elevation < 0) { @@ -198,11 +195,12 @@ class TitleBar @JvmOverloads constructor( fun transparent() { elevation = 0f - backgroundColor = Color.TRANSPARENT + setBackgroundColor(Color.TRANSPARENT) } fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, fullScreen: Boolean) { - topPadding = if (!isInMultiWindowMode && fullScreen) context.statusBarHeight else 0 + val topPadding = if (!isInMultiWindowMode && fullScreen) context.statusBarHeight else 0 + setPadding(paddingLeft, topPadding, paddingRight, paddingBottom) } private fun attachToActivity() { diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt index 840e8faac..088401abb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt @@ -7,12 +7,7 @@ import android.view.ViewGroup import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.databinding.ItemFontBinding -import io.legado.app.utils.DocItem -import io.legado.app.utils.RealPathUtil -import io.legado.app.utils.invisible -import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick -import org.jetbrains.anko.toast +import io.legado.app.utils.* import java.io.File import java.net.URLDecoder @@ -47,10 +42,10 @@ class FontAdapter(context: Context, val callBack: CallBack) : tvFont.typeface = typeface }.onFailure { it.printStackTrace() - context.toast("Read ${item.name} Error: ${it.localizedMessage}") + context.toastOnUI("Read ${item.name} Error: ${it.localizedMessage}") } tvFont.text = item.name - root.onClick { callBack.onClick(item) } + root.setOnClickListener { callBack.onClick(item) } if (item.name == URLDecoder.decode(callBack.curFilePath, "utf-8") .substringAfterLast(File.separator) ) { @@ -62,7 +57,7 @@ class FontAdapter(context: Context, val callBack: CallBack) : } override fun registerListener(holder: ItemViewHolder, binding: ItemFontBinding) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { callBack.onClick(it) } diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 5ddecbe54..1eeda60a6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -157,7 +157,7 @@ class FontSelectDialog : BaseDialogFragment(), }.onSuccess { adapter?.setItems(it) }.onError { - toast("getFontFiles:${it.localizedMessage}") + toastOnUI("getFontFiles:${it.localizedMessage}") } } @@ -192,7 +192,7 @@ class FontSelectDialog : BaseDialogFragment(), }.onSuccess { adapter?.setItems(it) }.onError { - toast("getFontFiles:${it.localizedMessage}") + toastOnUI("getFontFiles:${it.localizedMessage}") } } diff --git a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt index 5d80f087e..b028dd116 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt @@ -881,7 +881,7 @@ class PhotoView @JvmOverloads constructor( ) } - fun getImageViewInfo(imgView: ImageView): Info? { + fun getImageViewInfo(imgView: ImageView): Info { val p = IntArray(2) getLocation(imgView, p) val drawable: Drawable = imgView.drawable diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt index df63e08f8..cc65046e7 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -23,7 +23,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.utils.getCompatDrawable import io.legado.app.utils.getSize import io.legado.app.utils.viewbindingdelegate.viewBinding -import org.jetbrains.anko.sdk27.coroutines.onClick + class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { @@ -186,7 +186,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference } } label.isChecked = item.toString() == dialogValue - root.onClick { + root.setOnClickListener { onChanged?.invoke(item.toString()) this@IconDialog.dismiss() } @@ -197,7 +197,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference holder: ItemViewHolder, binding: ItemIconPreferenceBinding ) { - holder.itemView.onClick { + holder.itemView.setOnClickListener { getItem(holder.layoutPosition)?.let { onChanged?.invoke(it.toString()) } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt index dfb0f2f8d..3de75300c 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt @@ -17,8 +17,6 @@ import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.utils.ColorUtils -import org.jetbrains.anko.layoutInflater -import org.jetbrains.anko.sdk27.coroutines.onLongClick import kotlin.math.roundToInt class Preference(context: Context, attrs: AttributeSet) : @@ -77,7 +75,7 @@ class Preference(context: Context, attrs: AttributeSet) : var needRequestLayout = false var v = it.itemView.findViewById(viewId) if (v == null) { - val inflater: LayoutInflater = context.layoutInflater + val inflater: LayoutInflater = LayoutInflater.from(context) val childView = inflater.inflate(weightLayoutRes, null) lay.removeAllViews() lay.addView(childView) @@ -117,8 +115,9 @@ class Preference(context: Context, attrs: AttributeSet) : isBottomBackground = isBottomBackground ) super.onBindViewHolder(holder) - holder?.itemView?.onLongClick(returnValue = true) { + holder?.itemView?.setOnLongClickListener { onLongClick?.invoke() + true } } diff --git a/app/src/main/java/io/legado/app/ui/widget/text/AccentTextView.kt b/app/src/main/java/io/legado/app/ui/widget/text/AccentTextView.kt index be3074766..8dee26350 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/AccentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/AccentTextView.kt @@ -5,17 +5,16 @@ import android.util.AttributeSet import androidx.appcompat.widget.AppCompatTextView import io.legado.app.R import io.legado.app.lib.theme.accentColor -import org.jetbrains.anko.textColor -import org.jetbrains.anko.textColorResource +import io.legado.app.utils.getCompatColor class AccentTextView(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) { init { if (!isInEditMode) { - textColor = context.accentColor + setTextColor(context.accentColor) } else { - textColorResource = R.color.accent + setTextColor(context.getCompatColor(R.color.accent)) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt b/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt index 8e367df76..fbf4ac26c 100644 --- a/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt @@ -15,7 +15,7 @@ import io.legado.app.R import io.legado.app.lib.theme.ATH import io.legado.app.utils.gone import io.legado.app.utils.visible -import org.jetbrains.anko.sdk27.coroutines.onClick + @Suppress("unused") class AutoCompleteTextView @JvmOverloads constructor( @@ -61,7 +61,7 @@ class AutoCompleteTextView @JvmOverloads constructor( textView.text = getItem(position) val ivDelete = view.findViewById(R.id.iv_delete) if (delCallBack != null) ivDelete.visible() else ivDelete.gone() - ivDelete.onClick { + ivDelete.setOnClickListener { getItem(position)?.let { remove(it) delCallBack?.invoke(it) diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index d9d0fbf94..49e57cd84 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -3,29 +3,65 @@ package io.legado.app.utils import android.annotation.SuppressLint +import android.app.DownloadManager import android.content.* import android.content.pm.PackageManager import android.content.res.ColorStateList import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.drawable.Drawable +import android.net.ConnectivityManager import android.net.Uri import android.os.BatteryManager import android.provider.Settings +import android.widget.Toast import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.core.content.ContextCompat import androidx.core.content.FileProvider import androidx.core.content.edit +import androidx.preference.PreferenceManager import io.legado.app.BuildConfig import io.legado.app.R -import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.longToast -import org.jetbrains.anko.toast +import org.jetbrains.anko.runOnUiThread import java.io.File import java.io.FileOutputStream +val Context.downloadManager + get() = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager + +val Context.connectivityManager + get() = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + +fun Context.toastOnUI(message: Int) { + runOnUiThread { + Toast.makeText(this, message, Toast.LENGTH_SHORT).show() + } +} + +fun Context.toastOnUI(message: CharSequence?) { + runOnUiThread { + Toast.makeText(this, message, Toast.LENGTH_SHORT).show() + } +} + +fun Context.longToastOnUI(message: Int) { + runOnUiThread { + Toast.makeText(this, message, Toast.LENGTH_LONG).show() + } +} + +fun Context.longToastOnUI(message: CharSequence?) { + runOnUiThread { + Toast.makeText(this, message, Toast.LENGTH_LONG).show() + } +} + +val Context.defaultSharedPreferences: SharedPreferences + get() = PreferenceManager.getDefaultSharedPreferences(this) + fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) @@ -103,7 +139,7 @@ val Context.navigationBarHeight: Int fun Context.shareWithQr(title: String, text: String) { val bitmap = QRCodeUtils.createQRCode(text) if (bitmap == null) { - toast(R.string.text_too_long_qr_error) + toastOnUI(R.string.text_too_long_qr_error) } else { try { val file = File(externalCacheDir, "qr.png") @@ -123,7 +159,7 @@ fun Context.shareWithQr(title: String, text: String) { intent.type = "image/png" startActivity(Intent.createChooser(intent, title)) } catch (e: Exception) { - toast(e.localizedMessage ?: "ERROR") + toastOnUI(e.localizedMessage ?: "ERROR") } } } @@ -155,7 +191,7 @@ fun Context.sendMail(mail: String) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) startActivity(intent) } catch (e: Exception) { - toast(e.localizedMessage ?: "Error") + toastOnUI(e.localizedMessage ?: "Error") } } @@ -195,13 +231,13 @@ fun Context.openUrl(uri: Uri) { try { startActivity(intent) } catch (e: Exception) { - toast(e.localizedMessage ?: "open url error") + toastOnUI(e.localizedMessage ?: "open url error") } } else { try { startActivity(Intent.createChooser(intent, "请选择浏览器")) } catch (e: Exception) { - toast(e.localizedMessage ?: "open url error") + toastOnUI(e.localizedMessage ?: "open url error") } } } diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index 15787e7fe..c74ba5a0d 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -11,7 +11,6 @@ import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.edit import androidx.fragment.app.Fragment -import org.jetbrains.anko.connectivityManager import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.internals.AnkoInternals diff --git a/app/src/main/java/io/legado/app/utils/Toasts.kt b/app/src/main/java/io/legado/app/utils/Toasts.kt index 9038c2231..5516fa3a2 100644 --- a/app/src/main/java/io/legado/app/utils/Toasts.kt +++ b/app/src/main/java/io/legado/app/utils/Toasts.kt @@ -5,7 +5,6 @@ package io.legado.app.utils import android.widget.Toast import androidx.fragment.app.Fragment import org.jetbrains.anko.longToast -import org.jetbrains.anko.toast /** @@ -13,14 +12,14 @@ import org.jetbrains.anko.toast * * @param message the message text resource. */ -fun Fragment.toast(message: Int) = requireActivity().toast(message) +fun Fragment.toastOnUI(message: Int) = requireActivity().toastOnUI(message) /** * Display the simple Toast message with the [Toast.LENGTH_SHORT] duration. * * @param message the message text. */ -fun Fragment.toast(message: CharSequence) = requireActivity().toast(message) +fun Fragment.toastOnUI(message: CharSequence) = requireActivity().toastOnUI(message) /** * Display the simple Toast message with the [Toast.LENGTH_LONG] duration.