feat: add quotations from marked text, with citations and sharing
This commit is contained in:
parent
0e2027c9e2
commit
e6e84fdc01
25 changed files with 1558 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ import 'dart:io';
|
|||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:share_plus/share_plus.dart' show ShareParams, SharePlus;
|
||||
|
||||
import '../database/database.dart';
|
||||
import '../l10n/strings.dart';
|
||||
|
|
@ -11,6 +12,7 @@ import 'controllers/reader_settings_controller.dart'
|
|||
import 'controllers/subscriptions_controller.dart';
|
||||
import 'key_store.dart';
|
||||
import 'pages/mews_urls.dart';
|
||||
import 'pages/quotations_page.dart' show citationFor;
|
||||
import 'pem.dart';
|
||||
|
||||
/// Applies the change an action address encodes, e.g. mews:do/set-theme.
|
||||
|
|
@ -34,6 +36,7 @@ class InternalActions {
|
|||
required KeyStore keys,
|
||||
required Strings strings,
|
||||
Future<PickedPem?> Function(String title)? pickPemFile,
|
||||
Future<void> Function(String text)? share,
|
||||
}) : _db = db,
|
||||
_applyLanguage = applyLanguage,
|
||||
_settings = settings,
|
||||
|
|
@ -41,7 +44,8 @@ class InternalActions {
|
|||
_subscriptions = subscriptions,
|
||||
_keys = keys,
|
||||
_strings = strings,
|
||||
_pickPemFile = pickPemFile ?? _pickPemFromFileSystem;
|
||||
_pickPemFile = pickPemFile ?? _pickPemFromFileSystem,
|
||||
_share = share ?? _shareThroughSystem;
|
||||
|
||||
final MewsDatabase _db;
|
||||
final Future<void> Function() _applyLanguage;
|
||||
|
|
@ -51,6 +55,11 @@ class InternalActions {
|
|||
final KeyStore _keys;
|
||||
final Strings _strings;
|
||||
final Future<PickedPem?> Function(String title) _pickPemFile;
|
||||
final Future<void> Function(String text) _share;
|
||||
|
||||
/// Hands [text] to the system share sheet.
|
||||
static Future<void> _shareThroughSystem(String text) =>
|
||||
SharePlus.instance.share(ShareParams(text: text));
|
||||
|
||||
/// Opens the platform file picker for one PEM file, titled with what the
|
||||
/// step asks for. A single file may hold both the certificate and its key,
|
||||
|
|
@ -92,6 +101,8 @@ class InternalActions {
|
|||
'import-certificate' => _importCertificate(),
|
||||
'rename-certificate' => _renameCertificate(args),
|
||||
'delete-certificate' => _deleteCertificate(args),
|
||||
'share-quotation' => _shareQuotation(args['id']),
|
||||
'remove-quotation' => _removeQuotation(args['id']),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
|
@ -216,4 +227,27 @@ class InternalActions {
|
|||
await _subscriptions.refreshOne(siteUrl);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Shares the quotation with its citation. Nothing on the page changes, so
|
||||
/// the reader stays exactly where they were.
|
||||
Future<bool> _shareQuotation(String? id) async {
|
||||
final quotation = await _quotation(id);
|
||||
if (quotation == null) return false;
|
||||
await _share('${quotation.quote}\n\n'
|
||||
'${citationFor(quotation, _strings)}');
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool> _removeQuotation(String? id) async {
|
||||
final quotation = await _quotation(id);
|
||||
if (quotation == null) return false;
|
||||
await _db.removeQuotation(quotation.id);
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<Quotation?> _quotation(String? id) async {
|
||||
final parsed = int.tryParse(id ?? '');
|
||||
if (parsed == null) return null;
|
||||
return _db.quotationById(parsed);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue