3 Commits

Author SHA1 Message Date
963f7271a2 Rename todo to scratch 2025-04-22 00:22:01 +02:00
442403b5b9 DO save empty todo 2025-04-21 23:38:06 +02:00
ad767ac33a Fix backspace delete 2025-04-21 23:33:15 +02:00
3 changed files with 101 additions and 110 deletions

View File

@@ -21,13 +21,13 @@ 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);
'''; ''';
static Future<String> _getDatabasePath() async { static Future<String> _getDatabasePath() async {

View File

@@ -11,6 +11,7 @@ import 'package:audioplayers/audioplayers.dart';
// TODO: Add an entry field for the duration ie. the interval of apperance // TODO: Add an entry field for the duration ie. the interval of apperance
// TODO: Also the sound file, if possible... // TODO: Also the sound file, if possible...
// TODO: Cram the above into the database // TODO: Cram the above into the database
// TODO: Implement some sort of scroll through notes
const Duration popupInterval = Duration(minutes: 20); const Duration popupInterval = Duration(minutes: 20);
const String notificationSound = 'MeetTheSniper.mp3'; const String notificationSound = 'MeetTheSniper.mp3';
@@ -38,9 +39,6 @@ void main() async {
class JournalerApp extends StatelessWidget { class JournalerApp extends StatelessWidget {
const JournalerApp({super.key}); const JournalerApp({super.key});
static final GlobalKey<MainPageState> _mainPageKey =
GlobalKey<MainPageState>();
static final TextTheme _baseTextTheme = const TextTheme( static final TextTheme _baseTextTheme = const TextTheme(
bodyMedium: TextStyle(fontSize: 24), bodyMedium: TextStyle(fontSize: 24),
); );
@@ -114,30 +112,7 @@ class JournalerApp extends StatelessWidget {
theme: lightTheme, theme: lightTheme,
darkTheme: darkTheme, darkTheme: darkTheme,
themeMode: ThemeMode.system, themeMode: ThemeMode.system,
home: Focus( home: const MainPage(),
// Using RawKeyboardListener despite deprecation because KeyboardListener
// and Shortcuts/Actions didn't reliably capture the Escape key press
// before the TextField handled it for unfocusing, requiring two presses.
// RawKeyboardListener intercepts the event earlier.
child: RawKeyboardListener(
// Revert to RawKeyboardListener
focusNode: FocusNode(),
onKey: (RawKeyEvent event) {
// Revert to onKey and RawKeyEvent
if (event is RawKeyDownEvent && // Revert to RawKeyDownEvent
event.logicalKey == LogicalKeyboardKey.escape) {
debugPrint("Escape pressed (RawKeyboardListener - Workaround)");
final state = _mainPageKey.currentState;
if (state != null) {
// Re-add unfocus, as it seemed necessary with Raw listener
FocusManager.instance.primaryFocus?.unfocus();
state.onWindowClose();
}
}
},
child: MainPage(key: _mainPageKey),
),
),
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
); );
} }
@@ -159,7 +134,7 @@ 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();
Note? previousNote; Note? previousNote;
@@ -185,7 +160,7 @@ class MainPageState extends State<MainPage> with WindowListener {
_previousEntryController.dispose(); _previousEntryController.dispose();
_currentEntryController.dispose(); _currentEntryController.dispose();
_currentEntryFocusNode.dispose(); _currentEntryFocusNode.dispose();
_todoController.dispose(); _scratchController.dispose();
_audioPlayer.dispose(); _audioPlayer.dispose();
super.dispose(); super.dispose();
} }
@@ -258,25 +233,27 @@ class MainPageState extends State<MainPage> with WindowListener {
previousNote = note; previousNote = note;
_previousEntryController.text = note?.content ?? ""; _previousEntryController.text = note?.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)."); 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;
await createNote(currentEntry); await createNote(currentEntry);
await createTodo(todoList); await createScratch(scratchContent);
if (previousNote != null) {
previousNote!.content = previousEntry; previousNote!.content = previousEntry;
await updateNote(previousNote!); await updateNote(previousNote!);
}
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]",
); );
} }
@@ -286,7 +263,21 @@ class MainPageState extends State<MainPage> with WindowListener {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( // Wrap Scaffold with RawKeyboardListener as workaround for Escape key
return RawKeyboardListener(
focusNode: FocusNode(), // Needs its own node
onKey: (RawKeyEvent event) {
if (event is RawKeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.escape) {
debugPrint(
"Escape pressed inside MainPage (RawKeyboardListener - Workaround)",
);
// Call method directly since we are in the state
FocusManager.instance.primaryFocus?.unfocus(); // Keep unfocus attempt
onWindowClose();
}
},
child: Scaffold(
appBar: AppBar(title: const Text('Journaler'), actions: const []), appBar: AppBar(title: const Text('Journaler'), actions: const []),
body: Padding( body: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
@@ -331,7 +322,7 @@ class MainPageState extends State<MainPage> with WindowListener {
Expanded( Expanded(
flex: 3, flex: 3,
child: TextField( child: TextField(
controller: _todoController, controller: _scratchController,
maxLines: null, maxLines: null,
expands: true, expands: true,
style: style:
@@ -339,7 +330,7 @@ class MainPageState extends State<MainPage> with WindowListener {
context, context,
).textTheme.bodyMedium, // Apply theme text style ).textTheme.bodyMedium, // Apply theme text style
decoration: const InputDecoration( decoration: const InputDecoration(
labelText: 'Todo', labelText: 'Scratch',
// border: OutlineInputBorder(), // Handled by theme // border: OutlineInputBorder(), // Handled by theme
// contentPadding: EdgeInsets.all(8.0), // Handled by theme or default // contentPadding: EdgeInsets.all(8.0), // Handled by theme or default
), ),
@@ -348,6 +339,7 @@ class MainPageState extends State<MainPage> with WindowListener {
], ],
), ),
), ),
),
); );
} }
} }

View File

@@ -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,22 +43,21 @@ 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 Todo( return Scratch(
date: todo[0]['date'] as String, date: scratch[0]['date'] as String,
content: todo[0]['content'] as String, content: scratch[0]['content'] as String,
); );
} }
}
Future<void> createTodo(String content) async { Future<void> createScratch(String content) async {
if (content.isEmpty) { await DB.db.insert('scratches', {'content': content});
return;
}
await DB.db.insert('todos', {'content': content});
} }