Skip to content

Commit

Permalink
Merge pull request #22 from pablobaxter/develop
Browse files Browse the repository at this point in the history
Release v2.0.0
  • Loading branch information
pablobaxter authored Oct 1, 2024
2 parents bb7156e + bd4d1c9 commit ed04ffb
Show file tree
Hide file tree
Showing 60 changed files with 1,142 additions and 2,453 deletions.
34 changes: 17 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
version: 2.1

orbs:
android: circleci/android@2.2.0
android: circleci/android@2.5.0

jobs:
Core-Lint:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -27,7 +27,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -77,7 +77,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -96,7 +96,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -145,7 +145,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -164,7 +164,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand Down Expand Up @@ -192,7 +192,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -213,7 +213,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -232,7 +232,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand Down Expand Up @@ -260,7 +260,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -281,7 +281,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -300,7 +300,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand Down Expand Up @@ -328,7 +328,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand All @@ -349,7 +349,7 @@ jobs:
executor:
name: android/android-machine
resource-class: medium
tag: 2023.03.1
tag: default
steps:
- checkout
- android/restore-gradle-cache:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

### Version 2.0.0 / 2024-09-30
* **Breaking Change release**
* Use extension functions for Rx libraries
* This removes the uses of the various `*SharedPreference` classes, and provides a single `RxSharedPreferences` class
* This also removes the various `*Preference` classes in favor of a single `Preference` class
* All reactive frameworks are now accessible as extension functions against the `Preference` class.
* Java will have util classes to provide the access to extension functions
* Update CI to build against latest android images
* Update several dependencies
* Remove deprecated APIs from rx-sharedpreferences
* Add in utility to convert `Preference<T>` to `Preference<Optional<T>>` for reactive frameworks that don't allow `null`.

### Version 1.1.0 / 2023-10-03
* Update dependencies
* Move to compile sdk 34
Expand Down
135 changes: 119 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,140 @@ In order to handle the varying number of reactive frameworks available, there ar
## Available Reactive SharedPreferences Libraries

- [Core][3]
- `implementation 'com.frybits.rx.preferences:core:1.1.0'`
- `implementation 'com.frybits.rx.preferences:core:2.0.0'`
- [Coroutine/Flow][4]
- `implementation 'com.frybits.rx.preferences:coroutine:1.1.0'`
- `implementation 'com.frybits.rx.preferences:coroutine:2.0.0'`
- [LiveData][5]
- `implementation 'com.frybits.rx.preferences:livedata:1.1.0'`
- `implementation 'com.frybits.rx.preferences:livedata:2.0.0'`
- [Rx2][6]
- `implementation 'com.frybits.rx.preferences:rx2:1.1.0'`
- `implementation 'com.frybits.rx.preferences:rx2:2.0.0'`
- [Rx3][7]
- `implementation 'com.frybits.rx.preferences:rx3:1.1.0'`
- `implementation 'com.frybits.rx.preferences:rx3:2.0.0'`

For ease of ensuring all libraries are compatible, as they may have varying release cadences, a BOM is also provided:

```groovy
// Import BOM
implementation platform('com.frybits.rx.preferences:bom:1.1.0')
implementation platform('com.frybits.rx.preferences:bom:2.0.0')
implementation 'com.frybits.rx.preferences:core'
implementation 'com.frybits.rx.preferences:livedata'
implementation 'com.frybits.rx.preferences:rx2'
```

## Migration from `:rx-preferences` to `:rx2`
## Migration from `f2prateek/rx-preferences` to `pablobaxter/rx-preferences`

Many of the APIs are similar to [f2prateek/rx-preferences][8], however there were some changes to packages and class names, mainly due to the addition of the other reactive frameworks.
This guide can be used for migrating from `:rx-preferences` to `:rx2` library (and potentially even `:rx3`).
Many of the APIs are similar to [f2prateek/rx-preferences][8], however there were some changes to packages.
This guide can be used for migrating from `f2prateek/rx-preferences` to `pablobaxter/rx-preferences` library:

