Skip to content

Commit 2b5c108

Browse files
committed
1. PR suggestions update
2. Enhance robustness of stringEscapedForJavasacript method. 3. sDoc file share bug fix
1 parent fa505db commit 2b5c108

File tree

11 files changed

+155
-61
lines changed

11 files changed

+155
-61
lines changed

Pod/Classes/ExtentedString.m

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "ExtentedString.h"
10+
#import "Debug.h"
1011

1112
@implementation NSString (ExtentedString)
1213

@@ -75,10 +76,20 @@ - (BOOL)isValidFileName
7576

7677
- (NSString *)stringEscapedForJavasacript
7778
{
78-
// valid JSON object need to be an array or dictionary
79-
NSArray* arrayForEncoding = @[self];
80-
NSString* jsonString = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:arrayForEncoding options:0 error:nil] encoding:NSUTF8StringEncoding];
79+
NSError *error = nil;
80+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@[self] options:0 error:&error];
81+
if (error || !jsonData) {
82+
Debug(@"Error serializing string for javascript escaping: %@", error);
83+
return @"";
84+
}
85+
86+
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
87+
if (!jsonString || jsonString.length < 4) {
88+
return jsonString;
89+
}
90+
8191
NSString* escapedString = [jsonString substringWithRange:NSMakeRange(2, jsonString.length - 4)];
92+
8293
return escapedString;
8394
}
8495

