aboutsummaryrefslogtreecommitdiff
path: root/lib/pages/Home.dart
blob: 0e3ff5e842c45562524495fe2006268c75c27c00 (plain) (blame)
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 'dart:async';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:device_apps/device_apps.dart';

import '../components/Option.dart';
import '../components/AppList.dart';
import '../components/FixedContainer.dart';
import '../data/config.dart';
import '../data/applications.dart';
import '../data/favorites.dart';

class StatusInfoCard extends StatelessWidget {
  DateTime dateTime;

  StatusInfoCard({ this.dateTime }): super();

  final timeFormat = DateFormat('h:mm a'); // H fr 24 hrs
  final dateFormat = DateFormat('EEEE, d MMM');

  Widget buildOptionsMenu(BuildContext ctx) {
    var theme = Theme.of(ctx);

    return Dialog(
        child: Container(
            decoration: BoxDecoration(
                color: theme.backgroundColor,
            ),
            height: 120.0,
            child: ListView(
                children: [
                  Option(
                      icon: Icon(
                          Icons.brightness_4,
                          color: theme.primaryColor,
                          size: 16.0,
                          semanticLabel: 'Toggle dark mode',
                      ),
                      child: Text('Toggle dark mode'),
                      onTap: toggleTheme,
                  ),
                  Option(
                      icon: Icon(
                          Icons.refresh,
                          color: theme.primaryColor,
                          size: 16.0,
                          semanticLabel: 'Refresh',
                      ),
                      child: Text('Refresh'),
                      onTap: () {
                        refreshApplications();
                        refreshFavorites();
                      },
                  ),
                ],
            ),
        ),
    );
  }

  void showOptions(BuildContext ctx) {
    showDialog(context: ctx, builder: buildOptionsMenu);
  }

  @override
  Widget build(BuildContext ctx) {
    ThemeData theme = Theme.of(ctx);

    return Container(
        height: 100,
        padding: EdgeInsets.symmetric(vertical: 8.0),
        child: Align(
            alignment: Alignment.topLeft,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(timeFormat.format(dateTime),
                          key: Key('time'),
                          textAlign: TextAlign.left,
                          style: const TextStyle(
                              fontSize: 32.0,
                              fontWeight: FontWeight.bold,
                          ),
                      ),
                      Text(dateFormat.format(dateTime),
                          key: Key('date'),
                          textAlign: TextAlign.left,
                          style: const TextStyle(
                              fontSize: 16.0,
                              fontWeight: FontWeight.w300,
                          ),
                      ),
                    ]
                )),
                Container(
                    width: 40,
                    height: 30,
                    child: IconButton(
                        padding: const EdgeInsets.all(0.0),
                        visualDensity: const VisualDensity(vertical: 0.0, horizontal: 0.0),
                        icon: Icon(
                            Icons.more_vert,
                            color: theme.primaryColor,
                            size: 20.0,
                            semanticLabel: 'Options',
                        ),
                        tooltip: 'Options',
                        enableFeedback: true,
                        onPressed: () => showOptions(ctx),
                    ),
                ),
              ],
            ),
        ),
    );
  }
}

class HomeView extends StatelessWidget {
  DateTime dateTime;
  List<Application> favoriteApps;
  void Function(Application) openApp;
  void Function(BuildContext, Application) openOptionsMenu;

  HomeView({ this.dateTime, this.favoriteApps, this.openApp, this.openOptionsMenu }): super();

  @override
  Widget build(BuildContext ctx) {
    return FixedContainer(
        padding: const EdgeInsets.symmetric(vertical: 36.0, horizontal: 16.0),
        child: Column(
            children: [
              StatusInfoCard(dateTime: dateTime),
              Expanded(child: Container(
                child: AppList(
                    appList: favoriteApps,
                    openApp: openApp,
                    openOptionsMenu: (app) => openOptionsMenu(ctx, app),
                ),
              )),
            ],
        )
    );
  }
}