@@ -23,9 +23,6 @@ import androidx.compose.foundation.layout.Column
2323import androidx.compose.foundation.layout.Row
2424import androidx.compose.foundation.layout.fillMaxWidth
2525import androidx.compose.foundation.layout.padding
26- import androidx.compose.material.icons.Icons
27- import androidx.compose.material.icons.filled.AddCircle
28- import androidx.compose.material.icons.filled.Check
2926import androidx.compose.material3.CardDefaults
3027import androidx.compose.material3.ElevatedCard
3128import androidx.compose.material3.Icon
@@ -37,12 +34,14 @@ import androidx.compose.material3.Text
3734import androidx.compose.runtime.Composable
3835import androidx.compose.ui.Alignment
3936import androidx.compose.ui.Modifier
37+ import androidx.compose.ui.res.painterResource
4038import androidx.compose.ui.text.font.FontWeight
4139import androidx.compose.ui.text.style.TextAlign
4240import androidx.compose.ui.text.style.TextOverflow
4341import androidx.compose.ui.tooling.preview.Preview
4442import androidx.compose.ui.unit.dp
4543import org.comixedproject.variant.android.DIRECTORY_LIST
44+ import org.comixedproject.variant.android.R
4645import org.comixedproject.variant.android.VariantTheme
4746import org.comixedproject.variant.android.view.BYTES_PER_MB
4847import org.comixedproject.variant.model.library.DirectoryEntry
@@ -80,12 +79,24 @@ fun FileItemView(
8079 ) {
8180 if (comicBookFilenameList.contains(fileEntry.filename)) {
8281 IconButton (
83- onClick = {
84-
85- },
82+ onClick = { },
83+ enabled = downloadingState.size < 5
84+ ) {
85+ Icon (
86+ painterResource(id = R .drawable.ic_downloaded_file),
87+ contentDescription = fileEntry.title
88+ )
89+ }
90+ } else if (downloadingState.filter { it.filename.equals(fileEntry.filename) }
91+ .isNotEmpty()) {
92+ IconButton (
93+ onClick = { },
8694 enabled = downloadingState.size < 5
8795 ) {
88- Icon (Icons .Filled .Check , contentDescription = fileEntry.title)
96+ Icon (
97+ painterResource(R .drawable.ic_downloading_file),
98+ contentDescription = fileEntry.title
99+ )
89100 }
90101 } else {
91102 IconButton (
@@ -94,7 +105,10 @@ fun FileItemView(
94105 },
95106 enabled = downloadingState.size < 5
96107 ) {
97- Icon (Icons .Filled .AddCircle , contentDescription = fileEntry.title)
108+ Icon (
109+ painterResource(R .drawable.ic_download_file),
110+ contentDescription = fileEntry.title
111+ )
98112 }
99113 }
100114
@@ -107,34 +121,37 @@ fun FileItemView(
107121 maxLines = 1 ,
108122 overflow = TextOverflow .Ellipsis
109123 )
110- Text (
111- text = " ${fileEntry.filename} " ,
112- style = MaterialTheme .typography.bodySmall,
113- fontWeight = FontWeight .Bold ,
114- textAlign = TextAlign .Left ,
115- maxLines = 1 ,
116- overflow = TextOverflow .Ellipsis
117- )
118124
119- downloading?.let {
120- val received = it.received
121- val total = it.total
122- val progress = when (received > 0 ) {
123- true -> (received.toFloat() / total.toFloat())
124- false -> 0.0
125- }
126- val fileSize = String .format(" %.1f" , fileEntry.fileSize / BYTES_PER_MB )
127- Row (
128- modifier = Modifier .fillMaxWidth(),
129- verticalAlignment = Alignment .CenterVertically
130- ) {
131- Text (" ${fileSize} MB" , style = MaterialTheme .typography.bodySmall)
132- LinearProgressIndicator (
133- progress = { progress.toFloat() },
134- modifier = Modifier
135- .fillMaxWidth()
136- .padding(4 .dp)
137- )
125+ if (downloading == null ) {
126+ Text (
127+ text = " ${fileEntry.filename} " ,
128+ style = MaterialTheme .typography.bodySmall,
129+ fontWeight = FontWeight .Bold ,
130+ textAlign = TextAlign .Left ,
131+ maxLines = 1 ,
132+ overflow = TextOverflow .Ellipsis
133+ )
134+ } else {
135+ downloading?.let {
136+ val received = it.received
137+ val total = it.total
138+ val progress = when (received > 0 ) {
139+ true -> (received.toFloat() / total.toFloat())
140+ false -> 0.0
141+ }
142+ val fileSize = String .format(" %.1f" , fileEntry.fileSize / BYTES_PER_MB )
143+ Row (
144+ modifier = Modifier .fillMaxWidth(),
145+ verticalAlignment = Alignment .CenterVertically
146+ ) {
147+ Text (" ${fileSize} MB" , style = MaterialTheme .typography.bodySmall)
148+ LinearProgressIndicator (
149+ progress = { progress.toFloat() },
150+ modifier = Modifier
151+ .fillMaxWidth()
152+ .padding(4 .dp)
153+ )
154+ }
138155 }
139156 }
140157 }
@@ -146,9 +163,10 @@ fun FileItemView(
146163@Composable
147164@Preview
148165fun FileItemViewPreview () {
166+ val fileEntry = DIRECTORY_LIST .filter { ! it.isDirectory }.first()
149167 VariantTheme {
150168 FileItemView (
151- DIRECTORY_LIST .filter { ! it.isDirectory }.first() ,
169+ fileEntry ,
152170 listOf (),
153171 listOf (),
154172 onDownloadFile = { _, _ -> })
0 commit comments