-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKBDockCollectionView.mm
86 lines (72 loc) · 3.59 KB
/
KBDockCollectionView.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// KBDockCollectionView.m
// KBDock
//
// Created by 陈鹏宇 on 2019/3/26.
// Copyright © 2019年 陈鹏宇 . All rights reserved.
//
#import "KBDockCollectionView.h"
#import "KBDockCollectionViewCell.h"
#import <AppList/AppList.h>
#import "UIImpactFeedbackGenerator+Feedback.h"
#import "KBAppManager.h"
static NSString *sortedPlist = @"/var/mobile/Library/Preferences/com.nactro.kbdocksettings.sortedList.plist";
static NSString *originalPlist = @"/var/mobile/Library/Preferences/com.nactro.kbdocksettings.list.plist";
static LSApplicationWorkspace* workspace = [NSClassFromString(@"LSApplicationWorkspace") new];
static BOOL haveSortedPlist = NO;
@interface KBDockCollectionView() <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) KBDockCollectionViewCell *appCollectionCell;
@end
@implementation KBDockCollectionView
- (instancetype)init {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.minimumLineSpacing = 20;
if(self = [super initWithFrame:CGRectZero collectionViewLayout:flowLayout]) {
self.delegate = self;
self.dataSource = self;
self.showsHorizontalScrollIndicator = NO;
self.pagingEnabled = YES;
[self registerClass:NSClassFromString(@"KBDockCollectionViewCell") forCellWithReuseIdentifier:@"KBDock"];
self.backgroundColor = [UIColor clearColor];
[self checkSortedPlistIfExistWithPath:sortedPlist];
}
return self;
}
- (void)checkSortedPlistIfExistWithPath:(NSString *)sortedListPath{
NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:sortedListPath]) {
haveSortedPlist = YES;
}else{
haveSortedPlist = NO;
}
}
#pragma mark - UICollectionViewDelegate
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
KBDockCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KBDock" forIndexPath:indexPath];
UIImage *image;
if (haveSortedPlist) {
image = [[ALApplicationList sharedApplicationList] iconOfSize:ALApplicationIconSizeLarge forDisplayIdentifier:[[KBAppManager sharedManager]getSortedAppListArrayFromPath:sortedPlist][indexPath.row]];
}else{
image = [[ALApplicationList sharedApplicationList] iconOfSize:ALApplicationIconSizeLarge forDisplayIdentifier:[[KBAppManager sharedManager]getAppListToArrayWithAppPlistPath:originalPlist][indexPath.row]];
}
cell.appImageView.image = image;
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [[[KBAppManager sharedManager]getAppListToArrayWithAppPlistPath:originalPlist] count];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(30, 30);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[UIImpactFeedbackGenerator generateFeedbackWithLightStyle];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
if (haveSortedPlist) {
[workspace openApplicationWithBundleID:[[KBAppManager sharedManager]getSortedAppListArrayFromPath:sortedPlist][indexPath.row]];
}else{
[workspace openApplicationWithBundleID:[[KBAppManager sharedManager]getAppListToArrayWithAppPlistPath:originalPlist][indexPath.row]];
}
});
}
@end