Skip to content

Commit 15fcee0

Browse files
committed
add setting parameter: show preview text
1 parent f1846e0 commit 15fcee0

File tree

8 files changed

+49
-17
lines changed

8 files changed

+49
-17
lines changed

lib/habr/json_parsing.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ PostPreviews parsePostPreviewsFromJson(Map<String, dynamic> data) {
6969
id: id,
7070
corporative: article['isCorporative'],
7171
title: _prepareHtmlString(article['titleHtml']),
72-
tags: article['hubs']
72+
hubs: article['hubs']
73+
.map<String>((flow) => flow['title'] as String)
74+
.toList(),
75+
htmlPreview: "<div>${article['leadData']['textHtml']}</div>",
76+
flows: article['flows']
7377
.map<String>((flow) => flow['title'] as String)
7478
.toList(),
7579
publishDate: DateTime.parse(article['timePublished']),

lib/hive/post_preview.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class PostPreviewAdapter extends TypeAdapter<PostPreview> {
1111
PostPreview read(BinaryReader reader) {
1212
final id = reader.read();
1313
final title = reader.read();
14-
final tags = reader.readList().cast<String>();
14+
final hubs = reader.readList().cast<String>();
1515
final corporative = reader.read();
1616
final publishDate = reader.read();
1717
final author = reader.read();
1818
return PostPreview(
1919
id: id,
2020
title: title,
21-
tags: tags,
21+
hubs: hubs,
2222
corporative: corporative,
2323
publishDate: publishDate,
2424
author: author,
@@ -30,7 +30,7 @@ class PostPreviewAdapter extends TypeAdapter<PostPreview> {
3030
void write(BinaryWriter writer, PostPreview obj) {
3131
writer.write(obj.id);
3232
writer.write(obj.title);
33-
writer.writeList(obj.tags);
33+
writer.writeList(obj.hubs);
3434
writer.write(obj.corporative);
3535
writer.write(obj.publishDate);
3636
writer.write(obj.author);

lib/models/post_preview.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import 'statistics.dart';
44
class PostPreview {
55
final String id;
66
final String title;
7-
final List<String> tags;
7+
final List<String> hubs;
8+
final List<String> flows;
9+
final String htmlPreview;
810
final DateTime publishDate;
911
final Author author;
1012
final Statistics statistics;
@@ -13,7 +15,9 @@ class PostPreview {
1315
const PostPreview(
1416
{this.id,
1517
this.title,
16-
this.tags,
18+
this.hubs,
19+
this.flows,
20+
this.htmlPreview,
1721
this.publishDate,
1822
this.author,
1923
this.statistics,
@@ -25,5 +29,4 @@ class PostPreviews {
2529
final List<PostPreview> previews;
2630

2731
const PostPreviews({this.previews, this.maxCountPages});
28-
2932
}

lib/pages/article/article.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class _ArticlePageState extends State<ArticlePage> {
170170
final preview = PostPreview(
171171
id: articleId,
172172
title: post.title,
173-
tags: [],
173+
hubs: [],
174174
publishDate: post.publishDate,
175175
statistics: Models.Statistics.zero(),
176176
author: post.author,

lib/pages/settings.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ class Settings extends StatelessWidget {
102102
leading: const Icon(Icons.palette),
103103
title: Text(AppLocalizations.of(context).customization),
104104
),
105+
SwitchListTile(
106+
title: Text('Использовать расширенный вид ленты'),
107+
value: settings.showPreviewText,
108+
onChanged: (val) => settings.showPreviewText = val,
109+
),
105110
ListTile(
106111
// leading: const Icon(Icons.font_download_outlined),
107112
title: Text(localizations.fontSize),

lib/stores/app_settings.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class AppSettings extends ChangeNotifier {
6262
.put('ToTimeThemeSwitch', val)
6363
.whenComplete(() => changeThemeByTime());
6464

65+
bool get showPreviewText => data.get('ShowPreviewText', defaultValue: false);
66+
set showPreviewText(bool val) => data.put('ShowPreviewText', val);
67+
6568
static bool needSetLightTheme(
6669
TimeOfDay current, TimeOfDay from, TimeOfDay to) {
6770
final timeLower = (TimeOfDay d1, TimeOfDay d2) =>

lib/stores/habr_storage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class HabrStorage {
114114

115115
return PostPreview(
116116
id: post.id,
117-
tags: [],
117+
hubs: [],
118118
title: post.title,
119119
publishDate: post.publishDate,
120120
statistics: Statistics.zero(),

lib/widgets/article_preview.dart

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
import 'package:flutter/material.dart';
2+
import 'package:habr_app/stores/app_settings.dart';
23
import 'package:habr_app/utils/date_to_text.dart';
34
import 'package:habr_app/models/post_preview.dart';
5+
import 'package:habr_app/widgets/html_view.dart';
6+
import 'package:provider/provider.dart';
47

58
import 'small_author_preview.dart';
69
import 'statistics_icons.dart';
710

811
class ArticlePreview extends StatelessWidget {
912
final PostPreview postPreview;
13+
final bool showHtml;
1014
final Function(String articleId) onPressed;
1115

12-
ArticlePreview({Key key, @required this.postPreview, this.onPressed})
13-
: super(key: key);
16+
ArticlePreview({
17+
Key key,
18+
@required this.postPreview,
19+
this.showHtml,
20+
this.onPressed,
21+
}) : super(key: key);
1422

1523
@override
1624
Widget build(BuildContext context) {
25+
final needShowHtml =
26+
showHtml ?? context.watch<AppSettings>().showPreviewText;
1727
final upIconTextStyle = const TextStyle(fontSize: 15);
1828
final statisticIconTextStyle = const TextStyle(fontSize: 15);
1929
return InkWell(
@@ -45,13 +55,20 @@ class ArticlePreview extends StatelessWidget {
4555
const SizedBox(
4656
height: 10,
4757
),
58+
if (needShowHtml && postPreview.htmlPreview != null) ...[
59+
HtmlView.unparsed(postPreview.htmlPreview),
60+
const SizedBox(
61+
height: 20,
62+
),
63+
],
4864
Text(
49-
postPreview.tags
50-
.where((String el) => !el.startsWith('Блог компании'))
51-
.join(', '),
52-
style: const TextStyle(fontSize: 15),
53-
overflow: TextOverflow.ellipsis,
54-
textAlign: TextAlign.left),
65+
postPreview.flows
66+
.where((String el) => !el.startsWith('Блог компании'))
67+
.join(', '),
68+
style: const TextStyle(fontSize: 15),
69+
overflow: TextOverflow.ellipsis,
70+
textAlign: TextAlign.left,
71+
),
5572
const SizedBox(
5673
height: 5,
5774
),

0 commit comments

Comments
 (0)