|  |  |  | 
|---|
|  |  |  | private lateinit var toolbar: androidx.appcompat.widget.Toolbar | 
|---|
|  |  |  |  | 
|---|
|  |  |  | companion object { | 
|---|
|  |  |  | const val EXTRA_CONTENT_TYPE = "content_type" | 
|---|
|  |  |  | const val ID = "id" | 
|---|
|  |  |  | const val EXTRA_TITLE = "title" | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | toolbar.setNavigationOnClickListener { finish() } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 获取内容类型 | 
|---|
|  |  |  | val contentType = intent.getStringExtra(EXTRA_CONTENT_TYPE) | 
|---|
|  |  |  | if (contentType != null) { | 
|---|
|  |  |  | loadContent(contentType) | 
|---|
|  |  |  | val id = intent.getStringExtra(ID) | 
|---|
|  |  |  | if (id != null) { | 
|---|
|  |  |  | loadContent(id) | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Toast.makeText(this, "参数错误", Toast.LENGTH_SHORT).show() | 
|---|
|  |  |  | finish() | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private fun loadContent(type: String) { | 
|---|
|  |  |  | private fun loadContent(id: String) { | 
|---|
|  |  |  | lifecycleScope.launch { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | val response = RetrofitClient.apiService.getContentByType(type) | 
|---|
|  |  |  | if (response.code == 200 && response.data != null) { | 
|---|
|  |  |  | val response = RetrofitClient.apiService.getContentById(id) | 
|---|
|  |  |  | if (response.code == "0" && response.data != null) { | 
|---|
|  |  |  | // 构建HTML内容 | 
|---|
|  |  |  | val htmlContent = """ | 
|---|
|  |  |  | <!DOCTYPE html> | 
|---|