forked from hiddify/hiddify-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd4c5ee
commit 702c59c
Showing
21 changed files
with
503 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:dart_mappable/dart_mappable.dart'; | ||
import 'package:dartx/dartx.dart'; | ||
import 'package:hiddify/core/localization/translations.dart'; | ||
|
||
part 'optional_range.mapper.dart'; | ||
|
||
@MappableClass() | ||
class OptionalRange with OptionalRangeMappable { | ||
const OptionalRange({this.min, this.max}); | ||
|
||
final int? min; | ||
final int? max; | ||
|
||
String format() => [min, max].whereNotNull().join("-"); | ||
String present(TranslationsEn t) => | ||
format().isEmpty ? t.general.notSet : format(); | ||
|
||
factory OptionalRange._fromString( | ||
String input, { | ||
bool allowEmpty = true, | ||
}) => | ||
switch (input.split("-")) { | ||
[final String val] when val.isEmpty && allowEmpty => | ||
const OptionalRange(), | ||
[final String min] => OptionalRange(min: int.parse(min)), | ||
[final String min, final String max] => OptionalRange( | ||
min: int.parse(min), | ||
max: int.parse(max), | ||
), | ||
_ => throw Exception("Invalid range: $input"), | ||
}; | ||
|
||
static OptionalRange? tryParse( | ||
String input, { | ||
bool allowEmpty = false, | ||
}) { | ||
try { | ||
return OptionalRange._fromString(input); | ||
} catch (_) { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
class OptionalRangeJsonMapper extends SimpleMapper<OptionalRange> { | ||
const OptionalRangeJsonMapper(); | ||
|
||
@override | ||
OptionalRange decode(dynamic value) => | ||
OptionalRange._fromString(value as String); | ||
|
||
@override | ||
dynamic encode(OptionalRange self) => self.format(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:dart_mappable/dart_mappable.dart'; | ||
|
||
class IntervalInSecondsConverter implements JsonConverter<Duration, int> { | ||
const IntervalInSecondsConverter(); | ||
class IntervalInSecondsMapper extends SimpleMapper<Duration> { | ||
const IntervalInSecondsMapper(); | ||
|
||
@override | ||
Duration fromJson(int json) => Duration(seconds: json); | ||
Duration decode(dynamic value) => Duration(seconds: value as int); | ||
|
||
@override | ||
int toJson(Duration object) => object.inSeconds; | ||
dynamic encode(Duration self) => self.inSeconds; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.