mirror of
https://github.com/ente-io/ente.git
synced 2025-07-16 03:32:58 +00:00
71 lines
1.7 KiB
Dart
71 lines
1.7 KiB
Dart
import 'dart:convert';
|
|
|
|
/// Used to store the display settings of a code.
|
|
class CodeDisplay {
|
|
final bool pinned;
|
|
final bool trashed;
|
|
final int lastUsedAt;
|
|
final int tapCount;
|
|
final List<String> tags;
|
|
|
|
CodeDisplay({
|
|
this.pinned = false,
|
|
this.trashed = false,
|
|
this.lastUsedAt = 0,
|
|
this.tapCount = 0,
|
|
this.tags = const [],
|
|
});
|
|
|
|
// copyWith
|
|
CodeDisplay copyWith({
|
|
bool? pinned,
|
|
bool? trashed,
|
|
int? lastUsedAt,
|
|
int? tapCount,
|
|
List<String>? tags,
|
|
}) {
|
|
final bool updatedPinned = pinned ?? this.pinned;
|
|
final bool updatedTrashed = trashed ?? this.trashed;
|
|
final int updatedLastUsedAt = lastUsedAt ?? this.lastUsedAt;
|
|
final int updatedTapCount = tapCount ?? this.tapCount;
|
|
final List<String> updatedTags = tags ?? this.tags;
|
|
|
|
return CodeDisplay(
|
|
pinned: updatedPinned,
|
|
trashed: updatedTrashed,
|
|
lastUsedAt: updatedLastUsedAt,
|
|
tapCount: updatedTapCount,
|
|
tags: updatedTags,
|
|
);
|
|
}
|
|
|
|
factory CodeDisplay.fromJson(Map<String, dynamic>? json) {
|
|
if (json == null) {
|
|
return CodeDisplay();
|
|
}
|
|
return CodeDisplay(
|
|
pinned: json['pinned'] ?? false,
|
|
trashed: json['trashed'] ?? false,
|
|
lastUsedAt: json['lastUsedAt'] ?? 0,
|
|
tapCount: json['tapCount'] ?? 0,
|
|
);
|
|
}
|
|
|
|
static CodeDisplay? fromUri(Uri uri) {
|
|
if (!uri.queryParameters.containsKey("codeDisplay")) return null;
|
|
final String codeDisplay = uri.queryParameters['codeDisplay']!;
|
|
final decodedDisplay = jsonDecode(codeDisplay);
|
|
|
|
return CodeDisplay.fromJson(decodedDisplay);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'pinned': pinned,
|
|
'trashed': trashed,
|
|
'lastUsedAt': lastUsedAt,
|
|
'tapCount': tapCount,
|
|
};
|
|
}
|
|
}
|