|
@@ -0,0 +1,87 @@
|
|
|
+package com.example.test.view.ui.view.components
|
|
|
+
|
|
|
+import com.example.test.model.films
|
|
|
+import com.example.test.domain.utlls.Constant
|
|
|
+
|
|
|
+import android.util.Log
|
|
|
+import androidx.compose.foundation.Image
|
|
|
+import androidx.compose.foundation.layout.Box
|
|
|
+import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
+import androidx.compose.foundation.layout.height
|
|
|
+import androidx.compose.foundation.layout.padding
|
|
|
+import androidx.compose.foundation.lazy.LazyColumn
|
|
|
+import androidx.compose.foundation.lazy.items
|
|
|
+import androidx.compose.material3.CircularProgressIndicator
|
|
|
+import androidx.compose.material3.Text
|
|
|
+import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
+import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
+import androidx.compose.ui.Alignment
|
|
|
+import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.layout.ContentScale
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
+import androidx.compose.ui.unit.dp
|
|
|
+import coil.compose.AsyncImagePainter
|
|
|
+import coil.compose.rememberAsyncImagePainter
|
|
|
+import coil.request.ImageRequest
|
|
|
+import coil.size.Size
|
|
|
+import io.github.jan.supabase.postgrest.from
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
+import kotlinx.coroutines.withContext
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun FilmsList() {
|
|
|
+ var Films1 by remember { mutableStateOf<List<films>>(listOf()) }
|
|
|
+
|
|
|
+ LaunchedEffect(Unit) {
|
|
|
+ withContext(Dispatchers.IO) {
|
|
|
+ Films1 = Constant.supabase.from("films")
|
|
|
+ .select().decodeList<films>()
|
|
|
+ Films1.forEach{it->
|
|
|
+ Log.d("C",it.films_name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LazyColumn {
|
|
|
+
|
|
|
+ items(
|
|
|
+ Films1,
|
|
|
+ key = { films -> films.id },
|
|
|
+ ) { films ->
|
|
|
+ val imageState = rememberAsyncImagePainter(
|
|
|
+ model = ImageRequest.Builder(LocalContext.current).data(films.foto)
|
|
|
+ .size(Size.ORIGINAL).build()
|
|
|
+ ).state
|
|
|
+ if (imageState is AsyncImagePainter.State.Error) {
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(200.dp),
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
+ ) {
|
|
|
+ CircularProgressIndicator()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (imageState is AsyncImagePainter.State.Success) {
|
|
|
+ Image(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(200.dp),
|
|
|
+ painter = imageState.painter,
|
|
|
+ contentDescription = "",
|
|
|
+ contentScale = ContentScale.Crop
|
|
|
+ )
|
|
|
+ }
|
|
|
+ Text(
|
|
|
+ films.films_name,
|
|
|
+ modifier = Modifier.padding(8.dp),
|
|
|
+ )
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|