mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Transform LocalSource icon from XML vector to ImageVector
This commit is contained in:
parent
99bec41056
commit
f3cac7cac8
3 changed files with 47 additions and 26 deletions
|
@ -69,6 +69,7 @@ import kotlinx.coroutines.launch
|
|||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.manga.interactor.GetManga
|
||||
import yokai.i18n.MR
|
||||
import yokai.presentation.component.icons.LocalSource
|
||||
import yokai.util.lang.getString
|
||||
|
||||
/**
|
||||
|
@ -607,9 +608,9 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||
|
||||
binding.emptyView.show(
|
||||
if (presenter.source is HttpSource) {
|
||||
EmptyView.Image.Vector(Icons.Filled.ExploreOff)
|
||||
Icons.Filled.ExploreOff
|
||||
} else {
|
||||
EmptyView.Image.ResourceVector(R.drawable.ic_local_library_24dp)
|
||||
Icons.Filled.LocalSource
|
||||
},
|
||||
message,
|
||||
actions,
|
||||
|
|
|
@ -14,7 +14,6 @@ import androidx.compose.runtime.setValue
|
|||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.AbstractComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.core.view.isVisible
|
||||
import dev.icerock.moko.resources.StringResource
|
||||
import eu.kanade.tachiyomi.util.isTablet
|
||||
|
@ -28,7 +27,7 @@ class EmptyView @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0,
|
||||
) : AbstractComposeView(context, attrs, defStyleAttr) {
|
||||
|
||||
private var image by mutableStateOf<Image>(Image.Vector(Icons.Filled.Download))
|
||||
private var image by mutableStateOf(Icons.Filled.Download)
|
||||
private var message by mutableStateOf("")
|
||||
private var actions by mutableStateOf(emptyList<Action>())
|
||||
|
||||
|
@ -37,19 +36,11 @@ class EmptyView @JvmOverloads constructor(
|
|||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindowOrReleasedFromPool)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun image(): ImageVector {
|
||||
return when (image) {
|
||||
is Image.Vector -> (image as Image.Vector).image
|
||||
is Image.ResourceVector -> ImageVector.vectorResource((image as Image.ResourceVector).id)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
YokaiTheme {
|
||||
EmptyScreen(
|
||||
image = image(),
|
||||
image = image,
|
||||
message = message,
|
||||
isTablet = isTablet(),
|
||||
actions = actions,
|
||||
|
@ -69,7 +60,7 @@ class EmptyView @JvmOverloads constructor(
|
|||
* @param textResource text of information view
|
||||
*/
|
||||
fun show(image: ImageVector, textResource: StringResource, actions: List<Action> = emptyList()) {
|
||||
show(Image.Vector(image), context.getString(textResource), actions)
|
||||
show(image, context.getString(textResource), actions)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,12 +68,7 @@ class EmptyView @JvmOverloads constructor(
|
|||
* @param textResource text of information view
|
||||
*/
|
||||
fun show(image: ImageVector, @StringRes textResource: Int, actions: List<Action> = emptyList()) {
|
||||
show(Image.Vector(image), context.getString(textResource), actions)
|
||||
}
|
||||
|
||||
@Deprecated("Use EmptyView.Image instead of passing ImageVector directly")
|
||||
fun show(image: ImageVector, message: String, actions: List<Action> = emptyList()) {
|
||||
show(Image.Vector(image), message, actions)
|
||||
show(image, context.getString(textResource), actions)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,7 +76,7 @@ class EmptyView @JvmOverloads constructor(
|
|||
* @param drawable icon of information view
|
||||
* @param textResource text of information view
|
||||
*/
|
||||
fun show(image: Image, message: String, actions: List<Action> = emptyList()) {
|
||||
fun show(image: ImageVector, message: String, actions: List<Action> = emptyList()) {
|
||||
this.image = image
|
||||
this.message = message
|
||||
this.actions = actions
|
||||
|
@ -101,9 +87,4 @@ class EmptyView @JvmOverloads constructor(
|
|||
val resId: StringResource,
|
||||
val listener: () -> Unit,
|
||||
)
|
||||
|
||||
sealed class Image {
|
||||
data class Vector(val image: ImageVector) : Image()
|
||||
data class ResourceVector(val id: Int) : Image()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package yokai.presentation.component.icons
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.graphics.vector.path
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
private var _localSource: ImageVector? = null
|
||||
|
||||
val Icons.Filled.LocalSource: ImageVector get() {
|
||||
if (_localSource != null) return _localSource!!
|
||||
_localSource = ImageVector.Builder(
|
||||
name = "localSource",
|
||||
defaultWidth = 24.0.dp,
|
||||
defaultHeight = 24.0.dp,
|
||||
viewportWidth = 24.0f,
|
||||
viewportHeight = 24.0f,
|
||||
).apply {
|
||||
path(fill = SolidColor(Color.Black)) {
|
||||
moveTo(12f, 11.55f)
|
||||
curveTo(9.64f, 9.35f, 6.48f, 8f, 3f, 8f)
|
||||
verticalLineToRelative(11f)
|
||||
curveToRelative(3.48f, 0f, 6.64f, 1.35f, 9f, 3.55f)
|
||||
curveToRelative(2.36f, -2.19f, 5.52f, -3.55f, 9f, -3.55f)
|
||||
verticalLineTo(8f)
|
||||
curveToRelative(-3.48f, 0f, -6.64f, 1.35f, -9f, 3.55f)
|
||||
close()
|
||||
moveTo(12f, 8f)
|
||||
curveToRelative(1.66f, 0f, 3f, -1.34f, 3f, -3f)
|
||||
reflectiveCurveToRelative(-1.34f, -3f, -3f, -3f)
|
||||
reflectiveCurveToRelative(-3f, 1.34f, -3f, 3f)
|
||||
reflectiveCurveToRelative(1.34f, 3f, 3f, 3f)
|
||||
close()
|
||||
}
|
||||
}.build()
|
||||
return _localSource!!
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue