Minor code refactoring

This commit is contained in:
topjohnwu 2022-01-23 01:08:09 -08:00
parent e0410b6f10
commit c59a41a607
2 changed files with 13 additions and 18 deletions

View File

@ -1,15 +1,12 @@
package com.topjohnwu.magisk.di
import android.content.Context
import android.text.method.LinkMovementMethod
import com.squareup.moshi.Moshi
import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.ProviderInstaller
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.utils.currentLocale
import io.noties.markwon.Markwon
import io.noties.markwon.utils.NoCopySpannableFactory
import okhttp3.Cache
import okhttp3.ConnectionSpec
import okhttp3.Dns
@ -100,18 +97,3 @@ inline fun <reified T> createApiService(retrofitBuilder: Retrofit.Builder, baseU
.build()
.create(T::class.java)
}
fun createMarkwon(context: Context): Markwon {
return Markwon.builder(context)
.textSetter { textView, spanned, bufferType, onComplete ->
textView.apply {
post {
movementMethod = LinkMovementMethod.getInstance()
setSpannableFactory(NoCopySpannableFactory.getInstance())
setText(spanned, bufferType)
onComplete.run()
}
}
}
.build()
}

View File

@ -2,6 +2,7 @@ package com.topjohnwu.magisk.di
import android.annotation.SuppressLint
import android.content.Context
import android.text.method.LinkMovementMethod
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelStoreOwner
@ -19,6 +20,8 @@ import com.topjohnwu.magisk.ui.install.InstallViewModel
import com.topjohnwu.magisk.ui.log.LogViewModel
import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
import com.topjohnwu.magisk.ui.surequest.SuRequestViewModel
import io.noties.markwon.Markwon
import io.noties.markwon.utils.NoCopySpannableFactory
val AppContext: Context inline get() = ServiceLocator.context
@ -73,3 +76,13 @@ private fun createSuLogDatabase(context: Context) =
Room.databaseBuilder(context, SuLogDatabase::class.java, "sulogs.db")
.fallbackToDestructiveMigration()
.build()
private fun createMarkwon(context: Context) =
Markwon.builder(context).textSetter { textView, spanned, bufferType, onComplete ->
textView.apply {
movementMethod = LinkMovementMethod.getInstance()
setSpannableFactory(NoCopySpannableFactory.getInstance())
setText(spanned, bufferType)
onComplete.run()
}
}.build()