Skip to content

Commit 8e28ed7

Browse files
add sharescreen.kt because ide error accur
1 parent 8ad6ae8 commit 8e28ed7

1 file changed

Lines changed: 153 additions & 0 deletions

File tree

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package com.example.intra
2+
3+
import android.net.Uri
4+
import androidx.compose.foundation.background
5+
import androidx.compose.foundation.layout.*
6+
import androidx.compose.foundation.lazy.LazyColumn
7+
import androidx.compose.foundation.lazy.items
8+
import androidx.compose.material.icons.Icons
9+
import androidx.compose.material.icons.filled.ArrowBack
10+
import androidx.compose.material.icons.filled.Group
11+
import androidx.compose.material.icons.filled.Person
12+
import androidx.compose.material.icons.filled.Send
13+
import androidx.compose.material3.*
14+
import androidx.compose.runtime.*
15+
import androidx.compose.ui.Alignment
16+
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.graphics.Color
18+
import androidx.compose.ui.layout.ContentScale
19+
import androidx.compose.ui.platform.LocalContext
20+
import androidx.compose.ui.text.font.FontWeight
21+
import androidx.compose.ui.unit.dp
22+
import androidx.lifecycle.viewmodel.compose.viewModel
23+
import coil.compose.AsyncImage
24+
import androidx.compose.foundation.isSystemInDarkTheme
25+
26+
@OptIn(ExperimentalMaterial3Api::class)
27+
@Composable
28+
fun ShareScreen(
29+
imageUri: Uri,
30+
onBack: () -> Unit,
31+
onSend: (String) -> Unit
32+
) {
33+
val contactViewModel: ContactViewModel = viewModel()
34+
val contacts = contactViewModel.contacts
35+
var selectedRecipient by remember { mutableStateOf<String?>(null) }
36+
37+
val isDark = isSystemInDarkTheme()
38+
val colorScheme = MaterialTheme.colorScheme
39+
40+
val context = LocalContext.current
41+
val settingsManager = remember { SettingsManager(context) }
42+
val myUsername = remember { settingsManager.getUsername() ?: "" }
43+
44+
Scaffold(
45+
topBar = {
46+
TopAppBar(
47+
title = { Text("Share Photo") },
48+
navigationIcon = {
49+
IconButton(onClick = onBack) {
50+
Icon(Icons.Default.ArrowBack, contentDescription = "Back")
51+
}
52+
},
53+
colors = TopAppBarDefaults.topAppBarColors(
54+
containerColor = if (isDark) colorScheme.primaryContainer else Color(0xFF6741A8),
55+
titleContentColor = if (isDark) colorScheme.onPrimaryContainer else Color.White,
56+
navigationIconContentColor = if (isDark) colorScheme.onPrimaryContainer else Color.White
57+
)
58+
)
59+
},
60+
bottomBar = {
61+
Surface(
62+
tonalElevation = 3.dp,
63+
shadowElevation = 8.dp
64+
) {
65+
Button(
66+
onClick = { selectedRecipient?.let { onSend(it) } },
67+
enabled = selectedRecipient != null,
68+
modifier = Modifier
69+
.fillMaxWidth()
70+
.padding(16.dp),
71+
shape = MaterialTheme.shapes.medium,
72+
colors = ButtonDefaults.buttonColors(
73+
containerColor = if (isDark) colorScheme.primary else Color(0xFF673AB7)
74+
)
75+
) {
76+
Icon(Icons.Default.Send, contentDescription = null)
77+
Spacer(Modifier.width(8.dp))
78+
Text("Send Photo", fontWeight = FontWeight.Bold)
79+
}
80+
}
81+
}
82+
) { padding ->
83+
Column(modifier = Modifier.padding(padding)) {
84+
// Photo Preview
85+
Card(
86+
modifier = Modifier
87+
.fillMaxWidth()
88+
.height(220.dp)
89+
.padding(12.dp),
90+
shape = MaterialTheme.shapes.medium,
91+
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
92+
) {
93+
Box(
94+
modifier = Modifier
95+
.fillMaxSize()
96+
.background(Color.Black),
97+
contentAlignment = Alignment.Center
98+
) {
99+
AsyncImage(
100+
model = imageUri,
101+
contentDescription = "Preview",
102+
modifier = Modifier.fillMaxSize(),
103+
contentScale = ContentScale.Fit
104+
)
105+
}
106+
}
107+
108+
Text(
109+
"Select Recipient",
110+
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
111+
fontWeight = FontWeight.Bold,
112+
style = MaterialTheme.typography.titleMedium,
113+
color = if (isDark) colorScheme.onSurface else Color.Black
114+
)
115+
116+
LazyColumn(modifier = Modifier.weight(1f)) {
117+
// FAMILY GROUP
118+
item {
119+
ContactItem(
120+
name = "Family Group",
121+
subtitle = "Broadcast to everyone",
122+
isTyping = false,
123+
icon = Icons.Filled.Group,
124+
iconTint = Color(0xFF25BB4B),
125+
isDark = isDark,
126+
profilePhotoUrl = null,
127+
unreadCount = 0,
128+
isActive = selectedRecipient == "Family Group",
129+
onClick = { selectedRecipient = "Family Group" }
130+
)
131+
}
132+
133+
// USERS
134+
items(contacts) { user ->
135+
if (user.username != myUsername) {
136+
ContactItem(
137+
name = user.username,
138+
subtitle = "Select to share",
139+
isTyping = false,
140+
icon = Icons.Filled.Person,
141+
iconTint = Color(0xFFB39DDB),
142+
isDark = isDark,
143+
profilePhotoUrl = user.profilePhoto,
144+
unreadCount = 0,
145+
isActive = selectedRecipient == user.username,
146+
onClick = { selectedRecipient = user.username }
147+
)
148+
}
149+
}
150+
}
151+
}
152+
}
153+
}

0 commit comments

Comments
 (0)