UIShopTableCell added and configured

This commit is contained in:
Brieuc Viel 2016-09-27 17:22:56 +02:00
parent 672555513c
commit cbf7d39cd2
4 changed files with 191 additions and 19 deletions

View file

@ -0,0 +1,31 @@
/* UIShopTableCell.h
*
* Copyright (C) 2012 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <UIKit/UIKit.h>
@interface UIShopTableCell : UITableViewCell
@property(nonatomic, strong) IBOutlet UILabel *nameLabel;
@property(nonatomic, strong) IBOutlet UILabel *descriptionLabel;
@property(weak, nonatomic) IBOutlet UIImageView *linphoneImage;
@property(weak, nonatomic) IBOutlet UIImageView *infoImage;
- (id)initWithIdentifier:(NSString *)identifier;
@end

View file

@ -0,0 +1,83 @@
/* UIShopTableCell.m
*
* Copyright (C) 2012 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "UIShopTableCell.h"
#import "Utils.h"
#import "UILabel+Boldify.h"
@implementation UIShopTableCell
UILabel *nameLabel;
UILabel *descriptionLabel;
UIImageView *linphoneImage;
UIImageView *infoImage;
#pragma mark - Lifecycle Functions
- (id)initWithIdentifier:(NSString *)identifier {
if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) {
NSArray *arrayOfViews =
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:self options:nil];
// resize cell to match .nib size. It is needed when resized the cell to
// correctly adapt its height too
UIView *sub = ((UIView *)[arrayOfViews objectAtIndex:0]);
[self setFrame:CGRectMake(0, 0, sub.frame.size.width, sub.frame.size.height)];
[self addSubview:sub];
// Sections are wider on iPad and overlap linphone image - let's move it a bit
if (IPAD) {
CGRect frame = _linphoneImage.frame;
frame.origin.x -= frame.size.width / 2;
_linphoneImage.frame = frame;
}
}
return self;
}
#pragma mark -
- (void)touchUp:(id)sender {
[self setHighlighted:true animated:true];
}
- (void)touchDown:(id)sender {
[self setHighlighted:false animated:true];
}
- (NSString *)accessibilityLabel {
return _nameLabel.text;
}
- (void)setEditing:(BOOL)editing {
[self setEditing:editing animated:FALSE];
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
if (animated) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
}
_linphoneImage.alpha = editing ? 0 : 1;
if (animated) {
[UIView commitAnimations];
}
}
@end

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11198.2" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="UIShopTableCell">
<connections>
<outlet property="descriptionLabel" destination="ywN-JT-HTo" id="BnY-8x-cw4"/>
<outlet property="infoImage" destination="25" id="R8I-k9-Zg8"/>
<outlet property="linphoneImage" destination="ZKs-g7-On2" id="Rg2-R9-glb"/>
<outlet property="nameLabel" destination="6" id="26"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" misplaced="YES" id="16">
<rect key="frame" x="0.0" y="0.0" width="360" height="54"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="2" contentMode="left" misplaced="YES" text="John Doe" lineBreakMode="tailTruncation" minimumFontSize="9" id="6" userLabel="nameLabel">
<frame key="frameInset" minX="52" minY="-2" width="78.57%" height="24"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<accessibility key="accessibilityConfiguration" label="Firstname"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="2" contentMode="left" misplaced="YES" text="John Doe John DoeJohn DoeJohn DoeJohn DoeJohn DoeJohn DoeJohn Doe" lineBreakMode="tailTruncation" numberOfLines="2" minimumFontSize="6" id="ywN-JT-HTo" userLabel="descriptionLabel">
<frame key="frameInset" minX="14.44%" minY="19" width="67.22%" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<accessibility key="accessibilityConfiguration" label="Firstname"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="list_details_default.png" id="25" userLabel="infoImage">
<frame key="frameInset" minY="50.00%" width="25" height="22" maxX="25"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" misplaced="YES" image="linphone_logo.png" id="ZKs-g7-On2" userLabel="linphoneImage">
<frame key="frameInset" minX="1.22%" minY="50.00%" width="32" height="28"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</imageView>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="25" y="57"/>
</view>
</objects>
<resources>
<image name="linphone_logo.png" width="26" height="22"/>
<image name="list_details_default.png" width="34" height="34"/>
</resources>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4_7.fullscreen"/>
</simulatedMetricsContainer>
</document>

View file

@ -9,6 +9,7 @@
#import "ShopTableView.h"
#import "ShopView.h"
#import "PhoneMainView.h"
#import "LinphoneUI/UIShopTableCell.h"
@implementation ShopTableView
@ -16,7 +17,6 @@
[super viewDidLoad];
// remove separators between empty items, cf
// http://stackoverflow.com/questions/1633966/can-i-force-a-uitableview-to-hide-the-separator-between-empty-cells
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
@ -31,11 +31,13 @@
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class)];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:NSStringFromClass(self.class)];
static NSString *kCellId = @"UIShopTableCell";
UIShopTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId];
if (cell == nil) {
cell = [[UIShopTableCell alloc] initWithIdentifier:kCellId];
}
SKProduct *product = LinphoneManager.instance.iapManager.productsAvailable[indexPath.row];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
@ -44,13 +46,14 @@
[numberFormatter setLocale:product.priceLocale];
NSString *price = [numberFormatter stringFromNumber:product.price];
cell.textLabel.text = [NSString stringWithFormat:@"%@ (%@)", product.localizedTitle, price];
cell.detailTextLabel.text = product.localizedDescription;
cell.detailTextLabel.numberOfLines = 2;
cell.detailTextLabel.minimumScaleFactor = .5;
cell.detailTextLabel.adjustsFontSizeToFitWidth = cell.detailTextLabel.adjustsLetterSpacingToFitWidth = YES;
cell.accessoryType = UITableViewCellAccessoryDetailButton;
[cell setImage:[UIImage imageNamed:@"linphone_logo"]];
cell.nameLabel.text = [NSString stringWithFormat:@"%@ (%@)", product.localizedTitle, price];
cell.descriptionLabel.numberOfLines = 2;
cell.descriptionLabel.minimumScaleFactor = .5;
cell.descriptionLabel.adjustsFontSizeToFitWidth = cell.detailTextLabel.adjustsLetterSpacingToFitWidth = YES;
cell.descriptionLabel.text = [NSString stringWithFormat:@"%@", product.localizedDescription];
LOGE(@"ShopTableView : name = %@ - descr = %@",
[NSString stringWithFormat:@"%@ (%@)", product.localizedTitle, price], product.localizedDescription);
[cell.linphoneImage setImage:[UIImage imageNamed:@"linphone_logo"]];
return cell;
}
@ -60,13 +63,6 @@
SKProduct *product = LinphoneManager.instance.iapManager.productsAvailable[indexPath.row];
[LinphoneManager.instance.iapManager purchaseWithID:product.productIdentifier];
/* UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *topView = window.rootViewController.view;
UIView *waitview = (UIView*)[topView viewWithTag:288];
[waitview setHidden:FALSE];
*/
}
@end