This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-iOS/Devkit/Classes/DoricShowNodeTreeViewController.m

119 lines
19 KiB
Mathematica
Raw Normal View History

2021-07-14 19:54:34 +08:00
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// DoricShowNodeTreeViewController.m
// Doric
//
// Created by jingpeng.wang on 2021/7/8.
//
#import "DoricShowNodeTreeViewController.h"
#import "DoricShowNodeTreeViewCell.h"
#import "RATreeView.h"
#import <DoricCore/DoricContextManager.h>
#import <DoricCore/DoricContext.h>
#import <DoricCore/DoricGroupNode.h>
@interface DoricShowNodeTreeViewController () <RATreeViewDelegate, RATreeViewDataSource>
@property(nonatomic, weak) DoricContext *doricContext;
@property(nonatomic, weak) NSString *collapse;
@property(nonatomic, weak) NSString *expand;
@end
@implementation DoricShowNodeTreeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.collapse = @"iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAWIElEQVR4Xu2de5Tc9HXH79Wu7RpDAg3gBA4JIYEEOBAO0FAoCS55EEOA3ZW0tvFKYxuzo1ljwOFVnsa8Eh4xEOMdzWLsHck2eKUxHHMotDQFCjmkJDQPCpwSUk4hCaRAAi2pX7u6PRoT4oDtnfndmV1Jc+df/z5fXX2/+p7Z8Yx+QpCXOCAO7NQBzKI3XXbhq0jReYh4MAAcSAj3QkRBxS/9fRbPV86peQ5kqiC6XTgSkBYhwZwdWoZ0e1guLWqenaKcNQcyUxDdyp+KiAMAsP+uQiKAtRXPnZ21IOV8muNAJgpi9hQ+Bxo9SQ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PADBUxgEaW9o4Kk2OhlbKtWzly074KBXdw4RQpyZ2BNIY2nPXfs8M860y9vCIBOXW+cQBYMAyNlg9NkgCNKjgwM/mnays2yCs9PLfvugjrFBIjqXUxoB/S0FFPagLfaubBuDTFxufYyw+tq0+gajBL8kiKXK7pofcBqtk7arq/fwsU5jkAD+kln3w3PGMD08XPgfZpymydvKIBOXW6cR4iAQKG8wSg
self.doricContext = [[DoricContextManager instance] getContext:self.contextId];
RATreeView *treeView = [[RATreeView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:treeView];
treeView.delegate = self;
treeView.dataSource = self;
[treeView registerClass:DoricShowNodeTreeViewCell.self forCellReuseIdentifier:@"cell"];
[treeView reloadData];
}
#pragma mark ratreeview delegate
- (nonnull UITableViewCell *)treeView:(nonnull RATreeView *)treeView cellForItem:(nullable id)item {
DoricShowNodeTreeViewCell *cell = [treeView dequeueReusableCellWithIdentifier:@"cell"];
cell.nodeNameLabel.text = [item description];
[cell.nodeNameLabel sizeToFit];
if ([item isKindOfClass:[DoricGroupNode class]]) {
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:self.collapse
options:NSDataBase64DecodingIgnoreUnknownCharacters];
cell.nodeIcon.image = [UIImage imageWithData:imageData];
} else {
cell.nodeIcon.image = nil;
}
NSInteger indent = [treeView levelForCellForItem:item];
cell.nodeIcon.left = indent * 30;
cell.nodeNameLabel.left = 30 + indent * 30;
return cell;
}
- (nonnull id)treeView:(nonnull RATreeView *)treeView child:(NSInteger)index ofItem:(nullable id)item {
if (item == nil) {
return self.doricContext.rootNode;
} else {
DoricGroupNode *groupNode = item;
return groupNode.childNodes[index];
}
}
- (NSInteger)treeView:(nonnull RATreeView *)treeView numberOfChildrenOfItem:(nullable id)item {
if (item == nil) {
return 1;
} else if ([item isKindOfClass:[DoricGroupNode class]]) {
DoricGroupNode *groupNode = item;
return groupNode.childNodes.count;
}
return 0;
}
- (CGFloat)treeView:(RATreeView *)treeView heightForRowForItem:(id)item {
return 50;
}
- (void)treeView:(RATreeView *)treeView willExpandRowForItem:(id)item {
if ([item isKindOfClass:[DoricGroupNode class]]) {
DoricShowNodeTreeViewCell *cell = (DoricShowNodeTreeViewCell *)[treeView cellForItem:item];
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:self.expand
options:NSDataBase64DecodingIgnoreUnknownCharacters];
cell.nodeIcon.image = [UIImage imageWithData:imageData];
}
}
- (void)treeView:(RATreeView *)treeView willCollapseRowForItem:(id)item {
if ([item isKindOfClass:[DoricGroupNode class]]) {
DoricShowNodeTreeViewCell *cell = (DoricShowNodeTreeViewCell *)[treeView cellForItem:item];
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:self.collapse
options:NSDataBase64DecodingIgnoreUnknownCharacters];
cell.nodeIcon.image = [UIImage imageWithData:imageData];
}
}
@end