Skip to content

Commit

Permalink
Clean code and new settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymind committed Jul 17, 2017
1 parent 42529af commit 79b480f
Show file tree
Hide file tree
Showing 23 changed files with 599 additions and 433 deletions.
90 changes: 52 additions & 38 deletions LSUnusedResources.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
objects = {

/* Begin PBXBuildFile section */
114E8C711CCDC31B00434D1C /* LSFileUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 114E8C701CCDC31B00434D1C /* LSFileUtils.m */; };
B120ACA91F15D01F00930A95 /* FileUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = B120ACA41F15D01F00930A95 /* FileUtils.m */; };
B120ACAA1F15D01F00930A95 /* StringUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = B120ACA61F15D01F00930A95 /* StringUtils.m */; };
B120ACAE1F15D04000930A95 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B120ACAC1F15D04000930A95 /* Main.storyboard */; };
B120ACB11F16504A00930A95 /* ResourceSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = B120ACB01F16504900930A95 /* ResourceSettings.m */; };
B1313CAC1B942827001CD7CF /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B1313CAB1B942827001CD7CF /* AppDelegate.m */; };
B1313CAE1B942827001CD7CF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B1313CAD1B942827001CD7CF /* main.m */; };
B1313CC21B942828001CD7CF /* LSUnusedResourcesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B1313CC11B942828001CD7CF /* LSUnusedResourcesTests.m */; };
B1313CD41B943075001CD7CF /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B1313CCF1B943075001CD7CF /* Images.xcassets */; };
B1313CD51B943075001CD7CF /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1313CD21B943075001CD7CF /* MainViewController.m */; };
B1313CD91B943095001CD7CF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B1313CD71B943095001CD7CF /* Main.storyboard */; };
B16638261F1865CC0046CFC4 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B16638251F1865CC0046CFC4 /* Images.xcassets */; };
B19D81801B9451320097E947 /* ResourceFileSearcher.m in Sources */ = {isa = PBXBuildFile; fileRef = B19D817F1B9451320097E947 /* ResourceFileSearcher.m */; };
B19D81831B9451550097E947 /* ResourceStringSearcher.m in Sources */ = {isa = PBXBuildFile; fileRef = B19D81821B9451540097E947 /* ResourceStringSearcher.m */; };
B19D81861B959BDB0097E947 /* StringUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = B19D81851B959BDB0097E947 /* StringUtils.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -30,8 +31,13 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
114E8C6F1CCDC31B00434D1C /* LSFileUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSFileUtils.h; sourceTree = "<group>"; };
114E8C701CCDC31B00434D1C /* LSFileUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSFileUtils.m; sourceTree = "<group>"; };
B120ACA31F15D01F00930A95 /* FileUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileUtils.h; sourceTree = "<group>"; };
B120ACA41F15D01F00930A95 /* FileUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileUtils.m; sourceTree = "<group>"; };
B120ACA51F15D01F00930A95 /* StringUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtils.h; sourceTree = "<group>"; };
B120ACA61F15D01F00930A95 /* StringUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StringUtils.m; sourceTree = "<group>"; };
B120ACAD1F15D04000930A95 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Main.storyboard; sourceTree = "<group>"; };
B120ACAF1F16504900930A95 /* ResourceSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceSettings.h; sourceTree = "<group>"; };
B120ACB01F16504900930A95 /* ResourceSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ResourceSettings.m; sourceTree = "<group>"; };
B1313CA51B942827001CD7CF /* LSUnusedResources.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LSUnusedResources.app; sourceTree = BUILT_PRODUCTS_DIR; };
B1313CA91B942827001CD7CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B1313CAA1B942827001CD7CF /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand All @@ -40,16 +46,13 @@
B1313CBB1B942827001CD7CF /* LSUnusedResourcesTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LSUnusedResourcesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B1313CC01B942828001CD7CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B1313CC11B942828001CD7CF /* LSUnusedResourcesTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LSUnusedResourcesTests.m; sourceTree = "<group>"; };
B1313CCF1B943075001CD7CF /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
B1313CD11B943075001CD7CF /* MainViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainViewController.h; sourceTree = "<group>"; };
B1313CD21B943075001CD7CF /* MainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainViewController.m; sourceTree = "<group>"; };
B1313CD81B943095001CD7CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Main.storyboard; sourceTree = "<group>"; };
B16638251F1865CC0046CFC4 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
B19D817E1B9451320097E947 /* ResourceFileSearcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceFileSearcher.h; sourceTree = "<group>"; };
B19D817F1B9451320097E947 /* ResourceFileSearcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ResourceFileSearcher.m; sourceTree = "<group>"; };
B19D81811B9451540097E947 /* ResourceStringSearcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceStringSearcher.h; sourceTree = "<group>"; };
B19D81821B9451540097E947 /* ResourceStringSearcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ResourceStringSearcher.m; sourceTree = "<group>"; };
B19D81841B959BDB0097E947 /* StringUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringUtils.h; sourceTree = "<group>"; };
B19D81851B959BDB0097E947 /* StringUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StringUtils.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -70,6 +73,34 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
B120AC9E1F15D01F00930A95 /* Resource */ = {
isa = PBXGroup;
children = (
B16638251F1865CC0046CFC4 /* Images.xcassets */,
B120ACAB1F15D04000930A95 /* Base.lproj */,
);
path = Resource;
sourceTree = "<group>";
};
B120ACA21F15D01F00930A95 /* Utility */ = {
isa = PBXGroup;
children = (
B120ACA31F15D01F00930A95 /* FileUtils.h */,
B120ACA41F15D01F00930A95 /* FileUtils.m */,
B120ACA51F15D01F00930A95 /* StringUtils.h */,
B120ACA61F15D01F00930A95 /* StringUtils.m */,
);
path = Utility;
sourceTree = "<group>";
};
B120ACAB1F15D04000930A95 /* Base.lproj */ = {
isa = PBXGroup;
children = (
B120ACAC1F15D04000930A95 /* Main.storyboard */,
);
path = Base.lproj;
sourceTree = "<group>";
};
B1313C9C1B942827001CD7CF = {
isa = PBXGroup;
children = (
Expand All @@ -93,9 +124,10 @@
children = (
B1313CAA1B942827001CD7CF /* AppDelegate.h */,
B1313CAB1B942827001CD7CF /* AppDelegate.m */,
B120ACA21F15D01F00930A95 /* Utility */,
B1313CCB1B943075001CD7CF /* Model */,
B1313CD01B943075001CD7CF /* ViewController */,
B1313CCC1B943075001CD7CF /* Recourse */,
B120AC9E1F15D01F00930A95 /* Resource */,
B1313CA81B942827001CD7CF /* Supporting Files */,
);
path = LSUnusedResources;
Expand Down Expand Up @@ -134,23 +166,12 @@
B19D817F1B9451320097E947 /* ResourceFileSearcher.m */,
B19D81811B9451540097E947 /* ResourceStringSearcher.h */,
B19D81821B9451540097E947 /* ResourceStringSearcher.m */,
B19D81841B959BDB0097E947 /* StringUtils.h */,
B19D81851B959BDB0097E947 /* StringUtils.m */,
114E8C6F1CCDC31B00434D1C /* LSFileUtils.h */,
114E8C701CCDC31B00434D1C /* LSFileUtils.m */,
B120ACAF1F16504900930A95 /* ResourceSettings.h */,
B120ACB01F16504900930A95 /* ResourceSettings.m */,
);
path = Model;
sourceTree = "<group>";
};
B1313CCC1B943075001CD7CF /* Recourse */ = {
isa = PBXGroup;
children = (
B1313CD61B943095001CD7CF /* Base.lproj */,
B1313CCF1B943075001CD7CF /* Images.xcassets */,
);
path = Recourse;
sourceTree = "<group>";
};
B1313CD01B943075001CD7CF /* ViewController */ = {
isa = PBXGroup;
children = (
Expand All @@ -160,14 +181,6 @@
path = ViewController;
sourceTree = "<group>";
};
B1313CD61B943095001CD7CF /* Base.lproj */ = {
isa = PBXGroup;
children = (
B1313CD71B943095001CD7CF /* Main.storyboard */,
);
path = Base.lproj;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -248,8 +261,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B1313CD91B943095001CD7CF /* Main.storyboard in Resources */,
B1313CD41B943075001CD7CF /* Images.xcassets in Resources */,
B120ACAE1F15D04000930A95 /* Main.storyboard in Resources */,
B16638261F1865CC0046CFC4 /* Images.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -267,12 +280,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B120ACAA1F15D01F00930A95 /* StringUtils.m in Sources */,
B1313CAE1B942827001CD7CF /* main.m in Sources */,
B1313CAC1B942827001CD7CF /* AppDelegate.m in Sources */,
B120ACA91F15D01F00930A95 /* FileUtils.m in Sources */,
B19D81801B9451320097E947 /* ResourceFileSearcher.m in Sources */,
114E8C711CCDC31B00434D1C /* LSFileUtils.m in Sources */,
B19D81831B9451550097E947 /* ResourceStringSearcher.m in Sources */,
B19D81861B959BDB0097E947 /* StringUtils.m in Sources */,
B120ACB11F16504A00930A95 /* ResourceSettings.m in Sources */,
B1313CD51B943075001CD7CF /* MainViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -296,10 +310,10 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
B1313CD71B943095001CD7CF /* Main.storyboard */ = {
B120ACAC1F15D04000930A95 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
B1313CD81B943095001CD7CF /* Base */,
B120ACAD1F15D04000930A95 /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand Down
3 changes: 2 additions & 1 deletion LSUnusedResources/Model/ResourceFileSearcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ extern NSString * const kNotificationResourceFileQueryDone;

@interface ResourceFileSearcher : NSObject

@property (strong, nonatomic, readonly) NSMutableDictionary *resNameInfoDict;/**< dict<NSString name, ResourceFileInfo *info> */
@property (strong, nonatomic, readonly) NSMutableDictionary *resNameInfoDict;/**< dict<NSString *name, ResourceFileInfo *info> */

+ (instancetype)sharedObject;

- (void)startWithProjectPath:(NSString *)projectPath excludeFolders:(NSArray *)excludeFolders resourceSuffixs:(NSArray *)resourceSuffixs;

- (void)reset;

@end
6 changes: 3 additions & 3 deletions LSUnusedResources/Model/ResourceFileSearcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "ResourceFileSearcher.h"
#import "StringUtils.h"
#import "LSFileUtils.h"
#import "FileUtils.h"

NSString * const kNotificationResourceFileQueryDone = @"kNotificationResourceFileQueryDone";

Expand All @@ -30,7 +30,7 @@ - (NSImage *)image {
NSError *error = nil;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.path error:&error];
if (files.count == 0) {
return NO;
return nil;
}
for (NSString *file in files) {
if ([StringUtils isImageTypeWithName:file]) {
Expand Down Expand Up @@ -102,7 +102,7 @@ - (void)scanResourceFileWithProjectPath:(NSString *)projectPath excludeFolders:(
ResourceFileInfo *info = [ResourceFileInfo new];
info.name = name;
info.path = path;
info.fileSize = [LSFileUtils fileSizeAtPath:path isDir:&isDir];
info.fileSize = [FileUtils fileSizeAtPath:path isDir:&isDir];
info.isDir = isDir;
tempResNameInfoDict[keyName] = info;
}
Expand Down
29 changes: 29 additions & 0 deletions LSUnusedResources/Model/ResourceSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ResourceSettings.h
// LSUnusedResources
//
// Created by lslin on 2017/7/12.
// Copyright © 2017年 lessfun.com. All rights reserved.
//

#import <Foundation/Foundation.h>

#pragma mark - ResourceSettings

@interface ResourceSettings : NSObject

@property (strong, nonatomic) NSString *projectPath;
@property (strong, nonatomic) NSArray *excludeFolders; /**< <NSString *> */
@property (strong, nonatomic) NSArray *resourceSuffixs; /**< <NSString *> */
@property (strong, nonatomic) NSArray *resourcePatterns; /**< <NSDictionary *> */
@property (strong, nonatomic) NSNumber *matchSimilarName;

+ (instancetype)sharedObject;

- (void)updateResourcePatternAtIndex:(NSInteger)index withObject:(id)obj forKey:(NSString *)key;

- (void)addResourcePattern:(NSDictionary *)pattern;

- (void)removeResourcePatternAtIndex:(NSInteger)index;

@end
119 changes: 119 additions & 0 deletions LSUnusedResources/Model/ResourceSettings.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// ResourceSettings.m
// LSUnusedResources
//
// Created by lslin on 2017/7/12.
// Copyright © 2017年 lessfun.com. All rights reserved.
//

#import "ResourceSettings.h"

static NSString * const kSettingsKeyProjectPath = @"ProjectPath";
static NSString * const kSettingsKeyExcludeFolders = @"ExcludeFolders";
static NSString * const kSettingsKeyResourceSuffixs = @"ResourceSuffixs";
static NSString * const kSettingsKeyResourcePatterns = @"ResourcePatterns";
static NSString * const kSettingsKeyMatchSimilarName = @"MatchSimilarName";

#pragma mark - ResourceSettings

@interface ResourceSettings ()

@end

@implementation ResourceSettings

+ (instancetype)sharedObject {
static id _sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedInstance = [[self alloc] init];
});
return _sharedInstance;
}

- (id)init {
if (self = [super init]) {
_projectPath = [self getValueForKey:kSettingsKeyProjectPath];
_excludeFolders = [self getValueForKey:kSettingsKeyExcludeFolders];
_resourceSuffixs = [self getValueForKey:kSettingsKeyResourceSuffixs];
_resourcePatterns = [self getValueForKey:kSettingsKeyResourcePatterns];
_matchSimilarName = [self getValueForKey:kSettingsKeyMatchSimilarName];
}
return self;
}

#pragma mark - Public

- (void)updateResourcePatternAtIndex:(NSInteger)index withObject:(id)obj forKey:(NSString *)key {
NSMutableArray *patterns = [NSMutableArray arrayWithArray:self.resourcePatterns];
if (obj && patterns.count && index < patterns.count) {
NSMutableDictionary *pattern = [NSMutableDictionary dictionaryWithDictionary:[patterns objectAtIndex:index]];
[pattern setObject:obj forKey:key];
[patterns replaceObjectAtIndex:index withObject:[pattern copy]];
self.resourcePatterns = patterns;
}
}

- (void)addResourcePattern:(NSDictionary *)pattern {
if (pattern) {
NSMutableArray *patterns = [NSMutableArray arrayWithArray:self.resourcePatterns];
[patterns insertObject:pattern atIndex:0];
self.resourcePatterns = patterns;
}
}

- (void)removeResourcePatternAtIndex:(NSInteger)index {
NSMutableArray *patterns = [NSMutableArray arrayWithArray:self.resourcePatterns];
if (patterns.count && index < patterns.count) {
[patterns removeObjectAtIndex:index];
self.resourcePatterns = patterns;
}
}

#pragma mark - Property

- (void)setProjectPath:(NSString *)projectPath {
_projectPath = projectPath;
[self setValue:projectPath forKey:kSettingsKeyProjectPath];
}

- (void)setExcludeFolders:(NSArray *)excludeFolders {
_excludeFolders = excludeFolders;
[self setValue:excludeFolders forKey:kSettingsKeyExcludeFolders];
}

- (void)setResourceSuffixs:(NSArray *)resourceSuffixs {
_resourceSuffixs = resourceSuffixs;
[self setValue:resourceSuffixs forKey:kSettingsKeyResourceSuffixs];
}

- (void)setResourcePatterns:(NSArray *)resourcePatterns {
_resourcePatterns = resourcePatterns;
[self setValue:resourcePatterns forKey:kSettingsKeyResourcePatterns];
}

- (void)setMatchSimilarName:(NSNumber *)matchSimilarName {
_matchSimilarName = matchSimilarName;
[self setValue:matchSimilarName forKey:kSettingsKeyMatchSimilarName];
}

#pragma mark - Private

- (id)getValueForKey:(NSString *)key {
return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}

- (void)setValue:(id)value forKey:(NSString *)key {
if (!value || !key) {
return;
}
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)removeValueForKey:(NSString *)key {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
[[NSUserDefaults standardUserDefaults] synchronize];
}

@end
Loading

0 comments on commit 79b480f

Please sign in to comment.