Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
5a27ac75c7 | |||
900bcd866c | |||
963f7271a2 |
34
lib/db.dart
34
lib/db.dart
@@ -21,13 +21,18 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_notes_date_unique ON notes (date);
|
|||||||
-- ie. they're not really a list but instead a string
|
-- ie. they're not really a list but instead a string
|
||||||
-- But we will also keep a history of all todos
|
-- But we will also keep a history of all todos
|
||||||
-- Because we might as well
|
-- Because we might as well
|
||||||
CREATE TABLE IF NOT EXISTS todos (
|
CREATE TABLE IF NOT EXISTS scratches (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
date TEXT DEFAULT CURRENT_TIMESTAMP,
|
date TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||||
content TEXT NOT NULL
|
content TEXT NOT NULL
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS idx_todos_date ON todos (date);
|
CREATE INDEX IF NOT EXISTS idx_scratches_date ON scratches (date);
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_todos_date_unique ON todos (date);
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_scratches_date_unique ON scratches (date);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS settings (
|
||||||
|
key TEXT PRIMARY KEY NOT NULL,
|
||||||
|
value TEXT NOT NULL
|
||||||
|
);
|
||||||
''';
|
''';
|
||||||
|
|
||||||
static Future<String> _getDatabasePath() async {
|
static Future<String> _getDatabasePath() async {
|
||||||
@@ -83,4 +88,27 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_todos_date_unique ON todos (date);
|
|||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Settings Management
|
||||||
|
static Future<String?> getSetting(String key) async {
|
||||||
|
final List<Map<String, dynamic>> maps = await db.query(
|
||||||
|
'settings',
|
||||||
|
columns: ['value'],
|
||||||
|
where: 'key = ?',
|
||||||
|
whereArgs: [key],
|
||||||
|
);
|
||||||
|
if (maps.isNotEmpty) {
|
||||||
|
return maps.first['value'] as String?;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> setSetting(String key, String value) async {
|
||||||
|
await db.insert(
|
||||||
|
'settings',
|
||||||
|
{'key': key, 'value': value},
|
||||||
|
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||||
|
);
|
||||||
|
debugPrint("Setting updated: $key = $value");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
313
lib/main.dart
313
lib/main.dart
@@ -6,14 +6,14 @@ import 'package:journaler/notes.dart';
|
|||||||
import 'package:system_tray/system_tray.dart';
|
import 'package:system_tray/system_tray.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:audioplayers/audioplayers.dart';
|
import 'package:audioplayers/audioplayers.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
|
|
||||||
// TODO: Add an icon to the executable, simply use the existing tray icon
|
// TODO: Add an icon to the executable, simply use the existing tray icon
|
||||||
// TODO: Add an entry field for the duration ie. the interval of apperance
|
// TODO: Implement some sort of scroll through notes
|
||||||
// TODO: Also the sound file, if possible...
|
|
||||||
// TODO: Cram the above into the database
|
|
||||||
|
|
||||||
const Duration popupInterval = Duration(minutes: 20);
|
// Default values - will be replaced by DB values if they exist
|
||||||
const String notificationSound = 'MeetTheSniper.mp3';
|
const Duration _defaultPopupInterval = Duration(minutes: 20);
|
||||||
|
const String _defaultNotificationSound = 'MeetTheSniper.mp3';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
await DB.init();
|
await DB.init();
|
||||||
@@ -133,9 +133,17 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
TextEditingController();
|
TextEditingController();
|
||||||
final TextEditingController _currentEntryController = TextEditingController();
|
final TextEditingController _currentEntryController = TextEditingController();
|
||||||
final FocusNode _currentEntryFocusNode = FocusNode();
|
final FocusNode _currentEntryFocusNode = FocusNode();
|
||||||
final TextEditingController _todoController = TextEditingController();
|
final TextEditingController _scratchController = TextEditingController();
|
||||||
|
final TextEditingController _intervalController = TextEditingController();
|
||||||
|
final TextEditingController _soundController = TextEditingController();
|
||||||
|
|
||||||
Note? previousNote;
|
Note? previousNote;
|
||||||
|
Note? _currentlyDisplayedNote;
|
||||||
|
Duration _currentPopupInterval = _defaultPopupInterval;
|
||||||
|
String _currentNotificationSound = _defaultNotificationSound;
|
||||||
|
|
||||||
|
bool _canGoPrevious = false;
|
||||||
|
bool _canGoNext = false;
|
||||||
|
|
||||||
Timer? _popupTimer;
|
Timer? _popupTimer;
|
||||||
Timer? _debounceTimer;
|
Timer? _debounceTimer;
|
||||||
@@ -146,7 +154,6 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
windowManager.addListener(this);
|
windowManager.addListener(this);
|
||||||
_initSystemTray();
|
_initSystemTray();
|
||||||
_loadData();
|
_loadData();
|
||||||
_startPopupTimer();
|
|
||||||
windowManager.setPreventClose(true);
|
windowManager.setPreventClose(true);
|
||||||
_setWindowConfig();
|
_setWindowConfig();
|
||||||
}
|
}
|
||||||
@@ -159,7 +166,9 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
_previousEntryController.dispose();
|
_previousEntryController.dispose();
|
||||||
_currentEntryController.dispose();
|
_currentEntryController.dispose();
|
||||||
_currentEntryFocusNode.dispose();
|
_currentEntryFocusNode.dispose();
|
||||||
_todoController.dispose();
|
_scratchController.dispose();
|
||||||
|
_intervalController.dispose();
|
||||||
|
_soundController.dispose();
|
||||||
_audioPlayer.dispose();
|
_audioPlayer.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@@ -200,9 +209,11 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _startPopupTimer() {
|
void _startPopupTimer() {
|
||||||
_popupTimer = Timer.periodic(popupInterval, (timer) {
|
_popupTimer?.cancel();
|
||||||
|
_popupTimer = Timer.periodic(_currentPopupInterval, (timer) {
|
||||||
_showWindow();
|
_showWindow();
|
||||||
});
|
});
|
||||||
|
debugPrint("Popup timer started with interval: ${_currentPopupInterval.inMinutes} minutes");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _showWindow() async {
|
Future<void> _showWindow() async {
|
||||||
@@ -223,34 +234,118 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
Future<void> _playSound() async {
|
Future<void> _playSound() async {
|
||||||
await _audioPlayer.stop();
|
await _audioPlayer.stop();
|
||||||
await _audioPlayer.play(AssetSource('sounds/$notificationSound'));
|
try {
|
||||||
debugPrint("Played sound: $notificationSound");
|
await _audioPlayer.play(AssetSource('sounds/$_currentNotificationSound'));
|
||||||
|
debugPrint("Played sound: $_currentNotificationSound");
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("Error playing sound $_currentNotificationSound: e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _checkNavigation() async {
|
||||||
|
if (_currentlyDisplayedNote == null) {
|
||||||
|
setState(() {
|
||||||
|
_canGoPrevious = false;
|
||||||
|
_canGoNext = false;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final prev = await getPreviousNote(_currentlyDisplayedNote!.date);
|
||||||
|
final bool isLatest = _currentlyDisplayedNote!.date == previousNote?.date;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_canGoPrevious = prev != null;
|
||||||
|
_canGoNext = !isLatest;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _goToPreviousNote() async {
|
||||||
|
if (!_canGoPrevious || _currentlyDisplayedNote == null) return;
|
||||||
|
|
||||||
|
final prevNote = await getPreviousNote(_currentlyDisplayedNote!.date);
|
||||||
|
if (prevNote != null) {
|
||||||
|
setState(() {
|
||||||
|
_currentlyDisplayedNote = prevNote;
|
||||||
|
_previousEntryController.text = prevNote.content;
|
||||||
|
});
|
||||||
|
await _checkNavigation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _goToNextNote() async {
|
||||||
|
if (!_canGoNext || _currentlyDisplayedNote == null) return;
|
||||||
|
|
||||||
|
final nextNote = await getNextNote(_currentlyDisplayedNote!.date);
|
||||||
|
if (nextNote != null) {
|
||||||
|
setState(() {
|
||||||
|
_currentlyDisplayedNote = nextNote;
|
||||||
|
_previousEntryController.text = nextNote.content;
|
||||||
|
});
|
||||||
|
await _checkNavigation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _loadData() async {
|
void _loadData() async {
|
||||||
|
String? intervalMinutesStr = await DB.getSetting('popupIntervalMinutes');
|
||||||
|
String? soundFileStr = await DB.getSetting('notificationSound');
|
||||||
|
|
||||||
|
int intervalMinutes = int.tryParse(intervalMinutesStr ?? '') ?? _defaultPopupInterval.inMinutes;
|
||||||
|
_currentPopupInterval = Duration(minutes: intervalMinutes);
|
||||||
|
_currentNotificationSound = soundFileStr ?? _defaultNotificationSound;
|
||||||
|
|
||||||
|
_intervalController.text = intervalMinutes.toString();
|
||||||
|
_soundController.text = _currentNotificationSound;
|
||||||
|
|
||||||
|
_startPopupTimer();
|
||||||
|
|
||||||
final note = await getLatestNote();
|
final note = await getLatestNote();
|
||||||
previousNote = note;
|
previousNote = note;
|
||||||
_previousEntryController.text = note?.content ?? "";
|
_currentlyDisplayedNote = note;
|
||||||
|
_previousEntryController.text = _currentlyDisplayedNote?.content ?? "";
|
||||||
|
|
||||||
final todo = await getLatestTodo();
|
final scratch = await getLatestScratch();
|
||||||
_todoController.text = todo?.content ?? "";
|
_scratchController.text = scratch?.content ?? "";
|
||||||
_currentEntryController.text = "";
|
_currentEntryController.text = "";
|
||||||
|
|
||||||
debugPrint("Data loaded (placeholder).");
|
await _checkNavigation();
|
||||||
|
|
||||||
|
debugPrint("Data loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void _saveData() async {
|
void _saveData() async {
|
||||||
String previousEntry = _previousEntryController.text;
|
String previousEntry = _previousEntryController.text;
|
||||||
String currentEntry = _currentEntryController.text;
|
String currentEntry = _currentEntryController.text;
|
||||||
String todoList = _todoController.text;
|
String scratchContent = _scratchController.text;
|
||||||
|
String intervalStr = _intervalController.text;
|
||||||
|
String soundStr = _soundController.text;
|
||||||
|
|
||||||
await createNote(currentEntry);
|
await createNote(currentEntry);
|
||||||
await createTodo(todoList);
|
await createScratch(scratchContent);
|
||||||
previousNote!.content = previousEntry;
|
if (previousNote != null) {
|
||||||
await updateNote(previousNote!);
|
previousNote!.content = previousEntry;
|
||||||
|
await updateNote(previousNote!);
|
||||||
|
}
|
||||||
|
|
||||||
|
int newIntervalMinutes = int.tryParse(intervalStr) ?? _currentPopupInterval.inMinutes;
|
||||||
|
Duration newInterval = Duration(minutes: newIntervalMinutes);
|
||||||
|
if (newInterval != _currentPopupInterval) {
|
||||||
|
_currentPopupInterval = newInterval;
|
||||||
|
DB.setSetting('popupIntervalMinutes', newIntervalMinutes.toString());
|
||||||
|
_startPopupTimer();
|
||||||
|
} else {
|
||||||
|
DB.setSetting('popupIntervalMinutes', newIntervalMinutes.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (soundStr != _currentNotificationSound) {
|
||||||
|
_currentNotificationSound = soundStr;
|
||||||
|
DB.setSetting('notificationSound', soundStr);
|
||||||
|
} else {
|
||||||
|
DB.setSetting('notificationSound', soundStr);
|
||||||
|
}
|
||||||
|
|
||||||
debugPrint(
|
debugPrint(
|
||||||
"Saving data (placeholder)... Current Entry: [${currentEntry.length} chars], Todo: [${todoList.length} chars]",
|
"Saving data... Current Entry: [${currentEntry.length} chars], Scratch: [${scratchContent.length} chars]",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +370,72 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(title: const Text('Journaler'), actions: const []),
|
appBar: AppBar(
|
||||||
|
title: const Text('Journaler'),
|
||||||
|
actions: <Widget>[
|
||||||
|
// Group Label and Input for Interval
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0).copyWith(left: 8.0), // Add padding
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min, // Use minimum space
|
||||||
|
children: [
|
||||||
|
const Text("Interval (m):"),
|
||||||
|
const SizedBox(width: 4), // Space between label and input
|
||||||
|
SizedBox(
|
||||||
|
width: 60, // Constrain width
|
||||||
|
child: TextField(
|
||||||
|
controller: _intervalController,
|
||||||
|
// textAlignVertical: TextAlignVertical.center, // Let default alignment handle it
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
isDense: true,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
|
||||||
|
),
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: <TextInputFormatter>[
|
||||||
|
FilteringTextInputFormatter.digitsOnly
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Group Label and Input for Sound
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Text("Sound:"),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
SizedBox(
|
||||||
|
width: 150, // Constrain width
|
||||||
|
child: TextField(
|
||||||
|
controller: _soundController,
|
||||||
|
// textAlignVertical: TextAlignVertical.center,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
isDense: true,
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
|
||||||
|
hintText: 'sound.mp3',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Test Sound Button
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.volume_up),
|
||||||
|
tooltip: 'Test Sound',
|
||||||
|
onPressed: _playSound,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
],
|
||||||
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -283,53 +443,94 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 9,
|
flex: 9,
|
||||||
child: Column(
|
child: Listener(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
behavior: HitTestBehavior.opaque,
|
||||||
children: [
|
onPointerSignal: (pointerSignal) {
|
||||||
Expanded(
|
if (pointerSignal is PointerScrollEvent) {
|
||||||
child: TextField(
|
if (pointerSignal.scrollDelta.dy < 0) {
|
||||||
controller: _previousEntryController,
|
if (_canGoPrevious) {
|
||||||
maxLines: null,
|
_goToPreviousNote();
|
||||||
expands: true,
|
}
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
} else if (pointerSignal.scrollDelta.dy > 0) {
|
||||||
decoration: const InputDecoration(
|
if (_canGoNext) {
|
||||||
labelText: 'Previous Entry',
|
_goToNextNote();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
// Combine Label, Buttons, and TextField for Previous Entry
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
_currentlyDisplayedNote?.date == previousNote?.date
|
||||||
|
? 'Previous Entry (Latest)'
|
||||||
|
: 'Entry: ${_currentlyDisplayedNote?.date ?? 'N/A'}',
|
||||||
|
style: TextStyle(fontSize: 18, color: Colors.grey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back),
|
||||||
|
tooltip: 'Previous Note',
|
||||||
|
onPressed: _canGoPrevious ? _goToPreviousNote : null,
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_forward),
|
||||||
|
tooltip: 'Next Note',
|
||||||
|
onPressed: _canGoNext ? _goToNextNote : null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
controller: _previousEntryController,
|
||||||
|
readOnly: _currentlyDisplayedNote?.date != previousNote?.date,
|
||||||
|
maxLines: null,
|
||||||
|
expands: true,
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: _currentlyDisplayedNote?.date != previousNote?.date
|
||||||
|
? 'Viewing note from ${_currentlyDisplayedNote?.date} (Read-Only)'
|
||||||
|
: 'Latest Note',
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
filled: _currentlyDisplayedNote?.date != previousNote?.date,
|
||||||
|
fillColor: _currentlyDisplayedNote?.date != previousNote?.date
|
||||||
|
? Colors.grey.withOpacity(0.1)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 8),
|
||||||
const SizedBox(height: 8),
|
Expanded(
|
||||||
Expanded(
|
child: TextField(
|
||||||
child: TextField(
|
controller: _currentEntryController,
|
||||||
controller: _currentEntryController,
|
focusNode: _currentEntryFocusNode,
|
||||||
focusNode: _currentEntryFocusNode,
|
maxLines: null,
|
||||||
maxLines: null,
|
expands: true,
|
||||||
expands: true,
|
autofocus: true,
|
||||||
autofocus: true,
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
decoration: const InputDecoration(
|
||||||
decoration: const InputDecoration(
|
labelText: 'Current Entry (What\'s on your mind?)',
|
||||||
labelText: 'Current Entry (What\'s on your mind?)',
|
),
|
||||||
),
|
),
|
||||||
onChanged: (text) {},
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 3,
|
flex: 4, // Adjust flex factor as needed
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _todoController,
|
controller: _scratchController,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
expands: true,
|
expands: true,
|
||||||
style:
|
style: Theme.of(context).textTheme.bodyMedium, // Apply theme text style
|
||||||
Theme.of(
|
|
||||||
context,
|
|
||||||
).textTheme.bodyMedium, // Apply theme text style
|
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Todo',
|
labelText: 'Scratch',
|
||||||
// border: OutlineInputBorder(), // Handled by theme
|
|
||||||
// contentPadding: EdgeInsets.all(8.0), // Handled by theme or default
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@@ -7,11 +7,11 @@ class Note {
|
|||||||
Note({required this.date, required this.content});
|
Note({required this.date, required this.content});
|
||||||
}
|
}
|
||||||
|
|
||||||
class Todo {
|
class Scratch {
|
||||||
final String date;
|
final String date;
|
||||||
final String content;
|
String content;
|
||||||
|
|
||||||
Todo({required this.date, required this.content});
|
Scratch({required this.date, required this.content});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Note?> getLatestNote() async {
|
Future<Note?> getLatestNote() async {
|
||||||
@@ -43,19 +43,60 @@ Future<void> updateNote(Note note) async {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Todo?> getLatestTodo() async {
|
Future<Scratch?> getLatestScratch() async {
|
||||||
final todo = await DB.db.rawQuery(
|
final scratch = await DB.db.rawQuery(
|
||||||
'SELECT content, date FROM todos ORDER BY date DESC LIMIT 1',
|
'SELECT content, date FROM scratches ORDER BY date DESC LIMIT 1',
|
||||||
);
|
);
|
||||||
if (todo.isEmpty) {
|
|
||||||
|
if (scratch.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
|
} else {
|
||||||
|
return Scratch(
|
||||||
|
date: scratch[0]['date'] as String,
|
||||||
|
content: scratch[0]['content'] as String,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return Todo(
|
|
||||||
date: todo[0]['date'] as String,
|
|
||||||
content: todo[0]['content'] as String,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createTodo(String content) async {
|
Future<void> createScratch(String content) async {
|
||||||
await DB.db.insert('todos', {'content': content});
|
await DB.db.insert('scratches', {'content': content});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the note immediately older than the given date
|
||||||
|
Future<Note?> getPreviousNote(String currentDate) async {
|
||||||
|
final List<Map<String, dynamic>> notes = await DB.db.query(
|
||||||
|
'notes',
|
||||||
|
where: 'date < ?',
|
||||||
|
whereArgs: [currentDate],
|
||||||
|
orderBy: 'date DESC',
|
||||||
|
limit: 1,
|
||||||
|
);
|
||||||
|
if (notes.isNotEmpty) {
|
||||||
|
return Note(
|
||||||
|
date: notes.first['date'] as String,
|
||||||
|
content: notes.first['content'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the note immediately newer than the given date
|
||||||
|
Future<Note?> getNextNote(String currentDate) async {
|
||||||
|
final List<Map<String, dynamic>> notes = await DB.db.query(
|
||||||
|
'notes',
|
||||||
|
where: 'date > ?',
|
||||||
|
whereArgs: [currentDate],
|
||||||
|
orderBy: 'date ASC',
|
||||||
|
limit: 1,
|
||||||
|
);
|
||||||
|
if (notes.isNotEmpty) {
|
||||||
|
return Note(
|
||||||
|
date: notes.first['date'] as String,
|
||||||
|
content: notes.first['content'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// If there's no newer note, it means we might be at the latest
|
||||||
|
// but let's double-check by explicitly getting the latest again.
|
||||||
|
// This handles the case where the `currentDate` might not be the absolute latest.
|
||||||
|
return getLatestNote();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user