Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"@clearAll": {},
"selectAll": "Select all",
"@selectAll": {},
"select": "Select",
"@select":{},
"customizeFeed": "Customize feed",
"@customizeFeed": {},
"feedName": "Feed name",
Expand Down Expand Up @@ -506,6 +508,22 @@
"@zoteroApiKeyEmpty": {},
"zoteroArticleSent": "The article was sent to Zotero.",
"@zoteroArticleSent": {},
"zoteroSpecificCollection": "Always send to a specific collection",
"@zoteroSpecificCollection":{},
"zoteroSelectCollection": "Select a collection",
"@zoteroSelectCollection":{},
"noZoteroCollectionSelected": "No collection selected",
"@noZoteroCollectionSelected":{},
"zoteroSpecificCollection2": "Always send to this collection",
"@zoteroSpecificCollection2":{},
"zoteroNewCollection":"New collection",
"@zoteroNewCollection":{},
"zoteroCollectionName":"Collection name",
"@zoteroCollectionName":{},
"create":"Create",
"@create":{},
"send": "Send",
"@send":{},
"save": "Save",
"@save": {},
"savedOn": "Saved on {date}",
Expand Down
59 changes: 59 additions & 0 deletions lib/models/zotero_models.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class ZoteroCollection {
final String key;
final String name;
final String? parentKey;
final bool isGroupLibrary;
final String? libraryId;

ZoteroCollection(
{required this.key,
required this.name,
this.parentKey,
required this.isGroupLibrary,
this.libraryId});

factory ZoteroCollection.fromJson(
Map<String, dynamic> json, {
bool isGroupLibrary = false,
String? libraryId,
}) {
if (json.containsKey('name') && json.containsKey('key')) {
return ZoteroCollection(
key: json['key'] ?? '',
name: json['name'] ?? '',
parentKey: json['parentKey'] as String?,
isGroupLibrary: json['isGroupLibrary'] ?? false,
libraryId: json['libraryId'] as String?,
);
}

final data = json['data'] as Map<String, dynamic>?;

return ZoteroCollection(
key: json['key'] ?? '',
name: data?['name'] ?? '',
parentKey: data != null && data['parentCollection'] is String
? data['parentCollection'] as String
: null,
isGroupLibrary: isGroupLibrary,
libraryId: libraryId,
);
}
Map<String, dynamic> toJson() => {
'key': key,
'name': name,
'parentKey': parentKey,
'isGroupLibrary': isGroupLibrary,
'libraryId': libraryId,
};
}

class ZoteroItem {
final String key;
final String name;

ZoteroItem({
required this.key,
required this.name,
});
}
102 changes: 70 additions & 32 deletions lib/screens/article_screen.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../generated_l10n/app_localizations.dart';
import 'package:wispar/generated_l10n/app_localizations.dart';
import 'package:wispar/screens/article_website.dart';
import '../models/crossref_journals_works_models.dart';
import '../services/database_helper.dart';
import '../widgets/publication_card/publication_card.dart';
import './journals_details_screen.dart';
import '../services/zotero_api.dart';
import '../services/string_format_helper.dart';
import '../services/abstract_scraper.dart';
import 'package:wispar/models/crossref_journals_works_models.dart';
import 'package:wispar/services/database_helper.dart';
import 'package:wispar/widgets/publication_card/publication_card.dart';
import 'package:wispar/widgets/zotero_bottomsheet.dart';
import 'package:wispar/models/zotero_models.dart';
import 'package:wispar/screens/journals_details_screen.dart';
import 'package:wispar/services/zotero_api.dart';
import 'package:wispar/services/string_format_helper.dart';
import 'package:wispar/services/abstract_scraper.dart';
import 'package:share_plus/share_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:latext/latext.dart';
import '../services/logs_helper.dart';
import 'package:wispar/services/logs_helper.dart';
import 'dart:async';
import 'package:wispar/widgets/translate_sheet.dart';
import '../services/graphical_abstract_manager.dart';
import '../screens/graphical_abstract_screen.dart';
import 'package:wispar/services/graphical_abstract_manager.dart';
import 'package:wispar/screens/graphical_abstract_screen.dart';
import 'dart:convert';
import 'dart:io';

class ArticleScreen extends StatefulWidget {
Expand Down Expand Up @@ -955,27 +958,8 @@ class ArticleScreenState extends State<ArticleScreen> {
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
List<Map<String, dynamic>> authorsData = [];
for (PublicationAuthor author in widget.authors) {
authorsData.add({
'creatorType': 'author',
'firstName': author.given,
'lastName': author.family,
});
}
ZoteroService.sendToZotero(
context,
authorsData,
widget.title,
_showTranslatedAbstract
? _accumulatedTranslatedAbstract
: (abstract ?? widget.abstract),
widget.journalTitle,
widget.publishedDate,
widget.doi,
widget.issn,
);
onTap: () async {
await _sendToZotero();
},
borderRadius: BorderRadius.circular(8),
splashColor:
Expand Down Expand Up @@ -1033,4 +1017,58 @@ class ArticleScreenState extends State<ArticleScreen> {

return rows.isNotEmpty ? rows.first : null;
}

Future<void> _sendToZotero() async {
final prefs = await SharedPreferences.getInstance();

final bool alwaysSend = prefs.getBool('zoteroAlwaysSend') ?? false;
final String? savedCollectionRaw =
prefs.getString('zoteroDefaultCollection');

final authorsData = widget.authors
.map((author) => {
'creatorType': 'author',
'firstName': author.given,
'lastName': author.family,
})
.toList();

if (alwaysSend && savedCollectionRaw != null) {
final ZoteroCollection savedCollection =
ZoteroCollection.fromJson(jsonDecode(savedCollectionRaw));

await ZoteroService.sendToZotero(
context,
savedCollection,
authorsData,
widget.title,
widget.abstract,
widget.journalTitle,
widget.publishedDate,
widget.doi,
widget.issn,
);

return;
}

final ZoteroCollection? selectedCollection =
await selectZoteroCollection(context);

if (selectedCollection == null) return;

await ZoteroService.sendToZotero(
context,
selectedCollection,
authorsData,
widget.title,
_showTranslatedAbstract
? _accumulatedTranslatedAbstract
: (abstract ?? widget.abstract),
widget.journalTitle,
widget.publishedDate,
widget.doi,
widget.issn,
);
}
}
Loading