From 436233e7351df04d0f93d78681dd1ae57307b63d Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 8 Aug 2022 11:49:48 +0300 Subject: [PATCH] Fix description text color --- .../kotatsu/details/ui/DetailsViewModel.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt b/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt index d77ef9aba..a8bade779 100644 --- a/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt +++ b/app/src/main/java/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt @@ -1,11 +1,16 @@ package org.koitharu.kotatsu.details.ui import android.text.Html +import android.text.SpannableString +import android.text.Spanned +import android.text.style.ForegroundColorSpan +import androidx.core.text.getSpans import androidx.core.text.parseAsHtml import androidx.lifecycle.LiveData import androidx.lifecycle.asFlow import androidx.lifecycle.asLiveData import androidx.lifecycle.viewModelScope +import java.io.IOException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.flow.* @@ -33,7 +38,6 @@ import org.koitharu.kotatsu.tracker.domain.TrackingRepository import org.koitharu.kotatsu.utils.SingleLiveEvent import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct import org.koitharu.kotatsu.utils.ext.printStackTraceDebug -import java.io.IOException class DetailsViewModel( intent: MangaIntent, @@ -91,8 +95,8 @@ class DetailsViewModel( if (description.isNullOrEmpty()) { emit(null) } else { - emit(description.parseAsHtml()) - emit(description.parseAsHtml(imageGetter = imageGetter)) + emit(description.parseAsHtml().filterSpans()) + emit(description.parseAsHtml(imageGetter = imageGetter).filterSpans()) } }.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default, null) @@ -110,7 +114,7 @@ class DetailsViewModel( val selectedBranchIndex = combine( branches.asFlow(), - delegate.selectedBranch + delegate.selectedBranch, ) { branches, selected -> branches.indexOf(selected) }.asLiveDataDistinct(viewModelScope.coroutineContext + Dispatchers.Default) @@ -225,7 +229,7 @@ class DetailsViewModel( fun unregisterScrobbling() { launchJob(Dispatchers.Default) { scrobbler.unregisterScrobbling( - mangaId = delegate.mangaId + mangaId = delegate.mangaId, ) } } @@ -242,4 +246,13 @@ class DetailsViewModel( it.chapter.name.contains(query, ignoreCase = true) } } + + private fun Spanned.filterSpans(): CharSequence { + val spannable = SpannableString.valueOf(this) + val spans = spannable.getSpans() + for (span in spans) { + spannable.removeSpan(span) + } + return spannable.trim() + } } \ No newline at end of file