Skip to content

Commit

Permalink
Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
russhwolf committed Apr 26, 2020
1 parent e651456 commit 359e6e6
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion multiplatform-settings-no-arg/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ kotlin {
implementation("androidx.test.ext:junit:1.1.1")
implementation("org.robolectric:robolectric:4.3")

implementation("androidx.preference:preference:1.1.0")
implementation("androidx.preference:preference:1.1.1")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,33 @@ actual operator fun Settings.Companion.invoke(): Settings {
}

/** Use to provide a context reference to [invoke] */
@Suppress("DEPRECATION")
@Suppress("DEPRECATION", "KDocMissingDocumentation")
@Hidden
class ContextProvider : ContentProvider() {
override fun insert(uri: Uri, values: ContentValues?): Uri? {
return null
}
override fun insert(uri: Uri, values: ContentValues?): Uri? = null

override fun query(
uri: Uri,
projection: Array<out String>?,
selection: String?,
selectionArgs: Array<out String>?,
sortOrder: String?
): Cursor? {
return null
}
): Cursor? = null

override fun onCreate(): Boolean {
appContext = context!!.applicationContext
return true
}

override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int {
return 0
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
return 0
}
override fun update(
uri: Uri,
values: ContentValues?,
selection: String?,
selectionArgs: Array<out String>?
): Int = 0

override fun getType(uri: Uri): String? {
return null
}
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
override fun getType(uri: Uri): String? = null
}

@Deprecated(message = "Hidden annotation signifies non-public API", level = DeprecationLevel.WARNING)
Expand Down
5 changes: 5 additions & 0 deletions sample/app-tornadofx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
application
}

dependencies {
Expand All @@ -31,3 +32,7 @@ tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += "-Xuse-experimental=kotlin.Experimental"
}

application {
mainClassName = "com.russhwolf.settings.example.jvm.MainKt"
}
8 changes: 4 additions & 4 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

plugins {
kotlin("multiplatform") version "1.3.70" apply false
kotlin("android") version "1.3.70" apply false
id("com.android.library") version "3.6.1" apply false
id("com.android.application") version "3.6.1" apply false
kotlin("multiplatform") version "1.3.72" apply false
kotlin("android") version "1.3.72" apply false
id("com.android.library") version "3.6.3" apply false
id("com.android.application") version "3.6.3" apply false
}

allprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ import java.util.concurrent.atomic.AtomicReference
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

actual fun <T> threadSafeReference(initialValue: T?) = object : ReadWriteProperty<Any?, T?> {
private val reference = AtomicReference<T?>(initialValue)
/**
* Test helper atomic delegate.
*/
internal actual fun <T> threadSafeReference(initialValue: T?): ReadWriteProperty<Any?, T?> =
object : ReadWriteProperty<Any?, T?> {
private val reference = AtomicReference<T?>(initialValue)

override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
return reference.get()
}
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
return reference.get()
}

override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
reference.set(value)
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
reference.set(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ package com.russhwolf.settings

import kotlin.properties.ReadWriteProperty

expect fun <T> threadSafeReference(initialValue: T?): ReadWriteProperty<Any?, T?>
internal expect fun <T> threadSafeReference(initialValue: T?): ReadWriteProperty<Any?, T?>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ package com.russhwolf.settings
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

actual fun <T> threadSafeReference(initialValue: T?) = object : ReadWriteProperty<Any?, T?> {
/**
* JS equivalent of atomics is just wrapping a reference because the world is single-threaded
*/
internal actual fun <T> threadSafeReference(initialValue: T?) = object : ReadWriteProperty<Any?, T?> {
private var reference: T? = initialValue

override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import java.util.concurrent.atomic.AtomicReference
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

actual fun <T> threadSafeReference(initialValue: T?) = object : ReadWriteProperty<Any?, T?> {
/**
* Test helper atomic delegate.
*/
internal actual fun <T> threadSafeReference(initialValue: T?) = object : ReadWriteProperty<Any?, T?> {
private val reference = AtomicReference<T?>(initialValue)

override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import kotlin.native.concurrent.freeze
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

actual fun <T> threadSafeReference(initialValue: T?) = object : ReadWriteProperty<Any?, T?> {
/**
* Test helper atomic delegate.
*
* This is just living in tests, but note that this pattern can lead to memory leaks if the reference isn't nulled out
* when no longer being used.
*/
internal actual fun <T> threadSafeReference(initialValue: T?) = object : ReadWriteProperty<Any?, T?> {
private val reference = AtomicReference(initialValue.freeze())

override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
Expand Down

0 comments on commit 359e6e6

Please sign in to comment.