12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package com.example.task1.view.mainAct.components
- import android.media.Image
- 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.semantics.Role.Companion.Image
- import androidx.compose.ui.unit.dp
- import coil.compose.AsyncImagePainter
- import coil.compose.rememberAsyncImagePainter
- import coil.request.ImageRequest
- import coil.size.Size
- import com.example.task1.Model.Branches
- import com.example.task1.domain.Constants
- import io.github.jan.supabase.postgrest.postgrest
- import kotlinx.coroutines.Dispatchers
- import kotlinx.coroutines.withContext
- @Composable
- fun BranchesListTest()
- {
- var branches by remember { mutableStateOf<List<Branches>>(listOf()) }
- /* var bucket: ByteArray? = null
- var bytes:ByteArray? = null
- var files: List<BucketItem>? = null*/
- LaunchedEffect(Unit) {
- withContext(Dispatchers.IO) {
- try {
- branches = Constants.supabase.postgrest.from("Branches").
- select().decodeList()
- branches.forEach{it->
- println(it.address)
- }
- } catch (e: Exception) {
- println("Error")
- println(e.message)
- }
- }
- }
- LazyColumn {
- items(
- branches,
- key = { branch -> branch.id }
- )
- {
- branch ->
- val imageState = rememberAsyncImagePainter(
- model = ImageRequest.Builder(LocalContext.current).data(branch.image)
- .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(
- branch.address,
- modifier = Modifier.padding(8.dp),
- )
- }
- }
- }
|