Bump version
This commit is contained in:
parent
d76f30f13e
commit
10dcc2b72b
3 changed files with 17 additions and 7 deletions
|
@ -38,6 +38,11 @@ class TextActivity : ThematicActivity(R.layout.activity_text) {
|
|||
}
|
||||
|
||||
textViewModel.observeState().collect {
|
||||
if (it.body == null) {
|
||||
// The target resource doesn't exist.
|
||||
finish()
|
||||
}
|
||||
|
||||
textView.text = it.body
|
||||
progressBar.visibility = View.GONE
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@ package dev.lucasnlm.antimine.text.models
|
|||
|
||||
data class TextState(
|
||||
val title: String,
|
||||
val body: String,
|
||||
val body: String?,
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.lucasnlm.antimine.text.viewmodel
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import androidx.annotation.RawRes
|
||||
import dev.lucasnlm.antimine.core.viewmodel.IntentViewModel
|
||||
import dev.lucasnlm.antimine.text.models.TextState
|
||||
|
@ -12,12 +13,16 @@ class TextViewModel(
|
|||
private val context: Context,
|
||||
) : IntentViewModel<TextEvent, TextState>() {
|
||||
|
||||
private suspend fun loadText(@RawRes rawFile: Int): String {
|
||||
return withContext(Dispatchers.IO) {
|
||||
context.resources.openRawResource(rawFile)
|
||||
.bufferedReader()
|
||||
.readLines()
|
||||
.joinToString("\n")
|
||||
private suspend fun loadText(@RawRes rawFile: Int): String? {
|
||||
return try {
|
||||
withContext(Dispatchers.IO) {
|
||||
context.resources.openRawResource(rawFile)
|
||||
.bufferedReader()
|
||||
.readLines()
|
||||
.joinToString("\n")
|
||||
}
|
||||
} catch (e: Resources.NotFoundException) {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue