~cytrogen/fluent-reader-mobile

ref: 28b99e817dde641dec7cce333f69d2911758df23 fluent-reader-mobile/lib/components/subscription_item.dart -rw-r--r-- 4.5 KiB
28b99e81 — Cytrogen feat: add subscription search/sort, rewrite README, upgrade infrastructure 4 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import 'package:fluent_reader_lite/components/dismissible_background.dart';
import 'package:fluent_reader_lite/components/favicon.dart';
import 'package:fluent_reader_lite/components/mark_all_action_sheet.dart';
import 'package:fluent_reader_lite/components/time_text.dart';
import 'package:fluent_reader_lite/models/source.dart';
import 'package:fluent_reader_lite/utils/global.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart' hide Badge;
import 'package:flutter/services.dart';

import 'badge.dart';

class SubscriptionItem extends StatefulWidget {
  final RSSSource source;

  SubscriptionItem(this.source, {Key? key}) : super(key: key);

  @override
  _SubscriptionItemState createState() => _SubscriptionItemState();
}

class _SubscriptionItemState extends State<SubscriptionItem> {
  bool pressed = false;

  void _openSourcePage() async {
    await Global.feedsModel.initSourcesFeed([widget.source.id]);
    Navigator.of(context).pushNamed("/feed", arguments: widget.source.name);
  }

  static const _dismissThresholds = {
    DismissDirection.horizontal: 0.25,
  };

  Future<bool> _onDismiss(DismissDirection direction) async {
    HapticFeedback.mediumImpact();
    if (direction == DismissDirection.startToEnd) {
      showCupertinoModalPopup(
        context: context,
        builder: (context) => MarkAllActionSheet({widget.source.id}),
      );
    } else {
      Navigator.of(context, rootNavigator: true).pushNamed(
        "/settings/sources/edit",
        arguments: widget.source.id,
      );
    }
    return false;
  }

  @override
  Widget build(BuildContext context) {
    final _titleStyle = TextStyle(
      fontSize: 16,
      color: CupertinoColors.label.resolveFrom(context),
      fontWeight: FontWeight.bold,
    );
    final _descStyle = TextStyle(
      fontSize: 16,
      color: CupertinoColors.secondaryLabel.resolveFrom(context),
    );
    final _timeStyle = TextStyle(
      fontSize: 14,
      color: CupertinoColors.secondaryLabel.resolveFrom(context),
    );
    final topLine = Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Expanded(
          child: Row(children: [
            Padding(
              padding: EdgeInsets.only(right: 8),
              child: Favicon(widget.source),
            ),
            Expanded(
              child: Text(
                widget.source.name,
                style: _titleStyle,
                overflow: TextOverflow.ellipsis,
              ),
            ),
          ]),
        ),
        TimeText(widget.source.latest, style: _timeStyle),
      ],
    );
    final bottomLine = Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Expanded(
          child: Text(widget.source.lastTitle,
              style: _descStyle, overflow: TextOverflow.ellipsis),
        ),
        if (widget.source.unreadCount > 0) Badge(widget.source.unreadCount),
      ],
    );
    final body = GestureDetector(
      onTapDown: (_) {
        setState(() {
          pressed = true;
        });
      },
      onTapUp: (_) {
        setState(() {
          pressed = false;
        });
      },
      onTapCancel: () {
        setState(() {
          pressed = false;
        });
      },
      onTap: _openSourcePage,
      child: Column(
        children: [
          Container(
            constraints: BoxConstraints(minHeight: 64),
            color: pressed
                ? CupertinoColors.systemGrey4.resolveFrom(context)
                : CupertinoColors.systemBackground.resolveFrom(context),
            child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  topLine,
                  Padding(padding: EdgeInsets.only(top: 4)),
                  bottomLine
                ],
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 16),
            child: Divider(
                color: CupertinoColors.systemGrey4.resolveFrom(context),
                height: 1),
          ),
        ],
      ),
    );
    return Dismissible(
      key: Key("D-${widget.source.id}"),
      background: DismissibleBackground(CupertinoIcons.checkmark_circle, true),
      secondaryBackground:
          DismissibleBackground(CupertinoIcons.pencil_circle, false),
      dismissThresholds: _dismissThresholds,
      confirmDismiss: _onDismiss,
      child: body,
    );
  }
}