Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
0.3.0
  • Loading branch information
fzahner authored Mar 18, 2022
2 parents f5a2f0f + 846adab commit 17e3e59
Show file tree
Hide file tree
Showing 21 changed files with 434 additions and 101 deletions.
1 change: 0 additions & 1 deletion projects/lib/controller/eventHandler/deepLinkListener.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_branch_sdk/flutter_branch_sdk.dart';
Expand Down
23 changes: 22 additions & 1 deletion projects/lib/controller/internal/imageDataExtractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class ImageDataExtractor {

Future<List<Map>> futureCollector() async {
// TODO check if metadata tags are same on other devices
// Returns an empty list when something goes wrong
List<Map> maps = List.empty(growable: true);
try {
for (XFile image in collector.images) {
Map<String, dynamic> infoMap = new Map();
infoMap['image'] = Image.file(File(image.path), height: 100);
infoMap['image'] = Image.file(File(image.path),
scale: 0.5, filterQuality: FilterQuality.medium, fit: BoxFit.cover);
final imageBytes = await image.readAsBytes();
final decodedImage = await decodeImageFromList(imageBytes);
final exifData = await readExifFromBytes(imageBytes);
Expand Down Expand Up @@ -51,13 +53,32 @@ class ImageDataExtractor {
String fileName = infoMap['fileName'].toString().split(".")[1];
infoMap['fileType'] = "." + fileName.substring(0, fileName.length - 1);
collector.fileType = infoMap['fileType'];

maps.add(infoMap);
}
if (!_assureSameFiletype(maps)) return List.empty();
return maps;
} catch (e) {
// Somehow, thrown errors don't get printed to console, so I print them as well.
print("Error while processing image: $e");
throw ("Error while processing image: $e");
}
}

bool _assureSameFiletype(List<Map> maps) {
// Makes sure all selected files have the same filetype
String? fileType1;
String? fileType2;
for (Map map in maps) {
fileType1 = map['fileType'];
if (fileType2 != null) {
if (fileType1 != fileType2) {
// If different file types have been found
return false;
}
}
fileType2 = fileType1;
}
return true;
}
}
25 changes: 13 additions & 12 deletions projects/lib/controller/wiki/uploadService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class UploadService {
uploadImage(
List<XFile> images,
String fileName,
String fileType,
String source,
List<Description> description,
String author,
Expand All @@ -37,19 +38,19 @@ class UploadService {
XFile image = images[i];
progressStream.progress(progressNumber);

map = await _getCsrfToken();
map = await getCsrfToken();
token = map["tokens"]["csrftoken"];
String batchFileName = fileName;
String batchFileName = fileName + fileType;
if (images.length != 1) {
batchFileName = fileName + "_" + i.toString();
batchFileName = fileName + "_" + (i + 1).toString() + fileType;
}
await _sendImage(image, batchFileName, token);
progressStream.progress(progressNumber);

map = await _getCsrfToken();
map = await getCsrfToken();
token = map["tokens"]["csrftoken"];
await _editDetails(author, description, license, source, date,
categories, fileName, token);
categories, batchFileName, token);
progressStream.progress(progressNumber);

// map = await _getCsrfToken();
Expand Down Expand Up @@ -94,7 +95,7 @@ class UploadService {
Uri.parse("$WIKIMEDIA_API?format=json" +
"&action=upload" +
"&filename=$fileName"));
request.headers['Authorization'] = "Bearer " + await _getAccessToken();
request.headers['Authorization'] = "Bearer " + await getAccessToken();
request.fields['token'] = csrfToken;
request.files.add(await _convertToMultiPartFile(image, fileName));

Expand Down Expand Up @@ -142,7 +143,7 @@ ${_generateDescriptions(description)}
Uri.parse('$WIKIMEDIA_API?action=edit&format=json'),
headers: <String, String>{
'Content-Type': 'application/x-www-form-urlencoded ',
'Authorization': 'Bearer ${await _getAccessToken()}',
'Authorization': 'Bearer ${await getAccessToken()}',
},
body: <String, String>{
'title': 'File:' + filename,
Expand All @@ -166,12 +167,12 @@ ${_generateDescriptions(description)}
}

// For debug purposes
_checkCsrfToken(String token) async {
checkCsrfToken(String token) async {
Future<http.Response> response = http.post(
Uri.parse('$WIKIMEDIA_API?action=checktoken&type=csrf&format=json'),
headers: <String, String>{
'Content-Type': 'application/x-www-form-urlencoded ',
'Authorization': 'Bearer ${await _getAccessToken()}',
'Authorization': 'Bearer ${await getAccessToken()}',
},
body: <String, String>{
'token': token,
Expand All @@ -184,12 +185,12 @@ ${_generateDescriptions(description)}
}
}

Future<Map> _getCsrfToken() async {
Future<Map> getCsrfToken() async {
// Get a CSRF Token (https://www.mediawiki.org/wiki/API:Tokens)
Future<http.Response> response = http.get(
Uri.parse('$WIKIMEDIA_API?action=query&meta=tokens&format=json'),
headers: <String, String>{
'Authorization': 'Bearer ${await _getAccessToken()}',
'Authorization': 'Bearer ${await getAccessToken()}',
},
);
var responseJson = await response;
Expand Down Expand Up @@ -227,7 +228,7 @@ ${_generateDescriptions(description)}
return value;
}

Future<String> _getAccessToken() async {
Future<String> getAccessToken() async {
Userdata? data = await LoginHandler().getUserInformationFromFile();
if (data != null) {
return data.accessToken;
Expand Down
1 change: 1 addition & 0 deletions projects/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter/services.dart';
// TODO allow custom categories, but are you sure prompt
// TODO add gps coordinates from exif header if available
// TODO Guide to licences article
// TODO Handle Main activity destruction (https://pub.dev/packages/image_picker#handling-mainactivity-destruction-on-android)

void main() {
WidgetsFlutterBinding.ensureInitialized();
Expand Down
2 changes: 1 addition & 1 deletion projects/lib/model/informationCollector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class InformationCollector {
_source = "Own Work";
}
try {
await UploadService().uploadImage(images, fileName! + fileType!, _source,
await UploadService().uploadImage(images, fileName!, fileType!, _source,
description, _author, license!, date, categories, depictions);
} catch (e) {
throw (e);
Expand Down
2 changes: 1 addition & 1 deletion projects/lib/style/textStyles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ final TextStyle hyperlink = new TextStyle(
color: Colors.blue,
);
final TextStyle hintText = new TextStyle(
fontWeight: FontWeight.w300, fontSize: 15, color: Colors.grey.shade800);
fontWeight: FontWeight.w300, fontSize: 15, color: Colors.grey);
final TextStyle introBigText = GoogleFonts.blackHanSans(fontSize: 48);
final TextStyle introSmallText = GoogleFonts.blackHanSans(fontSize: 21);
67 changes: 67 additions & 0 deletions projects/lib/view/articles/licenseGuide.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'package:flutter/material.dart';
import 'package:projects/controller/internal/actionHelper.dart';
import 'package:projects/style/textStyles.dart' as customStyles;
import 'package:projects/style/unorderedListWidget.dart';

class LicenseGuide extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("License Guide"),
),
body: Center(
child: ListView(
padding: EdgeInsets.all(16),
children: [
Text("Acceptable licenses", style: customStyles.headerText),
Divider(),
Text(
"A copyright license is a formal permission stating who may use a copyrighted work and how they may use it. A license can only be granted by the copyright holder, which is usually the author (photographer, painter or similar). ",
style: customStyles.articleText,
),
Text(
'All copyrighted material on Commons (not in the public domain) must be licensed under a free license that specifically and irrevocably allows anyone to use the material for any purpose; simply writing that "the material may be used freely by anyone" or similar is not sufficient. In particular, the license must meet the following conditions: ',
style: customStyles.articleText,
),
UnorderedList([
"Republication and distribution must be allowed.",
"Publication of derivative work must be allowed.",
"Commercial use of the work must be allowed.",
"The license must be perpetual (non-expiring) and non-revocable.",
"Acknowledgment of all authors/contributors of a work may be required.",
"Publication of derivative work under the same license may be required.",
"For digital distribution, use of open file formats free of digital restrictions management (DRM) may be required."
], customStyles.articleText),
Text("Licenses supported by Commons Uploader",
style: customStyles.headerText),
Divider(),
Text(
"In Commons Uploader, you can select one of the five most commonly used licenses for uploading Media to Wikimedia Commons. These include: ",
style: customStyles.articleText,
),
UnorderedList([
"CC0",
"Attribution 3.0",
"Attribution-ShareAlike 3.0",
"Attribution 4.0",
"Attribution-ShareAlike 4.0",
], customStyles.articleText),
Text(
"The main similarity between all these licenses is that they allow others distribute, remix, adapt, and build upon your work, even commercially, as long as they credit you for the original creation. The only exception to this is the CCO license, where the author does not need to be credited.",
style: customStyles.articleText,
),
Padding(padding: EdgeInsets.only(bottom: 8)),
TextButton(
child: Text("Read more"),
onPressed: () async {
String url =
"https://commons.wikimedia.org/wiki/Commons:Licensing";
ActionHelper().launchUrl(url);
},
)
],
)),
);
}
}
File renamed without changes.
8 changes: 7 additions & 1 deletion projects/lib/view/commonsUploadFragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ class _CommonsUploadFragmentState extends State<CommonsUploadFragment> {
label: "Review"),
],
),
Divider(),
Padding(
padding: EdgeInsets.only(top: 8),
child: Divider(
height: 1,
thickness: 1,
),
),
Expanded(
child: _content(selectedTab),
),
Expand Down
24 changes: 10 additions & 14 deletions projects/lib/view/homeFragment.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'dart:core';
import 'package:flutter/material.dart';
import 'package:projects/controller/wiki/pictureOfTheDayService.dart';
import 'package:projects/view/articles/pictureOfTheDayFragment.dart';
import 'package:projects/view/articles/reusingContentFragment.dart';
import 'package:projects/view/articles/uploadGuideFragment.dart';
import 'package:projects/view/articles/licenseGuide.dart';
import 'package:projects/view/articles/pictureOfTheDay.dart';
import 'package:projects/view/articles/reusingContent.dart';
import 'package:projects/view/articles/uploadGuide.dart';
import 'package:projects/style/textStyles.dart' as customStyles;

class HomeFragment extends StatelessWidget {
Expand All @@ -25,17 +26,12 @@ class HomeFragment extends StatelessWidget {
"If you wish to reuse content from Wikimedia Commons - on your own website, in print, or otherwise - check out this article.",
onTap: ReusingContentFragment()));
articleList.add(new Article(
title: "Placeholder Text",
description:
"Quo quia ab unde dolor. Et eaque sapiente quia eum ad deleniti quisquam. Cupiditate cupiditate velit aperiam animi voluptatum ipsa. Minus nemo odio ratione ab fugiat aut. Ipsam sapiente exercitationem deleniti delectus ducimus quod quo at. ",
));
articleList.add(new Article(
title: "Text Place 2",
image: Image.network(
"https://upload.wikimedia.org/wikipedia/commons/5/59/SQM_GE_289A_Boxcab_Carmelita_-_Reverso.jpg"),
description:
"Quo quia ab unde dolor. Et eaque sapiente quia eum ad deleniti quisquam. ",
));
title: "License Guide",
image: Image.network(
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/CC-BY-SA_icon.svg/640px-CC-BY-SA_icon.svg.png"),
description:
"This page gives non-lawyers an overview of complicated copyright laws.",
onTap: LicenseGuide()));

// ------------------------------

Expand Down
2 changes: 1 addition & 1 deletion projects/lib/view/simpleUpload/simpleHomePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class _SimpleHomePageState extends State<SimpleHomePage> {
}

_openUploadPage() async {
if (collector.images != null) {
if (collector.images.isNotEmpty) {
Navigator.push<void>(
context,
MaterialPageRoute<void>(
Expand Down
4 changes: 2 additions & 2 deletions projects/lib/view/simpleUpload/simpleUploadPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class _SimpleUploadPageState extends State<SimpleUploadPage> {
}

Widget _previewImageProvider() {
if (collector.images != null) {
if (collector.images.isNotEmpty) {
return GestureDetector(
onTap: () {
Navigator.push(
Expand Down Expand Up @@ -173,7 +173,7 @@ class _SimpleUploadPageState extends State<SimpleUploadPage> {
}

Future<String?> _errorChecker() async {
if (collector.images == null) {
if (collector.images.isEmpty) {
return "Please go back and select an image.";
} else if (collector.fileName == null || collector.fileName!.isEmpty) {
return "Enter a file name";
Expand Down
2 changes: 0 additions & 2 deletions projects/lib/view/singlePage/introductionView.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:dots_indicator/dots_indicator.dart';
import 'package:flutter/material.dart';
import 'package:flutter_custom_clippers/flutter_custom_clippers.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:liquid_swipe/liquid_swipe.dart';
import 'package:projects/controller/internal/settingsManager.dart';
import 'package:projects/style/textStyles.dart' as customStyles;
import 'package:projects/model/texts.dart' as texts;
import 'package:projects/style/themes.dart';
import 'package:provider/provider.dart';

Expand Down
52 changes: 30 additions & 22 deletions projects/lib/view/uploadFlow/descriptionFragment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:projects/controller/wiki/filenameCheckService.dart';
import 'package:projects/model/datasets.dart' as data;
import 'package:projects/model/description.dart';
import 'package:projects/model/informationCollector.dart';
import 'package:projects/style/infoPopUp.dart';
import 'package:projects/style/themes.dart';
import 'package:projects/style/textStyles.dart' as customStyles;

Expand Down Expand Up @@ -221,31 +222,38 @@ class _MediaTitleWidget extends State<MediaTitleWidget> {
))),
if (collector.fileName != null && collector.fileName!.isNotEmpty)
Card(
margin: EdgeInsets.all(16),
margin: EdgeInsets.fromLTRB(16, 16, 16, 0),
child: SizedBox(
width: double.infinity,
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Text("Generated File Names:",
style: customStyles.objectDescription),
Column(
children: List<Widget>.generate(
collector.images.length, (index) {
return Text(
collector.fileName! +
"_" +
(index + 1).toString() +
collector.fileType!,
style: customStyles.hintText,
);
}),
)
],
),
)))
padding: EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Text("Generated File Names:",
style: customStyles.objectDescription),
Column(
children: List<Widget>.generate(
collector.images.length, (index) {
return Text(
collector.fileName! +
"_" +
(index + 1).toString() +
collector.fileType!,
style: customStyles.hintText,
);
}),
)
],
),
InfoPopUp(
"As you are uploading multiple files, multiple file names need to be generated. Descriptions, Categories and Licences will be applied to all images uploaded.")
],
))))
],
));
} else {
Expand Down
Loading

0 comments on commit 17e3e59

Please sign in to comment.