finish custom srs for now
This commit is contained in:
@@ -530,13 +530,21 @@ class _BrowseScreenState extends State<BrowseScreen> with SingleTickerProviderSt
|
|||||||
onPressed: _deleteSelected,
|
onPressed: _deleteSelected,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.timer_off),
|
icon: Icon(_toggleIntervalIcon),
|
||||||
onPressed: _toggleIntervalForSelected,
|
onPressed: _toggleIntervalForSelected,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IconData get _toggleIntervalIcon {
|
||||||
|
if (_selectedItems.isEmpty) {
|
||||||
|
return Icons.timer_off;
|
||||||
|
}
|
||||||
|
final bool willEnable = _selectedItems.any((item) => !item.useInterval);
|
||||||
|
return willEnable ? Icons.timer : Icons.timer_off;
|
||||||
|
}
|
||||||
|
|
||||||
void _selectAll() {
|
void _selectAll() {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (_selectedItems.length == _customDeck.length) {
|
if (_selectedItems.length == _customDeck.length) {
|
||||||
@@ -577,23 +585,40 @@ class _BrowseScreenState extends State<BrowseScreen> with SingleTickerProviderSt
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _toggleIntervalForSelected() {
|
Future<void> _toggleIntervalForSelected() async {
|
||||||
|
if (_selectedItems.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final bool targetState = _selectedItems.any((item) => !item.useInterval);
|
||||||
|
|
||||||
|
final selectedCharacters = _selectedItems.map((item) => item.characters).toSet();
|
||||||
|
|
||||||
|
final List<CustomKanjiItem> updatedItems = [];
|
||||||
for (final item in _selectedItems) {
|
for (final item in _selectedItems) {
|
||||||
final updatedItem = CustomKanjiItem(
|
final updatedItem = CustomKanjiItem(
|
||||||
characters: item.characters,
|
characters: item.characters,
|
||||||
meaning: item.meaning,
|
meaning: item.meaning,
|
||||||
kanji: item.kanji,
|
kanji: item.kanji,
|
||||||
useInterval: !item.useInterval,
|
useInterval: targetState,
|
||||||
srsLevel: item.srsLevel,
|
srsLevel: item.srsLevel,
|
||||||
nextReview: item.nextReview,
|
nextReview: item.nextReview,
|
||||||
);
|
);
|
||||||
_customDeckRepository.updateCard(updatedItem);
|
updatedItems.add(updatedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _customDeckRepository.updateCards(updatedItems);
|
||||||
|
await _loadCustomDeck();
|
||||||
|
|
||||||
|
final newSelectedItems = _customDeck
|
||||||
|
.where((item) => selectedCharacters.contains(item.characters))
|
||||||
|
.toList();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isSelectionMode = false;
|
_selectedItems = newSelectedItems;
|
||||||
_selectedItems.clear();
|
if (_selectedItems.isEmpty) {
|
||||||
|
_isSelectionMode = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
_loadCustomDeck();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCustomGridView(List<CustomKanjiItem> items) {
|
Widget _buildCustomGridView(List<CustomKanjiItem> items) {
|
||||||
@@ -639,35 +664,53 @@ class _BrowseScreenState extends State<BrowseScreen> with SingleTickerProviderSt
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Card(
|
child: Card(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
side: isSelected
|
||||||
|
? const BorderSide(color: Colors.blue, width: 2.0)
|
||||||
|
: BorderSide.none,
|
||||||
|
borderRadius: BorderRadius.circular(12.0),
|
||||||
|
),
|
||||||
color: isSelected
|
color: isSelected
|
||||||
? Colors.blue.withOpacity(0.5)
|
? Colors.blue.withOpacity(0.5)
|
||||||
: item.useInterval
|
: const Color(0xFF1E1E1E),
|
||||||
? Color.lerp(const Color(0xFF1E1E1E), Colors.blue, 0.1)
|
child: Stack(
|
||||||
: const Color(0xFF1E1E1E),
|
children: [
|
||||||
child: Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
FittedBox(
|
FittedBox(
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
child: Text(
|
child: Text(
|
||||||
item.kanji ?? item.characters,
|
item.kanji ?? item.characters,
|
||||||
style: const TextStyle(fontSize: 32, color: Colors.white),
|
style: const TextStyle(fontSize: 32, color: Colors.white),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
item.meaning,
|
||||||
|
style: const TextStyle(color: Colors.grey, fontSize: 16),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
_buildSrsIndicator(item.srsLevel),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (item.useInterval)
|
||||||
|
Positioned(
|
||||||
|
top: 4,
|
||||||
|
right: 4,
|
||||||
|
child: Icon(
|
||||||
|
Icons.timer,
|
||||||
|
color: Colors.green,
|
||||||
|
size: 16,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
],
|
||||||
Text(
|
|
||||||
item.meaning,
|
|
||||||
style: const TextStyle(color: Colors.grey, fontSize: 16),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
_buildSrsIndicator(item.srsLevel),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -675,6 +718,4 @@ class _BrowseScreenState extends State<BrowseScreen> with SingleTickerProviderSt
|
|||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,17 @@ class CustomDeckRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> updateCards(List<CustomKanjiItem> itemsToUpdate) async {
|
||||||
|
final deck = await getCustomDeck();
|
||||||
|
for (var item in itemsToUpdate) {
|
||||||
|
final index = deck.indexWhere((element) => element.characters == item.characters);
|
||||||
|
if (index != -1) {
|
||||||
|
deck[index] = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await saveDeck(deck);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> deleteCard(CustomKanjiItem item) async {
|
Future<void> deleteCard(CustomKanjiItem item) async {
|
||||||
final deck = await getCustomDeck();
|
final deck = await getCustomDeck();
|
||||||
deck.removeWhere((element) => element.characters == item.characters);
|
deck.removeWhere((element) => element.characters == item.characters);
|
||||||
|
|||||||
Reference in New Issue
Block a user