Skip to content

Commit

Permalink
extracted updat widget and padded settings button
Browse files Browse the repository at this point in the history
  • Loading branch information
Sivan22 committed Aug 1, 2024
1 parent 1cafd3e commit a896cf0
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 234 deletions.
289 changes: 102 additions & 187 deletions lib/screens/main_window_screen.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_settings_screens/flutter_settings_screens.dart';
import 'package:otzaria/models/app_model.dart';
import 'package:otzaria/screens/favoriets.dart';
import 'package:otzaria/screens/reading_screen.dart';
import 'package:updat/theme/chips/flat.dart';
import 'package:updat/updat_window_manager.dart';
import 'package:http/http.dart' as http;

//imports from otzaria
import 'package:otzaria/screens/library_browser.dart';
import 'package:otzaria/screens/settings_screen.dart';
import 'package:otzaria/widgets/keyboard_shortcuts.dart';
import 'package:otzaria/widgets/my_updat_widget.dart';
import 'package:provider/provider.dart';

class MainWindowScreen extends StatefulWidget {
Expand Down Expand Up @@ -77,48 +73,73 @@ class MainWindowScreenState extends State<MainWindowScreen>
return SafeArea(
child: KeyboardShortcuts(
child: Consumer<AppModel>(
builder: (context, appModel, child) => UpdatWindowManager(
getLatestVersion: () async {
// Github gives us a super useful latest endpoint, and we can use it to get the latest stable release
final data = await http.get(Uri.parse(
Settings.getValue<bool>('key-dev-channel') ?? false
? "https://api.github.com/repos/sivan22/otzaria-dev-channel/releases/latest"
: "https://api.github.com/repos/sivan22/otzaria/releases/latest",
));

// Return the tag name, which is always a semantically versioned string.
return jsonDecode(data.body)["tag_name"];
},
getBinaryUrl: (version) async {
// Github also gives us a great way to download the binary for a certain release (as long as we use a consistent naming scheme)

// Make sure that this link includes the platform extension with which to save your binary.
// If you use https://exapmle.com/latest/macos for instance then you need to create your own file using `getDownloadFileLocation`

final repo = Settings.getValue<bool>('key-dev-channel') ?? false
? "otzaria-dev-channel"
: "otzaria";
return "https://github.com/sivan22/$repo/releases/download/$version/otzaria-$version-${Platform.operatingSystem}.$platformExt";
},
appName: "otzaria", // This is used to name the downloaded files.
getChangelog: (_, __) async {
// That same latest endpoint gives us access to a markdown-flavored release body. Perfect!
final repo = Settings.getValue<bool>('key-dev-channel') ?? false
? "otzaria-dev-channel"
: "otzaria";
final data = await http.get(Uri.parse(
"https://api.github.com/repos/sivan22/$repo/releases/latest",
));
return jsonDecode(data.body)["body"];
},
currentVersion: '0.1.8-dev.2',
updateChipBuilder: flatChip,

callback: (status) {},
builder: (context, appModel, child) => MyUpdatWidget(
child: Scaffold(
body: OrientationBuilder(builder: (context, orientation) {
if (orientation == Orientation.landscape) {
return buildHorizontalLayout(appModel);
return Row(children: [
SizedBox.fromSize(
size: const Size.fromWidth(80),
child: LayoutBuilder(
builder: (context, constraints) => NavigationRail(
labelType: NavigationRailLabelType.all,
destinations: [
const NavigationRailDestination(
icon: Icon(Icons.library_books),
label: Text('ספרייה'),
),
const NavigationRailDestination(
icon: Icon(Icons.menu_book),
label: Text('עיון'),
),
const NavigationRailDestination(
icon: Icon(Icons.search),
label: Text('חיפוש'),
),
const NavigationRailDestination(
icon: Icon(Icons.star),
label: Text('מועדפים'),
),
NavigationRailDestination(
icon: const Icon(Icons.settings),
label: const Text('הגדרות'),
padding: EdgeInsets.only(
top: constraints.maxHeight - 340),
),
],
selectedIndex: appModel.currentView.value.index,
onDestinationSelected: (int index) {
appModel.currentView.value = Screens.values[index];
pageController = PageController(
initialPage: index, keepPage: true);
switch (index) {
case 2:
appModel.openNewSearchTab();
}
setState(() {});
}),
),
),
//mainWindow
Expanded(
child: OrientationBuilder(builder: (context, orientation) {
return PageView(
scrollDirection: orientation == Orientation.landscape
? Axis.vertical
: Axis.horizontal,
physics: const NeverScrollableScrollPhysics(),
controller: pageController,
children: const <Widget>[
LibraryBrowser(),
ReadingScreen(),
SizedBox.shrink(),
FavouritesScreen(),
MySettingsScreen(),
],
);
}),
),
]);
} else {
return Column(children: [
Expanded(
Expand All @@ -135,7 +156,43 @@ class MainWindowScreenState extends State<MainWindowScreen>
],
),
),
buildNavigationBottomBar(),
Consumer<AppModel>(
builder: (context, appModel, child) => NavigationBar(
destinations: const [
NavigationDestination(
icon: Icon(Icons.library_books),
label: 'ספרייה',
),
NavigationDestination(
icon: Icon(Icons.menu_book),
label: 'עיון',
),
NavigationDestination(
icon: Icon(Icons.search),
label: 'חיפוש',
),
NavigationDestination(
icon: Icon(Icons.star),
label: 'מועדפים',
),
NavigationDestination(
icon: Icon(Icons.settings),
label: 'הגדרות',
),
],
selectedIndex: appModel.currentView.value.index,
onDestinationSelected: (int index) {
setState(() {
appModel.currentView.value = Screens.values[index];
pageController = PageController(
initialPage: index, keepPage: true);
switch (index) {
case 2:
appModel.openNewSearchTab();
}
});
}),
),
]);
}
}),
Expand All @@ -145,146 +202,4 @@ class MainWindowScreenState extends State<MainWindowScreen>
// )
));
}

Widget buildHorizontalLayout(AppModel appModel) {
return Row(children: [
buildNavigationSideBar(appModel),
//mainWindow
Expanded(
child: OrientationBuilder(builder: (context, orientation) {
return PageView(
scrollDirection: orientation == Orientation.landscape
? Axis.vertical
: Axis.horizontal,
physics: const NeverScrollableScrollPhysics(),
controller: pageController,
children: const <Widget>[
LibraryBrowser(),
ReadingScreen(),
SizedBox.shrink(),
FavouritesScreen(),
MySettingsScreen(),
],
);
}),
),
]);
}

Widget buildLibraryBrowser(AppModel appModel) {
return const Expanded(
child: LibraryBrowser(),
);
}

Widget buildSettingsScreen() {
return const Expanded(
child: MySettingsScreen(),
);
}

SizedBox buildNavigationSideBar(AppModel appModel) {
return SizedBox.fromSize(
size: const Size.fromWidth(80),
child: NavigationRail(
labelType: NavigationRailLabelType.all,
destinations: const [
NavigationRailDestination(
icon: Icon(Icons.library_books),
label: Text('ספרייה'),
),
NavigationRailDestination(
icon: Icon(Icons.menu_book),
label: Text('עיון'),
),
NavigationRailDestination(
icon: Icon(Icons.search),
label: Text('חיפוש'),
),
NavigationRailDestination(
icon: Icon(Icons.star),
label: Text('מועדפים'),
),
NavigationRailDestination(
icon: Icon(Icons.settings),
label: Text('הגדרות'),
),
],
selectedIndex: appModel.currentView.value.index,
onDestinationSelected: (int index) {
appModel.currentView.value = Screens.values[index];
pageController = PageController(initialPage: index, keepPage: true);
switch (index) {
case 2:
appModel.openNewSearchTab();
}
setState(() {});
}),
);
}

Widget buildNavigationBottomBar() {
return Consumer<AppModel>(
builder: (context, appModel, child) => NavigationBar(
destinations: const [
NavigationDestination(
icon: Icon(Icons.library_books),
label: 'ספרייה',
),
NavigationDestination(
icon: Icon(Icons.menu_book),
label: 'עיון',
),
NavigationDestination(
icon: Icon(Icons.search),
label: 'חיפוש',
),
NavigationDestination(
icon: Icon(Icons.star),
label: 'מועדפים',
),
NavigationDestination(
icon: Icon(Icons.settings),
label: 'הגדרות',
),
],
selectedIndex: appModel.currentView.value.index,
onDestinationSelected: (int index) {
setState(() {
appModel.currentView.value = Screens.values[index];
pageController =
PageController(initialPage: index, keepPage: true);
switch (index) {
case 2:
appModel.openNewSearchTab();
}
});
}),
);
}

String get platformExt {
switch (Platform.operatingSystem) {
case 'windows':
{
return Settings.getValue<bool>('key-dev-channel') ?? false
? 'msix'
: 'exe';
}

case 'macos':
{
return 'dmg';
}

case 'linux':
{
return 'AppImage';
}
default:
{
return 'zip';
}
}
}
}
66 changes: 36 additions & 30 deletions lib/screens/simple_book_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,42 @@ class _SimpleBookViewState extends State<SimpleBookView> {

@override
Widget build(BuildContext context) {
return SelectionArea(
key: PageStorageKey(widget.tab),
child: ScrollablePositionedList.builder(
initialScrollIndex: widget.tab.index,
itemPositionsListener: widget.tab.positionsListener,
itemScrollController: widget.tab.scrollController,
scrollOffsetController: widget.tab.scrollOffsetController,
itemCount: widget.data.length,
itemBuilder: (context, index) {
return ValueListenableBuilder(
valueListenable: widget.tab.removeNikud,
builder: (context, removeNikud, child) => InkWell(
onTap: () => widget.tab.selectedIndex.value = index,
child: Html(
//remove nikud if needed
data: removeNikud
? highLight(removeVolwels(widget.data[index]),
widget.tab.searchTextController.text)
: highLight(widget.data[index],
widget.tab.searchTextController.text),
style: {
'body': Style(
fontSize: FontSize(widget.textSize),
fontFamily:
Settings.getValue('key-font-family') ?? 'candara',
textAlign: TextAlign.justify),
}),
),
);
}),
return ProgressiveScroll(
scrollController: widget.tab.scrollOffsetController,
maxSpeed: 10000.0,
curve: 10.0,
accelerationFactor: 5,
child: SelectionArea(
key: PageStorageKey(widget.tab),
child: ScrollablePositionedList.builder(
initialScrollIndex: widget.tab.index,
itemPositionsListener: widget.tab.positionsListener,
itemScrollController: widget.tab.scrollController,
scrollOffsetController: widget.tab.scrollOffsetController,
itemCount: widget.data.length,
itemBuilder: (context, index) {
return ValueListenableBuilder(
valueListenable: widget.tab.removeNikud,
builder: (context, removeNikud, child) => InkWell(
onTap: () => widget.tab.selectedIndex.value = index,
child: Html(
//remove nikud if needed
data: removeNikud
? highLight(removeVolwels(widget.data[index]),
widget.tab.searchTextController.text)
: highLight(widget.data[index],
widget.tab.searchTextController.text),
style: {
'body': Style(
fontSize: FontSize(widget.textSize),
fontFamily: Settings.getValue('key-font-family') ??
'candara',
textAlign: TextAlign.justify),
}),
),
);
}),
),
);
}
}
Loading

0 comments on commit a896cf0

Please sign in to comment.