mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-03 11:02:31 +00:00
Update dependencies
This commit is contained in:
@@ -9,6 +9,10 @@ import com.topjohnwu.magisk.data.network.GithubApiServices
|
||||
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||
import com.topjohnwu.magisk.net.Networking
|
||||
import com.topjohnwu.magisk.net.NoSSLv3SocketFactory
|
||||
import io.noties.markwon.Markwon
|
||||
import io.noties.markwon.html.HtmlPlugin
|
||||
import io.noties.markwon.image.ImagesPlugin
|
||||
import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import org.koin.dsl.module
|
||||
@@ -23,6 +27,7 @@ val networkingModule = module {
|
||||
single { createRetrofit(get()) }
|
||||
single { createApiService<GithubRawServices>(get(), Const.Url.GITHUB_RAW_URL) }
|
||||
single { createApiService<GithubApiServices>(get(), Const.Url.GITHUB_API_URL) }
|
||||
single { createMarkwon(get(), get()) }
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@@ -66,4 +71,13 @@ inline fun <reified T> createApiService(retrofitBuilder: Retrofit.Builder, baseU
|
||||
.baseUrl(baseUrl)
|
||||
.build()
|
||||
.create(T::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
fun createMarkwon(context: Context, okHttpClient: OkHttpClient): Markwon {
|
||||
return Markwon.builder(context)
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(ImagesPlugin.create {
|
||||
it.addSchemeHandler(OkHttpNetworkSchemeHandler.create(okHttpClient))
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -6,21 +6,20 @@ import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.data.repository.StringRepository
|
||||
import com.topjohnwu.magisk.extensions.inject
|
||||
import com.topjohnwu.magisk.extensions.subscribeK
|
||||
import io.noties.markwon.Markwon
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
import ru.noties.markwon.Markwon
|
||||
import ru.noties.markwon.html.HtmlPlugin
|
||||
import ru.noties.markwon.image.ImagesPlugin
|
||||
import ru.noties.markwon.image.svg.SvgPlugin
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
import timber.log.Timber
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
object MarkDownWindow {
|
||||
object MarkDownWindow : KoinComponent {
|
||||
|
||||
private val stringRepo: StringRepository by inject()
|
||||
private val markwon: Markwon by inject()
|
||||
|
||||
fun show(activity: Context, title: String?, url: String) {
|
||||
show(activity, title, stringRepo.getString(url))
|
||||
@@ -35,25 +34,14 @@ object MarkDownWindow {
|
||||
}
|
||||
|
||||
fun show(activity: Context, title: String?, content: Single<String>) {
|
||||
val markwon = Markwon.builder(activity)
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(ImagesPlugin.create(activity))
|
||||
.usePlugin(SvgPlugin.create(activity.resources))
|
||||
.build()
|
||||
val mv = LayoutInflater.from(activity).inflate(R.layout.markdown_window, null)
|
||||
val tv = mv.findViewById<TextView>(R.id.md_txt)
|
||||
|
||||
content.map {
|
||||
runCatching {
|
||||
markwon.setMarkdown(tv, it)
|
||||
}.onFailure {
|
||||
Timber.e(it)
|
||||
// Always wrap the actual exception as it could be ExceptionInInitializerError,
|
||||
// which is a fatal error and RxJava will send it to the global handler and crash
|
||||
throw MarkwonException(it)
|
||||
}
|
||||
markwon.setMarkdown(tv, it)
|
||||
}.ignoreElement().onErrorResumeNext {
|
||||
// Nothing we can actually do other than show error message
|
||||
Timber.e(it)
|
||||
tv.setText(R.string.download_file_error)
|
||||
Completable.complete()
|
||||
}.subscribeK {
|
||||
@@ -64,6 +52,4 @@ object MarkDownWindow {
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
class MarkwonException(e: Throwable): Exception(e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user