From 22e023b58dab8d77864936f45ac1b45f5e971827 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 6 Apr 2023 00:53:06 -0700 Subject: [PATCH] Set notes on main thread --- .../com/topjohnwu/magisk/arch/ViewModelHolder.kt | 3 ++- .../magisk/ui/install/InstallViewModel.kt | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/arch/ViewModelHolder.kt b/app/src/main/java/com/topjohnwu/magisk/arch/ViewModelHolder.kt index 011ba79c1..1ada2e542 100644 --- a/app/src/main/java/com/topjohnwu/magisk/arch/ViewModelHolder.kt +++ b/app/src/main/java/com/topjohnwu/magisk/arch/ViewModelHolder.kt @@ -34,7 +34,8 @@ object VMFactory : ViewModelProvider.Factory { HomeViewModel::class.java -> HomeViewModel(ServiceLocator.networkService) LogViewModel::class.java -> LogViewModel(ServiceLocator.logRepo) SuperuserViewModel::class.java -> SuperuserViewModel(ServiceLocator.policyDB) - InstallViewModel::class.java -> InstallViewModel(ServiceLocator.networkService) + InstallViewModel::class.java -> + InstallViewModel(ServiceLocator.networkService, ServiceLocator.markwon) SuRequestViewModel::class.java -> SuRequestViewModel(ServiceLocator.policyDB, ServiceLocator.timeoutPrefs) else -> modelClass.newInstance() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt index 1151007a4..af355941d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt @@ -3,8 +3,8 @@ package com.topjohnwu.magisk.ui.install import android.net.Uri import android.os.Bundle import android.os.Parcelable -import android.text.SpannableStringBuilder import android.text.Spanned +import android.text.SpannedString import android.widget.Toast import androidx.databinding.Bindable import androidx.lifecycle.LiveData @@ -19,23 +19,22 @@ import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.base.ContentResultCallback import com.topjohnwu.magisk.core.di.AppContext -import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.ktx.toast import com.topjohnwu.magisk.core.repository.NetworkService import com.topjohnwu.magisk.databinding.set import com.topjohnwu.magisk.dialog.SecondSlotWarningDialog import com.topjohnwu.magisk.events.GetContentEvent import com.topjohnwu.magisk.ui.flash.FlashFragment +import io.noties.markwon.Markwon import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import kotlinx.parcelize.Parcelize import timber.log.Timber import java.io.File import java.io.IOException -class InstallViewModel( - svc: NetworkService -) : BaseViewModel() { +class InstallViewModel(svc: NetworkService, markwon: Markwon) : BaseViewModel() { val isRooted get() = Info.isRooted val hideVbmeta = Info.vbmeta || Info.isSamsung || Info.isAB @@ -65,7 +64,7 @@ class InstallViewModel( val data: LiveData get() = uri @get:Bindable - var notes: Spanned = SpannableStringBuilder() + var notes: Spanned = SpannedString("") set(value) = set(value, field, { field = it }, BR.notes) init { @@ -81,7 +80,10 @@ class InstallViewModel( str } } - notes = ServiceLocator.markwon.toMarkdown(text) + val spanned = markwon.toMarkdown(text) + withContext(Dispatchers.Main) { + notes = spanned + } } catch (e: IOException) { Timber.e(e) }