Fixed lint warning and bug in codecs screen
This commit is contained in:
@ -30,11 +30,9 @@ import androidx.compose.material3.TopAppBar
|
|||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.runtime.snapshots.SnapshotStateList
|
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
@ -97,7 +95,28 @@ private fun CodecsScreen(
|
|||||||
) {
|
) {
|
||||||
val ua = UserAgent.ofAor(aor)!!
|
val ua = UserAgent.ofAor(aor)!!
|
||||||
val acc = ua.account
|
val acc = ua.account
|
||||||
var currentCodecsState by remember { mutableStateOf<List<Codec>>(emptyList()) }
|
val codecs = remember { mutableStateListOf<Codec>() }
|
||||||
|
|
||||||
|
LaunchedEffect(acc, media) {
|
||||||
|
val allCodecs: List<String> = if (media == "audio") {
|
||||||
|
Api.audio_codecs().split(",")
|
||||||
|
} else {
|
||||||
|
Api.video_codecs().split(",").distinct()
|
||||||
|
}
|
||||||
|
val accCodecs: List<String> = if (media == "audio") {
|
||||||
|
acc.audioCodec
|
||||||
|
} else {
|
||||||
|
acc.videoCodec
|
||||||
|
}
|
||||||
|
val currentCodecs = mutableListOf<Codec>()
|
||||||
|
for (codec in accCodecs)
|
||||||
|
currentCodecs.add(Codec(codec, mutableStateOf(true)))
|
||||||
|
for (codec in allCodecs)
|
||||||
|
if (codec !in accCodecs)
|
||||||
|
currentCodecs.add(Codec(codec, mutableStateOf(false)))
|
||||||
|
codecs.clear()
|
||||||
|
codecs.addAll(currentCodecs)
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.fillMaxSize().imePadding(),
|
modifier = Modifier.fillMaxSize().imePadding(),
|
||||||
@ -138,7 +157,7 @@ private fun CodecsScreen(
|
|||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(onClick = {
|
IconButton(onClick = {
|
||||||
checkOnClick(currentCodecsState)
|
checkOnClick(codecs)
|
||||||
}) {
|
}) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Filled.Check,
|
imageVector = Icons.Filled.Check,
|
||||||
@ -152,9 +171,7 @@ private fun CodecsScreen(
|
|||||||
content = { contentPadding ->
|
content = { contentPadding ->
|
||||||
CodecsContent(
|
CodecsContent(
|
||||||
contentPadding,
|
contentPadding,
|
||||||
acc,
|
codecs
|
||||||
media,
|
|
||||||
onUpdateCodecs = { updatedCodecs -> currentCodecsState = updatedCodecs }
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -163,33 +180,8 @@ private fun CodecsScreen(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun CodecsContent(
|
private fun CodecsContent(
|
||||||
contentPadding: PaddingValues,
|
contentPadding: PaddingValues,
|
||||||
acc: Account,
|
codecs: SnapshotStateList<Codec>
|
||||||
media: String,
|
|
||||||
onUpdateCodecs: (List<Codec>) -> Unit
|
|
||||||
) {
|
) {
|
||||||
val codecs = remember { mutableStateListOf<Codec>() }
|
|
||||||
|
|
||||||
LaunchedEffect(acc, media) {
|
|
||||||
val allCodecs: List<String> = if (media == "audio") {
|
|
||||||
Api.audio_codecs().split(",")
|
|
||||||
} else {
|
|
||||||
Api.video_codecs().split(",").distinct()
|
|
||||||
}
|
|
||||||
val accCodecs: List<String> = if (media == "audio") {
|
|
||||||
acc.audioCodec
|
|
||||||
} else {
|
|
||||||
acc.videoCodec
|
|
||||||
}
|
|
||||||
val currentCodecs = mutableListOf<Codec>()
|
|
||||||
for (codec in accCodecs)
|
|
||||||
currentCodecs.add(Codec(codec, mutableStateOf(true)))
|
|
||||||
for (codec in allCodecs)
|
|
||||||
if (codec !in accCodecs)
|
|
||||||
currentCodecs.add(Codec(codec, mutableStateOf(false)))
|
|
||||||
codecs.clear()
|
|
||||||
codecs.addAll(currentCodecs)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@ -197,21 +189,17 @@ private fun CodecsContent(
|
|||||||
.padding(contentPadding)
|
.padding(contentPadding)
|
||||||
.padding(bottom = 16.dp),
|
.padding(bottom = 16.dp),
|
||||||
) {
|
) {
|
||||||
Codecs(
|
Codecs(codecs = codecs)
|
||||||
codecs = codecs,
|
|
||||||
onUpdateCodecs = onUpdateCodecs
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
private fun Codecs(codecs: SnapshotStateList<Codec>, onUpdateCodecs: (List<Codec>) -> Unit) {
|
private fun Codecs(codecs: SnapshotStateList<Codec>) {
|
||||||
|
|
||||||
val draggableState = rememberDraggableListState(
|
val draggableState = rememberDraggableListState(
|
||||||
onMove = { fromIndex, toIndex ->
|
onMove = { fromIndex, toIndex ->
|
||||||
codecs.add(toIndex, codecs.removeAt(fromIndex))
|
codecs.add(toIndex, codecs.removeAt(fromIndex))
|
||||||
onUpdateCodecs(codecs.toList())
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -221,7 +209,6 @@ private fun Codecs(codecs: SnapshotStateList<Codec>, onUpdateCodecs: (List<Codec
|
|||||||
.verticalScrollbar(state = draggableState.listState),
|
.verticalScrollbar(state = draggableState.listState),
|
||||||
state = draggableState.listState,
|
state = draggableState.listState,
|
||||||
contentPadding = PaddingValues(start = 12.dp, end = 12.dp),
|
contentPadding = PaddingValues(start = 12.dp, end = 12.dp),
|
||||||
//verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
) {
|
||||||
draggableItems(
|
draggableItems(
|
||||||
state = draggableState,
|
state = draggableState,
|
||||||
@ -254,7 +241,6 @@ private fun Codecs(codecs: SnapshotStateList<Codec>, onUpdateCodecs: (List<Codec
|
|||||||
codecs.removeAt(index)
|
codecs.removeAt(index)
|
||||||
codecs.add(item)
|
codecs.add(item)
|
||||||
}
|
}
|
||||||
onUpdateCodecs(codecs.toList())
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -279,5 +265,3 @@ private fun Codecs(codecs: SnapshotStateList<Codec>, onUpdateCodecs: (List<Codec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user