|
1 | 1 | /// A Minecraft News item.
|
2 | 2 | class MinecraftNews {
|
3 | 3 | /// The title of this news item.
|
4 |
| - String title; |
| 4 | + final String title; |
| 5 | + |
| 6 | + final String tag; |
| 7 | + |
| 8 | + /// The category of this news article, e.g. "Minecraft: Java Edition" |
| 9 | + final String category; |
| 10 | + |
| 11 | + /// The date on which this news article was published. |
| 12 | + final String _date; |
5 | 13 |
|
6 | 14 | /// The description of this news. Formatted in HTML.
|
7 |
| - String description; |
| 15 | + final String text; |
8 | 16 |
|
9 | 17 | /// The url to this news article on https://minecraft.net.
|
10 |
| - String url; |
| 18 | + final String url; |
11 | 19 |
|
12 | 20 | /// The id of this news item.
|
13 |
| - String id; |
| 21 | + final String id; |
| 22 | + |
| 23 | + final bool important; |
14 | 24 |
|
15 | 25 | /// The shortened url to the patch's image.
|
16 | 26 | /// Can be properly obtained from [getImageUrl].
|
17 | 27 | final String _imageUrl;
|
18 | 28 |
|
19 |
| - /// If this news item is only for demo users who do not own the game. |
20 |
| - bool forDemoUsersOnly; |
21 |
| - |
22 | 29 | MinecraftNews.fromJson(Map<String, dynamic> data)
|
23 | 30 | : title = data['title'],
|
24 |
| - description = data['description'], |
25 |
| - url = data['url'], |
| 31 | + tag = data.containsKey('tag') ? data['tag'] : '', |
| 32 | + category = data['category'], |
| 33 | + _date = data['date'], |
| 34 | + text = data['text'], |
| 35 | + url = data['readMoreLink'], |
26 | 36 | id = data['id'],
|
27 |
| - _imageUrl = data['image']['url'], |
28 |
| - forDemoUsersOnly = data['forDemoUsersOnly'] ?? false; |
| 37 | + _imageUrl = data['newsPageImage']['url'], |
| 38 | + important = data.containsKey('cardBorder') ? data['cardBorder'] : false; |
29 | 39 |
|
30 | 40 | /// Get's the url to the image of this news item. News images are
|
31 | 41 | /// usually 1200x512 pixels in size.
|
32 | 42 | String get imageUrl => 'https://launchercontent.mojang.com/$_imageUrl';
|
| 43 | + |
| 44 | + /// Get's the date at which this article was published. |
| 45 | + /// Note that this is always at midnight, as the original |
| 46 | + /// timestamp does not provide any hours/minutes. |
| 47 | + DateTime get date => DateTime.parse(_date); |
33 | 48 | }
|
0 commit comments