From 236f97f10086df7e12159c1ae0c10a8b4e94d023 Mon Sep 17 00:00:00 2001 From: Patryk Goworowski Date: Sat, 21 Sep 2024 11:21:44 +0200 Subject: [PATCH] Replace deprecated APIs --- gradle/libs.versions.toml | 2 -- sample/build.gradle | 1 - .../patrykandpatrick/vico/sample/MainActivity.kt | 9 ++++++++- .../com/patrykandpatrick/vico/sample/VicoApp.kt | 15 +-------------- .../vico/views/chart/BaseChartView.kt | 11 +++++------ .../vico/views/extension/ContextExtensions.kt | 11 +++-------- .../vico/views/extension/ViewExtensions.kt | 6 +++--- 7 files changed, 20 insertions(+), 35 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bd30aa7ba..abda5ccbd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,4 @@ [versions] -accompanist = "0.36.0" activity = "1.9.2" agp = "8.6.1" androidXAnnotation = "1.8.2" @@ -42,7 +41,6 @@ lifecycleRuntime = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx material = { group = "com.google.android.material", name = "material", version.ref = "material" } mockK = { group = "io.mockk", name = "mockk", version.ref = "mockK" } paparazziGradlePlugin = { module = "app.cash.paparazzi:paparazzi-gradle-plugin", version.ref = "paparazziGradlePlugin" } -systemUIController = { group = "com.google.accompanist", name = "accompanist-systemuicontroller", version.ref = "accompanist" } testCore = { group = "androidx.test", name = "core-ktx", version.ref = "testCore" } viewModelCompose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycle" } diff --git a/sample/build.gradle b/sample/build.gradle index 7e2886456..3915fc0e8 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -71,7 +71,6 @@ dependencies { implementation libs.kotlinStdLib implementation libs.lifecycleRuntime implementation libs.material - implementation libs.systemUIController implementation libs.viewModelCompose testImplementation libs.JUnit testImplementation libs.JUnitExt diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/MainActivity.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/MainActivity.kt index 072635080..1fa71a497 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/MainActivity.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/MainActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 by Patryk Goworowski and Patrick Michalik. + * Copyright 2024 by Patryk Goworowski and Patrick Michalik. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,22 @@ package com.patrykandpatrick.vico.sample +import android.graphics.Color import android.os.Bundle import androidx.activity.ComponentActivity +import androidx.activity.SystemBarStyle import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.core.view.WindowCompat internal class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + enableEdgeToEdge( + statusBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT), + navigationBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT), + ) WindowCompat.setDecorFitsSystemWindows(window, false) setContent { VicoApp() } } diff --git a/sample/src/main/java/com/patrykandpatrick/vico/sample/VicoApp.kt b/sample/src/main/java/com/patrykandpatrick/vico/sample/VicoApp.kt index a0b1c1071..f92d30564 100644 --- a/sample/src/main/java/com/patrykandpatrick/vico/sample/VicoApp.kt +++ b/sample/src/main/java/com/patrykandpatrick/vico/sample/VicoApp.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 by Patryk Goworowski and Patrick Michalik. + * Copyright 2024 by Patryk Goworowski and Patrick Michalik. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,29 +17,16 @@ package com.patrykandpatrick.vico.sample import androidx.compose.foundation.background -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.patrykandpatrick.vico.sample.showcase.ShowcaseScreen import com.patrykandpatrick.vico.sample.utils.VicoTheme @Composable internal fun VicoApp() { - val systemUiController = rememberSystemUiController() - val useDarkIcons = isSystemInDarkTheme().not() - SideEffect { - systemUiController.setSystemBarsColor( - color = Color.Transparent, - darkIcons = useDarkIcons, - isNavigationBarContrastEnforced = false, - ) - } VicoTheme { Box( modifier = Modifier diff --git a/vico/views/src/main/java/com/patrykandpatrick/vico/views/chart/BaseChartView.kt b/vico/views/src/main/java/com/patrykandpatrick/vico/views/chart/BaseChartView.kt index 6f94484ba..0fba90774 100644 --- a/vico/views/src/main/java/com/patrykandpatrick/vico/views/chart/BaseChartView.kt +++ b/vico/views/src/main/java/com/patrykandpatrick/vico/views/chart/BaseChartView.kt @@ -28,7 +28,6 @@ import android.view.ViewGroup import android.view.animation.Interpolator import android.widget.FrameLayout import android.widget.OverScroller -import androidx.core.view.ViewCompat import androidx.core.view.isVisible import androidx.interpolator.view.animation.FastOutSlowInInterpolator import com.patrykandpatrick.vico.core.Animation @@ -125,7 +124,7 @@ public abstract class BaseChartView internal constructo private val measureContext = MutableMeasureContext( canvasBounds = contentBounds, density = context.density, - isLtr = context.isLtr, + isLtr = isLtr, isHorizontalScrollEnabled = false, spToPx = context::spToPx, chartValuesProvider = ChartValuesProvider.Empty, @@ -272,7 +271,7 @@ public abstract class BaseChartView internal constructo set(value) { field?.unregisterFromUpdates(key = this) field = value - if (ViewCompat.isAttachedToWindow(this)) registerForUpdates() + if (isAttachedToWindow) registerForUpdates() } private fun registerForUpdates() { @@ -396,7 +395,7 @@ public abstract class BaseChartView internal constructo chart.updateChartValues(chartValuesManager, model, getXStep?.invoke(model)) measureContext.chartValuesProvider = chartValuesManager.toChartValuesProvider() } - if (ViewCompat.isAttachedToWindow(this)) invalidate() + if (isAttachedToWindow) invalidate() } protected inline fun invalidatingObservable( @@ -480,7 +479,7 @@ public abstract class BaseChartView internal constructo motionEventHandler.isHorizontalScrollEnabled = chartScrollSpec.isScrollEnabled if (scroller.computeScrollOffset()) { scrollHandler.handleScroll(scroller.currX.toFloat()) - ViewCompat.postInvalidateOnAnimation(this) + postInvalidateOnAnimation() } var finalZoom = zoom @@ -688,6 +687,6 @@ public abstract class BaseChartView internal constructo // This function may be invoked inside of the View’s constructor, before the measureContext is initialized. // In this case, we can ignore this callback, as the layout direction will be determined when the MeasureContext // instance is created. - measureContext?.isLtr = layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR + measureContext?.isLtr = layoutDirection == LAYOUT_DIRECTION_LTR } } diff --git a/vico/views/src/main/java/com/patrykandpatrick/vico/views/extension/ContextExtensions.kt b/vico/views/src/main/java/com/patrykandpatrick/vico/views/extension/ContextExtensions.kt index dcb2f3b36..7ac219649 100644 --- a/vico/views/src/main/java/com/patrykandpatrick/vico/views/extension/ContextExtensions.kt +++ b/vico/views/src/main/java/com/patrykandpatrick/vico/views/extension/ContextExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 by Patryk Goworowski and Patrick Michalik. + * Copyright 2024 by Patryk Goworowski and Patrick Michalik. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,19 +18,14 @@ package com.patrykandpatrick.vico.views.extension import android.content.Context import android.content.res.Configuration -import android.os.Build -import androidx.core.view.ViewCompat +import android.view.View.LAYOUT_DIRECTION_LTR import com.patrykandpatrick.vico.core.DefaultColors internal val Context.density: Float get() = resources.displayMetrics.density internal val Context.isLtr: Boolean - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - resources.configuration.layoutDirection == ViewCompat.LAYOUT_DIRECTION_LTR - } else { - true - } + get() = resources.configuration.layoutDirection == LAYOUT_DIRECTION_LTR internal val Context.isDarkMode: Boolean get() = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES diff --git a/vico/views/src/main/java/com/patrykandpatrick/vico/views/extension/ViewExtensions.kt b/vico/views/src/main/java/com/patrykandpatrick/vico/views/extension/ViewExtensions.kt index 75870e1e8..93cfe743c 100644 --- a/vico/views/src/main/java/com/patrykandpatrick/vico/views/extension/ViewExtensions.kt +++ b/vico/views/src/main/java/com/patrykandpatrick/vico/views/extension/ViewExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 by Patryk Goworowski and Patrick Michalik. + * Copyright 2024 by Patryk Goworowski and Patrick Michalik. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ package com.patrykandpatrick.vico.views.extension import android.view.MotionEvent import android.view.View +import android.view.View.LAYOUT_DIRECTION_LTR import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.OverScroller -import androidx.core.view.ViewCompat import androidx.core.view.updatePadding import com.patrykandpatrick.vico.core.model.Point import kotlin.math.min @@ -60,7 +60,7 @@ internal var View.verticalPadding: Int } internal val View.isLtr: Boolean - get() = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR + get() = layoutDirection == LAYOUT_DIRECTION_LTR internal fun OverScroller.fling( startX: Int = 0,