Marino Faggiana 8 سال پیش
والد
کامیت
3ee81dc5f1

+ 62 - 13
iOSClient/MenuAccount+ControlCenter/CCControlCenterActivity.m

@@ -14,7 +14,8 @@
 @interface CCControlCenterActivity ()
 {
     // Datasource
-    CCSectionDataSourceActivity *_sectionDataSource;
+    NSArray *_sectionDataSource;
+    NSDate *_oldDate;
 }
 @end
 
@@ -37,7 +38,8 @@
     
     [super viewDidLoad];
     
-    _sectionDataSource = [CCSectionDataSourceActivity new];
+    _sectionDataSource = [NSArray new];
+    _oldDate = [NSDate date];
     
     // empty Data Source
   
@@ -80,11 +82,11 @@
     
     if (app.controlCenter.isOpen) {
         
-        NSArray *records = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@)", app.activeAccount]];
+         _sectionDataSource = [CCCoreData getAllTableActivityWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@)", app.activeAccount]];
         
-        _sectionDataSource = [CCSectionActivity creataDataSourseSectionActivity:records activeAccount:app.activeAccount];
+        //_sectionDataSource = [CCSectionActivity creataDataSourseSectionActivity:records activeAccount:app.activeAccount];
         
-        if ([records count] == 0) {
+        if ([_sectionDataSource count] == 0) {
             
             app.controlCenter.noRecord.text = NSLocalizedString(@"_no_activity_",nil);
             app.controlCenter.noRecord.hidden = NO;
@@ -106,12 +108,27 @@
 
 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
 {
-    return [[_sectionDataSource.sectionArrayRow allKeys] count];
+    return [_sectionDataSource count];
 }
 
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
 {
-    return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
+    //return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
+    return 10;
+}
+
+-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
+{
+    TableActivity *activity = [_sectionDataSource objectAtIndex:section];
+    
+    UILabel *subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, collectionView.frame.size.width , CGFLOAT_MAX)];
+    subjectLabel.numberOfLines = 0;
+    subjectLabel.lineBreakMode = NSLineBreakByWordWrapping;
+    [subjectLabel setFont:[UIFont fontWithName:@"System" size:12]];
+    subjectLabel.text = activity.subject;
+    [subjectLabel sizeToFit];
+
+    return CGSizeMake(collectionView.frame.size.width, subjectLabel.frame.size.height+22+20);
 }
 
 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
@@ -120,12 +137,26 @@
         
         UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
         
-        //headerView.backgroundColor = COLOR_GROUPBY_BAR_NO_BLUR;
+        TableActivity *activity = [_sectionDataSource objectAtIndex:indexPath.section];
+        
+        NSDateComponents* comps = [[NSCalendar currentCalendar] components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:activity.date];
+        NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:comps];
         
-        UILabel *titleLabel = (UILabel *)[headerView viewWithTag:100];
-        titleLabel.textColor = COLOR_TEXT_ANTHRACITE;
-        titleLabel.text = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
+        UILabel *dataLabel = (UILabel *)[headerView viewWithTag:100];
+        UILabel *subjectLabel = (UILabel *)[headerView viewWithTag:101];
         
+        dataLabel.textColor = COLOR_TEXT_ANTHRACITE;
+        dataLabel.text =  [CCUtility getTitleSectionDate:date];
+        
+        subjectLabel.textColor = COLOR_TEXT_ANTHRACITE;
+        subjectLabel.text = activity.subject;
+        
+        
+        CGFloat x = [self getLabelHeight:subjectLabel];
+        
+        headerView.frame = CGRectMake(headerView.frame.origin.x, headerView.frame.origin.y, headerView.frame.size.width, 20 + dataLabel.frame.size.height + x);
+        headerView.backgroundColor = [UIColor redColor];
+
         return headerView;
     }
     
@@ -137,11 +168,29 @@
     UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
     cell.backgroundColor = [UIColor clearColor];
     
-    NSArray *metadatasForKey = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
-    TableActivity *activity = [metadatasForKey objectAtIndex:indexPath.row];
+    //NSArray *metadatasForKey = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
+    //TableActivity *activity = [metadatasForKey objectAtIndex:indexPath.row];
 
     
     return cell;
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark - ==== Utility ====
+#pragma --------------------------------------------------------------------------------------------
+
+
+- (CGFloat)getLabelHeight:(UILabel*)label
+{
+    CGSize constraint = CGSizeMake(label.frame.size.width, CGFLOAT_MAX);
+    CGSize size;
+    
+    NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
+    CGSize boundingBox = [label.text boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:context].size;
+    
+    size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height));
+    
+    return size.height;
+}
+
 @end

