Skip to content

Commit 317c3b9

Browse files
spotless
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent ab9edfb commit 317c3b9

File tree

9 files changed

+35
-42
lines changed

9 files changed

+35
-42
lines changed

ui/src/main/java/com/nextcloud/android/common/ui/color/ColorUtil.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,11 @@ class ColorUtil
7676

7777
fun colorToHexString(
7878
@ColorInt color: Int
79-
): String {
80-
return String.format(null, "#%06X", HEX_WHITE and color)
81-
}
79+
): String = String.format(null, "#%06X", HEX_WHITE and color)
8280

8381
@ColorInt
84-
private fun String?.parseColorOrFallback(fallback: () -> Int): Int {
85-
return if (this?.isNotBlank() == true) {
82+
private fun String?.parseColorOrFallback(fallback: () -> Int): Int =
83+
if (this?.isNotBlank() == true) {
8684
try {
8785
Color.parseColor(this)
8886
} catch (e: IllegalArgumentException) {
@@ -92,20 +90,18 @@ class ColorUtil
9290
} else {
9391
fallback()
9492
}
95-
}
9693

9794
@ColorInt
9895
fun adjustOpacity(
9996
color: Int,
10097
opacity: Float
101-
): Int {
102-
return Color.argb(
98+
): Int =
99+
Color.argb(
103100
(Color.alpha(color) * opacity).roundToInt(),
104101
Color.red(color),
105102
Color.green(color),
106103
Color.blue(color)
107104
)
108-
}
109105

110106
companion object {
111107
private const val HSL_SIZE: Int = 3

ui/src/main/java/com/nextcloud/android/common/ui/theme/MaterialSchemesImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import hct.Hct
1313
import scheme.SchemeContent
1414
import scheme.SchemeTonalSpot
1515

16-
internal class MaterialSchemesImpl :
17-
MaterialSchemes {
16+
internal class MaterialSchemesImpl : MaterialSchemes {
1817
override val lightScheme: DynamicScheme
1918
override val darkScheme: DynamicScheme
2019

ui/src/main/java/com/nextcloud/android/common/ui/theme/ViewThemeUtilsBase.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import com.nextcloud.android.common.ui.util.PlatformThemeUtil
1515
import com.nextcloud.android.common.ui.util.extensions.toColorScheme
1616
import dynamiccolor.DynamicScheme
1717

18-
open class ViewThemeUtilsBase(private val schemes: MaterialSchemes) {
18+
open class ViewThemeUtilsBase(
19+
private val schemes: MaterialSchemes
20+
) {
1921
/**
2022
* Scheme for painting elements
2123
*/

ui/src/main/java/com/nextcloud/android/common/ui/theme/utils/AndroidViewThemeUtils.kt

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ import javax.inject.Inject
6363
@Suppress("TooManyFunctions")
6464
class AndroidViewThemeUtils
6565
@Inject
66-
constructor(schemes: MaterialSchemes, private val colorUtil: ColorUtil) :
67-
ViewThemeUtilsBase(schemes) {
66+
constructor(
67+
schemes: MaterialSchemes,
68+
private val colorUtil: ColorUtil
69+
) : ViewThemeUtilsBase(schemes) {
6870
private val dynamicColor = MaterialDynamicColors()
6971

7072
fun colorBottomNavigationView(bottomNavigationView: BottomNavigationView) {
@@ -128,11 +130,10 @@ class AndroidViewThemeUtils
128130
}
129131
}
130132

131-
fun getPrimaryColorDrawable(context: Context): Drawable {
132-
return withScheme(context) { scheme ->
133+
fun getPrimaryColorDrawable(context: Context): Drawable =
134+
withScheme(context) { scheme ->
133135
ColorDrawable(dynamicColor.primary().getArgb(scheme))
134136
}
135-
}
136137

137138
fun colorToolbarMenuIcon(
138139
context: Context,
@@ -196,20 +197,17 @@ class AndroidViewThemeUtils
196197
fun tintPrimaryDrawable(
197198
context: Context,
198199
@DrawableRes id: Int
199-
): Drawable? {
200-
return tintDrawable(context, id, ColorRole.PRIMARY)
201-
}
200+
): Drawable? = tintDrawable(context, id, ColorRole.PRIMARY)
202201

203202
@JvmOverloads
204203
fun tintDrawable(
205204
context: Context,
206205
drawable: Drawable,
207206
colorRole: ColorRole = ColorRole.PRIMARY
208-
): Drawable {
209-
return withScheme(context) { scheme: DynamicScheme ->
207+
): Drawable =
208+
withScheme(context) { scheme: DynamicScheme ->
210209
colorDrawable(drawable, colorRole.select(scheme))
211210
}
212-
}
213211

214212
@Deprecated(
215213
replaceWith =
@@ -222,9 +220,7 @@ class AndroidViewThemeUtils
222220
fun tintPrimaryDrawable(
223221
context: Context,
224222
drawable: Drawable?
225-
): Drawable? {
226-
return drawable?.let { tintDrawable(context, it, ColorRole.PRIMARY) }
227-
}
223+
): Drawable? = drawable?.let { tintDrawable(context, it, ColorRole.PRIMARY) }
228224

229225
@Deprecated(
230226
replaceWith =
@@ -237,9 +233,7 @@ class AndroidViewThemeUtils
237233
fun tintTextDrawable(
238234
context: Context,
239235
drawable: Drawable?
240-
): Drawable? {
241-
return drawable?.let { tintDrawable(context, it, ColorRole.ON_SURFACE) }
242-
}
236+
): Drawable? = drawable?.let { tintDrawable(context, it, ColorRole.ON_SURFACE) }
243237

244238
/**
245239
* Public for edge cases. For most cases use [tintDrawable] instead
@@ -696,11 +690,10 @@ class AndroidViewThemeUtils
696690
}
697691

698692
@Deprecated("Don't do this, implement custom viewThemeUtils instead")
699-
fun primaryColor(activity: Activity): Int {
700-
return withScheme(activity) { scheme ->
693+
fun primaryColor(activity: Activity): Int =
694+
withScheme(activity) { scheme ->
701695
dynamicColor.primary().getArgb(scheme)
702696
}
703-
}
704697

705698
companion object {
706699
private const val ON_SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.38f

ui/src/main/java/com/nextcloud/android/common/ui/theme/utils/AndroidXViewThemeUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class AndroidXViewThemeUtils
4040
constructor(
4141
schemes: MaterialSchemes,
4242
private val androidViewThemeUtils: AndroidViewThemeUtils
43-
) :
44-
ViewThemeUtilsBase(schemes) {
43+
) : ViewThemeUtilsBase(schemes) {
4544
private val dynamicColor = MaterialDynamicColors()
4645

4746
fun colorSwitchCompat(switchCompat: SwitchCompat) {

ui/src/main/java/com/nextcloud/android/common/ui/theme/utils/ColorRole.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import dynamiccolor.DynamicScheme
1313
/**
1414
* Parameter for library methods so that clients can choose color roles without accessing the Scheme directly
1515
*/
16-
enum class ColorRole(internal val select: (DynamicScheme) -> Int) {
16+
enum class ColorRole(
17+
internal val select: (DynamicScheme) -> Int
18+
) {
1719
PRIMARY({ dynamiccolor.MaterialDynamicColors().primary().getArgb(it) }),
1820
ON_PRIMARY({ dynamiccolor.MaterialDynamicColors().onPrimary().getArgb(it) }),
1921
PRIMARY_CONTAINER({ dynamiccolor.MaterialDynamicColors().primaryContainer().getArgb(it) }),

ui/src/main/java/com/nextcloud/android/common/ui/theme/utils/DialogViewThemeUtils.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import javax.inject.Inject
3030
*/
3131
class DialogViewThemeUtils
3232
@Inject
33-
constructor(schemes: MaterialSchemes) :
34-
ViewThemeUtilsBase(schemes) {
33+
constructor(
34+
schemes: MaterialSchemes
35+
) : ViewThemeUtilsBase(schemes) {
3536
private val dynamicColor = MaterialDynamicColors()
3637

3738
fun colorMaterialAlertDialogBackground(

ui/src/main/java/com/nextcloud/android/common/ui/theme/utils/MaterialViewThemeUtils.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ import javax.inject.Inject
5050
@Suppress("TooManyFunctions")
5151
class MaterialViewThemeUtils
5252
@Inject
53-
constructor(schemes: MaterialSchemes, private val colorUtil: ColorUtil) :
54-
ViewThemeUtilsBase(schemes) {
53+
constructor(
54+
schemes: MaterialSchemes,
55+
private val colorUtil: ColorUtil
56+
) : ViewThemeUtilsBase(schemes) {
5557
private val dynamicColor = MaterialDynamicColors()
5658

5759
fun colorToolbarOverflowIcon(toolbar: MaterialToolbar) {

ui/src/main/java/com/nextcloud/android/common/ui/util/extensions/SchemeExtensions.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import androidx.compose.ui.graphics.Color
1313
import dynamiccolor.DynamicScheme
1414
import dynamiccolor.MaterialDynamicColors
1515

16-
fun DynamicScheme.toColorScheme(): ColorScheme {
17-
return ColorScheme(
16+
fun DynamicScheme.toColorScheme(): ColorScheme =
17+
ColorScheme(
1818
primary = Color(MaterialDynamicColors().primary().getArgb(this)),
1919
onPrimary = Color(MaterialDynamicColors().onPrimary().getArgb(this)),
2020
primaryContainer = Color(MaterialDynamicColors().primaryContainer().getArgb(this)),
@@ -45,4 +45,3 @@ fun DynamicScheme.toColorScheme(): ColorScheme {
4545
outlineVariant = Color(MaterialDynamicColors().outlineVariant().getArgb(this)),
4646
scrim = Color(MaterialDynamicColors().scrim().getArgb(this))
4747
)
48-
}

0 commit comments

Comments
 (0)