refactor(json): share scalar adapters
This commit is contained in:
@@ -7,7 +7,7 @@ part 'plex_home.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class PlexHome {
|
||||
@JsonKey(fromJson: _intOr0)
|
||||
@JsonKey(fromJson: flexibleIntOrZero)
|
||||
final int id;
|
||||
@JsonKey(readValue: readStringField, defaultValue: '')
|
||||
final String name;
|
||||
@@ -52,5 +52,3 @@ class PlexHome {
|
||||
|
||||
bool get hasMultipleUsers => users.length > 1;
|
||||
}
|
||||
|
||||
int _intOr0(Object? value) => flexibleInt(value) ?? 0;
|
||||
|
||||
@@ -7,7 +7,7 @@ part of 'plex_home.dart';
|
||||
// **************************************************************************
|
||||
|
||||
PlexHome _$PlexHomeFromJson(Map<String, dynamic> json) => PlexHome(
|
||||
id: _intOr0(json['id']),
|
||||
id: flexibleIntOrZero(json['id']),
|
||||
name: readStringField(json, 'name') as String? ?? '',
|
||||
guestUserID: flexibleInt(json['guestUserID']),
|
||||
guestUserUUID: readStringField(json, 'guestUserUUID') as String? ?? '',
|
||||
|
||||
@@ -9,7 +9,7 @@ part 'plex_home_user.g.dart';
|
||||
/// coerce tolerantly instead of hard-casting.
|
||||
@JsonSerializable()
|
||||
class PlexHomeUser {
|
||||
@JsonKey(fromJson: _intOr0)
|
||||
@JsonKey(fromJson: flexibleIntOrZero)
|
||||
final int id;
|
||||
@JsonKey(readValue: readStringField, defaultValue: '')
|
||||
final String uuid;
|
||||
@@ -63,5 +63,3 @@ class PlexHomeUser {
|
||||
bool get isGuestUser => guest;
|
||||
bool get requiresPassword => protected;
|
||||
}
|
||||
|
||||
int _intOr0(Object? v) => flexibleInt(v) ?? 0;
|
||||
|
||||
@@ -7,7 +7,7 @@ part of 'plex_home_user.dart';
|
||||
// **************************************************************************
|
||||
|
||||
PlexHomeUser _$PlexHomeUserFromJson(Map<String, dynamic> json) => PlexHomeUser(
|
||||
id: _intOr0(json['id']),
|
||||
id: flexibleIntOrZero(json['id']),
|
||||
uuid: readStringField(json, 'uuid') as String? ?? '',
|
||||
title: readStringField(json, 'title') as String? ?? 'Unknown',
|
||||
username: readStringField(json, 'username') as String?,
|
||||
|
||||
@@ -4,11 +4,9 @@ import '../../utils/json_utils.dart';
|
||||
|
||||
part 'plex_subtitle_search_result.g.dart';
|
||||
|
||||
int _flexibleIntOrZero(Object? v) => flexibleInt(v) ?? 0;
|
||||
|
||||
@JsonSerializable()
|
||||
class PlexSubtitleSearchResult {
|
||||
@JsonKey(fromJson: _flexibleIntOrZero)
|
||||
@JsonKey(fromJson: flexibleIntOrZero)
|
||||
final int id;
|
||||
@JsonKey(readValue: readStringField, defaultValue: '')
|
||||
final String key;
|
||||
|
||||
@@ -9,7 +9,7 @@ part of 'plex_subtitle_search_result.dart';
|
||||
PlexSubtitleSearchResult _$PlexSubtitleSearchResultFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => PlexSubtitleSearchResult(
|
||||
id: _flexibleIntOrZero(json['id']),
|
||||
id: flexibleIntOrZero(json['id']),
|
||||
key: readStringField(json, 'key') as String? ?? '',
|
||||
codec: readStringField(json, 'codec') as String?,
|
||||
language: readStringField(json, 'language') as String?,
|
||||
|
||||
@@ -17,7 +17,7 @@ class PlexUserProfile implements MediaServerUserProfile {
|
||||
@JsonKey(fromJson: _boolOrTrue)
|
||||
@override
|
||||
final bool autoSelectAudio;
|
||||
@JsonKey(fromJson: _intOr0)
|
||||
@JsonKey(fromJson: flexibleIntOrZero)
|
||||
final int defaultAudioAccessibility;
|
||||
@JsonKey(fromJson: _flexibleLanguage)
|
||||
@override
|
||||
@@ -31,15 +31,15 @@ class PlexUserProfile implements MediaServerUserProfile {
|
||||
@JsonKey(fromJson: flexibleCsvStringList)
|
||||
@override
|
||||
final List<String>? defaultSubtitleLanguages;
|
||||
@JsonKey(fromJson: _intOr0)
|
||||
@JsonKey(fromJson: flexibleIntOrZero)
|
||||
final int autoSelectSubtitle;
|
||||
@JsonKey(fromJson: _intOr0)
|
||||
@JsonKey(fromJson: flexibleIntOrZero)
|
||||
final int defaultSubtitleAccessibility;
|
||||
@JsonKey(fromJson: _intOr1)
|
||||
final int defaultSubtitleForced;
|
||||
@JsonKey(fromJson: _intOr1)
|
||||
final int watchedIndicator;
|
||||
@JsonKey(fromJson: _intOr0)
|
||||
@JsonKey(fromJson: flexibleIntOrZero)
|
||||
final int mediaReviewsVisibility;
|
||||
@JsonKey(fromJson: flexibleCsvStringList)
|
||||
final List<String>? mediaReviewsLanguages;
|
||||
@@ -88,5 +88,4 @@ class PlexUserProfile implements MediaServerUserProfile {
|
||||
String? _flexibleLanguage(Object? v) => flexibleCsvStringList(v)?.first;
|
||||
|
||||
bool _boolOrTrue(Object? v) => flexibleBoolNullable(v) ?? true;
|
||||
int _intOr0(Object? v) => flexibleInt(v) ?? 0;
|
||||
int _intOr1(Object? v) => flexibleInt(v) ?? 1;
|
||||
|
||||
@@ -10,18 +10,22 @@ PlexUserProfile _$PlexUserProfileFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => PlexUserProfile(
|
||||
autoSelectAudio: _boolOrTrue(json['autoSelectAudio']),
|
||||
defaultAudioAccessibility: _intOr0(json['defaultAudioAccessibility']),
|
||||
defaultAudioAccessibility: flexibleIntOrZero(
|
||||
json['defaultAudioAccessibility'],
|
||||
),
|
||||
defaultAudioLanguage: _flexibleLanguage(json['defaultAudioLanguage']),
|
||||
defaultAudioLanguages: flexibleCsvStringList(json['defaultAudioLanguages']),
|
||||
defaultSubtitleLanguage: _flexibleLanguage(json['defaultSubtitleLanguage']),
|
||||
defaultSubtitleLanguages: flexibleCsvStringList(
|
||||
json['defaultSubtitleLanguages'],
|
||||
),
|
||||
autoSelectSubtitle: _intOr0(json['autoSelectSubtitle']),
|
||||
defaultSubtitleAccessibility: _intOr0(json['defaultSubtitleAccessibility']),
|
||||
autoSelectSubtitle: flexibleIntOrZero(json['autoSelectSubtitle']),
|
||||
defaultSubtitleAccessibility: flexibleIntOrZero(
|
||||
json['defaultSubtitleAccessibility'],
|
||||
),
|
||||
defaultSubtitleForced: _intOr1(json['defaultSubtitleForced']),
|
||||
watchedIndicator: _intOr1(json['watchedIndicator']),
|
||||
mediaReviewsVisibility: _intOr0(json['mediaReviewsVisibility']),
|
||||
mediaReviewsVisibility: flexibleIntOrZero(json['mediaReviewsVisibility']),
|
||||
mediaReviewsLanguages: flexibleCsvStringList(json['mediaReviewsLanguages']),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user