Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove parallel upload #187

Merged
merged 2 commits into from
Jun 24, 2024
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
16 changes: 6 additions & 10 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
Expand All @@ -21,10 +22,6 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
Expand Down Expand Up @@ -81,7 +78,6 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.window:window:1.0.0"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
13 changes: 0 additions & 13 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
Expand Down
30 changes: 22 additions & 8 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.1.3" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

include ":app"
20 changes: 7 additions & 13 deletions lib/network/upload.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ Future<List<int>> uploadPhotos(
if (url == null) return [];
String? username = await storage.read(key: Preferences.usernameKey);
String? password = await storage.read(key: Preferences.passwordKey);
UploadNotifier uploadNotifier =
App.appKey.currentContext!.read<UploadNotifier>();
UploadNotifier uploadNotifier = App.appKey.currentContext!.read<UploadNotifier>();
int nbError = 0;

// Creates Upload Item list for the upload notifier
Expand All @@ -106,8 +105,7 @@ Future<List<int>> uploadPhotos(
App.navigatorKey.currentState?.popAndPushNamed(UploadStatusPage.routeName);

// Iterate on each item
await Future.wait(List<Future<void>>.generate(items.length, (index) async {
UploadItem item = items[index];
for (UploadItem item in items) {
try {
// Upload image
Response? response = await uploadChunk(
Expand Down Expand Up @@ -152,7 +150,7 @@ Future<List<int>> uploadPhotos(
uploadNotifier.itemUploadCompleted(item, error: true);
nbError++;
}
}));
}

// Send notifications
showUploadNotification(nbError, result.length);
Expand Down Expand Up @@ -202,10 +200,8 @@ Future<Response?> uploadChunk({

// Filter fields
if (info['name'] != '' && info['name'] != null) fields['name'] = info['name'];
if (info['comment'] != '' && info['comment'] != null)
fields['comment'] = info['comment'];
if (info['tag_ids']?.isNotEmpty ?? false)
fields['tag_ids'] = info['tag_ids'].join(',');
if (info['comment'] != '' && info['comment'] != null) fields['comment'] = info['comment'];
if (info['tag_ids']?.isNotEmpty ?? false) fields['tag_ids'] = info['tag_ids'].join(',');
if (info['level'] != -1) fields['level'] = info['level'];

// Create dio client
Expand Down Expand Up @@ -247,8 +243,7 @@ Future<bool> uploadCompleted(List<int> imageId, int categoryId) async {
});

try {
Response response =
await ApiClient.post(data: formData, queryParameters: queries);
Response response = await ApiClient.post(data: formData, queryParameters: queries);
if (response.statusCode == 200) {
return true;
}
Expand All @@ -270,8 +265,7 @@ Future<bool> communityUploadCompleted(List<int> imageId, int categoryId) async {
'category_id': categoryId,
});
try {
Response response =
await ApiClient.post(data: formData, queryParameters: queries);
Response response = await ApiClient.post(data: formData, queryParameters: queries);
if (response.statusCode == 200) {
return true;
}
Expand Down
49 changes: 15 additions & 34 deletions lib/views/image/image_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ class _ImagePageState extends State<ImagePage> {
void initState() {
_imageList = widget.images.sublist(0);
_album = widget.album;
_imagePage =
((_imageList.length - 1) / Settings.defaultElementPerPage).floor();
_imagePage = ((_imageList.length - 1) / Settings.defaultElementPerPage).floor();

final ImageModel? startImage =
_imageList.firstWhere((image) => image.id == widget.startId);
final ImageModel? startImage = _imageList.firstWhere((image) => image.id == widget.startId);
if (startImage != null) {
_page = _imageList.indexOf(startImage);
if (_imageList.last == startImage) {
Expand Down Expand Up @@ -117,9 +115,7 @@ class _ImagePageState extends State<ImagePage> {
systemNavigationBarColor: Colors.black.withOpacity(0.001),
statusBarColor: Colors.black.withOpacity(0.001),
statusBarIconBrightness:
App.appKey.currentContext?.read<ThemeNotifier>().isDark ?? false
? Brightness.light
: Brightness.dark,
App.appKey.currentContext?.read<ThemeNotifier>().isDark ?? false ? Brightness.light : Brightness.dark,
));
super.dispose();
}
Expand All @@ -129,8 +125,7 @@ class _ImagePageState extends State<ImagePage> {
Future<void> _loadMoreImages() async {
if (_album.id == -1) return;
if (_album.nbImages <= _imageList.length) return;
ApiResponse<List<ImageModel>> result =
await fetchImages(_album.id, _imagePage + 1);
ApiResponse<List<ImageModel>> result = await fetchImages(_album.id, _imagePage + 1);
if (result.hasError || !result.hasData) return;
setState(() {
_imagePage += 1;
Expand All @@ -145,10 +140,8 @@ class _ImagePageState extends State<ImagePage> {
if (serverUrl == null) return {};

// Get server cookies
List<Cookie> cookies =
await ApiClient.cookieJar.loadForRequest(Uri.parse(serverUrl));
String cookiesStr =
cookies.map((cookie) => '${cookie.name}=${cookie.value}').join('; ');
List<Cookie> cookies = await ApiClient.cookieJar.loadForRequest(Uri.parse(serverUrl));
String cookiesStr = cookies.map((cookie) => '${cookie.name}=${cookie.value}').join('; ');

// Get HTTP Basic id
SharedPreferences prefs = await SharedPreferences.getInstance();
Expand Down Expand Up @@ -354,9 +347,7 @@ class _ImagePageState extends State<ImagePage> {
style: TextStyle(fontSize: 16.0, color: Colors.white),
),
),
if (MediaQuery.of(context).orientation ==
Orientation.landscape)
..._actions,
if (MediaQuery.of(context).orientation == Orientation.landscape) ..._actions,
if (widget.isAdmin)
PopupMenuButton(
position: PopupMenuPosition.under,
Expand Down Expand Up @@ -385,9 +376,7 @@ class _ImagePageState extends State<ImagePage> {
_onLike,
),
child: PopupListItem(
icon: !_currentImage.favorite
? Icons.favorite_border
: Icons.favorite,
icon: !_currentImage.favorite ? Icons.favorite_border : Icons.favorite,
text: !_currentImage.favorite
? appStrings.imageOptions_addFavorites
: appStrings.imageOptions_removeFavorites,
Expand Down Expand Up @@ -495,10 +484,7 @@ class _ImagePageState extends State<ImagePage> {
imageUrl = image.elementUrl;
imageUrl = HtmlUnescape().convert(imageUrl);
} else {
imageUrl = image
.getDerivativeFromString(Preferences.getImageFullScreenSize)
?.url ??
'';
imageUrl = image.getDerivativeFromString(Preferences.getImageFullScreenSize)?.url ?? '';
}

// ApiClient.cookieJar.loadForRequest(Uri.parse(imageUrl));
Expand All @@ -520,10 +506,8 @@ class _ImagePageState extends State<ImagePage> {
child: IconButton(
color: Colors.white,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith(
(states) => Colors.black.withOpacity(0.5)),
shape: MaterialStateProperty.resolveWith(
(states) => CircleBorder()),
backgroundColor: MaterialStateProperty.resolveWith((states) => Colors.black.withOpacity(0.5)),
shape: MaterialStateProperty.resolveWith((states) => CircleBorder()),
),
onPressed: () {
Navigator.of(context).pushNamed(
Expand Down Expand Up @@ -562,6 +546,7 @@ class _ImagePageState extends State<ImagePage> {
debugPrint("$o\n$s");
return const Icon(Icons.broken_image_outlined);
},
filterQuality: FilterQuality.medium,
);
},
);
Expand Down Expand Up @@ -601,14 +586,11 @@ class _ImagePageState extends State<ImagePage> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_pagination,
if (MediaQuery.of(context).orientation ==
Orientation.portrait)
if (MediaQuery.of(context).orientation == Orientation.portrait)
SizedBox(
height: 56.0,
child: Row(
children: _actions
.map((action) => Expanded(child: action))
.toList(),
children: _actions.map((action) => Expanded(child: action)).toList(),
),
),
],
Expand Down Expand Up @@ -667,8 +649,7 @@ class _ImagePageState extends State<ImagePage> {
duration: _overlayAnimationDuration,
curve: _overlayAnimationCurve,
child: Builder(builder: (context) {
if (_currentImage.comment == null || _currentImage.comment!.isEmpty)
return const SizedBox();
if (_currentImage.comment == null || _currentImage.comment!.isEmpty) return const SizedBox();
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _showImageDetails,
Expand Down
14 changes: 9 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 2.2.3+223

environment:
sdk: ">=2.17.6 <3.0.0"
sdk: ">=3.0.0 <4.0.0"
flutter: 3.22.2

dependencies:
flutter:
Expand All @@ -24,15 +25,18 @@ dependencies:
auto_size_text: ^3.0.0 # Text that auto-sizes (image thumbnail title)
cupertino_icons: ^1.0.2 # iOS style icons (might be useless)
font_awesome_flutter: ^10.1.0 # Font awesome icons (might be useless)
flutter_slidable: ^2.0.0 # Album card's sliding cations
flutter_slidable: ^3.0.1 # Album card's sliding cations
drag_select_grid_view: ^0.6.1 # Drag to select image grid
rounded_loading_button: ^2.1.0 # Loading button animation
rounded_loading_button: # Loading button animation
git:
url: https://github.com/scopendo/flutter_rounded_loading_button # A custom fork that can work with the latest flutter SDK
ref: dd4b76a
modal_bottom_sheet: ^3.0.0-pre # Custom modals (might be useless)
cached_network_image: ^3.2.2 # Better cache for images (used for album's thumbnail)
flutter_speed_dial: ^6.1.0+1 # Speed dial
pull_to_refresh: ^2.0.0 # Top and bottom refresh gestures
photo_view: ^0.14.0 # Zoom on fullscreen photos
extended_text: ^11.0.0 # Text overflow on left side
extended_text: ^13.0.0 # Text overflow on left side
flutter_easyloading: ^3.0.5 # Show loading dialog

# Storage
Expand Down Expand Up @@ -64,7 +68,7 @@ dependencies:
# Translations
flutter_localizations:
sdk: flutter
intl: ^0.18.0 # Used for translations
intl: ^0.19.0 # Used for translations
html_unescape: ^2.0.0

dev_dependencies:
Expand Down