Skip to content

Commit

Permalink
Fix little errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Jan 14, 2021
1 parent aa9d483 commit 2593a66
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 76 deletions.
11 changes: 2 additions & 9 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
class PauloniaRemoteConfConstants{

class PauloniaRemoteConfConstants {
static const int REMOTE_CONF_DEFAULT_EXPIRATION_TIME_IN_HOURS = 10;

}

enum PRCType{
STRING,
INT,
DOUBLE,
BOOL
}
enum PRCType { STRING, INT, DOUBLE, BOOL }
27 changes: 11 additions & 16 deletions lib/paulonia_remote_conf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ library paulonia_remote_conf;
import 'package:paulonia_remote_conf/constants.dart';
import 'package:paulonia_remote_conf/remote_conf_value.dart';
import 'package:paulonia_remote_conf/paulonia_remote_conf_mobile.dart'
if (dart.library.html) 'package:paulonia_remote_conf/paulonia_remote_conf_web.dart';

class PauloniaRemoteConf{
if (dart.library.html) 'package:paulonia_remote_conf/paulonia_remote_conf_web.dart';

class PauloniaRemoteConf {
/// Get the map of default values
static Map<String, dynamic> get defaultValues => PauloniaRemoteConfService.defaultValues;
static Map<String, dynamic> get defaultValues =>
PauloniaRemoteConfService.defaultValues;

/// Initialize the service
///
Expand All @@ -17,29 +17,24 @@ class PauloniaRemoteConf{
/// app is running on release.
/// Set [expirationTimeInHours] with the time that the functions stores the values
/// in cache (only for mobile).
static Future<void> init(
Map<String, dynamic> defaultValues, {
int expirationTimeInHours = PauloniaRemoteConfConstants
.REMOTE_CONF_DEFAULT_EXPIRATION_TIME_IN_HOURS
}){
return PauloniaRemoteConfService.initRemoteConf(
defaultValues,
expirationTimeInHours: expirationTimeInHours
);
static Future<void> init(Map<String, dynamic> defaultValues,
{int expirationTimeInHours = PauloniaRemoteConfConstants
.REMOTE_CONF_DEFAULT_EXPIRATION_TIME_IN_HOURS}) {
return PauloniaRemoteConfService.initRemoteConf(defaultValues,
expirationTimeInHours: expirationTimeInHours);
}

/// Get the value of [keyName] with [rcType]
///
/// This function converts the value in the desire type.
static dynamic get(String keyName, PRCType rcType){
static dynamic get(String keyName, PRCType rcType) {
return PauloniaRemoteConfService.get(keyName, rcType);
}

/// Get the value in [keyName]
///
/// This function returns the value without any conversion.
static PRemoteConfigValue getValue(String keyName){
static PRemoteConfigValue getValue(String keyName) {
return PauloniaRemoteConfService.getValue(keyName);
}

}
27 changes: 11 additions & 16 deletions lib/paulonia_remote_conf_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:paulonia_remote_conf/constants.dart';
import 'package:paulonia_remote_conf/remote_conf_value.dart';
import 'package:paulonia_utils/paulonia_utils.dart';

class PauloniaRemoteConfService{

class PauloniaRemoteConfService {
/// Remote configuration instance
static RemoteConfig _remoteConfig;

Expand All @@ -21,28 +20,25 @@ class PauloniaRemoteConfService{
/// app is running on release.
/// Set [expirationTimeInHours] with the time that the functions stores the values
/// in cache.
static Future<void> initRemoteConf(
Map<String, dynamic> defaultValues, {
int expirationTimeInHours = PauloniaRemoteConfConstants
.REMOTE_CONF_DEFAULT_EXPIRATION_TIME_IN_HOURS
}) async{
static Future<void> initRemoteConf(Map<String, dynamic> defaultValues,
{int expirationTimeInHours = PauloniaRemoteConfConstants
.REMOTE_CONF_DEFAULT_EXPIRATION_TIME_IN_HOURS}) async {
_remoteConfig = await RemoteConfig.instance;
_defaultValues = defaultValues;
await _remoteConfig.setDefaults(_defaultValues);
if(PUtils.isOnRelease() && (await PUtils.checkNetwork())){
if (PUtils.isOnRelease() && (await PUtils.checkNetwork())) {
await _remoteConfig.fetch(
expiration: Duration(hours: expirationTimeInHours)
);
expiration: Duration(hours: expirationTimeInHours));
}
await _remoteConfig.activateFetched();
}

/// Get the value of [keyName] with [rcType]
///
/// This function converts the value in the desire type.
static dynamic get(String keyName, PRCType rcType){
if(PUtils.isOnTest()) return _defaultValues[keyName];
switch(rcType){
static dynamic get(String keyName, PRCType rcType) {
if (PUtils.isOnTest()) return _defaultValues[keyName];
switch (rcType) {
case PRCType.STRING:
return _remoteConfig.getString(keyName);
case PRCType.INT:
Expand All @@ -59,8 +55,7 @@ class PauloniaRemoteConfService{
/// Get the value in [keyName]
///
/// This function returns the value without any conversion.
static PRemoteConfigValue getValue(String keyName){
static PRemoteConfigValue getValue(String keyName) {
return PRemoteConfigValue(_remoteConfig.getValue(keyName));
}

}
}
34 changes: 12 additions & 22 deletions lib/paulonia_remote_conf_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:paulonia_remote_conf/constants.dart';
import 'package:paulonia_remote_conf/remote_conf_value.dart';
import 'package:paulonia_utils/paulonia_utils.dart';

class PauloniaRemoteConfService{

class PauloniaRemoteConfService {
/// Remote configuration instance
static final _remoteConfig = fb.remoteConfig();

Expand All @@ -20,15 +19,13 @@ class PauloniaRemoteConfService{
/// [defaultValues]. The function fetch the values from the server if the
/// app is running on release.
/// In web, [expirationTimeInHours] is useless.
static Future<void> initRemoteConf(
Map<String, dynamic> defaultValues, {
int expirationTimeInHours = PauloniaRemoteConfConstants
.REMOTE_CONF_DEFAULT_EXPIRATION_TIME_IN_HOURS
}) async{
static Future<void> initRemoteConf(Map<String, dynamic> defaultValues,
{int expirationTimeInHours = PauloniaRemoteConfConstants
.REMOTE_CONF_DEFAULT_EXPIRATION_TIME_IN_HOURS}) async {
_defaultValues = defaultValues;
await _remoteConfig.ensureInitialized();
_remoteConfig.defaultConfig = _defaultValues;
if(PUtils.isOnRelease() && (await PUtils.checkNetwork())){
if (PUtils.isOnRelease() && (await PUtils.checkNetwork())) {
await _remoteConfig.fetch();
}
await _remoteConfig.activate();
Expand All @@ -37,9 +34,9 @@ class PauloniaRemoteConfService{
/// Get the value of [keyName] with [rcType]
///
/// This function converts the value in the desire type.
static dynamic get(String keyName, PRCType rcType){
if(PUtils.isOnTest()) return _defaultValues[keyName];
switch(rcType){
static dynamic get(String keyName, PRCType rcType) {
if (PUtils.isOnTest()) return _defaultValues[keyName];
switch (rcType) {
case PRCType.STRING:
return _remoteConfig.getString(keyName);
case PRCType.INT:
Expand All @@ -49,21 +46,14 @@ class PauloniaRemoteConfService{
case PRCType.BOOL:
return _remoteConfig.getBoolean(keyName);
default:
return PRemoteConfigValue(
_remoteConfig.getValue(keyName)
);
return PRemoteConfigValue(_remoteConfig.getValue(keyName));
}

}

/// Get the value in [keyName]
///
/// This function returns the value without any conversion.
static PRemoteConfigValue getValue(String keyName){
return PRemoteConfigValue(
_remoteConfig.getValue(keyName)
);
static PRemoteConfigValue getValue(String keyName) {
return PRemoteConfigValue(_remoteConfig.getValue(keyName));
}


}
}
6 changes: 2 additions & 4 deletions lib/remote_conf_value.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:paulonia_remote_conf/remote_conf_value_mobile.dart'
if (dart.library.html) 'package:paulonia_remote_conf/remote_conf_value_web.dart';

class PRemoteConfigValue{

class PRemoteConfigValue {
final _value;

PRemoteConfigValue(
Expand All @@ -16,5 +15,4 @@ class PRemoteConfigValue{
int asInt() => PRemoteConfigValueService.asInt(_value);

String asString() => PRemoteConfigValueService.asString(_value);

}
}
6 changes: 2 additions & 4 deletions lib/remote_conf_value_mobile.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'package:firebase_remote_config/firebase_remote_config.dart';

class PRemoteConfigValueService{

class PRemoteConfigValueService {
static bool asBool(RemoteConfigValue value) => value.asBool();

static double asDouble(RemoteConfigValue value) => value.asDouble();

static int asInt(RemoteConfigValue value) => value.asInt();

static String asString(RemoteConfigValue value) => value.asString();

}
}
9 changes: 4 additions & 5 deletions lib/remote_conf_value_web.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'package:firebase/firebase.dart' as fb;

class PRemoteConfigValueService{

class PRemoteConfigValueService {
static bool asBool(fb.RemoteConfigValue value) => value.asBoolean();

static double asDouble(fb.RemoteConfigValue value) => value.asNumber()?.toDouble();
static double asDouble(fb.RemoteConfigValue value) =>
value.asNumber()?.toDouble();

static int asInt(fb.RemoteConfigValue value) => value.asNumber()?.toInt();

static String asString(fb.RemoteConfigValue value) => value.asString();

}
}

0 comments on commit 2593a66

Please sign in to comment.