~cytrogen/fluent-reader-mobile

ref: b62144093d5def827aeb47e62253c11959615982 fluent-reader-mobile/lib/pages/settings/feed_page.dart -rw-r--r-- 4.1 KiB
b6214409 — 刘浩远 add customizable text scale 5 years 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
import 'package:fluent_reader_lite/components/list_tile_group.dart';
import 'package:fluent_reader_lite/components/my_list_tile.dart';
import 'package:fluent_reader_lite/generated/l10n.dart';
import 'package:fluent_reader_lite/models/feeds_model.dart';
import 'package:fluent_reader_lite/utils/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';

class FeedPage extends StatelessWidget {
  void _openGestureOptions(BuildContext context, bool isToRight) {
    Navigator.of(context).push(CupertinoPageRoute(
      builder: (context) => CupertinoPageScaffold(
        backgroundColor: MyColors.background,
        navigationBar: CupertinoNavigationBar(
          middle: Text(isToRight ? S.of(context).swipeRight : S.of(context).swipeLeft),
        ),
        child: Consumer<FeedsModel>(
          builder: (context, feedsModel, child) {
            final swipeOptons = [
              Tuple2(S.of(context).toggleRead, ItemSwipeOption.ToggleRead),
              Tuple2(S.of(context).toggleStar, ItemSwipeOption.ToggleStar),
              Tuple2(S.of(context).share, ItemSwipeOption.Share),
              Tuple2(S.of(context).openExternal, ItemSwipeOption.OpenExternal),
              Tuple2(S.of(context).openMenu, ItemSwipeOption.OpenMenu),
            ];
            return ListView(children: [
              ListTileGroup.fromOptions(
                swipeOptons,
                isToRight ? feedsModel.swipeR : feedsModel.swipeL,
                (v) { 
                  if (isToRight) feedsModel.swipeR = v;
                  else feedsModel.swipeL = v;
                },
              ),
            ]);
          },
        ),
      ),
    ));
  }

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      backgroundColor: MyColors.background,
      navigationBar: CupertinoNavigationBar(
        middle: Text(S.of(context).feed),
      ),
      child: Consumer<FeedsModel>(
        builder: (context, feedsModel, child) {
          final swipeOptons = {
            ItemSwipeOption.ToggleRead: S.of(context).toggleRead,
            ItemSwipeOption.ToggleStar: S.of(context).toggleStar,
            ItemSwipeOption.Share: S.of(context).share,
            ItemSwipeOption.OpenExternal: S.of(context).openExternal,
            ItemSwipeOption.OpenMenu: S.of(context).openMenu,
          };
          return ListView(
            children: [
              ListTileGroup([
                MyListTile(
                  title: Text(S.of(context).showThumb),
                  trailing: CupertinoSwitch(
                    value: feedsModel.showThumb,
                    onChanged: (v) { feedsModel.showThumb = v; },
                  ),
                  trailingChevron: false,
                ),
                MyListTile(
                  title: Text(S.of(context).showSnippet),
                  trailing: CupertinoSwitch(
                    value: feedsModel.showSnippet,
                    onChanged: (v) { feedsModel.showSnippet = v; },
                  ),
                  trailingChevron: false,
                ),
                MyListTile(
                  title: Text(S.of(context).dimRead),
                  trailing: CupertinoSwitch(
                    value: feedsModel.dimRead,
                    onChanged: (v) { feedsModel.dimRead = v; },
                  ),
                  trailingChevron: false,
                  withDivider: false,
                ),
              ], title: S.of(context).preferences),
              ListTileGroup([
                MyListTile(
                  title: Text(S.of(context).swipeRight),
                  trailing: Text(swipeOptons[feedsModel.swipeR]),
                  onTap: () { _openGestureOptions(context, true); },
                ),
                MyListTile(
                  title: Text(S.of(context).swipeLeft),
                  trailing: Text(swipeOptons[feedsModel.swipeL]),
                  onTap: () { _openGestureOptions(context, false); },
                  withDivider: false,
                ),
              ], title: S.of(context).gestures),
            ],
          );
        },
      ),
    );
  }
}