Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MyKSuite-11): Allow custom background for chips #277

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
Expand All @@ -39,11 +40,11 @@ import com.infomaniak.core.myksuite.ui.theme.Margin
import com.infomaniak.core.myksuite.ui.theme.MyKSuiteTheme

@Composable
fun MyKSuiteChip(modifier: Modifier = Modifier, tier: MyKSuiteTier) {
fun MyKSuiteChip(modifier: Modifier = Modifier, tier: MyKSuiteTier, backgroundColor: Int? = null) {
Image(
modifier = modifier
.background(
color = LocalMyKSuiteColors.current.chipBackground,
color = backgroundColor?.let(::Color) ?: LocalMyKSuiteColors.current.chipBackground,
shape = CircleShape,
)
.padding(horizontal = Margin.Mini, vertical = Margin.Micro),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import android.content.Context
import android.util.AttributeSet
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.AbstractComposeView
import androidx.core.content.res.ResourcesCompat
import com.infomaniak.core.myksuite.R
import com.infomaniak.core.myksuite.ui.components.MyKSuiteChip
import com.infomaniak.core.myksuite.ui.components.MyKSuiteTier
import com.infomaniak.core.myksuite.ui.theme.MyKSuiteTheme
Expand All @@ -32,8 +34,18 @@ abstract class BaseMyKSuiteChipView @JvmOverloads constructor(
val tier: MyKSuiteTier,
) : AbstractComposeView(context, attrs, defStyleAttr) {

private var backgroundColor: Int = ResourcesCompat.ID_NULL

init {
context.obtainStyledAttributes(attrs, R.styleable.BaseMyKSuiteChipView, defStyleAttr, 0).apply {
backgroundColor = getInt(R.styleable.BaseMyKSuiteChipView_backgroundColor, ResourcesCompat.ID_NULL)
recycle()
}
}

@Composable
override fun Content() {
MyKSuiteTheme { MyKSuiteChip(tier = tier) }
val colorRes = if (backgroundColor == ResourcesCompat.ID_NULL) null else backgroundColor
MyKSuiteTheme { MyKSuiteChip(tier = tier, backgroundColor = colorRes) }
}
}
24 changes: 24 additions & 0 deletions MykSuite/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Infomaniak Core - Android
~ Copyright (C) 2025 Infomaniak Network SA
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>

<declare-styleable name="BaseMyKSuiteChipView">
<attr name="backgroundColor" />
</declare-styleable>

</resources>