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 uy.kohesive.injekt.injectLazy
|
||||||
import yokai.domain.manga.interactor.GetManga
|
import yokai.domain.manga.interactor.GetManga
|
||||||
import yokai.i18n.MR
|
import yokai.i18n.MR
|
||||||
|
import yokai.presentation.component.icons.LocalSource
|
||||||
import yokai.util.lang.getString
|
import yokai.util.lang.getString
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -607,9 +608,9 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||||
|
|
||||||
binding.emptyView.show(
|
binding.emptyView.show(
|
||||||
if (presenter.source is HttpSource) {
|
if (presenter.source is HttpSource) {
|
||||||
EmptyView.Image.Vector(Icons.Filled.ExploreOff)
|
Icons.Filled.ExploreOff
|
||||||
} else {
|
} else {
|
||||||
EmptyView.Image.ResourceVector(R.drawable.ic_local_library_24dp)
|
Icons.Filled.LocalSource
|
||||||
},
|
},
|
||||||
message,
|
message,
|
||||||
actions,
|
actions,
|
||||||
|
|
|
@ -14,7 +14,6 @@ import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.platform.AbstractComposeView
|
import androidx.compose.ui.platform.AbstractComposeView
|
||||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||||
import androidx.compose.ui.res.vectorResource
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import dev.icerock.moko.resources.StringResource
|
import dev.icerock.moko.resources.StringResource
|
||||||
import eu.kanade.tachiyomi.util.isTablet
|
import eu.kanade.tachiyomi.util.isTablet
|
||||||
|
@ -28,7 +27,7 @@ class EmptyView @JvmOverloads constructor(
|
||||||
defStyleAttr: Int = 0,
|
defStyleAttr: Int = 0,
|
||||||
) : AbstractComposeView(context, attrs, defStyleAttr) {
|
) : 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 message by mutableStateOf("")
|
||||||
private var actions by mutableStateOf(emptyList<Action>())
|
private var actions by mutableStateOf(emptyList<Action>())
|
||||||
|
|
||||||
|
@ -37,19 +36,11 @@ class EmptyView @JvmOverloads constructor(
|
||||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindowOrReleasedFromPool)
|
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
|
@Composable
|
||||||
override fun Content() {
|
override fun Content() {
|
||||||
YokaiTheme {
|
YokaiTheme {
|
||||||
EmptyScreen(
|
EmptyScreen(
|
||||||
image = image(),
|
image = image,
|
||||||
message = message,
|
message = message,
|
||||||
isTablet = isTablet(),
|
isTablet = isTablet(),
|
||||||
actions = actions,
|
actions = actions,
|
||||||
|
@ -69,7 +60,7 @@ class EmptyView @JvmOverloads constructor(
|
||||||
* @param textResource text of information view
|
* @param textResource text of information view
|
||||||
*/
|
*/
|
||||||
fun show(image: ImageVector, textResource: StringResource, actions: List<Action> = emptyList()) {
|
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
|
* @param textResource text of information view
|
||||||
*/
|
*/
|
||||||
fun show(image: ImageVector, @StringRes textResource: Int, actions: List<Action> = emptyList()) {
|
fun show(image: ImageVector, @StringRes textResource: Int, actions: List<Action> = emptyList()) {
|
||||||
show(Image.Vector(image), context.getString(textResource), actions)
|
show(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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,7 +76,7 @@ class EmptyView @JvmOverloads constructor(
|
||||||
* @param drawable icon of information view
|
* @param drawable icon of information view
|
||||||
* @param textResource text 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.image = image
|
||||||
this.message = message
|
this.message = message
|
||||||
this.actions = actions
|
this.actions = actions
|
||||||
|
@ -101,9 +87,4 @@ class EmptyView @JvmOverloads constructor(
|
||||||
val resId: StringResource,
|
val resId: StringResource,
|
||||||
val listener: () -> Unit,
|
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