Pod/Classes/SeafCacheManager.m

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ - (NSString *)getCachePathForFile:(SeafFile *)file {
136136
// Check if there is a local cache
137137
- (BOOL)fileHasCache:(SeafFile *)file
138138
{
139-
if ([file isSdocFile]) {
140-
return YES;
141-
}
142139
// 1) If the local mpath exists and the file exists
143140
if (file.mpath && [[NSFileManager defaultManager] fileExistsAtPath:file.mpath]) {
144141
return YES;

Pod/Classes/Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
#ifndef version_h
1010
#define version_h
1111

12-
#define SEAFILE_VERSION @"3.0.0"
12+
#define SEAFILE_VERSION @"3.0.1"
1313

1414
#endif /* version_h */

Seafile.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Seafile"
3-
s.version = "3.0.0"
3+
s.version = "3.0.1"
44
s.summary = "iOS client for seafile."
55
s.homepage = "https://github.com/haiwen/seafile-iOS"
66
s.license = 'MIT'

seafile/SeafActivityViewController.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "SeafDateFormatter.h"
2424
#import "ExtentedString.h"
2525
#import "Debug.h"
26+
#import "SeafLoadingView.h"
2627

2728
typedef void (^ModificationHandler)(NSString *repoId, NSString *path);
2829

@@ -32,7 +33,7 @@ @interface SeafActivityViewController ()<UITableViewDelegate,UITableViewDataSour
3233
@property int eventsOffset;
3334

3435
@property (weak, nonatomic) IBOutlet UITableView *tableView;
35-
@property (strong, nonatomic) UIActivityIndicatorView *loadingView;
36+
@property (strong, nonatomic) SeafLoadingView *loadingView;
3637

3738
@property NSMutableDictionary *eventDetails;
3839
@property UIImage *defaultAccountImage;
@@ -60,12 +61,8 @@ - (void)viewDidLoad
6061
self.tableView.delegate = self;
6162
self.tableView.dataSource = self;
6263

63-
// Initialize loading indicator
64-
self.loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
65-
self.loadingView.color = [UIColor darkTextColor];
66-
self.loadingView.hidesWhenStopped = YES;
67-
[self.view addSubview:self.loadingView];
68-
self.loadingView.center = self.view.center;
64+
// Initialize loading view
65+
self.loadingView = [SeafLoadingView loadingViewWithParentView:self.view];
6966

7067
if (@available(iOS 15.0, *)) {
7168
UINavigationBarAppearance *barAppearance = [UINavigationBarAppearance new];
@@ -160,12 +157,11 @@ - (void)reloadData
160157
}
161158

162159
- (void)showLoadingView {
163-
self.loadingView.center = self.view.center;
164-
[self.loadingView startAnimating];
160+
[self.loadingView showInView:self.view];
165161
}
166162

167163
- (void)dismissLoadingView {
168-
[self.loadingView stopAnimating];
164+
[self.loadingView dismiss];
169165
}
170166

171167
- (void)moreEvents:(int)offset
@@ -182,9 +178,11 @@ - (void)moreEvents:(int)offset
182178

183179
// Standard request for older API versions
184180
NSString *url = [NSString stringWithFormat:API_URL"/events/?start=%d", offset];
181+
@weakify(self);
185182
[_connection sendRequest:url success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
186183
// Process data in background thread
187184
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
185+
@strongify(self);
188186
Debug("Succeeded to get events start=%d", offset);
189187
NSArray *arr = [JSON objectForKey:@"events"];
190188
NSMutableArray *marray = [NSMutableArray new];
@@ -198,6 +196,7 @@ - (void)moreEvents:(int)offset
198196

199197
// Update UI in main thread
200198
dispatch_async(dispatch_get_main_queue(), ^{
199+
@strongify(self);
201200
self->_events = marray;
202201
self->_eventsMore = hasMore;
203202
self->_eventsOffset = newOffset;
@@ -208,6 +207,7 @@ - (void)moreEvents:(int)offset
208207
});
209208
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error) {
210209
dispatch_async(dispatch_get_main_queue(), ^{
210+
@strongify(self);
211211
[self endRefreshing];
212212
[self.tableView.infiniteScrollingView stopAnimating];
213213
[self dismissLoadingView];
@@ -679,7 +679,7 @@ - (NSDictionary *)opsMap {
679679

680680
- (void)viewDidLayoutSubviews {
681681
[super viewDidLayoutSubviews];
682-
self.loadingView.center = self.view.center;
682+
[self.loadingView updatePosition];
683683
}
684684

685685
@end

seafile/SeafFileViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
typedef void(^DownloadCompleteBlock)(NSArray *array, NSString *errorStr);
1212

1313
@class SeafDetailViewController;
14+
@class SeafLoadingView;
1415

1516
#import <CoreData/CoreData.h>
1617

@@ -29,6 +30,8 @@ typedef void(^DownloadCompleteBlock)(NSArray *array, NSString *errorStr);
2930

3031
@property (strong, nonatomic) NSMutableDictionary *expandedSections; // To track expanded/collapsed sections
3132

33+
@property (strong, nonatomic) SeafLoadingView *loadingView;
34+
3235
- (void)refreshView;
3336
- (void)uploadFile:(SeafUploadFile *)file;
3437
- (void)deleteFile:(SeafFile *)file;

seafile/SeafFileViewController.m

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#import "SeafNavLeftItem.h"
4545
#import "SeafHeaderView.h"
4646
#import "SeafEditNavRightItem.h"
47+
#import "SeafLoadingView.h"
4748

4849
#define kCustomTabToolWithTopPadding 15
4950
#define kCustomTabToolButtonHeight 40
@@ -75,7 +76,6 @@ - (UITableViewCell *)getSeafDirCell:(SeafDir *)sdir forTableView:(UITableView *)
7576
- (UITableViewCell *)getSeafRepoCell:(SeafRepo *)srepo forTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath;
7677

7778
@property (strong) id curEntry; // Currently selected directory entry.
78-
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *loadingView;
7979

8080
@property (strong) UIBarButtonItem *selectAllItem;// Button to select all items in the directory.
8181
@property (strong) UIBarButtonItem *selectNoneItem;
@@ -136,6 +136,9 @@ - (void)viewDidLoad
136136
{
137137
[super viewDidLoad];
138138

139+
// Initialize loading view
140+
self.loadingView = [SeafLoadingView loadingViewWithParentView:self.view];
141+
139142
[self.tableView registerNib:[UINib nibWithNibName:@"SeafCell" bundle:nil]
140143
forCellReuseIdentifier:@"SeafCell"];
141144
[self.tableView registerNib:[UINib nibWithNibName:@"SeafDirCell" bundle:nil]
@@ -337,10 +340,7 @@ - (void)editSheet:(id)sender {
337340

338341
- (void)viewWillLayoutSubviews {
339342
[super viewWillLayoutSubviews];
340-
if (self.loadingView.isAnimating) {
341-
CGRect viewBounds = self.view.bounds;
342-
self.loadingView.center = CGPointMake(CGRectGetMidX(viewBounds), CGRectGetMidY(viewBounds));
343-
}
343+
[self.loadingView updatePosition];
344344
}
345345

346346

@@ -784,19 +784,19 @@ - (void)refreshView
784784

785785
- (void)showLoadingView
786786
{
787-
if (!self.loadingView) {
788-
self.loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
789-
self.loadingView.color = [UIColor darkTextColor];
790-
self.loadingView.hidesWhenStopped = YES;
791-
[self.view addSubview:self.loadingView];
792-
}
793-
self.loadingView.center = self.view.center;
794-
[self.loadingView startAnimating];
787+
// Get the key window for proper centering in the entire screen
788+
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
789+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
790+
// Only show loading view if still in loading state
791+
if (self.state == STATE_LOADING) {
792+
[self.loadingView showInView:keyWindow];
793+
}
794+
});
795795
}
796796

797797
- (void)dismissLoadingView
798798
{
799-
[self.loadingView stopAnimating];
799+
[self.loadingView dismiss];
800800
}
801801

802802
- (void)loadDataFromServerAndRefresh {
@@ -988,7 +988,6 @@ - (void)editDone:(id)sender
988988

989989
// Restore original title
990990
self.customTitleLabel.text = self.directory.name;
991-
_selectedindex = nil;
992991

993992
UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc] initWithCustomView:[SeafNavLeftItem navLeftItemWithDirectory:self.directory target:self action:@selector(backButtonTapped)]];
994993
self.navigationItem.leftBarButtonItem = customBarButton;
@@ -1059,7 +1058,6 @@ - (void)noneSelected:(BOOL)none
10591058
{
10601059
if (none) {
10611060
// Get done button container view
1062-
_selectedindex = nil;
10631061
UIView *containerView = (UIView *)self.doneItem.customView;
10641062
UILabel *countLabel = [containerView.subviews.lastObject isKindOfClass:[UILabel class]] ?
10651063
(UILabel *)containerView.subviews.lastObject : nil;
@@ -2926,7 +2924,7 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
29262924
if (![entry isKindOfClass:[SeafUploadFile class]]) {
29272925
// Select the cell that was long pressed
29282926
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
2929-
2927+
_selectedindex = indexPath;
29302928
// Update selection status
29312929
[self noneSelected:NO];
29322930
[self updateToolButtonsState];

seafile/SeafLoadingView.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// SeafLoadingView.h
3+
// seafilePro
4+
//
5+
// Created by henry on 2025/3/31.
6+
//
7+
8+
#import <UIKit/UIKit.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
@interface SeafLoadingView : UIView
13+
14+
+ (instancetype)loadingViewWithParentView:(UIView *)parentView;
15+
- (void)showInView:(UIView *)view;
16+
- (void)dismiss;
17+
- (void)updatePosition;
18+
19+
@end
20+
21+
NS_ASSUME_NONNULL_END

seafile/SeafLoadingView.m

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// SeafLoadingView.m
3+
// seafilePro
4+
//
5+
// Created by Seafile Ltd.
6+
// Copyright (c) 2024 Seafile Ltd. All rights reserved.
7+
//
8+
9+
#import "SeafLoadingView.h"
10+
11+
@interface SeafLoadingView()
12+
13+
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
14+
15+
@end
16+
17+
@implementation SeafLoadingView
18+
19+
+ (instancetype)loadingViewWithParentView:(UIView *)parentView {
20+
SeafLoadingView *loadingView = [[SeafLoadingView alloc] initWithFrame:CGRectMake(0, 0, parentView.bounds.size.width, parentView.bounds.size.height)];
21+
[loadingView setupActivityIndicator];
22+
return loadingView;
23+
}
24+
25+
- (void)setupActivityIndicator {
26+
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
27+
self.activityIndicator.color = [UIColor darkTextColor];
28+
self.activityIndicator.hidesWhenStopped = YES;
29+
[self addSubview:self.activityIndicator];
30+
31+
// Center the activity indicator in the loading view
32+
self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO;
33+
[NSLayoutConstraint activateConstraints:@[
34+
[self.activityIndicator.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
35+
[self.activityIndicator.centerYAnchor constraintEqualToAnchor:self.centerYAnchor]
36+
]];
37+
}
38+
39+
- (void)showInView:(UIView *)view {
40+
self.frame = view.bounds;
41+
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
42+
[view addSubview:self];
43+
[self.activityIndicator startAnimating];
44+
45+
// Ensure we're above all other views
46+
[view bringSubviewToFront:self];
47+
}
48+
49+
- (void)dismiss {
50+
[self.activityIndicator stopAnimating];
51+
[self removeFromSuperview];
52+
}
53+
54+
- (void)updatePosition {
55+
if (self.superview) {
56+
self.frame = self.superview.bounds;
57+
}
58+
}
59+
60+
@end

0 commit comments

Comments
 (0)