diff --git a/lib/ui/views/dictionary_list/dictionary_list_view.dart b/lib/ui/views/dictionary_list/dictionary_list_view.dart index 019beb5..c97c752 100644 --- a/lib/ui/views/dictionary_list/dictionary_list_view.dart +++ b/lib/ui/views/dictionary_list/dictionary_list_view.dart @@ -88,7 +88,7 @@ class _VocabList extends ViewModelWidget { return VocabListItem( vocab: current, - onPressed: () => viewModel.navigateToVocab(current), + onPressed: () => viewModel.navigateToVocab(current, index), ); }, ); @@ -112,7 +112,7 @@ class _KanjiList extends ViewModelWidget { return KanjiListItem( kanji: current, - onPressed: () => viewModel.navigateToKanji(current), + onPressed: () => viewModel.navigateToKanji(current, index), ); }, ); diff --git a/lib/ui/views/dictionary_list/dictionary_list_viewmodel.dart b/lib/ui/views/dictionary_list/dictionary_list_viewmodel.dart index b9ffb00..14bab84 100644 --- a/lib/ui/views/dictionary_list/dictionary_list_viewmodel.dart +++ b/lib/ui/views/dictionary_list/dictionary_list_viewmodel.dart @@ -50,17 +50,25 @@ class DictionaryListViewModel extends FutureViewModel { } } - Future navigateToVocab(Vocab vocab) async { + Future navigateToVocab(Vocab vocab, int index) async { await _navigationService.navigateTo( Routes.vocabView, - arguments: VocabViewArguments(vocab: vocab), + arguments: VocabViewArguments( + vocab: vocab, + vocabListIndex: index, + vocabList: vocabList, + ), ); } - Future navigateToKanji(Kanji kanji) async { + Future navigateToKanji(Kanji kanji, int index) async { await _navigationService.navigateTo( Routes.kanjiView, - arguments: KanjiViewArguments(kanji: kanji), + arguments: KanjiViewArguments( + kanji: kanji, + kanjiListIndex: index, + kanjiList: kanjiList, + ), ); } diff --git a/lib/ui/views/kanji/kanji_view.dart b/lib/ui/views/kanji/kanji_view.dart index 591931f..a10697a 100644 --- a/lib/ui/views/kanji/kanji_view.dart +++ b/lib/ui/views/kanji/kanji_view.dart @@ -14,17 +14,34 @@ import 'kanji_viewmodel.dart'; class KanjiView extends StackedView { final Kanji kanji; + final int? kanjiListIndex; + final List? kanjiList; - const KanjiView(this.kanji, {super.key}); + const KanjiView(this.kanji, {this.kanjiListIndex, this.kanjiList, super.key}); @override - KanjiViewModel viewModelBuilder(context) => KanjiViewModel(kanji); + KanjiViewModel viewModelBuilder(context) => + KanjiViewModel(kanji, kanjiListIndex, kanjiList); @override Widget builder(context, viewModel, child) { return Scaffold( appBar: AppBar( actions: [ + if (kanjiList != null) + IconButton( + onPressed: kanjiListIndex == 0 + ? null + : viewModel.navigateToPreviousKanji, + icon: const Icon(Icons.chevron_left), + ), + if (kanjiList != null) + IconButton( + onPressed: kanjiListIndex! == kanjiList!.length - 1 + ? null + : viewModel.navigateToNextKanji, + icon: const Icon(Icons.chevron_right), + ), IconButton( onPressed: viewModel.openMyDictionaryListsSheet, icon: Icon( diff --git a/lib/ui/views/kanji/kanji_viewmodel.dart b/lib/ui/views/kanji/kanji_viewmodel.dart index b354c69..330f213 100644 --- a/lib/ui/views/kanji/kanji_viewmodel.dart +++ b/lib/ui/views/kanji/kanji_viewmodel.dart @@ -19,6 +19,8 @@ class KanjiViewModel extends FutureViewModel { final _sharedPreferencesService = locator(); final Kanji kanji; + final int? kanjiListIndex; + final List? kanjiList; Radical? radical; List? components; @@ -31,7 +33,7 @@ class KanjiViewModel extends FutureViewModel { bool get strokeDiagramStartExpanded => _sharedPreferencesService.getStrokeDiagramStartExpanded(); - KanjiViewModel(this.kanji); + KanjiViewModel(this.kanji, this.kanjiListIndex, this.kanjiList); @override Future futureToRun() async { @@ -155,6 +157,28 @@ class KanjiViewModel extends FutureViewModel { _sharedPreferencesService.setStrokeDiagramStartExpanded(value); } + void navigateToPreviousKanji() { + _navigationService.replaceWith( + Routes.kanjiView, + arguments: KanjiViewArguments( + kanji: kanjiList![kanjiListIndex! - 1], + kanjiListIndex: kanjiListIndex! - 1, + kanjiList: kanjiList, + ), + ); + } + + void navigateToNextKanji() { + _navigationService.replaceWith( + Routes.kanjiView, + arguments: KanjiViewArguments( + kanji: kanjiList![kanjiListIndex! + 1], + kanjiListIndex: kanjiListIndex! + 1, + kanjiList: kanjiList, + ), + ); + } + @override void dispose() { _myDictionaryListsWatcher?.cancel(); diff --git a/lib/ui/views/kanji_compounds/kanji_compounds_view.dart b/lib/ui/views/kanji_compounds/kanji_compounds_view.dart index 024c62d..f725d29 100644 --- a/lib/ui/views/kanji_compounds/kanji_compounds_view.dart +++ b/lib/ui/views/kanji_compounds/kanji_compounds_view.dart @@ -31,8 +31,8 @@ class KanjiCompoundsView extends StackedView { itemCount: viewModel.vocabList.length, itemBuilder: (context, index) => VocabListItem( vocab: viewModel.vocabList[index], - onPressed: () => - viewModel.navigateToVocab(viewModel.vocabList[index]), + onPressed: () => viewModel.navigateToVocab( + viewModel.vocabList[index], index), ), ), ), diff --git a/lib/ui/views/kanji_compounds/kanji_compounds_viewmodel.dart b/lib/ui/views/kanji_compounds/kanji_compounds_viewmodel.dart index 014866c..94f5aea 100644 --- a/lib/ui/views/kanji_compounds/kanji_compounds_viewmodel.dart +++ b/lib/ui/views/kanji_compounds/kanji_compounds_viewmodel.dart @@ -37,10 +37,14 @@ class KanjiCompoundsViewModel extends FutureViewModel { vocabList = onlyKanji + inPrimaryWriting + other; } - void navigateToVocab(Vocab vocab) { + void navigateToVocab(Vocab vocab, int index) { _navigationService.navigateTo( Routes.vocabView, - arguments: VocabViewArguments(vocab: vocab), + arguments: VocabViewArguments( + vocab: vocab, + vocabListIndex: index, + vocabList: vocabList, + ), ); } } diff --git a/lib/ui/views/kanji_list/kanji_list_view.dart b/lib/ui/views/kanji_list/kanji_list_view.dart index 988e0dc..4009658 100644 --- a/lib/ui/views/kanji_list/kanji_list_view.dart +++ b/lib/ui/views/kanji_list/kanji_list_view.dart @@ -35,7 +35,7 @@ class KanjiListView extends StackedView { final current = kanjiList[index]; return KanjiListItem( kanji: current, - onPressed: () => viewModel.navigateToKanji(current), + onPressed: () => viewModel.navigateToKanji(current, index), ); }, ), diff --git a/lib/ui/views/kanji_list/kanji_list_viewmodel.dart b/lib/ui/views/kanji_list/kanji_list_viewmodel.dart index 8b81b90..3807724 100644 --- a/lib/ui/views/kanji_list/kanji_list_viewmodel.dart +++ b/lib/ui/views/kanji_list/kanji_list_viewmodel.dart @@ -11,10 +11,14 @@ class KanjiListViewModel extends BaseViewModel { KanjiListViewModel(this.kanjiList); - void navigateToKanji(Kanji kanji) { + void navigateToKanji(Kanji kanji, int index) { _navigationService.navigateTo( Routes.kanjiView, - arguments: KanjiViewArguments(kanji: kanji), + arguments: KanjiViewArguments( + kanji: kanji, + kanjiListIndex: index, + kanjiList: kanjiList, + ), ); } } diff --git a/lib/ui/views/vocab/vocab_view.dart b/lib/ui/views/vocab/vocab_view.dart index c05b42d..f41172a 100644 --- a/lib/ui/views/vocab/vocab_view.dart +++ b/lib/ui/views/vocab/vocab_view.dart @@ -15,14 +15,16 @@ import 'vocab_viewmodel.dart'; class VocabView extends StackedView { final Vocab vocab; + final int? vocabListIndex; + final List? vocabList; final pitchAccentKey = GlobalKey(); - VocabView(this.vocab, {super.key}); + VocabView(this.vocab, {this.vocabListIndex, this.vocabList, super.key}); @override VocabViewModel viewModelBuilder(context) { - final viewModel = VocabViewModel(vocab); + final viewModel = VocabViewModel(vocab, vocabListIndex, vocabList); if (viewModel.shouldShowTutorial()) { // Try to show tutorial after transition animation ends @@ -53,6 +55,20 @@ class VocabView extends StackedView { return Scaffold( appBar: AppBar( actions: [ + if (vocabList != null) + IconButton( + onPressed: vocabListIndex == 0 + ? null + : viewModel.navigateToPreviousVocab, + icon: const Icon(Icons.chevron_left), + ), + if (vocabList != null) + IconButton( + onPressed: vocabListIndex! == vocabList!.length - 1 + ? null + : viewModel.navigateToNextVocab, + icon: const Icon(Icons.chevron_right), + ), IconButton( key: pitchAccentKey, onPressed: vocab.readings[0].pitchAccents != null diff --git a/lib/ui/views/vocab/vocab_viewmodel.dart b/lib/ui/views/vocab/vocab_viewmodel.dart index c0a8408..b33ac7f 100644 --- a/lib/ui/views/vocab/vocab_viewmodel.dart +++ b/lib/ui/views/vocab/vocab_viewmodel.dart @@ -26,6 +26,8 @@ class VocabViewModel extends FutureViewModel { final _conjugationUtils = const ConjugationUtils(); final Vocab vocab; + final int? vocabListIndex; + final List? vocabList; late final List writingReadingPairs; List get kanjiList => isBusy ? _kanjiStringList : _kanjiList; @@ -40,7 +42,7 @@ class VocabViewModel extends FutureViewModel { bool get showPitchAccent => _sharedPreferencesService.getShowPitchAccent(); - VocabViewModel(this.vocab) { + VocabViewModel(this.vocab, this.vocabListIndex, this.vocabList) { // Create writing reading pairs writingReadingPairs = WritingReadingPair.fromVocab(vocab); @@ -197,6 +199,28 @@ class VocabViewModel extends FutureViewModel { } } + void navigateToPreviousVocab() { + _navigationService.replaceWith( + Routes.vocabView, + arguments: VocabViewArguments( + vocab: vocabList![vocabListIndex! - 1], + vocabListIndex: vocabListIndex! - 1, + vocabList: vocabList, + ), + ); + } + + void navigateToNextVocab() { + _navigationService.replaceWith( + Routes.vocabView, + arguments: VocabViewArguments( + vocab: vocabList![vocabListIndex! + 1], + vocabListIndex: vocabListIndex! + 1, + vocabList: vocabList, + ), + ); + } + @override void dispose() { _myDictionaryListsWatcher?.cancel();