Skip to content

Commit

Permalink
Post Screen: don't change currently shown file after returning
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroBrine1st committed Jan 6, 2025
1 parent d120cf0 commit ac5de6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/ru/herobrine1st/e621/api/model/File.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ data class NormalizedFile(
this(name, file.width, file.height, file.normalizedType, 0, file.urls.filterNotNull())

val aspectRatio get() = width.toFloat() / height.toFloat()

companion object {
val STUB = NormalizedFile(
"stub",
0,
0,
FileType.UNDEFINED,
0,
emptyList()
)
}
}

fun NormalizedFile.isOriginal() = name == "original"
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import okhttp3.OkHttpClient
import ru.herobrine1st.e621.BuildConfig
import ru.herobrine1st.e621.api.API
import ru.herobrine1st.e621.api.common.VoteResult
import ru.herobrine1st.e621.api.model.FileType
import ru.herobrine1st.e621.api.model.NormalizedFile
import ru.herobrine1st.e621.api.model.Pool
import ru.herobrine1st.e621.api.model.Post
Expand Down Expand Up @@ -111,16 +110,7 @@ class PostComponent(
// private var rememberedPositionMs = -1L
private val state = MutableValue<PostState>(PostState.Loading)

var currentFile by mutableStateOf(
NormalizedFile(
"stub",
0,
0,
FileType.UNDEFINED,
0,
emptyList()
)
)
var currentFile by mutableStateOf(NormalizedFile.STUB)
private set


Expand Down Expand Up @@ -173,7 +163,7 @@ class PostComponent(
state.value = stateKeeper.consume(POST_STATE_KEY, strategy = PostState.serializer())
?: initialPost?.let { PostState.Ready(it) } ?: PostState.Loading

if (state.value is PostState.Ready) useSample()
if (state.value is PostState.Ready) useSampleAsDefault()

lifecycle.doOnResume {
// TODO behavior preference
Expand All @@ -186,7 +176,7 @@ class PostComponent(
|| !dataStore.data.map { it.dataSaverModeEnabled }.first()
)
refreshPostInternal()
useSample()
useSampleAsDefault()
}

}
Expand Down Expand Up @@ -215,9 +205,10 @@ class PostComponent(
}
}

private fun useSample() {
private fun useSampleAsDefault() {
val state = state.value
assert(state is PostState.Ready) { "setMediaItem should be called only after post loading" }
if (currentFile !== NormalizedFile.STUB) return
state as PostState.Ready
setFile(state.post.selectSample())
}
Expand Down

0 comments on commit ac5de6d

Please sign in to comment.