1. Change Gradle dependency import from `com.f2prateek.rx.preferences2:rx-preferences` to `com.frybits.rx.preferences:rx2`
2. Rename all `com.f2prateek.rx.preferences2.Preference` imports to `com.frybits.rx.preferences.rx2.Rx2Preference`
3. Rename all `Preferences` class usages to `Rx2Preference`
4. Rename all `com.f2prateek.rx.preferences2.RxSharedPreferences` imports to `com.frybits.rx.preferences.rx2.Rx2SharedPreferences`
5. Rename all `RxSharedPreferences` class usages to `Rx2SharedPreferences`
1. Change Gradle dependency import from `com.f2prateek.rx.preferences2:rx-preferences` to `com.frybits.rx.preferences:core`
2. Rename all `com.f2prateek.rx.preferences2.Preference` imports to `com.frybits.rx.preferences.core.Preference`
3. Rename all `com.f2prateek.rx.preferences2.RxSharedPreferences` imports to `com.frybits.rx.preferences.core.RxSharedPreferences`
4. Add an import of the following package...
5. In Kotlin: `import com.frybits.rx.preferences.rx2.asObservable`
6. In Java: `import com.frybits.rx.preferences.rx2.Rx2Preference;` and change instances of `preference.asObservable()` to `Rx2Preference.asObservable(preference)`

All other API usages remain the same.
**NOTE**: Version 1.x of `pablobaxter/rx-preferences` had multiple "Preference" classes for each reactive framework. This has since been changed, so that all libraries share the same class.

## Usage
The `core` library provides the entryway to getting the `RxSharedPreferences`. This allows creating the `Preference<T>` objects that represent the requested preference, as well as providing a base for the various extension functions used to create the reactive object.

### Quick start (Kotlin)

Core:
```kotlin
val rxSharedPreferences: RxSharedPreferences = getSharedPreferences("foobar", MODE_PRIVATE).asRxSharedPreferences()
val username: Preference<String?> = rxSharedPreferences.getString("username")

println(username.value) // Outputs value of "username" preference
username.value = "myName" // Sets the preference to "myName"
```

Coroutines:
```kotlin
username.asFlow().collect { name ->
println("Username: $name") // Outputs value of "username" preference
}

flow {
emit("coroutineName")
}.collect(username.asCollector()) // username is updated to "coroutineName"
```

LiveData:
```kotlin
username.asLiveData().observeForever { name ->
println("Username: $name") // Outputs value of "username" preference
}

MutableLiveData("livedataName")
.observeForever(username.asObserver()) // username is updated to "livedataName"
```

Rx2 and Rx3:
```kotlin
username.asOptional() // Helper operator to convert nullable types to com.google.common.base.Optional<>
.asObservable()
.subscribe { name ->
println("Username: ${name.get()}") // Outputs value of "username" preference
}

Observable.just(Optional.fromNullable("observableName"))
.subscribe(
username.asOptional() // Helper operator to convert nullable types to com.google.common.base.Optional<>
.asConsumer() // username is updated to "observableName"
)
```

### Quickstart (Java)

Core:
```java
RxSharedPreferences rxSharedPreferences = RxSharedPreferences.create(getSharedPreferences("foobar", MODE_PRIVATE));
Preference<String> username = rxSharedPreferences.getString("username");

String name = username.getValue();

System.out.println(name); // Outputs value of "username" preference
username.setValue("myName"); // Sets the preference to "myName"
```

**Note:** Coroutines library is not accessible to Java

LiveData:
```java
LiveDataPreference.asLiveData(username).observeForever (s -> {
System.out.println("Username: " + s); // Outputs value of "username" preference
});

LiveData<String> stringLiveData = new MutableLiveData("livedataName");
stringLiveData.observeForever(LivedataPreference.asObserver(username)); // username is updated to "livedataName"
```

