mirror of
https://github.com/dstark5/Openlib.git
synced 2025-05-21 08:26:29 +08:00
Migated to new epub viewer for android and ios
This commit is contained in:
@ -37,7 +37,7 @@ class AboutPage extends StatelessWidget {
|
|||||||
padding: EdgeInsets.only(left: 7, right: 7, top: 10),
|
padding: EdgeInsets.only(left: 7, right: 7, top: 10),
|
||||||
child: Text(
|
child: Text(
|
||||||
"Github",
|
"Github",
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
style: TextStyle(fontSize: 19, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_UrlText(
|
_UrlText(
|
||||||
@ -55,7 +55,7 @@ class AboutPage extends StatelessWidget {
|
|||||||
padding: EdgeInsets.only(left: 7, right: 7, top: 10),
|
padding: EdgeInsets.only(left: 7, right: 7, top: 10),
|
||||||
child: Text(
|
child: Text(
|
||||||
"Licence",
|
"Licence",
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
style: TextStyle(fontSize: 19, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_UrlText(
|
_UrlText(
|
||||||
@ -93,7 +93,7 @@ class _UrlText extends StatelessWidget {
|
|||||||
Text(
|
Text(
|
||||||
text,
|
text,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 17,
|
fontSize: 15,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: Colors.blueAccent,
|
color: Colors.blueAccent,
|
||||||
),
|
),
|
||||||
@ -103,7 +103,7 @@ class _UrlText extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const Icon(
|
const Icon(
|
||||||
Icons.launch,
|
Icons.launch,
|
||||||
size: 20,
|
size: 17,
|
||||||
color: Colors.blueAccent,
|
color: Colors.blueAccent,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
import 'dart:io';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
|
||||||
import 'package:openlib/ui/components/delete_dialog_widget.dart';
|
import 'package:openlib/ui/components/delete_dialog_widget.dart';
|
||||||
import 'package:openlib/ui/epub_viewer.dart';
|
import 'package:openlib/ui/epub_viewer.dart' show launchEpubViewer;
|
||||||
import 'package:vocsy_epub_viewer/epub_viewer.dart';
|
|
||||||
import 'package:openlib/ui/pdf_viewer.dart';
|
import 'package:openlib/ui/pdf_viewer.dart';
|
||||||
import 'package:openlib/services/files.dart';
|
|
||||||
import 'package:openlib/state/state.dart' show saveEpubState, dbProvider;
|
|
||||||
|
|
||||||
class FileOpenAndDeleteButtons extends ConsumerWidget {
|
class FileOpenAndDeleteButtons extends ConsumerWidget {
|
||||||
final String id;
|
final String id;
|
||||||
@ -98,40 +93,3 @@ class FileOpenAndDeleteButtons extends ConsumerWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> launchEpubViewer(
|
|
||||||
{required String fileName,
|
|
||||||
required BuildContext context,
|
|
||||||
required WidgetRef ref}) async {
|
|
||||||
if (Platform.isAndroid || Platform.isIOS) {
|
|
||||||
String path = await getFilePath(fileName);
|
|
||||||
String? epubConfig = await ref.read(dbProvider).getBookState(fileName);
|
|
||||||
|
|
||||||
VocsyEpub.setConfig(
|
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
themeColor: Theme.of(context).colorScheme.secondary,
|
|
||||||
identifier: "iosBook",
|
|
||||||
scrollDirection: EpubScrollDirection.HORIZONTAL,
|
|
||||||
);
|
|
||||||
|
|
||||||
if ((epubConfig?.isNotEmpty ?? true) &&
|
|
||||||
(epubConfig != null) &&
|
|
||||||
(!(epubConfig.startsWith('epubcfi')))) {
|
|
||||||
VocsyEpub.open(path,
|
|
||||||
lastLocation: EpubLocator.fromJson(json.decode(epubConfig)));
|
|
||||||
} else {
|
|
||||||
VocsyEpub.open(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
VocsyEpub.locatorStream.listen((locator) {
|
|
||||||
saveEpubState(fileName, locator, ref);
|
|
||||||
// convert locator from string to json and save to your database to be retrieved later
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
|
|
||||||
return EpubViewerWidget(
|
|
||||||
fileName: fileName,
|
|
||||||
);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,10 +1,56 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:convert';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:epub_view/epub_view.dart';
|
import 'package:epub_view/epub_view.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:vocsy_epub_viewer/epub_viewer.dart';
|
||||||
|
|
||||||
|
import 'package:openlib/services/files.dart';
|
||||||
|
import 'package:openlib/ui/components/snack_bar_widget.dart';
|
||||||
import 'package:openlib/state/state.dart'
|
import 'package:openlib/state/state.dart'
|
||||||
show filePathProvider, saveEpubState, getBookPosition;
|
show filePathProvider, saveEpubState, dbProvider, getBookPosition;
|
||||||
|
|
||||||
|
Future<void> launchEpubViewer(
|
||||||
|
{required String fileName,
|
||||||
|
required BuildContext context,
|
||||||
|
required WidgetRef ref}) async {
|
||||||
|
if (Platform.isAndroid || Platform.isIOS) {
|
||||||
|
String path = await getFilePath(fileName);
|
||||||
|
String? epubConfig = await ref.read(dbProvider).getBookState(fileName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
VocsyEpub.setConfig(
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
themeColor: const Color.fromARGB(255, 210, 15, 1),
|
||||||
|
identifier: "iosBook",
|
||||||
|
scrollDirection: EpubScrollDirection.HORIZONTAL,
|
||||||
|
);
|
||||||
|
|
||||||
|
if ((epubConfig?.isNotEmpty ?? true) &&
|
||||||
|
(epubConfig != null) &&
|
||||||
|
(!(epubConfig.startsWith('epubcfi')))) {
|
||||||
|
VocsyEpub.open(path,
|
||||||
|
lastLocation: EpubLocator.fromJson(json.decode(epubConfig)));
|
||||||
|
} else {
|
||||||
|
VocsyEpub.open(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
VocsyEpub.locatorStream.listen((locator) async {
|
||||||
|
await saveEpubState(fileName, locator, ref);
|
||||||
|
// convert locator from string to json and save to your database to be retrieved later
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
showSnackBar(context: context, message: 'Unable to open pdf!');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
|
||||||
|
return EpubViewerWidget(
|
||||||
|
fileName: fileName,
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class EpubViewerWidget extends ConsumerStatefulWidget {
|
class EpubViewerWidget extends ConsumerStatefulWidget {
|
||||||
const EpubViewerWidget({super.key, required this.fileName});
|
const EpubViewerWidget({super.key, required this.fileName});
|
||||||
|
30
pubspec.lock
30
pubspec.lock
@ -93,10 +93,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: collection
|
name: collection
|
||||||
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
|
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.17.1"
|
version: "1.17.2"
|
||||||
convert:
|
convert:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -364,18 +364,18 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: matcher
|
name: matcher
|
||||||
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
|
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.15"
|
version: "0.12.16"
|
||||||
material_color_utilities:
|
material_color_utilities:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: material_color_utilities
|
name: material_color_utilities
|
||||||
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
|
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.0"
|
version: "0.5.0"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -529,10 +529,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: source_span
|
name: source_span
|
||||||
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
|
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.9.1"
|
version: "1.10.0"
|
||||||
sqflite:
|
sqflite:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -617,10 +617,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
|
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.1"
|
version: "0.6.0"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -749,6 +749,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.0.0"
|
||||||
|
web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: web
|
||||||
|
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.4-beta"
|
||||||
win32:
|
win32:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -782,5 +790,5 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.2"
|
version: "3.1.2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.0.5 <4.0.0"
|
dart: ">=3.1.0-185.0.dev <4.0.0"
|
||||||
flutter: ">=3.10.0"
|
flutter: ">=3.10.0"
|
||||||
|
Reference in New Issue
Block a user