Enhance cleanup dialog with sensitivity slider for problematic entries
This commit is contained in:
@@ -953,7 +953,10 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
|
||||
// Show cleanup dialog
|
||||
void _showCleanupDialog() async {
|
||||
final problematicEntries = await findProblematicEntries();
|
||||
double sensitivity = 0.7; // Default 70%
|
||||
final problematicEntries = await findProblematicEntries(
|
||||
maxCharPercentage: sensitivity,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
@@ -969,13 +972,44 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
height: MediaQuery.of(context).size.height * 0.7,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text('Sensitivity: '),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: sensitivity,
|
||||
min: 0.3,
|
||||
max: 0.9,
|
||||
divisions: 12,
|
||||
label: '${(sensitivity * 100).toInt()}%',
|
||||
onChanged: (value) async {
|
||||
dialogSetState(() {
|
||||
sensitivity =
|
||||
(value * 100).round() /
|
||||
100; // Round to 2 decimal places
|
||||
});
|
||||
// Refresh results with new sensitivity
|
||||
final newResults = await findProblematicEntries(
|
||||
maxCharPercentage: sensitivity,
|
||||
);
|
||||
dialogSetState(() {
|
||||
problematicEntries.clear();
|
||||
problematicEntries.addAll(newResults);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Text('${(sensitivity * 100).toInt()}%'),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
'Found ${problematicEntries.length} potentially problematic entries',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: problematicEntries.isEmpty
|
||||
child:
|
||||
problematicEntries.isEmpty
|
||||
? const Center(
|
||||
child: Text('No problematic entries found!'),
|
||||
)
|
||||
@@ -993,7 +1027,8 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
),
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Reason: ${note.problemReason}',
|
||||
@@ -1018,7 +1053,8 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
// Navigate to the note in main window
|
||||
setState(() {
|
||||
_currentlyDisplayedNote = note;
|
||||
_previousEntryController.text = note.content;
|
||||
_previousEntryController.text =
|
||||
note.content;
|
||||
});
|
||||
_checkNavigation();
|
||||
},
|
||||
@@ -1026,39 +1062,67 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
color: Colors.red,
|
||||
tooltip: 'Delete (hold Shift to skip confirmation)',
|
||||
tooltip:
|
||||
'Delete (hold Shift to skip confirmation)',
|
||||
onPressed: () async {
|
||||
// Check if shift is pressed
|
||||
final isShiftPressed = HardwareKeyboard.instance.isShiftPressed;
|
||||
final isShiftPressed =
|
||||
HardwareKeyboard
|
||||
.instance
|
||||
.isShiftPressed;
|
||||
|
||||
bool shouldDelete = isShiftPressed;
|
||||
bool shouldDelete =
|
||||
isShiftPressed;
|
||||
if (!isShiftPressed) {
|
||||
// Show confirmation dialog
|
||||
shouldDelete = await showDialog<bool>(
|
||||
shouldDelete =
|
||||
await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Delete Entry?'),
|
||||
builder:
|
||||
(
|
||||
context,
|
||||
) => AlertDialog(
|
||||
title: const Text(
|
||||
'Delete Entry?',
|
||||
),
|
||||
content: const Text(
|
||||
'Are you sure you want to delete this entry? This action cannot be undone.',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Cancel'),
|
||||
onPressed:
|
||||
() => Navigator.of(
|
||||
context,
|
||||
).pop(
|
||||
false,
|
||||
),
|
||||
child:
|
||||
const Text(
|
||||
'Cancel',
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Delete'),
|
||||
onPressed:
|
||||
() => Navigator.of(
|
||||
context,
|
||||
).pop(true),
|
||||
child:
|
||||
const Text(
|
||||
'Delete',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ?? false;
|
||||
) ??
|
||||
false;
|
||||
}
|
||||
|
||||
if (shouldDelete) {
|
||||
await deleteNote(note.date);
|
||||
dialogSetState(() {
|
||||
problematicEntries.removeAt(index);
|
||||
problematicEntries.removeAt(
|
||||
index,
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@@ -162,12 +162,12 @@ Future<List<Note>> searchNotes(String query) async {
|
||||
}
|
||||
|
||||
// Find potentially problematic entries based on character distribution
|
||||
Future<List<Note>> findProblematicEntries() async {
|
||||
const double maxCharPercentage = 0.7; // If a single char makes up more than 70%, it's suspicious
|
||||
const int minLength = 10; // Only check notes longer than this
|
||||
|
||||
Future<List<Note>> findProblematicEntries({
|
||||
double maxCharPercentage = 0.7,
|
||||
}) async {
|
||||
// Simple SQLite query that counts character occurrences using replace
|
||||
final List<Map<String, dynamic>> results = await DB.db.rawQuery('''
|
||||
final List<Map<String, dynamic>> results = await DB.db.rawQuery(
|
||||
'''
|
||||
WITH char_counts AS (
|
||||
SELECT
|
||||
id,
|
||||
@@ -178,18 +178,24 @@ Future<List<Note>> findProblematicEntries() async {
|
||||
length(content) as total_length,
|
||||
cast(length(content) - length(replace(content, substr(content, 1, 1), '')) as float) / length(content) as percentage
|
||||
FROM notes
|
||||
WHERE length(content) >= ?
|
||||
)
|
||||
SELECT *
|
||||
FROM char_counts
|
||||
WHERE percentage > ?
|
||||
ORDER BY date DESC
|
||||
''', [minLength, maxCharPercentage]);
|
||||
''',
|
||||
[maxCharPercentage],
|
||||
);
|
||||
|
||||
return results.map((row) => Note(
|
||||
return results
|
||||
.map(
|
||||
(row) => Note(
|
||||
date: row['date'] as String,
|
||||
content: row['content'] as String,
|
||||
isProblematic: true,
|
||||
problemReason: 'Character "${row['char']}" makes up ${(row['percentage'] * 100).toStringAsFixed(1)}% of the content',
|
||||
)).toList();
|
||||
problemReason:
|
||||
'Character "${row['char']}" makes up ${(row['percentage'] * 100).toStringAsFixed(1)}% of the content',
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
Reference in New Issue
Block a user