-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e728a60
commit 082d9e3
Showing
22 changed files
with
1,031 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/src/main/java/eu/kanade/presentation/more/storage/CumulativeStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package eu.kanade.presentation.more.storage | ||
|
||
import androidx.compose.foundation.Canvas | ||
import androidx.compose.foundation.layout.aspectRatio | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.StrokeCap | ||
import androidx.compose.ui.graphics.drawscope.Stroke | ||
import androidx.compose.ui.graphics.drawscope.rotate | ||
import androidx.compose.ui.layout.Layout | ||
import eu.kanade.tachiyomi.util.toSize | ||
|
||
@Composable | ||
fun CumulativeStorage( | ||
items: List<StorageItem>, | ||
modifier: Modifier = Modifier, | ||
borderWidth: Float = 15f, | ||
) { | ||
val totalSize = remember(items) { | ||
items.sumOf { it.size }.toFloat() | ||
} | ||
val totalSizeString = remember(totalSize) { | ||
totalSize.toLong().toSize() | ||
} | ||
Layout( | ||
modifier = modifier, | ||
content = { | ||
Canvas( | ||
modifier = Modifier.aspectRatio(1f), | ||
onDraw = { | ||
val totalAngle = 180f | ||
var currentAngle = 0f | ||
rotate(180f) { | ||
for (item in items) { | ||
val itemAngle = (item.size / totalSize) * totalAngle | ||
drawArc( | ||
color = item.color, | ||
startAngle = currentAngle, | ||
sweepAngle = itemAngle, | ||
useCenter = false, | ||
style = Stroke(width = borderWidth, cap = StrokeCap.Round), | ||
) | ||
currentAngle += itemAngle | ||
} | ||
} | ||
}, | ||
) | ||
Text( | ||
text = totalSizeString, | ||
style = MaterialTheme.typography.displaySmall, | ||
) | ||
}, | ||
measurePolicy = { measurables, constraints -> | ||
val placeables = measurables.map { measurable -> | ||
measurable.measure(constraints.copy(minWidth = 0, minHeight = 0)) | ||
} | ||
val canvas = placeables.first() | ||
val text = placeables.last() | ||
// use half the height of the canvas to avoid too much extra space | ||
layout(constraints.maxWidth, canvas.height / 2) { | ||
canvas.placeRelative(0, 0) | ||
text.placeRelative( | ||
(canvas.width / 2) - (text.width / 2), | ||
(canvas.height / 4) - (text.height / 2), | ||
) | ||
} | ||
}, | ||
) | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/eu/kanade/presentation/more/storage/SelectStorageCategory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package eu.kanade.presentation.more.storage | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import eu.kanade.presentation.components.SelectItem | ||
import eu.kanade.tachiyomi.R | ||
import tachiyomi.domain.category.model.Category | ||
|
||
@Composable | ||
fun SelectStorageCategory( | ||
selectedCategory: Category, | ||
categories: List<Category>, | ||
modifier: Modifier = Modifier, | ||
onCategorySelected: (Category) -> Unit, | ||
) { | ||
val all = stringResource(R.string.label_all) | ||
val default = stringResource(R.string.label_default) | ||
val mappedCategories = remember(categories) { | ||
categories.map { | ||
when (it.id) { | ||
-1L -> it.copy(name = all) | ||
Category.UNCATEGORIZED_ID -> it.copy(name = default) | ||
else -> it | ||
} | ||
}.toTypedArray() | ||
} | ||
|
||
SelectItem( | ||
modifier = modifier, | ||
label = stringResource(R.string.label_category), | ||
selectedIndex = mappedCategories.indexOfFirst { it.id == selectedCategory.id }, | ||
options = mappedCategories, | ||
onSelect = { index -> | ||
onCategorySelected(mappedCategories[index]) | ||
}, | ||
toString = { it.name }, | ||
) | ||
} |
Oops, something went wrong.