-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:otzaria/models/app_model.dart'; | ||
import 'package:otzaria/models/books.dart'; | ||
import 'package:pdfrx/pdfrx.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
void openDafYomiBook(BuildContext context, String tractate, String daf) async { | ||
final appModel = Provider.of<AppModel>(context, listen: false); | ||
final book = await appModel.findBookByTitle(tractate); | ||
var index = 0; | ||
if (book != null) { | ||
if (book is TextBook) { | ||
final tocEntry = await _findDafInToc(book, daf); | ||
index = tocEntry?.index ?? 0; | ||
} else if (book is PdfBook) { | ||
final outline = await getDafYomiOutline(book, daf); | ||
index = outline?.dest?.pageNumber ?? 0; | ||
} | ||
appModel.openBook(book, index, openLeftPane: true); | ||
} else { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text('לא נמצא דף $daf בספר $tractate'), | ||
), | ||
); | ||
} | ||
} | ||
|
||
Future<TocEntry?> _findDafInToc(TextBook book, String daf) async { | ||
final toc = await book.tableOfContents; | ||
TocEntry? findDafInEntries(List<TocEntry> entries) { | ||
for (var entry in entries) { | ||
String ref = entry.text; | ||
if (ref.contains('דף $daf.')) { | ||
return entry; | ||
} | ||
// Recursively search in children | ||
TocEntry? result = findDafInEntries(entry.children); | ||
if (result != null) { | ||
return result; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
return findDafInEntries(toc); | ||
} | ||
|
||
Future<PdfOutlineNode?> getDafYomiOutline(PdfBook book, String daf) async { | ||
final outlines = await PdfDocument.openFile(book.path) | ||
.then((value) => value.loadOutline()); | ||
|
||
PdfOutlineNode? findDafInEntries(List<PdfOutlineNode> entries) { | ||
for (var entry in entries) { | ||
String ref = entry.title; | ||
if (ref.contains(' $daf, א')) { | ||
return entry; | ||
} | ||
// Recursively search in children | ||
PdfOutlineNode? result = findDafInEntries(entry.children); | ||
if (result != null) { | ||
return result; | ||
} | ||
} | ||
} | ||
|
||
return findDafInEntries(outlines); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters