~cytrogen/fluent-reader-mobile

fluent-reader-mobile/lib/models/source.dart -rw-r--r-- 1.7 KiB
28b99e81 — Cytrogen feat: add subscription search/sort, rewrite README, upgrade infrastructure 9 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
enum SourceOpenTarget {
    Local, FullContent, Webpage, External, Inherit
}

SourceOpenTarget resolveOpenTargetCascade(
  SourceOpenTarget sourceTarget,
  SourceOpenTarget groupTarget,
  SourceOpenTarget globalTarget,
) {
  if (sourceTarget != SourceOpenTarget.Inherit) return sourceTarget;
  if (groupTarget != SourceOpenTarget.Inherit) return groupTarget;
  return globalTarget;
}

class RSSSource {
  String id;
  String url;
  String? iconUrl;
  String name;
  SourceOpenTarget openTarget;
  int unreadCount;
  DateTime latest;
  String lastTitle;

  RSSSource(this.id, this.url, this.name)
    : openTarget = SourceOpenTarget.Inherit,
      latest = DateTime.now(),
      unreadCount = 0,
      lastTitle = "";

  RSSSource._privateConstructor(
    this.id, this.url, this.iconUrl, this.name, this.openTarget,
    this.unreadCount, this.latest, this.lastTitle,
  );

  RSSSource clone() {
    return RSSSource._privateConstructor(
      this.id, this.url, this.iconUrl, this.name, this.openTarget,
      this.unreadCount, this.latest, this.lastTitle,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      "sid": id,
      "url": url,
      "iconUrl": iconUrl,
      "name": name,
      "openTarget": openTarget.index,
      "latest": latest.millisecondsSinceEpoch,
      "lastTitle": lastTitle,
    };
  }

  RSSSource.fromMap(Map<String, dynamic> map)
    : id = map["sid"],
      url = map["url"],
      iconUrl = map["iconUrl"],
      name = map["name"],
      openTarget = (map["openTarget"] as int) < SourceOpenTarget.values.length
          ? SourceOpenTarget.values[map["openTarget"]]
          : SourceOpenTarget.Local,
      latest = DateTime.fromMillisecondsSinceEpoch(map["latest"]),
      lastTitle = map["lastTitle"],
      unreadCount = 0;
}