Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/snackbar improvements #41

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/ui/dialogs/initial_interval_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ class InitialIntervalDialog extends HookWidget {
onPressed: () {
if (correctController.text.isEmpty ||
veryCorrectController.text.isEmpty) {
_snackbarService.showSnackbar(
message: 'Both intervals must be provided',
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message: 'Both intervals must be provided',
);
}
return;
}

Expand All @@ -105,10 +107,12 @@ class InitialIntervalDialog extends HookWidget {
if (correctInterval == 0 ||
veryCorrectInterval == 0 ||
correctInterval > veryCorrectInterval) {
_snackbarService.showSnackbar(
message:
'Both intervals must be greater than 0 and the very correct answer interval must be larger',
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message:
'Both intervals must be greater than 0 and the very correct answer interval must be larger',
);
}
return;
}

Expand Down
32 changes: 15 additions & 17 deletions lib/ui/dialogs/search_filter_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import 'package:flutter/material.dart';
import 'package:sagase/app/app.locator.dart';
import 'package:sagase/services/dictionary_service.dart' show SearchFilter;
import 'package:sagase/services/shared_preferences_service.dart';
import 'package:stacked_services/stacked_services.dart';

class SearchFilterDialog extends StatelessWidget {
final DialogRequest request;
final Function(DialogResponse) completer;

const SearchFilterDialog({
final SearchFilter searchFilter;
final bool properNounsEnabled;

SearchFilterDialog({
required this.request,
required this.completer,
super.key,
});
}) : searchFilter = request.data.$1,
properNounsEnabled = request.data.$2;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -41,7 +43,7 @@ class SearchFilterDialog extends StatelessWidget {
toggleable: true,
title: const Text('Vocab'),
groupValue: SearchFilter.vocab,
value: request.data,
value: searchFilter,
onChanged: (_) => completer(
DialogResponse(data: SearchFilter.vocab),
),
Expand All @@ -50,26 +52,22 @@ class SearchFilterDialog extends StatelessWidget {
toggleable: true,
title: const Text('Kanji'),
groupValue: SearchFilter.kanji,
value: request.data,
value: searchFilter,
onChanged: (_) => completer(
DialogResponse(data: SearchFilter.kanji),
),
),
RadioListTile<SearchFilter>(
toggleable: true,
title: const Text('Proper nouns'),
subtitle:
properNounsEnabled ? null : const Text('Enable in settings'),
groupValue: SearchFilter.properNouns,
value: request.data,
onChanged: (_) {
if (locator<SharedPreferencesService>()
.getProperNounsEnabled()) {
completer(DialogResponse(data: SearchFilter.properNouns));
} else {
locator<SnackbarService>().showSnackbar(
message: 'Enable proper noun dictionary in settings',
);
}
},
value: searchFilter,
onChanged: properNounsEnabled
? (_) =>
completer(DialogResponse(data: SearchFilter.properNouns))
: null,
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ class FlashcardSetSettingsViewModel extends FutureViewModel {
void openFlashcardSet() {
if (flashcardSet.myDictionaryLists.isEmpty &&
flashcardSet.predefinedDictionaryLists.isEmpty) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
}
return;
}

Expand Down
10 changes: 6 additions & 4 deletions lib/ui/views/kanji/kanji_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ class KanjiViewModel extends FutureViewModel {

void copyKanji() {
Clipboard.setData(ClipboardData(text: kanji.kanji));
_snackbarService.showSnackbar(
message: '${kanji.kanji} copied to clipboard',
duration: const Duration(seconds: 1),
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message: '${kanji.kanji} copied to clipboard',
duration: const Duration(seconds: 1),
);
}
}

void setStrokeDiagramStartExpanded(bool value) {
Expand Down
16 changes: 10 additions & 6 deletions lib/ui/views/learning/learning_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ class LearningViewModel extends FutureViewModel {
void openFlashcardSet(FlashcardSet flashcardSet) {
if (flashcardSet.myDictionaryLists.isEmpty &&
flashcardSet.predefinedDictionaryLists.isEmpty) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
}
return;
}

Expand All @@ -65,9 +67,11 @@ class LearningViewModel extends FutureViewModel {

if (flashcardSet.myDictionaryLists.isEmpty &&
flashcardSet.predefinedDictionaryLists.isEmpty) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message: 'Add lists to your flashcard set to open flashcards',
);
}
return;
}

Expand Down
10 changes: 6 additions & 4 deletions lib/ui/views/radical/radical_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ class RadicalViewModel extends FutureViewModel {

void copyToClipboard(String text) {
Clipboard.setData(ClipboardData(text: text));
_snackbarService.showSnackbar(
message: '$text copied to clipboard',
duration: const Duration(seconds: 1),
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message: '$text copied to clipboard',
duration: const Duration(seconds: 1),
);
}
}

void setStrokeDiagramStartExpanded(bool value) {
Expand Down
14 changes: 9 additions & 5 deletions lib/ui/views/search/search_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:sagase/app/app.dialogs.dart';
import 'package:sagase/app/app.locator.dart';
import 'package:sagase/app/app.router.dart';
import 'package:sagase/services/mecab_service.dart';
import 'package:sagase/services/shared_preferences_service.dart';
import 'package:sagase_dictionary/sagase_dictionary.dart';
import 'package:sagase/services/digital_ink_service.dart';
import 'package:sagase/services/dictionary_service.dart';
Expand All @@ -19,6 +20,7 @@ class SearchViewModel extends FutureViewModel {
final _snackbarService = locator<SnackbarService>();
final _dialogService = locator<DialogService>();
final _mecabService = locator<MecabService>();
final _sharedPreferencesService = locator<SharedPreferencesService>();

final _kanaKit = const KanaKit();

Expand Down Expand Up @@ -122,10 +124,12 @@ class SearchViewModel extends FutureViewModel {

void toggleHandWriting() {
if (!_digitalInkService.ready) {
_snackbarService.showSnackbar(
message:
'Hand writing detection is setting up. Please try again later.',
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message:
'Hand writing detection is setting up. Please try again later.',
);
}
return;
}
_showHandWriting = !showHandWriting;
Expand Down Expand Up @@ -165,7 +169,7 @@ class SearchViewModel extends FutureViewModel {
Future<void> setSearchFilter() async {
final response = await _dialogService.showCustomDialog(
variant: DialogType.searchFilter,
data: _searchFilter,
data: (_searchFilter, _sharedPreferencesService.getProperNounsEnabled()),
barrierDismissible: true,
);

Expand Down
10 changes: 6 additions & 4 deletions lib/ui/views/text_analysis/text_analysis_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ class TextAnalysisViewModel extends FutureViewModel {
// Copy to clipboard
Clipboard.setData(ClipboardData(text: buffer.toString()));

_snackbarService.showSnackbar(
message: '$buffer copied to clipboard',
duration: const Duration(seconds: 1),
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message: '$buffer copied to clipboard',
duration: const Duration(seconds: 1),
);
}
}

void textAnalysisHistoryItemSelected(TextAnalysisHistoryItem item) {
Expand Down
9 changes: 6 additions & 3 deletions lib/ui/views/vocab/vocab_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,12 @@ class VocabViewModel extends FutureViewModel {
}
} else {
Clipboard.setData(ClipboardData(text: reference.text));
_snackbarService.showSnackbar(
message: 'Reference not found. ${reference.text} copied to clipboard.',
);
if (!_snackbarService.isSnackbarOpen) {
_snackbarService.showSnackbar(
message:
'Reference not found. ${reference.text} copied to clipboard.',
);
}
}
}

Expand Down