Skip to content

Commit 02b077d

Browse files
Reload reader after navigating back from another view
1 parent 5900626 commit 02b077d

15 files changed

Lines changed: 488 additions & 539 deletions

lib/app/app.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:bible_side/services/settings_service.dart';
66
import 'package:bible_side/ui/views/settings/settings_view.dart';
77
import 'package:bible_side/ui/views/reader/reader_view.dart';
88
import 'package:bible_side/services/app_info_service.dart';
9-
import 'package:bible_side/services/side_navigation_service.dart';
109
import 'package:stacked_themes/stacked_themes.dart';
1110
import 'package:bible_side/services/reader_service.dart';
1211
import 'package:bible_side/services/json_service.dart';
@@ -36,7 +35,6 @@ import 'package:bible_side/ui/views/navigation_sections_chapters/navigation_sect
3635
LazySingleton(classType: BiblesService),
3736
LazySingleton(classType: SettingsService),
3837
LazySingleton(classType: AppInfoService),
39-
LazySingleton(classType: SideNavigationService),
4038
LazySingleton(classType: ThemeService),
4139
LazySingleton(classType: ReaderService),
4240
LazySingleton(classType: JsonService),

lib/app/app.locator.dart

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/services/side_navigation_service.dart

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/ui/views/navigation_bible_divisions/navigation_bible_divisions_view.dart

