~cytrogen/fluent-reader-mobile

ref: 04b0485dd34f28501285943b0d0097b315fb637b fluent-reader-mobile/lib/models/global_model.dart -rw-r--r-- 1.9 KiB
04b0485d — Bruce Liu sort groups and sources 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
import 'dart:io';

import 'package:fluent_reader_lite/utils/store.dart';
import 'package:flutter/material.dart';

enum ThemeSetting {
  Default, Light, Dark
}

class GlobalModel with ChangeNotifier {
  ThemeSetting _theme = Store.getTheme();
  Locale _locale = Store.getLocale();
  int _keepItemsDays = Store.sp.getInt(StoreKeys.KEEP_ITEMS_DAYS) ?? 21;
  bool _syncOnStart = Store.sp.getBool(StoreKeys.SYNC_ON_START) ?? true;
  bool _inAppBrowser = Store.sp.getBool(StoreKeys.IN_APP_BROWSER) ?? Platform.isIOS;
  double _textScale = Store.sp.getDouble(StoreKeys.TEXT_SCALE);

  ThemeSetting get theme => _theme;
  set theme(ThemeSetting value) {
    if (value != _theme) {
      _theme = value;
      notifyListeners();
      Store.setTheme(value);
    }
  }
  Brightness getBrightness() {
    if (_theme == ThemeSetting.Default) return null;
    else return _theme == ThemeSetting.Light ? Brightness.light : Brightness.dark;
  }

  Locale get locale => _locale;
  set locale(Locale value) {
    if (value != _locale) {
      _locale = value;
      notifyListeners();
      Store.setLocale(value);
    }
  }

  int get keepItemsDays => _keepItemsDays;
  set keepItemsDays(int value) {
    _keepItemsDays = value;
    Store.sp.setInt(StoreKeys.KEEP_ITEMS_DAYS, value);
  }

  bool get syncOnStart => _syncOnStart;
  set syncOnStart(bool value) {
    _syncOnStart = value;
    Store.sp.setBool(StoreKeys.SYNC_ON_START, value);
  }

  bool get inAppBrowser => _inAppBrowser;
  set inAppBrowser(bool value) {
    _inAppBrowser = value;
    Store.sp.setBool(StoreKeys.IN_APP_BROWSER, value);
  }

  double get textScale => _textScale;
  set textScale(double value) {
    if (_textScale != value) {
      _textScale = value;
      notifyListeners();
      if (value == null) {
        Store.sp.remove(StoreKeys.TEXT_SCALE);
      } else {
        Store.sp.setDouble(StoreKeys.TEXT_SCALE, value);
      }
    }
  }
}