Skip to content

Commit

Permalink
Replace deprecated APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowsky committed Oct 11, 2024
1 parent b62e436 commit 236f97f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 35 deletions.
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[versions]
accompanist = "0.36.0"
activity = "1.9.2"
agp = "8.6.1"
androidXAnnotation = "1.8.2"
Expand Down Expand Up @@ -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" }

Expand Down
1 change: 0 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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() }
}
Expand Down
15 changes: 1 addition & 14 deletions sample/src/main/java/com/patrykandpatrick/vico/sample/VicoApp.kt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,7 +124,7 @@ public abstract class BaseChartView<Model : ChartEntryModel> internal constructo
private val measureContext = MutableMeasureContext(
canvasBounds = contentBounds,
density = context.density,
isLtr = context.isLtr,
isLtr = isLtr,
isHorizontalScrollEnabled = false,
spToPx = context::spToPx,
chartValuesProvider = ChartValuesProvider.Empty,
Expand Down Expand Up @@ -272,7 +271,7 @@ public abstract class BaseChartView<Model : ChartEntryModel> internal constructo
set(value) {
field?.unregisterFromUpdates(key = this)
field = value
if (ViewCompat.isAttachedToWindow(this)) registerForUpdates()
if (isAttachedToWindow) registerForUpdates()
}

private fun registerForUpdates() {
Expand Down Expand Up @@ -396,7 +395,7 @@ public abstract class BaseChartView<Model : ChartEntryModel> internal constructo
chart.updateChartValues(chartValuesManager, model, getXStep?.invoke(model))
measureContext.chartValuesProvider = chartValuesManager.toChartValuesProvider()
}
if (ViewCompat.isAttachedToWindow(this)) invalidate()
if (isAttachedToWindow) invalidate()
}

protected inline fun <T> invalidatingObservable(
Expand Down Expand Up @@ -480,7 +479,7 @@ public abstract class BaseChartView<Model : ChartEntryModel> internal constructo
motionEventHandler.isHorizontalScrollEnabled = chartScrollSpec.isScrollEnabled
if (scroller.computeScrollOffset()) {
scrollHandler.handleScroll(scroller.currX.toFloat())
ViewCompat.postInvalidateOnAnimation(this)
postInvalidateOnAnimation()
}

var finalZoom = zoom
Expand Down Expand Up @@ -688,6 +687,6 @@ public abstract class BaseChartView<Model : ChartEntryModel> 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
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 236f97f

Please sign in to comment.