Lines changed: 123 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -22,141 +22,145 @@ class NavigationBibleDivisionsView extends StackedView<NavigationBibleDivisionsV
2222
NavigationBibleDivisionsViewModel viewModel,
2323
Widget? child,
2424
) {
25-
return Scaffold(
26-
backgroundColor: context.theme.appColors.background,
27-
appBar: AppBar(
25+
return PopScope(
26+
canPop: false,
27+
onPopInvoked: viewModel.onPopInvoked,
28+
child: Scaffold(
2829
backgroundColor: context.theme.appColors.background,
29-
centerTitle: true,
30-
scrolledUnderElevation: 0.0,
31-
title: Text(
32-
viewModel.getTitle(),
33-
style: TextStyle(
34-
color: context.theme.appColors.primary,
35-
fontSize: 18.0,
36-
fontWeight: FontWeight.w500,
30+
appBar: AppBar(
31+
backgroundColor: context.theme.appColors.background,
32+
centerTitle: true,
33+
scrolledUnderElevation: 0.0,
34+
title: Text(
35+
viewModel.getTitle(),
36+
style: TextStyle(
37+
color: context.theme.appColors.primary,
38+
fontSize: 18.0,
39+
fontWeight: FontWeight.w500,
40+
),
3741
),
3842
),
39-
),
40-
body: Container(
41-
padding: const EdgeInsets.only(top: 12.0),
42-
child: Column(
43-
mainAxisSize: MainAxisSize.min,
44-
children: [
45-
Expanded(
46-
child: ListView.builder(
47-
itemCount: booksMapping.keys.length,
48-
itemBuilder: (BuildContext context, int index) {
49-
String bibleDivisionCode = BooksMapping.bibleDivisionCodeFromIndex(index);
50-
return InkWell(
51-
onTap: () => viewModel.onTapBibleDivisionItem(bibleDivisionCode),
52-
child: Padding(
53-
padding: const EdgeInsets.symmetric(vertical: 15.0, horizontal: 25.0),
54-
child: Row(
55-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
56-
crossAxisAlignment: CrossAxisAlignment.center,
57-
children: [
58-
Row(
59-
children: [
60-
Align(
61-
alignment: Alignment.topLeft,
62-
child: Padding(
63-
padding: const EdgeInsets.only(bottom: 13.0, right: 8),
64-
child: BibleDivisionIndicator(
65-
color: BooksMapping.colorFromBibleDivisionCode(bibleDivisionCode),
43+
body: Container(
44+
padding: const EdgeInsets.only(top: 12.0),
45+
child: Column(
46+
mainAxisSize: MainAxisSize.min,
47+
children: [
48+
Expanded(
49+
child: ListView.builder(
50+
itemCount: booksMapping.keys.length,
51+
itemBuilder: (BuildContext context, int index) {
52+
String bibleDivisionCode = BooksMapping.bibleDivisionCodeFromIndex(index);
53+
return InkWell(
54+
onTap: () => viewModel.onTapBibleDivisionItem(bibleDivisionCode),
55+
child: Padding(
56+
padding: const EdgeInsets.symmetric(vertical: 15.0, horizontal: 25.0),
57+
child: Row(
58+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
59+
crossAxisAlignment: CrossAxisAlignment.center,
60+
children: [
61+
Row(
62+
children: [
63+
Align(
64+
alignment: Alignment.topLeft,
65+
child: Padding(
66+
padding: const EdgeInsets.only(bottom: 13.0, right: 8),
67+
child: BibleDivisionIndicator(
68+
color: BooksMapping.colorFromBibleDivisionCode(bibleDivisionCode),
69+
),
6670
),
6771
),
68-
),
69-
Text(
70-
BooksMapping.bibleDivisionNameFromCode(bibleDivisionCode),
71-
style: TextStyle(
72-
color: context.theme.appColors.primary,
73-
fontSize: 16.0,
72+
Text(
73+
BooksMapping.bibleDivisionNameFromCode(bibleDivisionCode),
74+
style: TextStyle(
75+
color: context.theme.appColors.primary,
76+
fontSize: 16.0,
77+
),
7478
),
75-
),
76-
],
77-
),
78-
PhosphorIcon(
79-
PhosphorIcons.caretRight(PhosphorIconsStyle.bold),
80-
color: context.theme.appColors.primary,
81-
size: 18.0,
82-
semanticLabel: 'Caret right',
83-
),
84-
],
79+
],
80+
),
81+
PhosphorIcon(
82+
PhosphorIcons.caretRight(PhosphorIconsStyle.bold),
83+
color: context.theme.appColors.primary,
84+
size: 18.0,
85+
semanticLabel: 'Caret right',
86+
),
87+
],
88+
),
8589
),
86-
),
87-
);
88-
},
90+
);
91+
},
92+
),
8993
),
90-
),
91-
Container(
92-
color: context.theme.appColors.appbarBackground,
93-
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
94-
child: Column(
95-
children: [
96-
Row(
97-
children: [
98-
PhosphorIcon(
99-
PhosphorIcons.clockCounterClockwise(PhosphorIconsStyle.regular),
100-
color: context.theme.appColors.primaryOnDark,
101-
size: 16.0,
102-
),
103-
const SizedBox(width: 4),
104-
Text(
105-
'RECENT',
106-
style: TextStyle(
94+
Container(
95+
color: context.theme.appColors.appbarBackground,
96+
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 25.0),
97+
child: Column(
98+
children: [
99+
Row(
100+
children: [
101+
PhosphorIcon(
102+
PhosphorIcons.clockCounterClockwise(PhosphorIconsStyle.regular),
107103
color: context.theme.appColors.primaryOnDark,
108-
fontSize: 12.0,
109-
fontWeight: FontWeight.w500,
104+
size: 16.0,
110105
),
111-
),
112-
],
113-
),
114-
const SizedBox(height: 7.0),
115-
SizedBox(
116-
height: 50,
117-
child: viewModel.recentBooks.isNotEmpty
118-
? GridView.builder(
119-
itemCount: viewModel.recentBooks.length,
120-
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
121-
maxCrossAxisExtent: 120,
122-
childAspectRatio: 4 / 2,
123-
crossAxisSpacing: 18,
124-
mainAxisSpacing: 8,
125-
),
126-
itemBuilder: (BuildContext context, int index) {
127-
String bookCode = viewModel.recentBooks.elementAt(index);
128-
return InkWell(
129-
borderRadius: BorderRadius.circular(12.0),
130-
onTap: () => viewModel.onTapRecentBookItem(bookCode),
131-
child: Center(
132-
child: Text(
133-
BooksMapping.bookNameFromBookCode(bookCode),
134-
maxLines: 1,
135-
overflow: TextOverflow.ellipsis,
136-
style: TextStyle(
137-
color: context.theme.appColors.primaryOnDark,
138-
fontSize: 16.0,
106+
const SizedBox(width: 4),
107+
Text(
108+
'RECENT',
109+
style: TextStyle(
110+
color: context.theme.appColors.primaryOnDark,
111+
fontSize: 12.0,
112+
fontWeight: FontWeight.w500,
113+
),
114+
),
115+
],
116+
),
117+
const SizedBox(height: 7.0),
118+
SizedBox(
119+
height: 50,
120+
child: viewModel.recentBooks.isNotEmpty
121+
? GridView.builder(
122+
itemCount: viewModel.recentBooks.length,
123+
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
124+
maxCrossAxisExtent: 120,
125+
childAspectRatio: 4 / 2,
126+
crossAxisSpacing: 18,
127+
mainAxisSpacing: 8,
128+
),
129+
itemBuilder: (BuildContext context, int index) {
130+
String bookCode = viewModel.recentBooks.elementAt(index);
131+
return InkWell(
132+
borderRadius: BorderRadius.circular(12.0),
133+
onTap: () => viewModel.onTapRecentBookItem(bookCode),
134+
child: Center(
135+
child: Text(
136+
BooksMapping.bookNameFromBookCode(bookCode),
137+
maxLines: 1,
138+
overflow: TextOverflow.ellipsis,
139+
style: TextStyle(
140+
color: context.theme.appColors.primaryOnDark,
141+
fontSize: 16.0,
142+
),
139143
),
140144
),
145+
);
146+
},
147+
)
148+
: Padding(
149+
padding: const EdgeInsets.only(top: 14.0),
150+
child: Text(
151+
'Your recent books will appear here.',
152+
style: TextStyle(
153+
color: context.theme.appColors.secondaryOnDark,
154+
fontSize: 13.0,
141155
),
142-
);
143-
},
144-
)
145-
: Padding(
146-
padding: const EdgeInsets.only(top: 14.0),
147-
child: Text(
148-
'Your recent books will appear here.',
149-
style: TextStyle(
150-
color: context.theme.appColors.secondaryOnDark,
151-
fontSize: 13.0,
152156
),
153157
),
154-
),
155-
),
156-
],
158+
),
159+
],
160+
),
157161
),
158-
),
159-
],
162+
],
163+
),
160164
),
161165
),
162166
);

lib/ui/views/navigation_bible_divisions/navigation_bible_divisions_viewmodel.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ class NavigationBibleDivisionsViewModel extends BaseViewModel {
3939
void onTapRecentBookItem(String bookCode) {
4040
_navigationService.navigateToNavigationSectionsChaptersView(bookCode: bookCode);
4141
}
42+
43+
void onPopInvoked(bool onPopInvoked) async {
44+
_navigationService.clearStackAndShow(Routes.readerView);
45+
}
4246
}

lib/ui/views/navigation_sections_chapters/navigation_sections_chapters_viewmodel.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class NavigationSectionsChaptersViewModel extends BaseViewModel {
5858

5959
// For bibles that do not have a by section implementation
6060
//_biblesService.setChapter();
61-
62-
_navigationService.navigateToReaderView();
61+
_navigationService.clearStackAndShow(Routes.readerView);
6362
await _biblesService.reloadBiblesJson();
6463
}
6564

lib/ui/views/reader/reader_viewmodel.dart

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@ import '../../../common/oet_rv_section_start_end.dart';
1212
import '../../../services/bibles_service.dart';
1313
import '../../../services/reader_service.dart';
1414
import '../../../services/settings_service.dart';
15-
import '../../../services/side_navigation_service.dart';
1615

1716
class ReaderViewModel extends ReactiveViewModel {
18-
final _sideNavigationService = locator<SideNavigationService>();
1917
final _biblesService = locator<BiblesService>();
2018
final _readerService = locator<ReaderService>();
2119
final _settingsService = locator<SettingsService>();
2220
final _navigationService = locator<NavigationService>();
2321

24-
int get currentIndex => _sideNavigationService.currentIndex;
25-
2622
String get primaryAreaBible => _settingsService.primaryBible;
2723
String get secondaryAreaBible => _settingsService.secondaryBible;
2824
String get bookCode => _biblesService.bookCode;
@@ -72,6 +68,7 @@ class ReaderViewModel extends ReactiveViewModel {
7268
primaryAreaController = areasParentController.addAndGet();
7369
secondaryAreaController = areasParentController.addAndGet();
7470
} else {
71+
areasParentController = LinkedScrollControllerGroup();
7572
primaryAreaController = ScrollController();
7673
secondaryAreaController = ScrollController();
7774
}
@@ -146,11 +143,6 @@ class ReaderViewModel extends ReactiveViewModel {
146143
rebuildUi();
147144
}
148145

149-
void setCurrentIndex(int index) {
150-
_sideNavigationService.setCurrentIndex(index);
151-
rebuildUi();
152-
}
153-
154146
void fetchUp(int pageKey, ViewBy viewBy, Area area) {
155147
if (viewBy == ViewBy.section) {
156148
fetchUpSection(pageKey, area);
@@ -335,7 +327,10 @@ class ReaderViewModel extends ReactiveViewModel {
335327
}
336328

337329
void onTapBook(Area area) {
338-
_navigationService.navigateToNavigationBibleDivisionsView(readerArea: area);
330+
_navigationService.clearStackAndShow(
331+
Routes.navigationBibleDivisionsView,
332+
arguments: NavigationBibleDivisionsViewArguments(readerArea: area),
333+
);
339334
}
340335

341336
void onTapBibleVersion(Area? area) {
@@ -353,7 +348,7 @@ class ReaderViewModel extends ReactiveViewModel {
353348
}
354349

355350
void onTapSearch() {
356-
_navigationService.navigateToSearchView();
351+
_navigationService.clearStackAndShow(Routes.searchView);
357352
}
358353

359354
void toggleSecondaryArea() {

0 commit comments

Comments
 (0)