-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
ChartValuesManager
-related concurrency issues (WIP)
Co-authored-by: Patryk Goworowski <[email protected]>
- Loading branch information
1 parent
f4b30a9
commit 9f644c5
Showing
24 changed files
with
178 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
vico/compose/src/main/java/com/patrykandpatrick/vico/compose/state/ChartEntryModelState.kt
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
vico/compose/src/main/java/com/patrykandpatrick/vico/compose/state/ChartEntryModelWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2023 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.patrykandpatrick.vico.compose.state | ||
|
||
import androidx.compose.runtime.Immutable | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import com.patrykandpatrick.vico.core.chart.values.ChartValuesProvider | ||
import com.patrykandpatrick.vico.core.entry.ChartEntryModel | ||
|
||
/** | ||
* Holds a chart’s current [ChartEntryModel] ([chartEntryModel]), previous [ChartEntryModel] | ||
* ([previousChartEntryModel]), and [ChartValuesProvider] ([chartValuesProvider]). | ||
*/ | ||
@Immutable | ||
public class ChartEntryModelWrapper<T : ChartEntryModel>( | ||
public val chartEntryModel: T, | ||
public val previousChartEntryModel: T?, | ||
public val chartValuesProvider: ChartValuesProvider, | ||
) | ||
|
||
/** | ||
* Returns [ChartEntryModelWrapper.chartEntryModel]. | ||
*/ | ||
public operator fun <T : ChartEntryModel> ChartEntryModelWrapper<T>.component1(): T = chartEntryModel | ||
|
||
/** | ||
* Returns [ChartEntryModelWrapper.previousChartEntryModel]. | ||
*/ | ||
public operator fun <T : ChartEntryModel> ChartEntryModelWrapper<T>.component2(): T? = previousChartEntryModel | ||
|
||
/** | ||
* Returns [ChartEntryModelWrapper.chartValuesProvider]. | ||
*/ | ||
public operator fun <T : ChartEntryModel> ChartEntryModelWrapper<T>.component3(): ChartValuesProvider = | ||
chartValuesProvider | ||
|
||
internal class ChartEntryModelWrapperState<T : ChartEntryModel> : State<ChartEntryModelWrapper<T>?> { | ||
private var previousChartEntryModel: T? = null | ||
|
||
override var value by mutableStateOf<ChartEntryModelWrapper<T>?>(null) | ||
private set | ||
|
||
fun set(chartEntryModel: T, chartValuesProvider: ChartValuesProvider) { | ||
val currentChartEntryModel = value?.chartEntryModel | ||
if (chartEntryModel.id != currentChartEntryModel?.id) previousChartEntryModel = currentChartEntryModel | ||
value = ChartEntryModelWrapper(chartEntryModel, previousChartEntryModel, chartValuesProvider) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.