Skip to content

Commit 853ef2c

Browse files
committed
Added an icon to indicate a file is downloading [#132]
Also hid the filename to display the downloading progress bar.
1 parent 2f85557 commit 853ef2c

24 files changed

Lines changed: 203 additions & 43 deletions

File tree

androidVariant/src/main/java/org/comixedproject/variant/android/view/server/FileItemView.kt

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ import androidx.compose.foundation.layout.Column
2323
import androidx.compose.foundation.layout.Row
2424
import androidx.compose.foundation.layout.fillMaxWidth
2525
import 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
2926
import androidx.compose.material3.CardDefaults
3027
import androidx.compose.material3.ElevatedCard
3128
import androidx.compose.material3.Icon
@@ -37,12 +34,14 @@ import androidx.compose.material3.Text
3734
import androidx.compose.runtime.Composable
3835
import androidx.compose.ui.Alignment
3936
import androidx.compose.ui.Modifier
37+
import androidx.compose.ui.res.painterResource
4038
import androidx.compose.ui.text.font.FontWeight
4139
import androidx.compose.ui.text.style.TextAlign
4240
import androidx.compose.ui.text.style.TextOverflow
4341
import androidx.compose.ui.tooling.preview.Preview
4442
import androidx.compose.ui.unit.dp
4543
import org.comixedproject.variant.android.DIRECTORY_LIST
44+
import org.comixedproject.variant.android.R
4645
import org.comixedproject.variant.android.VariantTheme
4746
import org.comixedproject.variant.android.view.BYTES_PER_MB
4847
import 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
148165
fun 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 = { _, _ -> })
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="#333333"
7+
android:alpha="0.6">
8+
<path
9+
android:fillColor="#FF000000"
10+
android:pathData="M12,24A12,12 0,1 1,24 12,12.013 12.013,0 0,1 12,24ZM12,2A10,10 0,1 0,22 12,10.011 10.011,0 0,0 12,2Z"/>
11+
<path
12+
android:fillColor="#FF000000"
13+
android:pathData="M12,14.414l-4.707,-4.707l1.414,-1.414l3.293,3.293l3.293,-3.293l1.414,1.414l-4.707,4.707z"/>
14+
<path
15+
android:fillColor="#FF000000"
16+
android:pathData="M11,5h2v8h-2z"/>
17+
<path
18+
android:fillColor="#FF000000"
19+
android:pathData="M17,19l-10,0l0,-3l2,0l0,1l6,0l0,-1l2,0l0,3z"/>
20+
</vector>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="64"
5+
android:viewportHeight="64"
6+
android:tint="#333333"
7+
android:alpha="0.6">
8+
<path
9+
android:pathData="M54,8V0H12C6.49,0 2,4.49 2,10v44c0,5.51 4.49,10 10,10h50V8H54zM6,10c0,-3.31 2.69,-6 6,-6h38v40H12c-2.25,0 -4.33,0.75 -6,2V10zM12,60c-3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6h42V12h4v40H20v4h38v4H12z"
10+
android:fillColor="#231F20"/>
11+
</vector>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="#333333"
7+
android:alpha="0.6">
8+
<group android:scaleX="1.2631578"
9+
android:scaleY="1.2631578"
10+
android:translateX="-3.1578948"
11+
android:translateY="-3.7894738">
12+
<path
13+
android:pathData="M11.292,16.706a1,1 0,0 0,1.416 0l3,-3a1,1 0,0 0,-1.414 -1.414L13,13.586V4a1,1 0,0 0,-2 0v9.586L9.707,12.293a1,1 0,0 0,-1.414 1.414Z"
14+
android:fillColor="#1c1b1e"/>
15+
<path
16+
android:pathData="M17,19H7a1,1 0,0 0,0 2H17a1,1 0,0 0,0 -2Z"
17+
android:fillColor="#1c1b1e"/>
18+
</group>
19+
</vector>
953 Bytes
Loading
407 Bytes
Loading
352 Bytes
Loading
575 Bytes
Loading
280 Bytes
Loading
263 Bytes
Loading

0 commit comments

Comments
 (0)