mirror of
https://github.com/dstark5/Openlib.git
synced 2025-09-19 22:31:18 +08:00
chore: remove in-app reader
This commit is contained in:
@ -18,7 +18,6 @@ import 'package:openlib/state/state.dart'
|
|||||||
selectedIndexProvider,
|
selectedIndexProvider,
|
||||||
themeModeProvider,
|
themeModeProvider,
|
||||||
openPdfWithExternalAppProvider,
|
openPdfWithExternalAppProvider,
|
||||||
openEpubWithExternalAppProvider,
|
|
||||||
userAgentProvider,
|
userAgentProvider,
|
||||||
cookieProvider,
|
cookieProvider,
|
||||||
dbProvider;
|
dbProvider;
|
||||||
@ -58,8 +57,6 @@ void main() async {
|
|||||||
(ref) => isDarkMode ? ThemeMode.dark : ThemeMode.light),
|
(ref) => isDarkMode ? ThemeMode.dark : ThemeMode.light),
|
||||||
openPdfWithExternalAppProvider
|
openPdfWithExternalAppProvider
|
||||||
.overrideWith((ref) => openPdfwithExternalapp),
|
.overrideWith((ref) => openPdfwithExternalapp),
|
||||||
openEpubWithExternalAppProvider
|
|
||||||
.overrideWith((ref) => openEpubwithExternalapp),
|
|
||||||
userAgentProvider.overrideWith((ref) => browserUserAgent),
|
userAgentProvider.overrideWith((ref) => browserUserAgent),
|
||||||
cookieProvider.overrideWith((ref) => browserCookie),
|
cookieProvider.overrideWith((ref) => browserCookie),
|
||||||
],
|
],
|
||||||
|
@ -188,7 +188,6 @@ final getBookPosition =
|
|||||||
});
|
});
|
||||||
|
|
||||||
final openPdfWithExternalAppProvider = StateProvider<bool>((ref) => false);
|
final openPdfWithExternalAppProvider = StateProvider<bool>((ref) => false);
|
||||||
final openEpubWithExternalAppProvider = StateProvider<bool>((ref) => false);
|
|
||||||
|
|
||||||
final filePathProvider =
|
final filePathProvider =
|
||||||
FutureProvider.family<String, String>((ref, fileName) async {
|
FutureProvider.family<String, String>((ref, fileName) async {
|
||||||
|
@ -3,18 +3,12 @@ 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:open_file/open_file.dart';
|
import 'package:open_file/open_file.dart';
|
||||||
|
|
||||||
import 'package:openlib/services/files.dart' show getFilePath;
|
import 'package:openlib/services/files.dart' show getFilePath;
|
||||||
import 'package:openlib/ui/components/snack_bar_widget.dart';
|
import 'package:openlib/ui/components/snack_bar_widget.dart';
|
||||||
import 'package:openlib/state/state.dart'
|
import 'package:openlib/state/state.dart'
|
||||||
show
|
show filePathProvider, saveEpubState, dbProvider, getBookPosition;
|
||||||
filePathProvider,
|
|
||||||
saveEpubState,
|
|
||||||
dbProvider,
|
|
||||||
getBookPosition,
|
|
||||||
openEpubWithExternalAppProvider;
|
|
||||||
|
|
||||||
Future<void> launchEpubViewer(
|
Future<void> launchEpubViewer(
|
||||||
{required String fileName,
|
{required String fileName,
|
||||||
@ -23,37 +17,7 @@ Future<void> launchEpubViewer(
|
|||||||
if (Platform.isAndroid || Platform.isIOS) {
|
if (Platform.isAndroid || Platform.isIOS) {
|
||||||
String path = await getFilePath(fileName);
|
String path = await getFilePath(fileName);
|
||||||
String? epubConfig = await ref.read(dbProvider).getBookState(fileName);
|
String? epubConfig = await ref.read(dbProvider).getBookState(fileName);
|
||||||
bool openWithExternalApp = ref.watch(openEpubWithExternalAppProvider);
|
await OpenFile.open(path);
|
||||||
|
|
||||||
if (openWithExternalApp) {
|
|
||||||
await OpenFile.open(path);
|
|
||||||
} else {
|
|
||||||
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 {
|
} else {
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
|
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
|
||||||
return EpubViewerWidget(
|
return EpubViewerWidget(
|
||||||
|
@ -6,11 +6,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:openlib/ui/components/page_title_widget.dart';
|
import 'package:openlib/ui/components/page_title_widget.dart';
|
||||||
import 'package:openlib/ui/about_page.dart';
|
import 'package:openlib/ui/about_page.dart';
|
||||||
import 'package:openlib/state/state.dart'
|
import 'package:openlib/state/state.dart'
|
||||||
show
|
show themeModeProvider, openPdfWithExternalAppProvider, dbProvider;
|
||||||
themeModeProvider,
|
|
||||||
openPdfWithExternalAppProvider,
|
|
||||||
openEpubWithExternalAppProvider,
|
|
||||||
dbProvider;
|
|
||||||
|
|
||||||
class SettingsPage extends ConsumerWidget {
|
class SettingsPage extends ConsumerWidget {
|
||||||
const SettingsPage({super.key});
|
const SettingsPage({super.key});
|
||||||
@ -78,32 +74,6 @@ class SettingsPage extends ConsumerWidget {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
_PaddedContainer(
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"Open Epub with External Reader",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Theme.of(context).colorScheme.tertiary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Switch(
|
|
||||||
// This bool value toggles the switch.
|
|
||||||
value: ref.watch(
|
|
||||||
openEpubWithExternalAppProvider,
|
|
||||||
),
|
|
||||||
activeColor: Colors.red,
|
|
||||||
onChanged: (bool value) {
|
|
||||||
ref.read(openEpubWithExternalAppProvider.notifier).state =
|
|
||||||
value;
|
|
||||||
ref
|
|
||||||
.read(dbProvider)
|
|
||||||
.savePreference('openEpubwithExternalApp', value);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
_PaddedContainer(
|
_PaddedContainer(
|
||||||
onClick: () {
|
onClick: () {
|
||||||
Navigator.push(context,
|
Navigator.push(context,
|
||||||
|
Reference in New Issue
Block a user