Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major 7 #264

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "io.qonversion.sandwich:sandwich:2.0.2"
implementation "io.qonversion.sandwich:sandwich:3.0.0"
implementation 'com.google.code.gson:gson:2.9.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class QonversionPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
"offerings" -> {
return offerings(result)
}
"userProperties" -> {
return userProperties(result)
}
"remoteConfig" -> {
return remoteConfig(result)
}
Expand Down Expand Up @@ -222,6 +225,10 @@ class QonversionPlugin : MethodCallHandler, FlutterPlugin, ActivityAware {
qonversionSandwich.offerings(result.toJsonResultListener())
}

private fun userProperties(result: Result) {
qonversionSandwich.userProperties(result.toJsonResultListener())
}

private fun remoteConfig(result: Result) {
qonversionSandwich.remoteConfig(result.toJsonResultListener())
}
Expand Down
4 changes: 2 additions & 2 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class _HomeViewState extends State<HomeView> {
child: Text('Set custom userId'),
color: Colors.blue,
textColor: Colors.white,
onPressed: () => Qonversion.getSharedInstance().setProperty(
QUserProperty.customUserId, 'userId')),
onPressed: () => Qonversion.getSharedInstance().setUserProperty(
QUserPropertyKey.customUserId, 'userId')),
),
Padding(
padding: const EdgeInsets.only(
Expand Down
27 changes: 23 additions & 4 deletions example/lib/params_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,31 @@ class ParamsView extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FlatButton(
child: Text('Get user properties'),
color: Colors.amber,
textColor: Colors.white,
onPressed: () async {
try {
QUserProperties userProperties =
await Qonversion.getSharedInstance().userProperties();
userProperties.properties.forEach((userProperty) {
print('User property - key: ' +
userProperty.key +
', value: ' +
userProperty.value);
});
} catch (e) {
// handle error here
}
},
),
FlatButton(
child: Text('Set User ID'),
color: Colors.green,
textColor: Colors.white,
onPressed: () {
Qonversion.getSharedInstance().setProperty(QUserProperty.customUserId, 'customId');
Qonversion.getSharedInstance().setUserProperty(QUserPropertyKey.customUserId, 'customId');
print('did set user id');
},
),
Expand All @@ -31,17 +50,17 @@ class ParamsView extends StatelessWidget {
color: Colors.blue,
textColor: Colors.white,
onPressed: () {
Qonversion.getSharedInstance().setUserProperty('customProperty', 'customValue');
Qonversion.getSharedInstance().setCustomUserProperty('customProperty', 'customValue');
print('did set user property');
},
),
for (final v in QUserProperty.values)
for (final v in QUserPropertyKey.values)
FlatButton(
child: Text('Set ${describeEnum(v)}'),
color: Colors.purple,
textColor: Colors.white,
onPressed: () {
Qonversion.getSharedInstance().setProperty(v, 'email@email.com');
Qonversion.getSharedInstance().setUserProperty(v, 'email@email.com');
print('did set property');
},
),
Expand Down
14 changes: 12 additions & 2 deletions ios/Classes/SwiftQonversionPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ public class SwiftQonversionPlugin: NSObject, FlutterPlugin {
return result(nil)

case "userInfo":
qonversionSandwich?.userInfo(getDefaultCompletion(result))
return result(nil)
return userInfo(result)

case "userProperties":
return userProperties(result)

case "presentCodeRedemptionSheet":
return presentCodeRedemptionSheet(result)
Expand Down Expand Up @@ -226,6 +228,14 @@ public class SwiftQonversionPlugin: NSObject, FlutterPlugin {
private func remoteConfig(_ result: @escaping FlutterResult) {
qonversionSandwich?.remoteConfig(getJsonCompletion(result))
}

private func userInfo(_ result: @escaping FlutterResult) {
qonversionSandwich?.userInfo(getDefaultCompletion(result))
}

private func userProperties(_ result: @escaping FlutterResult) {
qonversionSandwich?.userProperties(getJsonCompletion(result))
}

private func restore(_ result: @escaping FlutterResult) {
qonversionSandwich?.restore(getDefaultCompletion(result))
Expand Down
2 changes: 1 addition & 1 deletion ios/qonversion_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '9.0'
s.dependency "QonversionSandwich", "2.0.2"
s.dependency "QonversionSandwich", "3.0.0"

# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
Expand Down
2 changes: 2 additions & 0 deletions lib/qonversion_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export 'src/dto/remote_config.dart';
export 'src/dto/screen_presentation_config.dart';
export 'src/dto/screen_presentation_style.dart';
export 'src/dto/user.dart';
export 'src/dto/user_properties.dart';
export 'src/dto/user_property.dart';
export 'src/dto/user_property_key.dart';
export 'src/dto/sk_product/discount_payment_mode.dart';
export 'src/dto/sk_product/subscription_period_unit.dart';
export 'src/qonversion.dart';
Expand Down
95 changes: 95 additions & 0 deletions lib/src/dto/user_properties.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'package:collection/collection.dart' show IterableExtension;
import 'package:json_annotation/json_annotation.dart';
import 'package:qonversion_flutter/qonversion_flutter.dart';

part 'user_properties.g.dart';

@JsonSerializable(createToJson: false)
class QUserProperties {
/// List of all user properties.
@JsonKey(name: "properties")
final List<QUserProperty> properties;

/// List of user properties, set for the Qonversion defined keys.
/// This is a subset of all [properties] list.
/// See [Qonversion.setUserProperty].
final List<QUserProperty> definedProperties;

/// List of user properties, set for custom keys.
/// This is a subset of all [properties] list.
/// See [Qonversion.setCustomUserProperty].
final List<QUserProperty> customProperties;

/// Map of all user properties.
/// This is a flattened version of the [properties] list as a key-value map.
final Map<String, String> flatPropertiesMap;

/// Map of user properties, set for the Qonversion defined keys.
/// This is a flattened version of the [definedProperties] list as a key-value map.
/// See [Qonversion.setUserProperty].
final Map<QUserPropertyKey, String> flatDefinedPropertiesMap;

/// Map of user properties, set for custom keys.
/// This is a flattened version of the [customProperties] list as a key-value map.
/// See [Qonversion.setCustomUserProperty].
final Map<String, String> flatCustomPropertiesMap;

QUserProperties._(
this.properties,
this.definedProperties,
this.customProperties,
this.flatPropertiesMap,
this.flatDefinedPropertiesMap,
this.flatCustomPropertiesMap,
);

factory QUserProperties(List<QUserProperty> properties) {
final List<QUserProperty> definedProperties = properties.whereNot(
(userProperty) => userProperty.definedKey == QUserPropertyKey.custom
).toList();
final List<QUserProperty> customProperties = properties.where(
(userProperty) => userProperty.definedKey == QUserPropertyKey.custom
).toList();

final Map<String, String> flatPropertiesMap = Map.fromIterable(
properties,
key: (userProperty) => userProperty.key,
value: (userProperty) => userProperty.value,
);

final Map<QUserPropertyKey, String> flatDefinedPropertiesMap = Map.fromIterable(
definedProperties,
key: (userProperty) => userProperty.definedKey,
value: (userProperty) => userProperty.value,
);

final Map<String, String> flatCustomPropertiesMap = Map.fromIterable(
customProperties,
key: (userProperty) => userProperty.key,
value: (userProperty) => userProperty.value,
);

return QUserProperties._(
properties,
definedProperties,
customProperties,
flatPropertiesMap,
flatDefinedPropertiesMap,
flatCustomPropertiesMap,
);
}

factory QUserProperties.fromJson(Map<String, dynamic> json) =>
_$QUserPropertiesFromJson(json);

/// Searches for a property with the given property [key] in all properties list.
QUserProperty? getProperty(String key) {
return properties.firstWhereOrNull((userProperty) => userProperty.key == key);
}

/// Searches for a property with the given Qonversion defined property [key]
/// in defined properties list.
QUserProperty? getDefinedProperty(QUserPropertyKey key) {
return definedProperties.firstWhereOrNull((userProperty) => userProperty.definedKey == key);
}
}
15 changes: 15 additions & 0 deletions lib/src/dto/user_properties.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 25 additions & 11 deletions lib/src/dto/user_property.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
enum QUserProperty {
email,
name,
kochavaDeviceId,
appsFlyerUserId,
adjustAdId,
customUserId,
facebookAttribution,
firebaseAppInstanceId,
appSetId, // Android only
advertisingId, // iOS only
import 'package:json_annotation/json_annotation.dart';
import 'package:qonversion_flutter/src/dto/user_property_key.dart';
import 'package:qonversion_flutter/src/internal/mapper.dart';

part 'user_property.g.dart';

@JsonSerializable(createToJson: false)
class QUserProperty {
@JsonKey(name: "key")
final String key;

@JsonKey(name: "value")
final String value;

final QUserPropertyKey definedKey;

QUserProperty._(this.key, this.value, this.definedKey);

factory QUserProperty(String key, String value) {
final calculatedKey = QMapper.userPropertyKeyFromString(key);
return QUserProperty._(key, value, calculatedKey);
}

factory QUserProperty.fromJson(Map<String, dynamic> json) =>
_$QUserPropertyFromJson(json);
}
14 changes: 14 additions & 0 deletions lib/src/dto/user_property.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions lib/src/dto/user_property_key.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
enum QUserPropertyKey {
email,
name,
kochavaDeviceId,
appsFlyerUserId,
adjustAdId,
customUserId,
facebookAttribution, // Android only
firebaseAppInstanceId,
appSetId, // Android only
advertisingId, // iOS only
custom,
}
1 change: 1 addition & 0 deletions lib/src/internal/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Constants {
static const mRestore = 'restore';
static const mSetDefinedUserProperty = 'setDefinedUserProperty';
static const mSetCustomUserProperty = 'setCustomUserProperty';
static const mUserProperties = 'userProperties';
static const mSetEntitlementsCacheLifetime = 'setEntitlementsCacheLifetime';
static const mSyncPurchases = 'syncPurchases';
static const mAddAttributionData = 'addAttributionData';
Expand Down
35 changes: 35 additions & 0 deletions lib/src/internal/mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,41 @@ class QMapper {
.map((key, value) => MapEntry(key, QEligibility.fromJson(value)));
}

static QUserPropertyKey userPropertyKeyFromString(String sourceKey) {
switch (sourceKey) {
case '_q_email':
return QUserPropertyKey.email;
case '_q_name':
return QUserPropertyKey.name;
case '_q_kochava_device_id':
return QUserPropertyKey.kochavaDeviceId;
case '_q_appsflyer_user_id':
return QUserPropertyKey.appsFlyerUserId;
case '_q_adjust_adid':
return QUserPropertyKey.adjustAdId;
case '_q_custom_user_id':
return QUserPropertyKey.customUserId;
case '_q_fb_attribution':
return QUserPropertyKey.facebookAttribution;
case '_q_firebase_instance_id':
return QUserPropertyKey.firebaseAppInstanceId;
case '_q_app_set_id':
return QUserPropertyKey.appSetId;
case '_q_advertising_id':
return QUserPropertyKey.advertisingId;
}

return QUserPropertyKey.custom;
}

static QUserProperties? userPropertiesFromJson(String? jsonString) {
if (jsonString == null) return null;

final propertiesMap = Map<String, dynamic>.from(jsonDecode(jsonString));

return QUserProperties.fromJson(propertiesMap);
}

static SKProductWrapper? skProductFromJson(dynamic json) {
if (json == null) return null;

Expand Down
Loading