Improvements to the online check
This commit is contained in:
@@ -54,9 +54,9 @@ object MediaSaverToDisk {
|
|||||||
localContext: Context,
|
localContext: Context,
|
||||||
onSuccess: () -> Any?,
|
onSuccess: () -> Any?,
|
||||||
onError: (Throwable) -> Any?,
|
onError: (Throwable) -> Any?,
|
||||||
) {
|
) = withContext(Dispatchers.IO) {
|
||||||
when {
|
when {
|
||||||
videoUri.isNullOrBlank() -> return
|
videoUri.isNullOrBlank() -> return@withContext
|
||||||
videoUri.startsWith("file") ->
|
videoUri.startsWith("file") ->
|
||||||
save(
|
save(
|
||||||
localFile = videoUri.toUri().toFile(),
|
localFile = videoUri.toUri().toFile(),
|
||||||
|
|||||||
+3
-9
@@ -1158,16 +1158,10 @@ class AccountViewModel(
|
|||||||
.sortedBy { account.isFollowing(it) }
|
.sortedBy { account.isFollowing(it) }
|
||||||
.reversed()
|
.reversed()
|
||||||
|
|
||||||
fun checkVideoIsOnline(
|
suspend fun checkVideoIsOnline(videoUrl: String): Boolean =
|
||||||
videoUrl: String,
|
withContext(Dispatchers.IO) {
|
||||||
onDone: (Boolean) -> Unit,
|
OnlineChecker.isOnline(videoUrl, ::okHttpClientForVideo)
|
||||||
) {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
onDone(
|
|
||||||
OnlineChecker.isOnline(videoUrl, ::okHttpClientForVideo),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun loadAndMarkAsRead(
|
fun loadAndMarkAsRead(
|
||||||
routeForLastRead: String,
|
routeForLastRead: String,
|
||||||
|
|||||||
+17
-22
@@ -45,6 +45,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.produceState
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
@@ -57,6 +58,7 @@ import com.vitorpamplona.amethyst.Amethyst
|
|||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.AROUND_ME
|
import com.vitorpamplona.amethyst.model.AROUND_ME
|
||||||
import com.vitorpamplona.amethyst.service.OnlineChecker
|
import com.vitorpamplona.amethyst.service.OnlineChecker
|
||||||
|
import com.vitorpamplona.amethyst.service.OnlineChecker.isOnline
|
||||||
import com.vitorpamplona.amethyst.service.location.LocationState
|
import com.vitorpamplona.amethyst.service.location.LocationState
|
||||||
import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled
|
import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled
|
||||||
import com.vitorpamplona.amethyst.ui.feeds.ChannelFeedContentState
|
import com.vitorpamplona.amethyst.ui.feeds.ChannelFeedContentState
|
||||||
@@ -90,6 +92,7 @@ import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonRow
|
|||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.collections.forEachIndexed
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun HomeScreen(
|
fun HomeScreen(
|
||||||
@@ -375,17 +378,13 @@ fun CheckIfVideoIsOnline(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
whenOnline: @Composable (Boolean) -> Unit,
|
whenOnline: @Composable (Boolean) -> Unit,
|
||||||
) {
|
) {
|
||||||
var online by remember {
|
val online by produceState(
|
||||||
mutableStateOf(
|
initialValue = OnlineChecker.isOnlineCached(url),
|
||||||
OnlineChecker.isOnlineCached(url),
|
key1 = url,
|
||||||
)
|
) {
|
||||||
}
|
val isOnline = accountViewModel.checkVideoIsOnline(url)
|
||||||
|
if (value != isOnline) {
|
||||||
LaunchedEffect(key1 = url) {
|
value = isOnline
|
||||||
accountViewModel.checkVideoIsOnline(url) { isOnline ->
|
|
||||||
if (online != isOnline) {
|
|
||||||
online = isOnline
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,17 +397,13 @@ fun CrossfadeCheckIfVideoIsOnline(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
whenOnline: @Composable () -> Unit,
|
whenOnline: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
var online by remember {
|
val online by produceState(
|
||||||
mutableStateOf(
|
initialValue = OnlineChecker.isOnlineCached(url),
|
||||||
OnlineChecker.isOnlineCached(url),
|
key1 = url,
|
||||||
)
|
) {
|
||||||
}
|
val isOnline = accountViewModel.checkVideoIsOnline(url)
|
||||||
|
if (value != isOnline) {
|
||||||
LaunchedEffect(key1 = url) {
|
value = isOnline
|
||||||
accountViewModel.checkVideoIsOnline(url) { isOnline ->
|
|
||||||
if (online != isOnline) {
|
|
||||||
online = isOnline
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user