Show error message when loading icon picker failed
This commit is contained in:
@@ -223,4 +223,5 @@
|
||||
<string name="always_open_website_description">Open search provider’s website even if their app is installed.</string>
|
||||
<string name="search_provider">Search Provider</string>
|
||||
<string name="status_bar_label">Status Bar</string>
|
||||
<string name="icon_picker_load_failed">Failed to load more icons</string>
|
||||
</resources>
|
||||
|
||||
@@ -144,29 +144,25 @@ class CustomIconPack(context: Context, packPackageName: String) :
|
||||
emit(ArrayList(result))
|
||||
}
|
||||
|
||||
try {
|
||||
val parser = getXml("drawable")
|
||||
while (parser != null && parser.next() != XmlPullParser.END_DOCUMENT) {
|
||||
if (parser.eventType != XmlPullParser.START_TAG) continue
|
||||
when (parser.name) {
|
||||
"category" -> {
|
||||
endCategory()
|
||||
currentTitle = parser["title"]!!
|
||||
}
|
||||
"item" -> {
|
||||
val drawableName = parser["drawable"]!!
|
||||
val resId = getDrawableId(drawableName)
|
||||
if (resId != 0) {
|
||||
val item = IconPickerItem(packPackageName, drawableName, drawableName, IconType.Normal)
|
||||
currentItems.add(item)
|
||||
}
|
||||
val parser = getXml("drawable")
|
||||
while (parser != null && parser.next() != XmlPullParser.END_DOCUMENT) {
|
||||
if (parser.eventType != XmlPullParser.START_TAG) continue
|
||||
when (parser.name) {
|
||||
"category" -> {
|
||||
endCategory()
|
||||
currentTitle = parser["title"]!!
|
||||
}
|
||||
"item" -> {
|
||||
val drawableName = parser["drawable"]!!
|
||||
val resId = getDrawableId(drawableName)
|
||||
if (resId != 0) {
|
||||
val item = IconPickerItem(packPackageName, drawableName, drawableName, IconType.Normal)
|
||||
currentItems.add(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
endCategory()
|
||||
} catch (e: Exception) {
|
||||
|
||||
}
|
||||
endCategory()
|
||||
}.flowOn(Dispatchers.IO)
|
||||
|
||||
private fun getDrawableId(name: String) = idCache.getOrPut(name) {
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.google.accompanist.drawablepainter.rememberDrawablePainter
|
||||
import com.google.accompanist.insets.ui.LocalScaffoldPadding
|
||||
import com.google.accompanist.navigation.animation.composable
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.material.MaterialTheme as Material2Theme
|
||||
|
||||
@@ -136,7 +137,6 @@ fun IconPickerPreference(packageName: String) {
|
||||
searchQuery = searchQuery,
|
||||
onClickItem = onClickItem,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 8.dp)
|
||||
.padding(top = topPadding)
|
||||
)
|
||||
}
|
||||
@@ -157,7 +157,12 @@ fun IconPickerGrid(
|
||||
onClickItem: (item: IconPickerItem) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val categories by iconPack.getAllIcons().collectAsState(emptyList())
|
||||
var loadFailed by remember { mutableStateOf(false) }
|
||||
val categoriesFlow = remember {
|
||||
iconPack.getAllIcons()
|
||||
.catch { loadFailed = true }
|
||||
}
|
||||
val categories by categoriesFlow.collectAsState(emptyList())
|
||||
val filteredCategories by derivedStateOf {
|
||||
categories
|
||||
.map { it.filter(searchQuery) }
|
||||
@@ -183,15 +188,14 @@ fun IconPickerGrid(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(MaterialTheme.colorScheme.background)
|
||||
.padding(
|
||||
vertical = 16.dp,
|
||||
horizontal = 8.dp,
|
||||
),
|
||||
.padding(16.dp),
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
verticalGridItems(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 8.dp),
|
||||
items = category.items,
|
||||
numColumns = numColumns,
|
||||
gap = 0.dp,
|
||||
@@ -206,6 +210,13 @@ fun IconPickerGrid(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (loadFailed) {
|
||||
item {
|
||||
PreferenceGroupDescription(
|
||||
description = stringResource(id = R.string.icon_picker_load_failed)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
|
||||
fun LazyListScope.verticalGridItems(
|
||||
modifier: Modifier = Modifier,
|
||||
count: Int,
|
||||
numColumns: Int,
|
||||
gap: Dp,
|
||||
@@ -18,7 +19,7 @@ fun LazyListScope.verticalGridItems(
|
||||
Spacer(modifier = Modifier.height(gap))
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
for (col in 0 until numColumns) {
|
||||
@@ -39,12 +40,14 @@ fun LazyListScope.verticalGridItems(
|
||||
}
|
||||
|
||||
fun <T> LazyListScope.verticalGridItems(
|
||||
modifier: Modifier = Modifier,
|
||||
items: List<T>,
|
||||
numColumns: Int,
|
||||
gap: Dp,
|
||||
itemContent: @Composable (index: Int, item: T) -> Unit
|
||||
) {
|
||||
verticalGridItems(
|
||||
modifier = modifier,
|
||||
count = items.size,
|
||||
numColumns = numColumns,
|
||||
gap = gap
|
||||
|
||||
@@ -17,20 +17,16 @@
|
||||
package app.lawnchair.ui.preferences.components
|
||||
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.ContentAlpha
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material3.LocalAbsoluteTonalElevation
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.lawnchair.theme.surfaceColorAtElevation
|
||||
import androidx.compose.material3.MaterialTheme as Material3Theme
|
||||
|
||||
@Composable
|
||||
@@ -98,7 +94,6 @@ fun PreferenceGroupHeading(
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ExperimentalAnimationApi
|
||||
fun PreferenceGroupDescription(description: String? = null, showDescription: Boolean = true) {
|
||||
description?.let {
|
||||
AnimatedVisibility(
|
||||
|
||||
Reference in New Issue
Block a user