This commit is contained in:
kunfei
2023-02-20 12:47:30 +08:00
parent f6727a9c8b
commit 305c07cdec
28 changed files with 74 additions and 82 deletions
@@ -57,10 +57,10 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
} }
viewModel.loadStateLiveData.observe(this) { viewModel.loadStateLiveData.observe(this) {
if (it) { if (it) {
binding.rotateLoading.show() binding.rotateLoading.visible()
binding.bookInfo.invisible() binding.bookInfo.invisible()
} else { } else {
binding.rotateLoading.hide() binding.rotateLoading.gone()
} }
} }
viewModel.loadErrorLiveData.observe(this) { viewModel.loadErrorLiveData.observe(this) {
@@ -47,7 +47,7 @@ class FileAssociationActivity :
override val viewModel by viewModels<FileAssociationViewModel>() override val viewModel by viewModels<FileAssociationViewModel>()
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.rotateLoading.show() binding.rotateLoading.visible()
viewModel.importBookLiveData.observe(this) { uri -> viewModel.importBookLiveData.observe(this) { uri ->
importBook(uri) importBook(uri)
} }
@@ -80,19 +80,19 @@ class FileAssociationActivity :
} }
} }
viewModel.errorLive.observe(this) { viewModel.errorLive.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
toastOnUi(it) toastOnUi(it)
finish() finish()
} }
viewModel.openBookLiveData.observe(this) { viewModel.openBookLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
startActivity<ReadBookActivity> { startActivity<ReadBookActivity> {
putExtra("bookUrl", it) putExtra("bookUrl", it)
} }
finish() finish()
} }
viewModel.notSupportedLiveData.observe(this) { data -> viewModel.notSupportedLiveData.observe(this) { data ->
binding.rotateLoading.hide() binding.rotateLoading.gone()
alert( alert(
title = appCtx.getString(R.string.draw), title = appCtx.getString(R.string.draw),
message = appCtx.getString(R.string.file_not_supported, data.second) message = appCtx.getString(R.string.file_not_supported, data.second)
@@ -64,7 +64,7 @@ class ImportBookSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_vie
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.setTitle(R.string.import_book_source) binding.toolBar.setTitle(R.string.import_book_source)
binding.rotateLoading.show() binding.rotateLoading.visible()
initMenu() initMenu()
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
@@ -93,14 +93,14 @@ class ImportBookSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_vie
upSelectText() upSelectText()
} }
viewModel.errorLiveData.observe(this) { viewModel.errorLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
binding.tvMsg.apply { binding.tvMsg.apply {
text = it text = it
visible() visible()
} }
} }
viewModel.successLiveData.observe(this) { viewModel.successLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
if (it > 0) { if (it > 0) {
adapter.setItems(viewModel.allSources) adapter.setItems(viewModel.allSources)
upSelectText() upSelectText()
@@ -55,7 +55,7 @@ class ImportHttpTtsDialog() : BaseDialogFragment(R.layout.dialog_recycler_view),
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.setTitle(R.string.import_tts) binding.toolBar.setTitle(R.string.import_tts)
binding.rotateLoading.show() binding.rotateLoading.visible()
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
binding.tvCancel.visible() binding.tvCancel.visible()
@@ -83,14 +83,14 @@ class ImportHttpTtsDialog() : BaseDialogFragment(R.layout.dialog_recycler_view),
upSelectText() upSelectText()
} }
viewModel.errorLiveData.observe(this) { viewModel.errorLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
binding.tvMsg.apply { binding.tvMsg.apply {
text = it text = it
visible() visible()
} }
} }
viewModel.successLiveData.observe(this) { viewModel.successLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
if (it > 0) { if (it > 0) {
adapter.setItems(viewModel.allSources) adapter.setItems(viewModel.allSources)
upSelectText() upSelectText()
@@ -41,18 +41,18 @@ class ImportOnLineBookFileDialog : BaseDialogFragment(R.layout.dialog_recycler_v
viewModel.initData(bookUrl) viewModel.initData(bookUrl)
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.setTitle(R.string.download_and_import_file) binding.toolBar.setTitle(R.string.download_and_import_file)
binding.rotateLoading.show() binding.rotateLoading.visible()
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
viewModel.errorLiveData.observe(this) { viewModel.errorLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
binding.tvMsg.apply { binding.tvMsg.apply {
text = it text = it
visible() visible()
} }
} }
viewModel.successLiveData.observe(this) { viewModel.successLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
if (it > 0) { if (it > 0) {
adapter.setItems(viewModel.allBookFiles) adapter.setItems(viewModel.allBookFiles)
} }
@@ -59,7 +59,7 @@ class ImportReplaceRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vi
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.setTitle(R.string.import_replace_rule) binding.toolBar.setTitle(R.string.import_replace_rule)
binding.rotateLoading.show() binding.rotateLoading.visible()
initMenu() initMenu()
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
@@ -88,14 +88,14 @@ class ImportReplaceRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vi
upSelectText() upSelectText()
} }
viewModel.errorLiveData.observe(this) { viewModel.errorLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
binding.tvMsg.apply { binding.tvMsg.apply {
text = it text = it
visible() visible()
} }
} }
viewModel.successLiveData.observe(this) { viewModel.successLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
if (it > 0) { if (it > 0) {
adapter.setItems(viewModel.allRules) adapter.setItems(viewModel.allRules)
upSelectText() upSelectText()
@@ -63,7 +63,7 @@ class ImportRssSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_view
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.setTitle(R.string.import_rss_source) binding.toolBar.setTitle(R.string.import_rss_source)
binding.rotateLoading.show() binding.rotateLoading.visible()
initMenu() initMenu()
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
@@ -92,14 +92,14 @@ class ImportRssSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_view
upSelectText() upSelectText()
} }
viewModel.errorLiveData.observe(this) { viewModel.errorLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
binding.tvMsg.apply { binding.tvMsg.apply {
text = it text = it
visible() visible()
} }
} }
viewModel.successLiveData.observe(this) { viewModel.successLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
if (it > 0) { if (it > 0) {
adapter.setItems(viewModel.allSources) adapter.setItems(viewModel.allSources)
upSelectText() upSelectText()
@@ -54,7 +54,7 @@ class ImportThemeDialog() : BaseDialogFragment(R.layout.dialog_recycler_view) {
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.setTitle(R.string.import_theme) binding.toolBar.setTitle(R.string.import_theme)
binding.rotateLoading.show() binding.rotateLoading.visible()
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
binding.tvCancel.visible() binding.tvCancel.visible()
@@ -82,14 +82,14 @@ class ImportThemeDialog() : BaseDialogFragment(R.layout.dialog_recycler_view) {
upSelectText() upSelectText()
} }
viewModel.errorLiveData.observe(this) { viewModel.errorLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
binding.tvMsg.apply { binding.tvMsg.apply {
text = it text = it
visible() visible()
} }
} }
viewModel.successLiveData.observe(this) { viewModel.successLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
if (it > 0) { if (it > 0) {
adapter.setItems(viewModel.allSources) adapter.setItems(viewModel.allSources)
upSelectText() upSelectText()
@@ -54,7 +54,7 @@ class ImportTxtTocRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vie
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
binding.toolBar.setTitle(R.string.import_txt_toc_rule) binding.toolBar.setTitle(R.string.import_txt_toc_rule)
binding.rotateLoading.show() binding.rotateLoading.visible()
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
binding.tvCancel.visible() binding.tvCancel.visible()
@@ -82,14 +82,14 @@ class ImportTxtTocRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vie
upSelectText() upSelectText()
} }
viewModel.errorLiveData.observe(this) { viewModel.errorLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
binding.tvMsg.apply { binding.tvMsg.apply {
text = it text = it
visible() visible()
} }
} }
viewModel.successLiveData.observe(this) { viewModel.successLiveData.observe(this) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
if (it > 0) { if (it > 0) {
adapter.setItems(viewModel.allSources) adapter.setItems(viewModel.allSources)
upSelectText() upSelectText()
@@ -66,7 +66,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
ChangeChapterTocAdapter(requireContext(), this) ChangeChapterTocAdapter(requireContext(), this)
} }
private val contentSuccess: (content: String) -> Unit = { private val contentSuccess: (content: String) -> Unit = {
binding.loadingToc.hide() binding.loadingToc.gone()
callBack?.replaceContent(it) callBack?.replaceContent(it)
dismissAllowingStateLoss() dismissAllowingStateLoss()
} }
@@ -267,7 +267,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
this.searchBook = searchBook this.searchBook = searchBook
tocAdapter.setItems(null) tocAdapter.setItems(null)
binding.clToc.visible() binding.clToc.visible()
binding.loadingToc.show() binding.loadingToc.visible()
val book = searchBook.toBook() val book = searchBook.toBook()
viewModel.getToc(book, { viewModel.getToc(book, {
binding.clToc.gone() binding.clToc.gone()
@@ -275,7 +275,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
}) { toc: List<BookChapter>, _: BookSource -> }) { toc: List<BookChapter>, _: BookSource ->
tocAdapter.durChapterIndex = tocAdapter.durChapterIndex =
BookHelp.getDurChapter(viewModel.chapterIndex, viewModel.chapterTitle, toc) BookHelp.getDurChapter(viewModel.chapterIndex, viewModel.chapterTitle, toc)
binding.loadingToc.hide() binding.loadingToc.gone()
tocAdapter.setItems(toc) tocAdapter.setItems(toc)
binding.recyclerViewToc.scrollToPosition(tocAdapter.durChapterIndex - 5) binding.recyclerViewToc.scrollToPosition(tocAdapter.durChapterIndex - 5)
} }
@@ -321,9 +321,9 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
override fun clickChapter(bookChapter: BookChapter, nextChapterUrl: String?) { override fun clickChapter(bookChapter: BookChapter, nextChapterUrl: String?) {
searchBook?.let { searchBook?.let {
binding.loadingToc.show() binding.loadingToc.visible()
viewModel.getContent(it.toBook(), bookChapter, nextChapterUrl, contentSuccess) { msg -> viewModel.getContent(it.toBook(), bookChapter, nextChapterUrl, contentSuccess) { msg ->
binding.loadingToc.hide() binding.loadingToc.gone()
binding.clToc.gone() binding.clToc.gone()
toastOnUi(msg) toastOnUi(msg)
} }
@@ -58,9 +58,9 @@ class ContentEditDialog : BaseDialogFragment(R.layout.dialog_content_edit) {
} }
viewModel.loadStateLiveData.observe(viewLifecycleOwner) { viewModel.loadStateLiveData.observe(viewLifecycleOwner) {
if (it) { if (it) {
binding.rlLoading.show() binding.rlLoading.visible()
} else { } else {
binding.rlLoading.hide() binding.rlLoading.gone()
} }
} }
viewModel.initContent { viewModel.initContent {
@@ -50,7 +50,7 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
launch { launch {
adapter.addItem(msg) adapter.addItem(msg)
if (state == -1 || state == 1000) { if (state == -1 || state == 1000) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
} }
} }
} }
@@ -165,7 +165,7 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
private fun startSearch(key: String) { private fun startSearch(key: String) {
adapter.clearItems() adapter.clearItems()
viewModel.startDebug(key, { viewModel.startDebug(key, {
binding.rotateLoading.show() binding.rotateLoading.visible()
}, { }, {
toastOnUi("未获取到书源") toastOnUi("未获取到书源")
}) })
@@ -12,7 +12,6 @@ import io.legado.app.data.entities.DictRule
import io.legado.app.databinding.DialogDictBinding import io.legado.app.databinding.DialogDictBinding
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.utils.invisible
import io.legado.app.utils.setHtml import io.legado.app.utils.setHtml
import io.legado.app.utils.setLayout import io.legado.app.utils.setLayout
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
@@ -60,11 +59,12 @@ class DictDialog() : BaseDialogFragment(R.layout.dialog_dict) {
override fun onTabSelected(tab: TabLayout.Tab) { override fun onTabSelected(tab: TabLayout.Tab) {
val dictRule = tab.tag as DictRule val dictRule = tab.tag as DictRule
binding.rotateLoading.visible()
viewModel.dict(dictRule, word!!) viewModel.dict(dictRule, word!!)
} }
}) })
viewModel.dictHtmlData.observe(viewLifecycleOwner) { viewModel.dictHtmlData.observe(viewLifecycleOwner) {
binding.rotateLoading.invisible() binding.rotateLoading.inVisible()
binding.tvDict.setHtml(it) binding.tvDict.setHtml(it)
} }
viewModel.initData { viewModel.initData {
@@ -6,7 +6,6 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.DictRule import io.legado.app.data.entities.DictRule
import io.legado.app.help.DefaultData import io.legado.app.help.DefaultData
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import java.util.regex.Pattern
class DictViewModel(application: Application) : BaseViewModel(application) { class DictViewModel(application: Application) : BaseViewModel(application) {
var dictRules: List<DictRule>? = null var dictRules: List<DictRule>? = null
@@ -31,16 +30,5 @@ class DictViewModel(application: Application) : BaseViewModel(application) {
} }
} }
/**
* 判断是否包含汉字
* @param str
* @return
*/
private fun isChinese(str: String): Boolean {
val p = Pattern.compile("[\u4e00-\u9fa5]")
val m = p.matcher(str)
return m.find()
}
} }
@@ -43,9 +43,9 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) { private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) { if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
binding.bvUnread.invisible() binding.bvUnread.invisible()
binding.rlLoading.show() binding.rlLoading.visible()
} else { } else {
binding.rlLoading.hide() binding.rlLoading.inVisible()
if (AppConfig.showUnread) { if (AppConfig.showUnread) {
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum()) binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
binding.bvUnread.setHighlight(item.lastCheckCount > 0) binding.bvUnread.setHighlight(item.lastCheckCount > 0)
@@ -52,9 +52,9 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) :
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) { private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) { if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
binding.bvUnread.invisible() binding.bvUnread.invisible()
binding.rlLoading.show() binding.rlLoading.visible()
} else { } else {
binding.rlLoading.hide() binding.rlLoading.gone()
if (AppConfig.showUnread) { if (AppConfig.showUnread) {
binding.bvUnread.setHighlight(item.lastCheckCount > 0) binding.bvUnread.setHighlight(item.lastCheckCount > 0)
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum()) binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
@@ -113,9 +113,9 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) { private fun upRefresh(binding: ItemBookshelfGridBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) { if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
binding.bvUnread.invisible() binding.bvUnread.invisible()
binding.rlLoading.show() binding.rlLoading.visible()
} else { } else {
binding.rlLoading.hide() binding.rlLoading.inVisible()
if (AppConfig.showUnread) { if (AppConfig.showUnread) {
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum()) binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
binding.bvUnread.setHighlight(item.lastCheckCount > 0) binding.bvUnread.setHighlight(item.lastCheckCount > 0)
@@ -128,9 +128,9 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) { private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) { if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
binding.bvUnread.invisible() binding.bvUnread.invisible()
binding.rlLoading.show() binding.rlLoading.visible()
} else { } else {
binding.rlLoading.hide() binding.rlLoading.gone()
if (AppConfig.showUnread) { if (AppConfig.showUnread) {
binding.bvUnread.setHighlight(item.lastCheckCount > 0) binding.bvUnread.setHighlight(item.lastCheckCount > 0)
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum()) binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
@@ -53,7 +53,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
if (exIndex == holder.layoutPosition) { if (exIndex == holder.layoutPosition) {
ivStatus.setImageResource(R.drawable.ic_arrow_down) ivStatus.setImageResource(R.drawable.ic_arrow_down)
rotateLoading.loadingColor = context.accentColor rotateLoading.loadingColor = context.accentColor
rotateLoading.show() rotateLoading.visible()
if (scrollTo >= 0) { if (scrollTo >= 0) {
callBack.scrollTo(scrollTo) callBack.scrollTo(scrollTo)
} }
@@ -62,7 +62,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
}.onSuccess { kindList -> }.onSuccess { kindList ->
upKindList(flexbox, item.bookSourceUrl, kindList) upKindList(flexbox, item.bookSourceUrl, kindList)
}.onFinally { }.onFinally {
rotateLoading.hide() rotateLoading.gone()
if (scrollTo >= 0) { if (scrollTo >= 0) {
callBack.scrollTo(scrollTo) callBack.scrollTo(scrollTo)
scrollTo = -1 scrollTo = -1
@@ -70,7 +70,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
} }
} else kotlin.runCatching { } else kotlin.runCatching {
ivStatus.setImageResource(R.drawable.ic_arrow_right) ivStatus.setImageResource(R.drawable.ic_arrow_right)
rotateLoading.hide() rotateLoading.gone()
recyclerFlexbox(flexbox) recyclerFlexbox(flexbox)
flexbox.gone() flexbox.gone()
} }
@@ -33,7 +33,7 @@ class RssSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, RssSou
launch { launch {
adapter.addItem(msg) adapter.addItem(msg)
if (state == -1 || state == 1000) { if (state == -1 || state == 1000) {
binding.rotateLoading.hide() binding.rotateLoading.gone()
} }
} }
} }
@@ -68,7 +68,7 @@ class RssSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, RssSou
private fun startDebug() { private fun startDebug() {
adapter.clearItems() adapter.clearItems()
viewModel.rssSource?.let { viewModel.rssSource?.let {
binding.rotateLoading.show() binding.rotateLoading.visible()
viewModel.startDebug(it) viewModel.startDebug(it)
} ?: toastOnUi(R.string.error_no_source) } ?: toastOnUi(R.string.error_no_source)
} }
@@ -39,7 +39,7 @@ class RotateLoading @JvmOverloads constructor(
private var shadowPosition: Int = 0 private var shadowPosition: Int = 0
var hideMode = GONE private var hideMode = GONE
var isStarted = false var isStarted = false
private set private set
@@ -78,10 +78,6 @@ class RotateLoading @JvmOverloads constructor(
) )
speedOfDegree = speedOfDegree =
typedArray.getInt(R.styleable.RotateLoading_loading_speed, DEFAULT_SPEED_OF_DEGREE) typedArray.getInt(R.styleable.RotateLoading_loading_speed, DEFAULT_SPEED_OF_DEGREE)
hideMode = when (typedArray.getInt(R.styleable.RotateLoading_hide_mode, 2)) {
1 -> INVISIBLE
else -> GONE
}
typedArray.recycle() typedArray.recycle()
} }
speedOfArc = (speedOfDegree / 4).toFloat() speedOfArc = (speedOfDegree / 4).toFloat()
@@ -174,13 +170,21 @@ class RotateLoading @JvmOverloads constructor(
removeCallbacks(hidden) removeCallbacks(hidden)
} }
fun show() { fun visible() {
removeCallbacks(shown) removeCallbacks(shown)
removeCallbacks(hidden) removeCallbacks(hidden)
post(shown) post(shown)
} }
fun hide() { fun inVisible() {
hideMode = INVISIBLE
removeCallbacks(shown)
removeCallbacks(hidden)
stopInternal()
}
fun gone() {
hideMode = GONE
removeCallbacks(shown) removeCallbacks(shown)
removeCallbacks(hidden) removeCallbacks(hidden)
stopInternal() stopInternal()
@@ -44,12 +44,12 @@ class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(
fun startLoad() { fun startLoad() {
isLoading = true isLoading = true
binding.tvText.invisible() binding.tvText.invisible()
binding.rotateLoading.show() binding.rotateLoading.visible()
} }
fun stopLoad() { fun stopLoad() {
isLoading = false isLoading = false
binding.rotateLoading.hide() binding.rotateLoading.inVisible()
} }
fun hasMore() { fun hasMore() {
@@ -11,6 +11,7 @@ import java.io.File
import java.lang.Character.codePointCount import java.lang.Character.codePointCount
import java.lang.Character.offsetByCodePoints import java.lang.Character.offsetByCodePoints
import java.util.* import java.util.*
import java.util.regex.Pattern
fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim()
@@ -99,6 +100,15 @@ fun String?.memorySize(): Int {
return 40 + 2 * length return 40 + 2 * length
} }
/**
* 是否中文
*/
fun String.isChinese(): Boolean {
val p = Pattern.compile("[\u4e00-\u9fa5]")
val m = p.matcher(this)
return m.find()
}
/** /**
* 将字符串拆分为单个字符,包含emoji * 将字符串拆分为单个字符,包含emoji
*/ */
@@ -52,7 +52,6 @@
android:layout_height="22dp" android:layout_height="22dp"
android:layout_gravity="right" android:layout_gravity="right"
android:visibility="invisible" android:visibility="invisible"
app:hide_mode="invisible"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:loading_width="2dp" app:loading_width="2dp"
@@ -51,7 +51,6 @@
android:layout_height="22dp" android:layout_height="22dp"
android:layout_gravity="right" android:layout_gravity="right"
android:visibility="invisible" android:visibility="invisible"
app:hide_mode="invisible"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:loading_width="2dp" app:loading_width="2dp"
@@ -36,7 +36,6 @@
android:visibility="gone" android:visibility="gone"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginRight="4dp" android:layout_marginRight="4dp"
app:hide_mode="gone"
app:loading_width="1dp" app:loading_width="1dp"
tools:ignore="RtlHardcoded" /> tools:ignore="RtlHardcoded" />
@@ -12,7 +12,6 @@
android:layout_margin="6dp" android:layout_margin="6dp"
android:layout_gravity="center" android:layout_gravity="center"
android:visibility="invisible" android:visibility="invisible"
app:hide_mode="invisible"
app:loading_width="2dp" /> app:loading_width="2dp" />
<TextView <TextView
-6
View File
@@ -128,12 +128,6 @@
<attr name="loading_color" format="color" /> <attr name="loading_color" format="color" />
<attr name="shadow_position" format="integer" /> <attr name="shadow_position" format="integer" />
<attr name="loading_speed" format="integer" /> <attr name="loading_speed" format="integer" />
<attr name="hide_mode">
<!-- Not displayed, but taken into account during layout (space is left for it). -->
<enum name="invisible" value="1" />
<!-- Completely hidden, as if the view had not been added. -->
<enum name="gone" value="2" />
</attr>
</declare-styleable> </declare-styleable>
<declare-styleable name="CircleImageView"> <declare-styleable name="CircleImageView">