Skip to content

Commit

Permalink
[shared_preferences] Platform implementations of async api (flutter#6965
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrinneal authored Jul 30, 2024
1 parent 99e8606 commit 315ed8a
Show file tree
Hide file tree
Showing 64 changed files with 6,838 additions and 1,225 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.0

* Adds new `SharedPreferencesAsyncAndroid` API.

## 2.2.4

* Updates lint checks to ignore NewerVersionAvailable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ group 'io.flutter.plugins.sharedpreferences'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand All @@ -28,6 +30,7 @@ allprojects {
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
// Conditional for compatibility with AGP <4.2.
Expand All @@ -41,6 +44,14 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
minSdkVersion 19
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -51,8 +62,14 @@ android {
disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency', 'NewerVersionAvailable'
}
dependencies {
implementation 'androidx.datastore:datastore:1.0.0'
implementation 'androidx.datastore:datastore-preferences:1.0.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test:core-ktx:1.5.0'
testImplementation 'androidx.test.ext:junit-ktx:1.1.5'
testImplementation 'org.robolectric:robolectric:4.12.1'
testImplementation 'org.mockito:mockito-inline:5.2.0'
testImplementation 'io.mockk:mockk:1.13.12'
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.Map;
import java.util.Set;

/** SharedPreferencesPlugin */
public class SharedPreferencesPlugin implements FlutterPlugin, SharedPreferencesApi {
/** LegacySharedPreferencesPlugin */
public class LegacySharedPreferencesPlugin implements FlutterPlugin, SharedPreferencesApi {
private static final String TAG = "SharedPreferencesPlugin";
private static final String SHARED_PREFERENCES_NAME = "FlutterSharedPreferences";
private static final String LIST_IDENTIFIER = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu";
Expand All @@ -38,19 +38,19 @@ public class SharedPreferencesPlugin implements FlutterPlugin, SharedPreferences
private SharedPreferences preferences;
private SharedPreferencesListEncoder listEncoder;

public SharedPreferencesPlugin() {
public LegacySharedPreferencesPlugin() {
this(new ListEncoder());
}

@VisibleForTesting
SharedPreferencesPlugin(@NonNull SharedPreferencesListEncoder listEncoder) {
LegacySharedPreferencesPlugin(@NonNull SharedPreferencesListEncoder listEncoder) {
this.listEncoder = listEncoder;
}

private void setUp(@NonNull BinaryMessenger messenger, @NonNull Context context) {
preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
try {
SharedPreferencesApi.setup(messenger, this);
SharedPreferencesApi.setUp(messenger, this);
} catch (Exception ex) {
Log.e(TAG, "Received exception while setting up SharedPreferencesPlugin", ex);
}
Expand All @@ -63,7 +63,7 @@ public void onAttachedToEngine(@NonNull FlutterPlugin.FlutterPluginBinding bindi

@Override
public void onDetachedFromEngine(@NonNull FlutterPlugin.FlutterPluginBinding binding) {
SharedPreferencesApi.setup(binding.getBinaryMessenger(), null);
SharedPreferencesApi.setUp(binding.getBinaryMessenger(), null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v9.2.5), do not edit directly.
// Autogenerated from Pigeon (v16.0.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package io.flutter.plugins.sharedpreferences;
Expand Down Expand Up @@ -88,14 +88,14 @@ public interface SharedPreferencesApi {
* Sets up an instance of `SharedPreferencesApi` to handle messages through the
* `binaryMessenger`.
*/
static void setup(
static void setUp(
@NonNull BinaryMessenger binaryMessenger, @Nullable SharedPreferencesApi api) {
{
BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.SharedPreferencesApi.remove",
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.remove",
getCodec(),
taskQueue);
if (api != null) {
Expand All @@ -122,7 +122,7 @@ static void setup(
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.SharedPreferencesApi.setBool",
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setBool",
getCodec(),
taskQueue);
if (api != null) {
Expand Down Expand Up @@ -150,7 +150,7 @@ static void setup(
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.SharedPreferencesApi.setString",
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setString",
getCodec(),
taskQueue);
if (api != null) {
Expand Down Expand Up @@ -178,7 +178,7 @@ static void setup(
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.SharedPreferencesApi.setInt",
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setInt",
getCodec(),
taskQueue);
if (api != null) {
Expand Down Expand Up @@ -207,7 +207,7 @@ static void setup(
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.SharedPreferencesApi.setDouble",
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setDouble",
getCodec(),
taskQueue);
if (api != null) {
Expand Down Expand Up @@ -235,7 +235,7 @@ static void setup(
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.SharedPreferencesApi.setStringList",
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.setStringList",
getCodec(),
taskQueue);
if (api != null) {
Expand Down Expand Up @@ -263,7 +263,7 @@ static void setup(
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.SharedPreferencesApi.clear",
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.clear",
getCodec(),
taskQueue);
if (api != null) {
Expand Down Expand Up @@ -291,7 +291,7 @@ static void setup(
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger,
"dev.flutter.pigeon.SharedPreferencesApi.getAll",
"dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.getAll",
getCodec(),
taskQueue);
if (api != null) {
Expand Down
Loading

0 comments on commit 315ed8a

Please sign in to comment.