@@ -2,55 +2,50 @@ package st.slex.csplashscreen.ui.detail
2
2
3
3
import androidx.compose.foundation.Image
4
4
import androidx.compose.foundation.clickable
5
- import androidx.compose.foundation.layout.Column
6
- import androidx.compose.foundation.layout.fillMaxWidth
7
- import androidx.compose.foundation.layout.height
5
+ import androidx.compose.foundation.layout.*
6
+ import androidx.compose.foundation.shape.CircleShape
7
+ import androidx.compose.material.ExperimentalMaterialApi
8
+ import androidx.compose.material.Surface
9
+ import androidx.compose.material.Text
8
10
import androidx.compose.runtime.Composable
9
11
import androidx.compose.runtime.collectAsState
10
- import androidx.compose.runtime.rememberCoroutineScope
12
+ import androidx.compose.ui.Alignment
11
13
import androidx.compose.ui.Modifier
12
- import androidx.compose.ui.graphics.Color
13
- import androidx.compose.ui.platform.LocalContext
14
+ import androidx.compose.ui.draw.clip
15
+ import androidx.compose.ui.draw.shadow
16
+ import androidx.compose.ui.text.font.FontFamily
17
+ import androidx.compose.ui.unit.TextUnit
14
18
import androidx.compose.ui.unit.dp
15
19
import androidx.navigation.NavController
16
20
import coil.annotation.ExperimentalCoilApi
17
21
import coil.compose.rememberImagePainter
18
- import coil.transform.BlurTransformation
19
22
import coil.transform.RoundedCornersTransformation
20
- import com.google.accompanist.placeholder.PlaceholderHighlight
21
- import com.google.accompanist.placeholder.fade
22
- import com.google.accompanist.placeholder.placeholder
23
23
import kotlinx.coroutines.ExperimentalCoroutinesApi
24
24
import kotlinx.coroutines.flow.SharedFlow
25
- import st.slex.csplashscreen.R
26
25
import st.slex.csplashscreen.data.model.ui.image.ImageModel
27
- import st.slex.csplashscreen.ui.core.UIResult
26
+ import st.slex.csplashscreen.ui.main.UserImageHead
27
+ import st.slex.csplashscreen.ui.theme.Shapes
28
+ import st.slex.csplashscreen.ui.theme.Typography
28
29
import java.net.URLEncoder
29
30
import java.nio.charset.StandardCharsets
30
31
32
+ @ExperimentalMaterialApi
31
33
@ExperimentalCoroutinesApi
32
34
@ExperimentalCoilApi
33
35
@Composable
34
36
fun ImageDetailScreen (
35
37
url : String ,
36
38
navController : NavController ,
37
- imageFlow : () -> SharedFlow <UIResult < ImageModel > >
39
+ imageFlow : () -> SharedFlow <ImageModel >
38
40
) {
39
- val imageModel = imageFlow().collectAsState(
40
- initial = UIResult .Loading ,
41
- context = rememberCoroutineScope().coroutineContext
42
- ).value
43
-
44
- when (imageModel) {
45
- is UIResult .Success -> BindImage (navController, imageModel.data)
46
- is UIResult .Loading -> BindImageLoading (url = url)
47
- is UIResult .Failure -> BindImageFailure (url = url)
48
- }
41
+ val imageModel = imageFlow().collectAsState(initial = null ).value
42
+ BindDetailImage (navController, imageModel)
49
43
}
50
44
45
+ @ExperimentalMaterialApi
51
46
@ExperimentalCoilApi
52
47
@Composable
53
- private fun BindImage (navController : NavController , imageModel : ImageModel ) {
48
+ private fun BindDetailImage (navController : NavController , imageModel : ImageModel ? ) {
54
49
Column {
55
50
Image (
56
51
modifier = Modifier
@@ -59,68 +54,74 @@ private fun BindImage(navController: NavController, imageModel: ImageModel) {
59
54
.clickable {
60
55
val encodedUrl =
61
56
URLEncoder .encode(
62
- imageModel.urls.regular,
57
+ imageModel? .urls? .regular,
63
58
StandardCharsets .UTF_8 .toString()
64
59
)
65
60
navController.navigate(" raw_image/$encodedUrl " )
66
61
},
67
62
painter = rememberImagePainter(
68
- data = imageModel.urls.regular,
63
+ data = imageModel? .urls? .regular,
69
64
builder = {
70
65
transformations(RoundedCornersTransformation ())
71
66
allowHardware(false )
72
67
}
73
68
),
74
69
contentDescription = " TestImage"
75
70
)
71
+
72
+ Spacer (modifier = Modifier .padding(4 .dp))
73
+
74
+ UserImageHead (
75
+ modifier = Modifier .padding(start = 16 .dp),
76
+ username = imageModel?.user?.username.toString(),
77
+ url = imageModel?.user?.profile_image?.medium.toString(),
78
+ navController = navController
79
+ )
76
80
}
77
- }
78
81
79
- @ExperimentalCoilApi
80
- @Composable
81
- private fun BindImageLoading (url : String ) {
82
- androidx.compose.material.Surface (
83
- modifier = Modifier
84
- .height(300 .dp)
85
- .fillMaxWidth()
86
- .placeholder(
87
- visible = true ,
88
- highlight = PlaceholderHighlight .fade(highlightColor = Color .LightGray ),
89
- color = Color .Gray
90
- )
91
- ) {}
92
82
93
83
}
94
84
95
85
@ExperimentalCoilApi
86
+ @ExperimentalMaterialApi
96
87
@Composable
97
- private fun BindImageFailure (url : String ) {
98
-
99
- Image (
88
+ fun CurrentImageUser (username : String , url : String , navController : NavController ) {
89
+ Surface (
100
90
modifier = Modifier
101
91
.fillMaxWidth()
102
- .height(300 .dp),
103
- painter = rememberImagePainter(
104
- data = url,
105
- builder = {
106
- transformations(
107
- RoundedCornersTransformation (),
108
- BlurTransformation (LocalContext .current)
109
- )
110
- allowHardware(false )
111
- crossfade(500 )
112
- }
113
- ),
114
- contentDescription = " TestImage"
115
- )
116
- Image (
117
- modifier = Modifier
118
- .fillMaxWidth()
119
- .height(300 .dp),
120
- painter = rememberImagePainter(
121
- data = R .drawable.ic_baseline_sentiment_very_dissatisfied_24
122
- ),
123
- contentDescription = " TestImage"
124
- )
92
+ .shadow(elevation = 0 .dp, Shapes .medium),
93
+ onClick = {
94
+ // navController.navigate("user_profile")
95
+ }
96
+ ) {
97
+ Row (
98
+ modifier = Modifier
99
+ .padding(8 .dp),
100
+ verticalAlignment = Alignment .CenterVertically
101
+ ) {
102
+ Image (
103
+ modifier = Modifier
104
+ .size(48 .dp)
105
+ .clip(CircleShape ),
106
+ painter = rememberImagePainter(
107
+ data = url,
108
+ builder = {
109
+ allowHardware(false )
110
+ crossfade(500 )
111
+ }
112
+ ),
113
+ contentDescription = " User Avatar"
114
+ )
115
+ Spacer (modifier = Modifier .padding(8 .dp))
116
+ Text (
117
+ text = username,
118
+ style = Typography .h5,
119
+ maxLines = 1 ,
120
+ lineHeight = TextUnit .Unspecified ,
121
+ fontFamily = FontFamily .SansSerif
122
+ )
123
+ }
124
+ }
125
+
125
126
}
126
127
0 commit comments