|
1 | | -import 'package:adaptive_dialog/adaptive_dialog.dart'; |
2 | | -import 'package:flutter/widgets.dart'; |
3 | | -import 'package:price_tracker/models/product.dart'; |
4 | | -import 'package:price_tracker/screens/settings/settings.dart'; |
5 | | -import 'package:price_tracker/services/backup.dart'; |
6 | | -import 'package:price_tracker/services/database.dart'; |
7 | | -import 'package:price_tracker/services/init.dart'; |
8 | | -import 'package:price_tracker/services/product_utils.dart'; |
9 | | -import 'package:toast/toast.dart'; |
10 | | -import 'package:workmanager/workmanager.dart'; |
11 | | - |
12 | | -class Settings extends State<SettingsScreen> { |
13 | | - static const String VERSION = "0.1.4"; |
14 | | - static const String APP_NAME = "Price Tracker BETA"; |
15 | | - |
16 | | - Product testProduct = Product.fromMap({ |
17 | | - "_id": 0, |
18 | | - "name": |
19 | | - "Apple iPad (10.2-inch, WiFi, 32GB) - Gold (latest model) - with extra dolphins", |
20 | | - "productUrl": "testUrl.com", |
21 | | - "prices": "[-1.0, 269.0, 260.0]", |
22 | | - "dates": |
23 | | - "[2020-07-02 00:00:00.000, 2020-07-03 15:43:12.345, 2020-07-04 04:00:45.000]", |
24 | | - "targetPrice": "261.0", |
25 | | - "imageUrl": "", |
26 | | - "parseSuccess": "true", |
27 | | - }); |
28 | | - |
29 | | - showToast(String text, {int sec = 2}) => |
30 | | - Toast.show(text, context, duration: sec); |
31 | | - |
32 | | - clearDB() async { |
33 | | - OkCancelResult result = await showOkCancelAlertDialog( |
34 | | - context: context, |
35 | | - title: "Do you really want to empty the database?", |
36 | | - message: "All tracked products will be lost without a backup", |
37 | | - okLabel: "Clear DB", |
38 | | - barrierDismissible: true, |
39 | | - isDestructiveAction: true, |
40 | | - ); |
41 | | - if (result == OkCancelResult.ok) { |
42 | | - DatabaseService _db = await DatabaseService.getInstance(); |
43 | | - if (await _db.deleteAll() > 0) { |
44 | | - showToast("Database cleared!"); |
45 | | - navigatorKey.currentState |
46 | | - .pushNamedAndRemoveUntil("/", (route) => false); |
47 | | - } else |
48 | | - showToast("Database already empty"); |
49 | | - } |
50 | | - } |
51 | | - |
52 | | - backup() async { |
53 | | - if (await BackupService.instance.backup()) |
54 | | - showToast("Backup file saved"); |
55 | | - else |
56 | | - showToast("Error saving backup file"); |
57 | | - } |
58 | | - |
59 | | - restore() async { |
60 | | - if (await BackupService.instance.restore()) { |
61 | | - showToast("Products loaded from backup"); |
62 | | - navigatorKey.currentState.pushNamedAndRemoveUntil("/", (route) => false); |
63 | | - } else |
64 | | - showToast("Error reading backup file"); |
65 | | - } |
66 | | - |
67 | | - void testPriceFallNotification() { |
68 | | - sendPriceFallNotification(testProduct); |
69 | | - } |
70 | | - |
71 | | - void testUnderTargetNotification() { |
72 | | - sendUnderTargetNotification(testProduct); |
73 | | - } |
74 | | - |
75 | | - void testAvailableAgainNotification() { |
76 | | - sendAvailableAgainNotification(testProduct); |
77 | | - } |
78 | | - |
79 | | - void testBackgroundService() { |
80 | | - Workmanager.registerOneOffTask( |
81 | | - "manualPriceScraping", "Manual Price Tracker Scraper"); |
82 | | - } |
83 | | - |
84 | | - @override |
85 | | - Widget build(BuildContext context) => SettingsScreenView(this); |
86 | | -} |
| 1 | +import 'package:adaptive_dialog/adaptive_dialog.dart'; |
| 2 | +import 'package:flutter/widgets.dart'; |
| 3 | +import 'package:price_tracker/models/product.dart'; |
| 4 | +import 'package:price_tracker/screens/settings/settings.dart'; |
| 5 | +import 'package:price_tracker/services/backup.dart'; |
| 6 | +import 'package:price_tracker/services/database.dart'; |
| 7 | +import 'package:price_tracker/services/init.dart'; |
| 8 | +import 'package:price_tracker/services/product_utils.dart'; |
| 9 | +import 'package:toast/toast.dart'; |
| 10 | +import 'package:workmanager/workmanager.dart'; |
| 11 | + |
| 12 | +class Settings extends State<SettingsScreen> { |
| 13 | + static const String VERSION = "0.1.5"; |
| 14 | + static const String APP_NAME = "Price Tracker BETA"; |
| 15 | + |
| 16 | + Product testProduct = Product.fromMap({ |
| 17 | + "_id": 0, |
| 18 | + "name": |
| 19 | + "Apple iPad (10.2-inch, WiFi, 32GB) - Gold (latest model) - with extra dolphins", |
| 20 | + "productUrl": "testUrl.com", |
| 21 | + "prices": "[-1.0, 269.0, 260.0]", |
| 22 | + "dates": |
| 23 | + "[2020-07-02 00:00:00.000, 2020-07-03 15:43:12.345, 2020-07-04 04:00:45.000]", |
| 24 | + "targetPrice": "261.0", |
| 25 | + "imageUrl": "", |
| 26 | + "parseSuccess": "true", |
| 27 | + }); |
| 28 | + |
| 29 | + showToast(String text, {int sec = 2}) => |
| 30 | + Toast.show(text, context, duration: sec); |
| 31 | + |
| 32 | + clearDB() async { |
| 33 | + OkCancelResult result = await showOkCancelAlertDialog( |
| 34 | + context: context, |
| 35 | + title: "Do you really want to empty the database?", |
| 36 | + message: "All tracked products will be lost without a backup", |
| 37 | + okLabel: "Clear DB", |
| 38 | + barrierDismissible: true, |
| 39 | + isDestructiveAction: true, |
| 40 | + ); |
| 41 | + if (result == OkCancelResult.ok) { |
| 42 | + DatabaseService _db = await DatabaseService.getInstance(); |
| 43 | + if (await _db.deleteAll() > 0) { |
| 44 | + showToast("Database cleared!"); |
| 45 | + navigatorKey.currentState |
| 46 | + .pushNamedAndRemoveUntil("/", (route) => false); |
| 47 | + } else |
| 48 | + showToast("Database already empty"); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + backup() async { |
| 53 | + if (await BackupService.instance.backup()) |
| 54 | + showToast("Backup file saved"); |
| 55 | + else |
| 56 | + showToast("Error saving backup file"); |
| 57 | + } |
| 58 | + |
| 59 | + restore() async { |
| 60 | + if (await BackupService.instance.restore()) { |
| 61 | + showToast("Products loaded from backup"); |
| 62 | + navigatorKey.currentState.pushNamedAndRemoveUntil("/", (route) => false); |
| 63 | + } else |
| 64 | + showToast("Error reading backup file"); |
| 65 | + } |
| 66 | + |
| 67 | + void testPriceFallNotification() { |
| 68 | + sendPriceFallNotification(testProduct); |
| 69 | + } |
| 70 | + |
| 71 | + void testUnderTargetNotification() { |
| 72 | + sendUnderTargetNotification(testProduct); |
| 73 | + } |
| 74 | + |
| 75 | + void testAvailableAgainNotification() { |
| 76 | + sendAvailableAgainNotification(testProduct); |
| 77 | + } |
| 78 | + |
| 79 | + void testBackgroundService() { |
| 80 | + Workmanager.registerOneOffTask( |
| 81 | + "manualPriceScraping", "Manual Price Tracker Scraper"); |
| 82 | + } |
| 83 | + |
| 84 | + @override |
| 85 | + Widget build(BuildContext context) => SettingsScreenView(this); |
| 86 | +} |
0 commit comments