//
|
// FileDownView.m
|
// GoldRich
|
//
|
// Created by WindShan on 2017/2/13.
|
// Copyright © 2017年 WindShan. All rights reserved.
|
//
|
|
#import "FileDownView.h"
|
#import "GloriaLabel.h"
|
#import "UIImageView+WebCache.h"
|
#import "FileDownCell.h"
|
#import "MBProgressHUD+Add.h"
|
#import "NetworkSingleton.h"
|
#import "LHDB.h"
|
#import "JXTAlertManagerHeader.h"
|
|
|
@interface FileDownView()<UITableViewDelegate,UITableViewDataSource,cellHandleDelegate,
|
DirectoryWatcherDelegate,
|
UIDocumentInteractionControllerDelegate>
|
/*
|
// Only override drawRect: if you perform custom drawing.
|
// An empty implementation adversely affects performance during animation.
|
- (void)drawRect:(CGRect)rect {
|
// Drawing code
|
}
|
*/
|
{
|
UIButton* deviceOpenBtn;
|
NSInteger pageIndex;
|
NSInteger pageSize;
|
|
}
|
|
@end
|
|
|
@implementation FileDownView
|
|
- (void)setupDocumentControllerWithURL:(NSURL *)url
|
{
|
if (self.docInteractionController == nil)
|
{
|
self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
|
self.docInteractionController.delegate = self;
|
}
|
else
|
{
|
self.docInteractionController.URL = url;
|
}
|
}
|
|
- (void)directoryDidChange:(DirectoryWatcher *)folderWatcher
|
{
|
|
}
|
|
- (UITableView *)tableView
|
{
|
if (!_tableView)
|
{
|
_tableView = [[UITableView alloc] init];
|
|
|
_tableView.delegate = self;
|
_tableView.dataSource = self;
|
_tableView.separatorColor = [UIColor clearColor];
|
|
[self addSubview:_tableView];
|
|
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.edges.mas_equalTo(UIEdgeInsetsMake(0 , 0, 0, 0));
|
}];
|
|
_tableView.tableFooterView = [UIView new];
|
}
|
return _tableView;
|
}
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
{
|
if (self = [super initWithFrame:frame])
|
{
|
self.tableView.frame = frame;
|
self.tableView.hidden = NO;
|
self.modelArray = [[NSMutableArray alloc] init];
|
pageIndex = 1;
|
pageSize = 20;
|
|
[self createTable];
|
|
[self loadDataFromDB];
|
|
[self setUpTableView];
|
}
|
|
return self;
|
}
|
|
|
|
- (void)didCellHandleSection:(FileStatus*)model
|
{
|
//NSString * handleCmd; // 操作命令 1 下载 2 暂停 3 删除 4 查看 5 更新
|
if([model.handleCmd intValue] == 3)
|
{
|
jxt_showAlertTwoButton(@"系统提示", @"是否删除该文件", @"取消", ^(NSInteger buttonIndex)
|
{
|
NSLog(@"取消");
|
}, @"确定", ^(NSInteger buttonIndex)
|
{
|
|
LHPredicate* predicate = [LHPredicate predicateWithFormat:@"path = '%@'",((FileStatus*)model).path];
|
[self deleteDataWithPredicate:predicate];
|
|
[self loadDataFromDB];
|
NSLog(@"确定");
|
});
|
}
|
else if([model.handleCmd intValue] == 4)
|
{
|
// 查看文件
|
if ( _delegate && [_delegate respondsToSelector:@selector(didSelectedDownSection:)])
|
{
|
[_delegate didSelectedDownSection:model];
|
}
|
}
|
}
|
|
|
-(void)setUpTableView
|
{
|
//添加下拉的动画图片
|
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadNewData方法)
|
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getFirstPageData)];
|
|
// 马上进入刷新状态
|
// [_tableView.mj_header beginRefreshing];
|
|
|
// 设置回调(一旦进入刷新状态,就调用target的action,也就是调用self的loadMoreData方法)
|
//_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(reloadData)];
|
|
}
|
|
-(void)getFirstPageData
|
{
|
if (self.modelArray.count>0)
|
{
|
[self.modelArray removeAllObjects];
|
}
|
|
[LHDBPath instanceManagerWith:DEFAULT_PATH];
|
NSArray* array = [self selectDataWithPredicate:nil];
|
[self.modelArray addObjectsFromArray:array];
|
|
[self.tableView reloadData];
|
|
[self.tableView.mj_header endRefreshing];
|
}
|
|
- (void) reSetView
|
{
|
if (self.modelArray.count>0)
|
{
|
[self.modelArray removeAllObjects];
|
}
|
|
[LHDBPath instanceManagerWith:DEFAULT_PATH];
|
NSArray* array = [self selectDataWithPredicate:nil];
|
[self.modelArray addObjectsFromArray:array];
|
|
[self.tableView reloadData];
|
|
}
|
|
#pragma mark - UITableViewDelegate&UITableViewDataSource
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
{
|
return 1;
|
}
|
|
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
//{
|
// return 0;
|
//}
|
//
|
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
{
|
return 0;
|
}
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
{
|
return self.modelArray.count;
|
}
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
return 65;
|
}
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
|
NSString * identifier = @"StatusCell";
|
FileDownCell * statusCell = [tableView dequeueReusableCellWithIdentifier:identifier];
|
if (nil == statusCell)
|
{
|
statusCell = [[FileDownCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
|
}
|
|
statusCell.delegate = self;
|
statusCell.selectionStyle = UITableViewCellSelectionStyleNone;
|
statusCell.userInteractionEnabled = YES;
|
|
FileStatus * model = [self.modelArray objectAtIndex:indexPath.row];
|
model.row = [[NSString stringWithFormat:@"%ld",indexPath.row] integerValue];
|
[statusCell setItemView:model];
|
|
return statusCell;
|
}
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
{
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
// if ( _delegate && [_delegate respondsToSelector:@selector(didSelectedDownSection:)])
|
// {
|
// FileStatus * model = [self.modelArray objectAtIndex:indexPath.row];
|
// [_delegate didSelectedDownSection:model];
|
// }
|
}
|
|
|
#pragma mark- LHDB
|
- (void)loadDataFromDB
|
{
|
if (self.modelArray.count>0)
|
{
|
[self.modelArray removeAllObjects];
|
}
|
|
[LHDBPath instanceManagerWith:DEFAULT_PATH];
|
NSArray* array = [self selectDataWithPredicate:nil];
|
[self.modelArray addObjectsFromArray:array];
|
|
[self.tableView reloadData];
|
}
|
|
|
//建表
|
- (void)createTable
|
{
|
[FileStatus createTable];
|
}
|
|
//数据插入
|
- (void)insertDataWithDic:(NSDictionary*)dic
|
{
|
[FileStatus saveWithDic:dic];
|
}
|
|
- (void)insertDataWithModel:(id)model
|
{
|
LHPredicate* predicate = [LHPredicate predicateWithFormat:@"path = '%@'",((FileStatus*)model).path];
|
|
NSArray* select = [self selectDataWithPredicate:predicate];
|
|
// 防止重复插入
|
if(select.count > 0)
|
{
|
[self updateDataWithModel:model predicate:predicate];
|
}
|
else
|
{
|
[model save];
|
}
|
}
|
|
//数据更新
|
- (void)updateDataWithDic:(NSDictionary*)dic predicate:(LHPredicate*)predicate
|
{
|
[FileStatus updateWithDic:dic predicate:predicate];
|
}
|
|
- (void)updateDataWithModel:(id)model predicate:(LHPredicate*)predicate
|
{
|
[model updateWithPredicate:predicate];
|
}
|
|
//数据删除
|
- (void)deleteDataWithPredicate:(LHPredicate*)predicate
|
{
|
[FileStatus deleteWithPredicate:predicate];
|
}
|
|
//数据查询
|
- (NSArray*)selectDataWithPredicate:(LHPredicate*)predicate
|
{
|
return [FileStatus selectWithPredicate:predicate];
|
}
|
|
|
@end
|