Skip to content

Commit

Permalink
Merge pull request badoo#85 from Viacheslav-Radchenko/dev
Browse files Browse the repository at this point in the history
Show placeholder cells in photo input if not enough photos
  • Loading branch information
diegosanchezr committed Mar 24, 2016
2 parents f20f978 + e102878 commit 036beb2
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 4 deletions.
8 changes: 8 additions & 0 deletions ChattoAdditions/ChattoAdditions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
C3C0CC8D1BFE49700052747C /* ObservableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C0CC7F1BFE49700052747C /* ObservableTests.swift */; };
C3EFA6B01C03607A0063CE22 /* BaseMessagePresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3EFA6AF1C03607A0063CE22 /* BaseMessagePresenterTests.swift */; };
CA073E791C47F5B9009D5EBF /* Chatto.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA073E781C47F5B9009D5EBF /* Chatto.framework */; };
F6D04BA71CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6D04BA61CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift */; };
F6D04BA91CA46D5000E803FA /* PhotosInputWithPlaceholdersDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6D04BA81CA46D5000E803FA /* PhotosInputWithPlaceholdersDataProviderTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -165,6 +167,8 @@
C3C0CC961BFE4A2A0052747C /* ChattoAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChattoAdditions.h; sourceTree = "<group>"; };
C3EFA6AF1C03607A0063CE22 /* BaseMessagePresenterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseMessagePresenterTests.swift; sourceTree = "<group>"; };
CA073E781C47F5B9009D5EBF /* Chatto.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Chatto.framework; path = "../../../../Library/Developer/Xcode/DerivedData/Chatto-gyrilfusfbpmohajjvmmctphuabr/Build/Products/Debug-iphoneos/Chatto.framework"; sourceTree = "<group>"; };
F6D04BA61CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosInputPlaceholderDataProviderTests.swift; sourceTree = "<group>"; };
F6D04BA81CA46D5000E803FA /* PhotosInputWithPlaceholdersDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosInputWithPlaceholdersDataProviderTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -415,6 +419,8 @@
C3C0CC7C1BFE49700052747C /* PhotosChatInputItemTests.swift */,
C3C0CC7D1BFE49700052747C /* PhotosInputViewItemSizeCalculatorTests.swift */,
C3C0CC7E1BFE49700052747C /* TextChatInputItemTests.swift */,
F6D04BA61CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift */,
F6D04BA81CA46D5000E803FA /* PhotosInputWithPlaceholdersDataProviderTests.swift */,
);
path = Input;
sourceTree = "<group>";
Expand Down Expand Up @@ -617,9 +623,11 @@
C3C0CC881BFE49700052747C /* ChatInputPresenterTests.swift in Sources */,
C3815D001C036B3000DF95CA /* PhotoMessagePresenterBuilderTests.swift in Sources */,
C3C0CC891BFE49700052747C /* LiveCameraCellTests.swift in Sources */,
F6D04BA91CA46D5000E803FA /* PhotosInputWithPlaceholdersDataProviderTests.swift in Sources */,
C35FE3C51C0331CF00D42980 /* TextMessagePresenterTests.swift in Sources */,
C3C0CC8A1BFE49700052747C /* PhotosChatInputItemTests.swift in Sources */,
C3C0CC8B1BFE49700052747C /* PhotosInputViewItemSizeCalculatorTests.swift in Sources */,
F6D04BA71CA46C0200E803FA /* PhotosInputPlaceholderDataProviderTests.swift in Sources */,
C3C0CC851BFE49700052747C /* ChatInputBarTests.swift in Sources */,
C3C0CC8D1BFE49700052747C /* ObservableTests.swift in Sources */,
C3C0CC871BFE49700052747C /* ChatInputItemViewTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class PhotosInputPlaceholderCellProvider: PhotosInputCellProviderProtocol {
class PhotosInputCellProvider: PhotosInputCellProviderProtocol {
private var reuseIdentifier = "PhotosCellProvider"
private let collectionView: UICollectionView
private let dataProvider: PhotosInputDataProvider
init(collectionView: UICollectionView, dataProvider: PhotosInputDataProvider) {
private let dataProvider: PhotosInputDataProviderProtocol
init(collectionView: UICollectionView, dataProvider: PhotosInputDataProviderProtocol) {
self.dataProvider = dataProvider
self.collectionView = collectionView
self.collectionView.registerClass(PhotosInputCell.self, forCellWithReuseIdentifier: self.reuseIdentifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ protocol PhotosInputDataProviderProtocol {
}

class PhotosInputPlaceholderDataProvider: PhotosInputDataProviderProtocol {

let numberOfPlaceholders: Int

init(numberOfPlaceholders: Int = 5) {
self.numberOfPlaceholders = numberOfPlaceholders
}

var count: Int {
return 5
return self.numberOfPlaceholders
}

func requestPreviewImageAtIndex(index: Int, targetSize: CGSize, completion: (UIImage) -> Void) -> Int32 {
Expand Down Expand Up @@ -86,3 +93,38 @@ class PhotosInputDataProvider: PhotosInputDataProviderProtocol {
}
}
}

class PhotosInputWithPlaceholdersDataProvider: PhotosInputDataProviderProtocol {

private let photosDataProvider: PhotosInputDataProviderProtocol
private let placeholdersDataProvider: PhotosInputDataProviderProtocol

init(photosDataProvider: PhotosInputDataProviderProtocol, placeholdersDataProvider: PhotosInputDataProviderProtocol) {
self.photosDataProvider = photosDataProvider
self.placeholdersDataProvider = placeholdersDataProvider
}

var count: Int {
return max(self.photosDataProvider.count, self.placeholdersDataProvider.count)
}

func requestPreviewImageAtIndex(index: Int, targetSize: CGSize, completion: (UIImage) -> Void) -> Int32 {
if index < self.photosDataProvider.count {
return self.photosDataProvider.requestPreviewImageAtIndex(index, targetSize: targetSize, completion: completion)
} else {
return self.placeholdersDataProvider.requestPreviewImageAtIndex(index, targetSize: targetSize, completion: completion)
}
}

func requestFullImageAtIndex(index: Int, completion: (UIImage) -> Void) {
if index < self.photosDataProvider.count {
return self.photosDataProvider.requestFullImageAtIndex(index, completion: completion)
} else {
return self.placeholdersDataProvider.requestFullImageAtIndex(index, completion: completion)
}
}

func cancelPreviewImageRequest(requestID: Int32) {
return self.photosDataProvider.cancelPreviewImageRequest(requestID)
}
}
2 changes: 1 addition & 1 deletion ChattoAdditions/Source/Input/Photos/PhotosInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class PhotosInputView: UIView, PhotosInputViewProtocol {
}

private func replacePlaceholderItemsWithPhotoItems() {
let newDataProvider = PhotosInputDataProvider()
let newDataProvider = PhotosInputWithPlaceholdersDataProvider(photosDataProvider: PhotosInputDataProvider(), placeholdersDataProvider: PhotosInputPlaceholderDataProvider())
self.dataProvider = newDataProvider
self.cellProvider = PhotosInputCellProvider(collectionView: self.collectionView, dataProvider: newDataProvider)
self.collectionView.reloadSections(NSIndexSet(index: 0))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
The MIT License (MIT)

Copyright (c) 2015-present Badoo Trading Limited.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import XCTest
@testable import ChattoAdditions

class PhotosInputPlaceholderDataProviderTests: XCTestCase {

func testThat_ProviderWithNumberOfPlaceholder_ThenCountReturnsThisNumber() {
let numberOfPlaceholders = 10
let dataProvider = PhotosInputPlaceholderDataProvider(numberOfPlaceholders: numberOfPlaceholders)
XCTAssertEqual(numberOfPlaceholders, dataProvider.count)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
The MIT License (MIT)

Copyright (c) 2015-present Badoo Trading Limited.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import XCTest
@testable import ChattoAdditions

class PhotosInputWithPlaceholderDataProviderTests: XCTestCase {

func testThat_GivenProviderWithNumberOfPlaceholdersGreaterThenNumberOfPhotos_ThenCountReturnsGreaterNumber() {
let numberOfPhotos = 1
let photosDataProvider = PhotosInputPlaceholderDataProvider(numberOfPlaceholders: numberOfPhotos)
let numberOfPlaceholders = 10
let placeholdersDataProvider = PhotosInputPlaceholderDataProvider(numberOfPlaceholders: numberOfPlaceholders)
let dataProvider = PhotosInputWithPlaceholdersDataProvider(photosDataProvider: photosDataProvider, placeholdersDataProvider: placeholdersDataProvider)
XCTAssertEqual(numberOfPlaceholders, dataProvider.count)
}

func testThat_GivenProviderWithNumberOfPhotosGreaterThenNumberOfPlaceholders_ThenCountReturnsGreaterNumber() {
let numberOfPhotos = 10
let photosDataProvider = PhotosInputPlaceholderDataProvider(numberOfPlaceholders: numberOfPhotos)
let numberOfPlaceholders = 1
let placeholdersDataProvider = PhotosInputPlaceholderDataProvider(numberOfPlaceholders: numberOfPlaceholders)
let dataProvider = PhotosInputWithPlaceholdersDataProvider(photosDataProvider: photosDataProvider, placeholdersDataProvider: placeholdersDataProvider)
XCTAssertEqual(numberOfPhotos, dataProvider.count)
}
}

0 comments on commit 036beb2

Please sign in to comment.