+ 27 - 7
iOSClient/MenuAccount+ControlCenter/ControlCenter.storyboard

@@ -6,6 +6,7 @@
     <dependencies>
         <deployment identifier="iOS"/>
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
+        <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
@@ -27,13 +28,13 @@
                         <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
                         <collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="cmY-iB-PWk">
                             <size key="itemSize" width="50" height="50"/>
-                            <size key="headerReferenceSize" width="50" height="24"/>
+                            <size key="headerReferenceSize" width="50" height="52"/>
                             <size key="footerReferenceSize" width="0.0" height="0.0"/>
                             <inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
                         </collectionViewFlowLayout>
                         <cells>
                             <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="cell" id="btw-Qo-oNg">
-                                <rect key="frame" x="0.0" y="24" width="50" height="50"/>
+                                <rect key="frame" x="0.0" y="52" width="50" height="50"/>
                                 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                 <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
                                     <rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
@@ -48,17 +49,36 @@
                             </collectionViewCell>
                         </cells>
                         <collectionReusableView key="sectionHeaderView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="header" id="6Zg-lt-YR9">
-                            <rect key="frame" x="0.0" y="0.0" width="375" height="24"/>
+                            <rect key="frame" x="0.0" y="0.0" width="375" height="52"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <subviews>
-                                <label opaque="NO" userInteractionEnabled="NO" tag="100" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CHD-zb-9Fb">
-                                    <rect key="frame" x="0.0" y="0.0" width="375" height="24"/>
-                                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                                <label opaque="NO" userInteractionEnabled="NO" tag="100" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CHD-zb-9Fb">
+                                    <rect key="frame" x="8" y="0.0" width="359" height="22"/>
+                                    <constraints>
+                                        <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="22" id="KNG-FZ-Mkw"/>
+                                    </constraints>
+                                    <fontDescription key="fontDescription" type="system" pointSize="12"/>
+                                    <nil key="textColor"/>
+                                    <nil key="highlightedColor"/>
+                                </label>
+                                <label opaque="NO" userInteractionEnabled="NO" tag="101" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="suK-ZC-07d">
+                                    <rect key="frame" x="8" y="30" width="359" height="22"/>
+                                    <constraints>
+                                        <constraint firstAttribute="height" relation="greaterThanOrEqual" constant="22" id="v2e-1C-t22"/>
+                                    </constraints>
                                     <fontDescription key="fontDescription" type="system" pointSize="12"/>
                                     <nil key="textColor"/>
                                     <nil key="highlightedColor"/>
                                 </label>
                             </subviews>
+                            <constraints>
+                                <constraint firstItem="CHD-zb-9Fb" firstAttribute="top" secondItem="6Zg-lt-YR9" secondAttribute="topMargin" constant="-8" id="E28-8I-PGy"/>
+                                <constraint firstAttribute="trailingMargin" secondItem="CHD-zb-9Fb" secondAttribute="trailing" id="LGu-oz-7Eo"/>
+                                <constraint firstAttribute="leadingMargin" secondItem="CHD-zb-9Fb" secondAttribute="leading" id="TE8-eb-tc2"/>
+                                <constraint firstAttribute="leadingMargin" secondItem="suK-ZC-07d" secondAttribute="leading" id="bsM-XS-4MA"/>
+                                <constraint firstItem="suK-ZC-07d" firstAttribute="top" secondItem="CHD-zb-9Fb" secondAttribute="bottom" constant="8" id="snE-f4-Nuo"/>
+                                <constraint firstAttribute="trailingMargin" secondItem="suK-ZC-07d" secondAttribute="trailing" id="uOW-VG-4zZ"/>
+                            </constraints>
                         </collectionReusableView>
                         <connections>
                             <outlet property="dataSource" destination="Sa9-Gr-Uug" id="TzW-IT-Zqv"/>
@@ -68,7 +88,7 @@
                 </collectionViewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="0k6-oO-NJC" userLabel="First Responder" sceneMemberID="firstResponder"/>
             </objects>
-            <point key="canvasLocation" x="7160.8000000000002" y="1646.6266866566718"/>
+            <point key="canvasLocation" x="7160.8000000000002" y="1667.3163418290856"/>
         </scene>
         <!--Control Center Transfer-->
         <scene sceneID="Gv7-Uy-0Cg">