@@ -8,6 +8,7 @@ import androidx.compose.material.icons.Icons
88import androidx.compose.material.icons.filled.GifBox
99import androidx.compose.material.icons.filled.Image
1010import androidx.compose.material.icons.filled.Smartphone
11+ import androidx.compose.material.icons.filled.Star
1112import androidx.compose.material3.ExperimentalMaterial3Api
1213import androidx.compose.material3.Icon
1314import androidx.compose.material3.MaterialTheme
@@ -24,8 +25,13 @@ import androidx.compose.runtime.remember
2425import androidx.compose.ui.Modifier
2526import androidx.compose.ui.tooling.preview.Preview
2627import androidx.compose.ui.unit.dp
28+ import androidx.core.net.toUri
2729import androidx.lifecycle.ViewModel
30+ import com.troplo.privateuploader.api.ChatStore
31+ import com.troplo.privateuploader.api.stores.UserStore
2832import com.troplo.privateuploader.components.chat.attachment.MyDevice
33+ import com.troplo.privateuploader.data.model.Upload
34+ import com.troplo.privateuploader.data.model.UploadTarget
2935import com.troplo.privateuploader.screens.GalleryScreen
3036
3137@OptIn(ExperimentalMaterial3Api ::class )
@@ -35,7 +41,7 @@ fun Attachment(openBottomSheet: MutableState<Boolean>) {
3541 val bottomSheetState = rememberModalBottomSheetState(
3642 skipPartiallyExpanded = true
3743 )
38- val selectedTab = remember { mutableIntStateOf(0 ) }
44+ val selectedTab: MutableState < Int > = remember { mutableIntStateOf(0 ) }
3945 ModalBottomSheet (
4046 onDismissRequest = { openBottomSheet.value = false },
4147 sheetState = bottomSheetState,
@@ -48,29 +54,46 @@ fun Attachment(openBottomSheet: MutableState<Boolean>) {
4854 ) {
4955 Tab (
5056 selected = selectedTab.value == 0 ,
51- onClick = { openBottomSheet .value = true },
57+ onClick = { selectedTab .value = 0 },
5258 text = { Text (" My Device" ) },
53- icon = { Icon (Icons .Default .Smartphone , contentDescription = null ) }
59+ icon = { Icon (Icons .Default .Smartphone , contentDescription = " My Device " ) }
5460 )
5561 Tab (
5662 selected = selectedTab.value == 1 ,
57- onClick = { openBottomSheet .value = true },
63+ onClick = { selectedTab .value = 1 },
5864 text = { Text (" Gallery" ) },
59- icon = { Icon (Icons .Default .Image , contentDescription = null ) }
65+ icon = { Icon (Icons .Default .Image , contentDescription = " Gallery " ) }
6066 )
6167 Tab (
6268 selected = selectedTab.value == 2 ,
63- onClick = { openBottomSheet .value = true },
69+ onClick = { selectedTab .value = 2 },
6470 text = { Text (" Starred" ) },
65- icon = { Icon (Icons .Default .Image , contentDescription = null ) }
71+ icon = { Icon (Icons .Default .Star , contentDescription = " Starred " ) }
6672 )
6773 Tab (
6874 selected = selectedTab.value == 3 ,
69- onClick = { openBottomSheet .value = true },
75+ onClick = { selectedTab .value = 3 },
7076 text = { Text (" GIFs" ) },
71- icon = { Icon (Icons .Default .GifBox , contentDescription = null ) }
77+ icon = { Icon (Icons .Default .GifBox , contentDescription = " GIFs " ) }
7278 )
7379 }
80+
81+ fun onClick (upload : Upload , tenor : Boolean = false) {
82+ openBottomSheet.value = false
83+ ChatStore .attachmentsToUpload.add(
84+ UploadTarget (
85+ uri = if (tenor) {
86+ upload.attachment.toUri()
87+ } else {
88+ " https://${UserStore .user.value?.domain?.domain} /i/${upload.attachment} " .toUri()
89+ },
90+ started = true ,
91+ progress = 100f ,
92+ url = upload.attachment
93+ )
94+ )
95+ }
96+
7497 Box (
7598 modifier = Modifier .padding(start = 16 .dp, end = 16 .dp, top = 16 .dp, bottom = 32 .dp)
7699 ) {
@@ -80,15 +103,21 @@ fun Attachment(openBottomSheet: MutableState<Boolean>) {
80103 }
81104
82105 1 -> {
83- GalleryScreen ()
106+ GalleryScreen (" gallery" , true , onClick = {
107+ onClick(it)
108+ })
84109 }
85110
86111 2 -> {
87- GalleryScreen ()
112+ GalleryScreen (" starred" , true , onClick = {
113+ onClick(it)
114+ })
88115 }
89116
90117 3 -> {
91- GalleryScreen ()
118+ GalleryScreen (" tenor" , true , onClick = {
119+ onClick(it, true )
120+ })
92121 }
93122 }
94123 }
0 commit comments