[optimize] Optimize HomeScreen
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.acitelight.aether.service
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import com.acitelight.aether.model.Video
|
||||
import com.acitelight.aether.model.VideoQueryIndex
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -50,11 +51,15 @@ object RecentManager
|
||||
try{
|
||||
val r = Json.decodeFromString<List<VideoQueryIndex>>(content)
|
||||
|
||||
val vn = r.map{
|
||||
MediaManager.queryVideo(it.klass, it.id)
|
||||
}.filter { it != null }
|
||||
recent.clear()
|
||||
|
||||
for(it in r)
|
||||
{
|
||||
val v = MediaManager.queryVideo(it.klass, it.id)
|
||||
if(v != null)
|
||||
recent.add(recent.size, v)
|
||||
}
|
||||
|
||||
_recent.value = vn.map { it!! }
|
||||
return r
|
||||
}catch (e: Exception)
|
||||
{
|
||||
@@ -74,6 +79,7 @@ object RecentManager
|
||||
{
|
||||
val temp = o[0]
|
||||
val index = o.indexOf(video)
|
||||
recent.removeAt(index)
|
||||
o[0] = o[index]
|
||||
o[index] = temp
|
||||
}
|
||||
@@ -85,15 +91,10 @@ object RecentManager
|
||||
if(o.size >= 21)
|
||||
o.removeAt(o.size - 1)
|
||||
|
||||
val vn = o.map{
|
||||
MediaManager.queryVideo(it.klass, it.id)
|
||||
}.filter { it != null }
|
||||
_recent.value = vn.map { it!! }
|
||||
|
||||
recent.add(0, MediaManager.queryVideo(video.klass, video.id)!!)
|
||||
writeFile(context, "recent.json", Json.encodeToString(o))
|
||||
}
|
||||
}
|
||||
|
||||
private val _recent = MutableStateFlow<List<Video>>(emptyList())
|
||||
val recent: StateFlow<List<Video>> = _recent
|
||||
val recent = mutableStateListOf<Video>()
|
||||
}
|
||||
@@ -34,7 +34,6 @@ fun HomeScreen(homeScreenViewModel: HomeScreenViewModel = viewModel(), navContro
|
||||
{
|
||||
if(Global.loggedIn)
|
||||
homeScreenViewModel.Init()
|
||||
val recent by RecentManager.recent.collectAsState()
|
||||
|
||||
LazyColumn(modifier = Modifier.fillMaxWidth())
|
||||
{
|
||||
@@ -49,14 +48,14 @@ fun HomeScreen(homeScreenViewModel: HomeScreenViewModel = viewModel(), navContro
|
||||
|
||||
HorizontalDivider(Modifier.padding(8.dp), 2.dp, DividerDefaults.color)
|
||||
|
||||
for(i in recent)
|
||||
for(i in RecentManager.recent)
|
||||
{
|
||||
MiniVideoCard(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 12.dp),
|
||||
i,
|
||||
{
|
||||
Global.sameClassVideos = recent
|
||||
Global.sameClassVideos = RecentManager.recent
|
||||
val route = "video_player_route/${ "${i.klass}/${i.id}".toHex() }"
|
||||
navController.navigate(route)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user