Rx2:
```java
// Helper operator to convert nullable types to com.google.common.base.Optional<>
Preference<Optional<String>> optionalUsername = PreferenceUtil.asOptional(username);

Rx2SharedPreference.asObservable(optionalUsername).subscribe(s -> {
System.out.println("Username: " + s.orNull()); // Outputs value of "username" preference
});

Observable<Optional<String>> rx2Observable = Observable.just(Optional.fromNullable("observableName"));
rx2Observable.subscribe(Rx2SharedPreferences.asConsumer(optionalUsername)); // username is updated to "observableName"
```

Rx3:
```java
// Helper operator to convert nullable types to com.google.common.base.Optional<>
Preference<Optional<String>> optionalUsername = PreferenceUtil.asOptional(username);

Rx3SharedPreference.asObservable(optionalUsername).subscribe(s -> {
System.out.println("Username: " + s.orNull()); // Outputs value of "username" preference
});

Observable<Optional<String>> rx3Observable = Observable.just(Optional.fromNullable("observableName"));
rx3Observable.subscribe(Rx3SharedPreferences.asConsumer(optionalUsername)); // username is updated to "observableName"
```

License
-------
Expand Down Expand Up @@ -79,4 +182,4 @@ License
[12]:./LICENSE

[13]:https://img.shields.io/maven-central/v/com.frybits.rx.preferences/bom?label=bom
[14]:https://central.sonatype.com/artifact/com.frybits.rx.preferences/bom/1.1.0
[14]:https://central.sonatype.com/artifact/com.frybits.rx.preferences/bom/2.0.0
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
`kotlin-dsl`
kotlin("jvm") version "1.8.10"
kotlin("jvm") version "2.0.20"
}

dependencies {
Expand Down
7 changes: 5 additions & 2 deletions buildSrc/src/main/kotlin/com/frybits/gradle/PluginUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.android.build.api.dsl.BuildFeatures
import com.android.build.api.dsl.BuildType
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.DefaultConfig
import com.android.build.api.dsl.Installation
import com.android.build.api.dsl.ProductFlavor
import com.autonomousapps.DependencyAnalysisPlugin
import com.autonomousapps.DependencyAnalysisSubExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
Expand Down Expand Up @@ -35,8 +37,8 @@ import org.jlleitschuh.gradle.ktlint.KtlintPlugin
*/

@Suppress("UnstableApiUsage")
internal fun <BuildFeaturesT : BuildFeatures, BuildTypeT : BuildType, DefaultConfigT : DefaultConfig, ProductFlavorT : ProductFlavor, AndroidResourcesT: AndroidResources>
CommonExtension<BuildFeaturesT, BuildTypeT, DefaultConfigT, ProductFlavorT, AndroidResourcesT>.configureCommonAndroid() {
internal fun <BuildFeaturesT : BuildFeatures, BuildTypeT : BuildType, DefaultConfigT : DefaultConfig, ProductFlavorT : ProductFlavor, AndroidResourcesT: AndroidResources, InstallationT: Installation>
CommonExtension<BuildFeaturesT, BuildTypeT, DefaultConfigT, ProductFlavorT, AndroidResourcesT, InstallationT>.configureCommonAndroid() {
compileSdk = 34

defaultConfig {
Expand Down Expand Up @@ -75,6 +77,7 @@ internal fun Project.applyKtlint() {
}

internal fun Project.applyDependencyAnalysis() {
apply<DependencyAnalysisPlugin>()
configure<DependencyAnalysisSubExtension> {
issues {
onAny {
Expand Down
16 changes: 0 additions & 16 deletions core/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies {
implementation libs.kotlin.stdlib
implementation libs.androidx.annotation

api libs.guava

// Test
testImplementation libs.junit
testImplementation libs.kotlin.test
Expand Down
Loading

0 comments on commit ed04ffb

Please sign in to comment.