├── .gitignore ├── CONTRIBUTING ├── ChatBot.xcodeproj └── project.pbxproj ├── ChatBot ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── chat.imageset │ │ ├── Contents.json │ │ ├── ic_chat_black_1x_ios_24dp.png │ │ ├── ic_chat_black_2x_ios_24dp.png │ │ └── ic_chat_black_3x_ios_24dp.png │ ├── close.imageset │ │ ├── Contents.json │ │ ├── ic_close_black_1x_ios_24dp.png │ │ ├── ic_close_black_2x_ios_24dp.png │ │ └── ic_close_black_3x_ios_24dp.png │ ├── direction.imageset │ │ ├── Contents.json │ │ └── direction.PNG │ ├── mic.imageset │ │ ├── Contents.json │ │ ├── ic_mic_black_1x_ios_24dp.png │ │ ├── ic_mic_black_2x_ios_24dp.png │ │ └── ic_mic_black_3x_ios_24dp.png │ ├── parade.imageset │ │ ├── Contents.json │ │ └── parade.jpg │ └── walk.imageset │ │ ├── Contents.json │ │ ├── ic_directions_walk_black_1x_ios_36dp.png │ │ ├── ic_directions_walk_black_2x_ios_36dp.png │ │ └── ic_directions_walk_black_3x_ios_36dp.png ├── Base.lproj │ └── LaunchScreen.storyboard ├── ChatBot │ ├── CBLandmarkDetectionService.h │ ├── CBLandmarkDetectionService.m │ ├── CBTranslationService.h │ ├── CBTranslationService.m │ ├── Helpers │ │ ├── CBDefines.h │ │ └── CBDefines.m │ ├── Infrastructure │ │ ├── Adapters │ │ │ ├── GILGridViewAdapter.h │ │ │ ├── GILGridViewAdapter.m │ │ │ ├── GILReusableViewAdapter.h │ │ │ ├── GILVerticalStackViewAdapter.h │ │ │ └── GILVerticalStackViewAdapter.m │ │ ├── Categories │ │ │ ├── UIColor+GILAdditions.h │ │ │ └── UIColor+GILAdditions.m │ │ ├── Controllers │ │ │ ├── GILCollectionComponentController.h │ │ │ ├── GILCollectionComponentController.m │ │ │ └── GILFlowCollectionController.h │ │ ├── Helpers │ │ │ ├── GILConstants.h │ │ │ ├── GILConstants.m │ │ │ ├── GILDefines.h │ │ │ ├── GILDefines.m │ │ │ ├── UIView+GILAutolayoutAdditions.h │ │ │ └── UIView+GILAutolayoutAdditions.m │ │ ├── ViewComponents │ │ │ ├── GILAttributedLabelComponent.h │ │ │ ├── GILAttributedLabelComponent.m │ │ │ ├── GILAttributedLabelGroupComponent.h │ │ │ ├── GILAttributedLabelGroupComponent.m │ │ │ ├── GILCarouselComponent.h │ │ │ ├── GILCarouselComponent.m │ │ │ ├── GILCellViewComponent.h │ │ │ ├── GILComponentDataSource.h │ │ │ ├── GILComponentDataSource.m │ │ │ ├── GILComponentDataSourceSection.h │ │ │ ├── GILComponentDataSourceSection.m │ │ │ ├── GILImageCollageComponent.h │ │ │ ├── GILImageCollageComponent.m │ │ │ ├── GILImageLabelsComponent.h │ │ │ ├── GILImageLabelsComponent.m │ │ │ ├── GILImageViewComponent.h │ │ │ ├── GILImageViewComponent.m │ │ │ ├── GILViewComponent.h │ │ │ ├── GILViewComponent.m │ │ │ ├── GILViewComponentConstants.h │ │ │ ├── GILWebImageComponent.h │ │ │ └── GILWebImageComponent.m │ │ └── Views │ │ │ ├── GILCarouselView.h │ │ │ ├── GILCarouselView.m │ │ │ ├── GILImageCollageView.h │ │ │ ├── GILImageCollageView.m │ │ │ ├── GILLabeledImageView.h │ │ │ ├── GILLabeledImageView.m │ │ │ ├── GILMinimumTapAreaButton.h │ │ │ ├── GILMinimumTapAreaButton.m │ │ │ ├── GILReusableView.h │ │ │ ├── GILReusableView.m │ │ │ ├── GILTitleLabelsView.h │ │ │ ├── GILTitleLabelsView.m │ │ │ ├── GILWebImageView.h │ │ │ └── GILWebImageView.m │ ├── SpeechRecognitionService.h │ ├── SpeechRecognitionService.m │ ├── ViewComponents │ │ ├── CBImageMessageCellComponent.h │ │ ├── CBImageMessageCellComponent.m │ │ ├── CBLoadingIndicatorMessageCellComponent.h │ │ ├── CBLoadingIndicatorMessageCellComponent.m │ │ ├── CBMessageCellComponent.h │ │ ├── CBMessageCellComponent.m │ │ ├── CBSystemMessageCellComponent.h │ │ └── CBSystemMessageCellComponent.m │ ├── ViewControllers │ │ ├── CBViewController.h │ │ └── CBViewController.m │ └── Views │ │ ├── CBChatBubbleView.h │ │ ├── CBChatBubbleView.m │ │ └── Cells │ │ ├── CBBubbleCell.h │ │ ├── CBBubbleCell.m │ │ ├── CBImageMessageCell.h │ │ ├── CBImageMessageCell.m │ │ ├── CBLoadingIndicatorMessageCell.h │ │ ├── CBLoadingIndicatorMessageCell.m │ │ ├── CBMessageCell.h │ │ ├── CBMessageCell.m │ │ ├── CBPaddingCell.h │ │ ├── CBPaddingCell.m │ │ ├── CBSystemMessageCell.h │ │ └── CBSystemMessageCell.m ├── DemoMapViewController.h ├── DemoMapViewController.m ├── DemoViewController.h ├── DemoViewController.m ├── Info.plist └── main.m ├── ChatBotTests └── CBTranslationServiceTests.m ├── LICENSE ├── Podfile ├── README.md ├── api.ai ├── TourGuide.zip ├── TourGuideChinese.zip ├── webhook-cloud-function │ ├── index.js │ └── package.json └── webhook │ ├── Procfile │ ├── app.json │ ├── app.py │ └── requirements.txt ├── google ├── api │ ├── Annotations.pbobjc.h │ ├── Annotations.pbobjc.m │ ├── HTTP.pbobjc.h │ ├── HTTP.pbobjc.m │ ├── Label.pbobjc.h │ ├── Label.pbobjc.m │ ├── MonitoredResource.pbobjc.h │ ├── MonitoredResource.pbobjc.m │ ├── annotations.proto │ ├── http.proto │ ├── label.proto │ └── monitored_resource.proto ├── cloud │ └── speech │ │ └── v1 │ │ ├── CloudSpeech.pbobjc.h │ │ ├── CloudSpeech.pbobjc.m │ │ ├── CloudSpeech.pbrpc.h │ │ ├── CloudSpeech.pbrpc.m │ │ └── cloud_speech.proto ├── longrunning │ ├── Operations.pbobjc.h │ ├── Operations.pbobjc.m │ ├── Operations.pbrpc.h │ ├── Operations.pbrpc.m │ ├── README.md │ └── operations.proto ├── protobuf │ ├── Descriptor.pbobjc.h │ ├── Descriptor.pbobjc.m │ └── descriptor.proto └── rpc │ ├── Code.pbobjc.h │ ├── Code.pbobjc.m │ ├── ErrorDetails.pbobjc.h │ ├── ErrorDetails.pbobjc.m │ ├── README.md │ ├── Status.pbobjc.h │ ├── Status.pbobjc.m │ ├── code.proto │ ├── error_details.proto │ └── status.proto └── googleapis.podspec /.gitignore: -------------------------------------------------------------------------------- 1 | Podfile.lock 2 | Pods 3 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement 9 | (CLA). 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then you'll need to sign an [individual CLA] 13 | (https://developers.google.com/open-source/cla/individual). 14 | * If you work for a company that wants to allow you to contribute your work, 15 | then you'll need to sign a [corporate CLA] 16 | (https://developers.google.com/open-source/cla/corporate). 17 | 18 | Follow either of the two links above to access the appropriate CLA and 19 | instructions for how to sign and return it. Once we receive it, we'll be able to 20 | accept your pull requests. 21 | 22 | ## Contributing A Patch 23 | 24 | 1. Submit an issue describing your proposed change to the repo in question. 25 | 1. The repo owner will respond to your issue promptly. 26 | 1. If your proposed change is accepted, and you haven't already done so, sign a 27 | Contributor License Agreement (see details above). 28 | 1. Fork the desired repo, develop and test your code changes. 29 | 1. Ensure that your code adheres to the existing style in the sample to which 30 | you are contributing. Refer to the 31 | [Google Cloud Platform Samples Style Guide] 32 | (https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the 33 | recommended coding standards for this organization. 34 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 35 | 1. Submit a pull request. -------------------------------------------------------------------------------- /ChatBot/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | @interface AppDelegate : UIResponder 48 | 49 | @property(strong, nonatomic) UIWindow *window; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /ChatBot/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "AppDelegate.h" 46 | 47 | #import "CBDefines.h" 48 | #import "DemoViewController.h" 49 | #import "UIColor+GILAdditions.h" 50 | 51 | @interface AppDelegate () 52 | @end 53 | 54 | @implementation AppDelegate 55 | 56 | - (BOOL)application:(UIApplication *)application 57 | didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 58 | _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 59 | 60 | NSURL *URL = [NSURL URLWithString:@"http://sfgov.org/"]; 61 | DemoViewController *viewController = 62 | [[DemoViewController alloc] initWithURL:URL 63 | name:@"Welcome to San Francisco" 64 | agentAccessToken:CBApiAiToken]; 65 | 66 | _window.rootViewController = viewController; 67 | [_window makeKeyAndVisible]; 68 | return YES; 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/chat.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "ic_chat_black_1x_ios_24dp.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "ic_chat_black_2x_ios_24dp.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "ic_chat_black_3x_ios_24dp.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/chat.imageset/ic_chat_black_1x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/chat.imageset/ic_chat_black_1x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/chat.imageset/ic_chat_black_2x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/chat.imageset/ic_chat_black_2x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/chat.imageset/ic_chat_black_3x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/chat.imageset/ic_chat_black_3x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/close.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "ic_close_black_1x_ios_24dp.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "ic_close_black_2x_ios_24dp.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "ic_close_black_3x_ios_24dp.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/close.imageset/ic_close_black_1x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/close.imageset/ic_close_black_1x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/close.imageset/ic_close_black_2x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/close.imageset/ic_close_black_2x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/close.imageset/ic_close_black_3x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/close.imageset/ic_close_black_3x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/direction.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "direction.PNG", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/direction.imageset/direction.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/direction.imageset/direction.PNG -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/mic.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "ic_mic_black_1x_ios_24dp.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "ic_mic_black_2x_ios_24dp.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "ic_mic_black_3x_ios_24dp.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/mic.imageset/ic_mic_black_1x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/mic.imageset/ic_mic_black_1x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/mic.imageset/ic_mic_black_2x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/mic.imageset/ic_mic_black_2x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/mic.imageset/ic_mic_black_3x_ios_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/mic.imageset/ic_mic_black_3x_ios_24dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/parade.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "parade.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/parade.imageset/parade.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/parade.imageset/parade.jpg -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/walk.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "ic_directions_walk_black_1x_ios_36dp.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "ic_directions_walk_black_2x_ios_36dp.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "ic_directions_walk_black_3x_ios_36dp.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/walk.imageset/ic_directions_walk_black_1x_ios_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/walk.imageset/ic_directions_walk_black_1x_ios_36dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/walk.imageset/ic_directions_walk_black_2x_ios_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/walk.imageset/ic_directions_walk_black_2x_ios_36dp.png -------------------------------------------------------------------------------- /ChatBot/Assets.xcassets/walk.imageset/ic_directions_walk_black_3x_ios_36dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/ChatBot/Assets.xcassets/walk.imageset/ic_directions_walk_black_3x_ios_36dp.png -------------------------------------------------------------------------------- /ChatBot/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/CBLandmarkDetectionService.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | typedef void (^CBLandmarkDetectionCallback)(NSDictionary *response, NSError *error); 48 | 49 | @interface CBLandmarkDetectionService : NSObject 50 | 51 | + (instancetype)sharedService; 52 | 53 | - (void)analyze:(UIImage *)image completion:(CBLandmarkDetectionCallback)completion; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/CBTranslationService.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | typedef void (^CBTranslationCallback)(NSString *translatedText, 48 | NSString *sourceLangauge, 49 | NSError *error); 50 | 51 | @interface CBTranslationService : NSObject 52 | 53 | + (instancetype)sharedService; 54 | 55 | - (void)translate:(NSString *)query 56 | targetLangaugeCode:(NSString *)targetLangaugeCode 57 | completion:(CBTranslationCallback)completion; 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Helpers/CBDefines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | #ifdef __cplusplus 48 | #define CB_EXTERN extern "C" __attribute__((visibility("default"))) 49 | #else 50 | #define CB_EXTERN extern __attribute__((visibility("default"))) 51 | #endif 52 | 53 | typedef NS_ENUM(NSInteger, CBChatBubbleArrowPosition) { 54 | CBChatBubbleArrowPositionLeft, 55 | CBChatBubbleArrowPositionRight 56 | }; 57 | 58 | typedef void (^CBUserImageSelectedCompletionBlock)(UIImage *image); 59 | 60 | extern NSString *const CBApiKey; 61 | extern NSString *const CBLanguage; 62 | extern NSString *const CBApiAiToken; 63 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Helpers/CBDefines.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBDefines.h" 46 | 47 | NSString *const CBApiKey = @"your google API key"; 48 | 49 | // English Settings 50 | NSString *const CBLanguage = @"en-US"; 51 | NSString *const CBApiAiToken = @"a1410b188f924a2ba7d72a93cbf3ea65"; 52 | 53 | // Chinese Settings 54 | //NSString *const CBLanguage = @"zh-Hans"; 55 | //NSString *const CBApiAiToken = @"2b8fa8f201f14ac28fae4861d020bd7c"; 56 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Adapters/GILReusableViewAdapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | /** 48 | * A protocol defines the required implementations for a adapter intended for super views such as 49 | * @c GILReusableView. A conforming adapter is responsible for laying out its managed views and 50 | * providing essential logic needed by @c GILReusableView in relation to its managed views. The 51 | * adapter may utilize additional abstractions to facilitate logic consistency and scalability. 52 | * 53 | * This allows layout and view update logic to be more reusable, encapsulated, and consistent. 54 | * However, it may not be suitable for all use cases. Best judgments should be applied when 55 | * determining whether the adapter approach is suitable. 56 | */ 57 | @protocol GILReusableViewAdapter 58 | 59 | /** 60 | * An array of views managed by the adapter and intended to be added to a superview such as @c 61 | * GILReusableView. 62 | */ 63 | @property(nonatomic, readonly) NSArray *managedViews; 64 | 65 | /** 66 | * Lays out the managed views in the size representing the layout area. 67 | */ 68 | - (void)layoutManagedViewsForSize:(CGSize)size; 69 | 70 | /** 71 | * Returns the size the managed views will occupy if laid out in the size representing the layout 72 | * area. 73 | */ 74 | - (CGSize)sizeThatFits:(CGSize)size; 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Categories/UIColor+GILAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | @interface UIColor (GILAdditions) 48 | 49 | + (UIColor *)gil_colorWithARGB:(NSUInteger)argb; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Categories/UIColor+GILAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "UIColor+GILAdditions.h" 46 | 47 | @implementation UIColor (GILAdditions) 48 | 49 | + (UIColor *)gil_colorWithARGB:(NSUInteger)argb { 50 | int blue = argb & 0xff; 51 | int green = argb >> 8 & 0xff; 52 | int red = argb >> 16 & 0xff; 53 | int alpha = argb >> 24 & 0xff; 54 | 55 | return [UIColor colorWithRed:red / 255.0f 56 | green:green / 255.0f 57 | blue:blue / 255.0f 58 | alpha:alpha / 255.f]; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Controllers/GILCollectionComponentController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILFlowCollectionController.h" 46 | 47 | #import "GILViewComponentConstants.h" 48 | 49 | NS_ASSUME_NONNULL_BEGIN 50 | 51 | @protocol GILCellViewComponent; 52 | @protocol GILComponentDataSource; 53 | @class GILCollectionComponentController; 54 | 55 | @protocol GILCollectionComponentControllerDelegate 56 | 57 | @optional 58 | 59 | - (void)controller:(GILCollectionComponentController *)controller 60 | didScrollWithContentOffset:(CGPoint)offset; 61 | 62 | @end 63 | 64 | @interface GILCollectionComponentController : NSObject 65 | 66 | @property(nonatomic, readonly) UICollectionView *collectionView; 67 | 68 | @property(nullable, nonatomic) id data; 69 | 70 | @property(nullable, nonatomic, copy) GILCollectionComponentSizeBlock cellSizeBlock; 71 | 72 | @property(nullable, nonatomic, weak) id delegate; 73 | 74 | - (instancetype)initWithCollectionView:(nullable UICollectionView *)collectionView 75 | cellSizeBlock:(nullable GILCollectionComponentSizeBlock)cellSizeBlock 76 | NS_DESIGNATED_INITIALIZER; 77 | 78 | - (nullable instancetype)init NS_UNAVAILABLE; 79 | 80 | @end 81 | 82 | NS_ASSUME_NONNULL_END 83 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Controllers/GILFlowCollectionController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | @protocol GILFlowCollectionController 48 | 49 | @optional 50 | 51 | + (void)configureFlowLayout:(UICollectionViewFlowLayout *)flowLayout; 52 | 53 | + (void)configureCollectionView:(UICollectionView *)collectionView; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Helpers/GILConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | extern CGFloat const kGILShadowRadius; 48 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Helpers/GILConstants.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILConstants.h" 46 | 47 | CGFloat const kGILShadowRadius = 2.0f; 48 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Helpers/GILDefines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | #import "GILViewComponent.h" 48 | 49 | #ifdef __cplusplus 50 | #define GIL_EXTERN extern "C" __attribute__((visibility("default"))) 51 | #else 52 | #define GIL_EXTERN extern __attribute__((visibility("default"))) 53 | #endif 54 | 55 | #if defined(__LP64__) && __LP64__ 56 | #define GIL_CGFloatCeil(x) ceil(x) 57 | #define GIL_CGFloatMax(a, b) fmax(a, b) 58 | #define GIL_CGFloatMin(a, b) fmin(a, b) 59 | #else 60 | #define GIL_CGFloatCeil(x) ceilf(x) 61 | #define GIL_CGFloatMax(a, b) fmaxf(a, b) 62 | #define GIL_CGFloatMin(a, b) fmin(a, b) 63 | #endif 64 | 65 | NS_ASSUME_NONNULL_BEGIN 66 | 67 | GIL_EXTERN id _Nullable GILViewComponentClassCast(id _Nullable component, 68 | Class aClass); 69 | 70 | GIL_EXTERN UIView *_Nullable GILViewClassCast(UIView *_Nullable view, Class aClass); 71 | 72 | NS_ASSUME_NONNULL_END 73 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Helpers/GILDefines.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILDefines.h" 46 | 47 | NS_ASSUME_NONNULL_BEGIN 48 | 49 | id _Nullable GILViewComponentClassCast(id _Nullable component, Class aClass) { 50 | if (!component || [component isKindOfClass:[GILViewComponentNull class]]) { 51 | return nil; 52 | } else if ([component isKindOfClass:aClass]) { 53 | return component; 54 | } else { 55 | NSCAssert(NO, @"Unexpected view component type."); 56 | return nil; 57 | } 58 | } 59 | 60 | UIView *_Nullable GILViewClassCast(UIView *_Nullable view, Class aClass) { 61 | if (!view) { 62 | return nil; 63 | } else if ([view isKindOfClass:aClass]) { 64 | return view; 65 | } else { 66 | NSCAssert(NO, @"Unexpected view type."); 67 | return nil; 68 | } 69 | } 70 | 71 | NS_ASSUME_NONNULL_END 72 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILCarouselComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | #import "GILCellViewComponent.h" 48 | #import "GILViewComponent.h" 49 | #import "GILViewComponentConstants.h" 50 | 51 | NS_ASSUME_NONNULL_BEGIN 52 | 53 | @interface GILCarouselComponent : NSObject 54 | 55 | - (instancetype)initWithCellComponents:(NSArray> *)cellComponents 56 | contentInset:(UIEdgeInsets)contentInset 57 | padding:(UIEdgeInsets)padding 58 | backgroundColor:(UIColor *)backgroundColor 59 | cellSizeBlock:(GILCollectionComponentSizeBlock)cellSizeBlock 60 | sizeBlock:(GILViewComponentSizeBlock)sizeBlock; 61 | 62 | - (instancetype)initWithCellClasses:(NSArray *)cellClasses 63 | cellReuseIdentifiers:(NSArray *)cellReuseIdentifiers 64 | cellComponents:(NSArray> *)cellComponents 65 | contentInset:(UIEdgeInsets)contentInset 66 | padding:(UIEdgeInsets)padding 67 | backgroundColor:(UIColor *)backgroundColor 68 | cellSizeBlock:(GILCollectionComponentSizeBlock)cellSizeBlock 69 | sizeBlock:(GILViewComponentSizeBlock)sizeBlock NS_DESIGNATED_INITIALIZER; 70 | 71 | - (nullable instancetype)init NS_UNAVAILABLE; 72 | 73 | @property(nonatomic, copy, readonly) NSArray *cellClasses; 74 | 75 | @property(nonatomic, copy, readonly) NSArray *cellReuseIdentifiers; 76 | 77 | @property(nonatomic, copy, readonly) NSArray> *cellComponents; 78 | 79 | @property(nonatomic, readonly) UIEdgeInsets contentInset; 80 | 81 | @property(nonatomic, readonly) UIEdgeInsets padding; 82 | 83 | @property(nonatomic, copy, readonly) UIColor *backgroundColor; 84 | 85 | @property(nonatomic, copy, readonly) GILCollectionComponentSizeBlock cellSizeBlock; 86 | 87 | @property(nonatomic, copy, readonly) GILViewComponentSizeBlock sizeBlock; 88 | 89 | @end 90 | 91 | NS_ASSUME_NONNULL_END 92 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILCellViewComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | #import "GILViewComponent.h" 48 | 49 | @protocol GILCellViewComponent 50 | 51 | + (Class)cellClass; 52 | 53 | + (NSString *)reuseIdentifier; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILComponentDataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | NS_ASSUME_NONNULL_BEGIN 48 | 49 | @protocol GILComponentDataSourceSection; 50 | @protocol GILViewComponent; 51 | 52 | @protocol GILComponentDataSource 53 | 54 | - (NSUInteger)sectionCount; 55 | 56 | - (nullable id)section:(NSUInteger)section; 57 | 58 | - (nullable id)componentForIndexPath:(NSIndexPath *)indexPath; 59 | 60 | - (void)addSection:(id)section; 61 | 62 | @end 63 | 64 | @interface GILComponentDataSource : NSObject 65 | 66 | @property(nullable, nonatomic) NSMutableArray> *sections; 67 | 68 | @end 69 | 70 | NS_ASSUME_NONNULL_END 71 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILComponentDataSource.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILComponentDataSource.h" 46 | 47 | #import "GILComponentDataSourceSection.h" 48 | 49 | NS_ASSUME_NONNULL_BEGIN 50 | 51 | @implementation GILComponentDataSource 52 | 53 | - (instancetype)init { 54 | self = [super init]; 55 | _sections = [NSMutableArray array]; 56 | return self; 57 | } 58 | 59 | #pragma mark - GILComponentDataSourceSection 60 | 61 | - (NSUInteger)sectionCount { 62 | return self.sections.count; 63 | } 64 | 65 | - (nullable id)section:(NSUInteger)section { 66 | if (section < self.sections.count) { 67 | return self.sections[section]; 68 | } else { 69 | return nil; 70 | } 71 | } 72 | 73 | - (nullable id)componentForIndexPath:(NSIndexPath *)indexPath { 74 | return [[self section:indexPath.section] componentAtIndex:indexPath.item]; 75 | } 76 | 77 | - (void)addSection:(id)section { 78 | if (!section) { 79 | return; 80 | } 81 | [_sections addObject:section]; 82 | } 83 | 84 | @end 85 | 86 | NS_ASSUME_NONNULL_END 87 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILComponentDataSourceSection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | NS_ASSUME_NONNULL_BEGIN 48 | 49 | @protocol GILViewComponent; 50 | 51 | @protocol GILComponentDataSourceSection 52 | 53 | - (NSUInteger)componentsCount; 54 | 55 | - (nullable id)componentAtIndex:(NSUInteger)index; 56 | 57 | - (void)addComponent:(id)component; 58 | 59 | @end 60 | 61 | @interface GILComponentDataSourceSection : NSObject 62 | 63 | @property(nullable, nonatomic) NSMutableArray> *components; 64 | 65 | @end 66 | 67 | NS_ASSUME_NONNULL_END 68 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILComponentDataSourceSection.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILComponentDataSourceSection.h" 46 | 47 | NS_ASSUME_NONNULL_BEGIN 48 | 49 | @implementation GILComponentDataSourceSection 50 | 51 | - (instancetype)init { 52 | self = [super init]; 53 | _components = [NSMutableArray array]; 54 | return self; 55 | } 56 | 57 | #pragma mark - GILComponentDataSourceSection 58 | 59 | - (NSUInteger)componentsCount { 60 | return self.components.count; 61 | } 62 | 63 | - (nullable id)componentAtIndex:(NSUInteger)index { 64 | if (index < self.components.count) { 65 | return self.components[index]; 66 | } else { 67 | return nil; 68 | } 69 | } 70 | 71 | - (void)addComponent:(id)component { 72 | [self.components addObject:component]; 73 | } 74 | 75 | @end 76 | 77 | NS_ASSUME_NONNULL_END 78 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILViewComponent.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILViewComponent.h" 46 | 47 | @implementation GILViewComponentNull 48 | 49 | + (instancetype)null { 50 | return [[GILViewComponentNull alloc] init]; 51 | } 52 | 53 | #pragma mark - NSCopying 54 | 55 | - (instancetype)copyWithZone:(NSZone *)zone { 56 | return self; 57 | } 58 | 59 | #pragma mark - GILViewComponent 60 | 61 | + (BOOL)updateView:(UIView *)view withComponent:(id)component { 62 | NSAssert(NO, @"GILViewComponentNull should be treated as a nil object."); 63 | return NO; 64 | } 65 | 66 | + (UIView *)view { 67 | NSAssert(NO, @"GILViewComponentNull should be treated as a nil object."); 68 | return [[UIView alloc] initWithFrame:CGRectZero]; 69 | } 70 | 71 | + (CGSize)sizeThatFits:(CGSize)size forComponent:(id)component { 72 | return CGSizeZero; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILViewComponentConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | @protocol GILCellViewComponent; 48 | @protocol GILViewComponent; 49 | 50 | NS_ASSUME_NONNULL_BEGIN 51 | 52 | /** 53 | * Defines the horizontal alignment of the associated item. 54 | */ 55 | typedef NS_ENUM(NSInteger, GILHorizontalAlignment) { 56 | GILHorizontalAlignmentLeft, 57 | GILHorizontalAlignmentCenter, 58 | GILHorizontalAlignmentRight, 59 | }; 60 | 61 | /** 62 | * A block that provides the sizing logic for a view component. 63 | * 64 | * @param layoutSize The layout size available to layout the component view. 65 | * @param component The view component used to update a component view. 66 | * @return The size the superview should use to lay out the view. 67 | */ 68 | typedef CGSize (^GILViewComponentSizeBlock)(CGSize layoutSize, 69 | id _Nullable component); 70 | 71 | /** 72 | * A block that provides the sizing logic for a view. 73 | * 74 | * @param layoutSize The layout size available to layout the view. 75 | * @param view The view to be laid out. 76 | * @return The size the superview should use to lay out the view. 77 | */ 78 | typedef CGSize (^GILViewSizeBlock)(CGSize layoutSize, UIView *view); 79 | 80 | typedef CGSize (^GILCollectionComponentSizeBlock)(UICollectionView *collectionView, 81 | UICollectionViewLayout *layout, 82 | _Nullable id component, 83 | NSIndexPath *indexPath); 84 | 85 | NS_ASSUME_NONNULL_END 86 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/ViewComponents/GILWebImageComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | #import "GILViewComponent.h" 48 | #import "GILViewComponentConstants.h" 49 | 50 | NS_ASSUME_NONNULL_BEGIN 51 | 52 | /** 53 | * A view component representing an image view that loads an image from the web URL. The caller 54 | * can assume the component handles caching and request cancelation logic. 55 | */ 56 | @interface GILWebImageComponent : NSObject 57 | 58 | /** 59 | * Returns an instance of the view component. 60 | * 61 | * @param imageURL The web URL of the image file. 62 | * @param contentMode The content mode of the image view. 63 | * @param sizeBlock The block that encapsulates the sizing logic of the image view. Regardless of 64 | * the actual implementation. The caller should always assume the block is retained by the 65 | * view component and be aware of creating retain cycles. 66 | * @return An instance of the view component. 67 | */ 68 | - (instancetype)initWithImageURL:(nullable NSURL *)imageURL 69 | contentMode:(UIViewContentMode)contentMode 70 | sizeBlock:(GILViewComponentSizeBlock)sizeBlock NS_DESIGNATED_INITIALIZER; 71 | 72 | /** 73 | * Use the designated initializer instead. 74 | */ 75 | - (nullable instancetype)init NS_UNAVAILABLE; 76 | 77 | /** 78 | * The URL of the image. 79 | */ 80 | @property(nullable, nonatomic, copy, readonly) NSURL *imageURL; 81 | 82 | /** 83 | * The view content mode applied to the image view. 84 | */ 85 | @property(nonatomic, readonly) UIViewContentMode contentMode; 86 | 87 | /** 88 | * The block that encapsulates the sizing logic of the image view. 89 | */ 90 | @property(nonatomic, copy, readonly) GILViewComponentSizeBlock sizeBlock; 91 | 92 | @end 93 | 94 | NS_ASSUME_NONNULL_END 95 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILCarouselView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | @class GILCarouselView; 48 | @class GILCollectionComponentController; 49 | 50 | NS_ASSUME_NONNULL_BEGIN 51 | 52 | typedef CGSize (^GILCarouselViewSizeBlock)(CGSize layoutSize, GILCarouselView *carouselView); 53 | 54 | @interface GILCarouselView : UIView 55 | 56 | @property(nonatomic, readonly) GILCollectionComponentController *controller; 57 | 58 | @property(nonatomic) UIEdgeInsets padding; 59 | 60 | @property(nullable, nonatomic, copy) GILCarouselViewSizeBlock sizeBlock; 61 | 62 | @end 63 | 64 | NS_ASSUME_NONNULL_END 65 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILCarouselView.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILCarouselView.h" 46 | 47 | #import "GILCollectionComponentController.h" 48 | #import "GILComponentDataSource.h" 49 | 50 | NS_ASSUME_NONNULL_BEGIN 51 | 52 | @implementation GILCarouselView 53 | 54 | - (instancetype)initWithFrame:(CGRect)frame { 55 | self = [super initWithFrame:frame]; 56 | [self GIL_commonInit]; 57 | return self; 58 | } 59 | 60 | - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder { 61 | self = [super initWithCoder:aDecoder]; 62 | [self GIL_commonInit]; 63 | return self; 64 | } 65 | 66 | - (void)GIL_commonInit { 67 | UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; 68 | // Configure layout. 69 | layout.minimumLineSpacing = 8.0f; 70 | layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; 71 | 72 | UICollectionView *collectionView = 73 | [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout]; 74 | // Register the classes externally. 75 | 76 | GILCollectionComponentController *controller = 77 | [[GILCollectionComponentController alloc] initWithCollectionView:collectionView 78 | cellSizeBlock:NULL]; 79 | 80 | GILComponentDataSource *data = [[GILComponentDataSource alloc] init]; 81 | controller.data = data; 82 | _controller = controller; 83 | [self addSubview:controller.collectionView]; 84 | } 85 | 86 | - (CGSize)sizeThatFits:(CGSize)size { 87 | if (_sizeBlock) { 88 | CGRect layoutArea = CGRectMake(0.0f, 0.0f, size.width, size.height); 89 | layoutArea = UIEdgeInsetsInsetRect(layoutArea, _padding); 90 | CGSize carouselSize = _sizeBlock(size, self); 91 | carouselSize.height += self.padding.top + self.padding.bottom; 92 | return carouselSize; 93 | } else { 94 | return size; 95 | } 96 | } 97 | 98 | - (void)layoutSubviews { 99 | [super layoutSubviews]; 100 | CGRect layoutArea = UIEdgeInsetsInsetRect(self.bounds, _padding); 101 | _controller.collectionView.frame = layoutArea; 102 | } 103 | 104 | @end 105 | 106 | NS_ASSUME_NONNULL_END 107 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILImageCollageView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | /** 48 | * A collage that displays images laid out in a spiral formation. 49 | * 50 | */ 51 | @interface GILImageCollageView : UIView 52 | 53 | /** 54 | * Returns a collage with the specified values for the maximum number of images and image spacing. 55 | * 56 | * @param maximumNumberOfImages The maximum number of images in the collage. 57 | * @return A collage. 58 | */ 59 | - (instancetype)initWithMaximumNumberOfImages:(NSInteger)maximumNumberOfImages; 60 | 61 | /** 62 | * The maximum number of images that the collage can display. 63 | */ 64 | @property(nonatomic, readonly) NSInteger maximumNumberOfImages; 65 | 66 | /** 67 | * Number of images to display. By default, it is the same as @c maximumNumberOfImages. 68 | */ 69 | @property(nonatomic) NSInteger numberOfImagesToDisplay; 70 | 71 | /** 72 | * The vertical and horizontal spacing between the images. 73 | */ 74 | @property(nonatomic) CGFloat imageSpacing; 75 | 76 | /** 77 | * The web URLs of the images. 78 | */ 79 | @property(nonatomic, copy) NSArray *imageURLs; 80 | 81 | /** 82 | * The content mode of the images views in the collage. 83 | */ 84 | @property(nonatomic) UIViewContentMode imageContentMode; 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILLabeledImageView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | NS_ASSUME_NONNULL_BEGIN 48 | 49 | /** 50 | * A specialized image view that displays an overlay label when @c imageLabelText is set. 51 | */ 52 | @interface GILLabeledImageView : UIView 53 | 54 | // TODO(bobyliu): Support attributed text if needed. 55 | /** 56 | * The text to overlay on top of the image view if it is not nil. 57 | */ 58 | @property(nullable, nonatomic, copy) NSString *imageLabelText; 59 | 60 | /** 61 | * The URL of the image. 62 | */ 63 | @property(nullable, nonatomic, copy) NSURL *imageURL; 64 | 65 | @end 66 | 67 | NS_ASSUME_NONNULL_END 68 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILMinimumTapAreaButton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | /** 48 | * A @c UIButton subclass that allows a button to have a larger tap area than itself.' 49 | * 50 | * TODO(bobyliu): Although QTMButton also supports tap area customization, it seems to have some 51 | * issues with the insets that cause smaller fonts to not display correctly. Investigate the 52 | * QTMButton further to see if the issue can be addressed. This is a workaround for now. 53 | */ 54 | @interface GILMinimumTapAreaButton : UIButton 55 | 56 | /** 57 | * The insets that will be applied ot the tap area. 58 | */ 59 | @property(nonatomic) UIEdgeInsets tapAreaInsets; 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILMinimumTapAreaButton.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILMinimumTapAreaButton.h" 46 | 47 | @implementation GILMinimumTapAreaButton 48 | 49 | - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { 50 | if (UIEdgeInsetsEqualToEdgeInsets(_tapAreaInsets, UIEdgeInsetsZero)) { 51 | return [super pointInside:point withEvent:event]; 52 | } else { 53 | CGRect adjustedFrame = UIEdgeInsetsInsetRect(self.bounds, _tapAreaInsets); 54 | return CGRectContainsPoint(adjustedFrame, point); 55 | } 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILReusableView.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILReusableView.h" 46 | 47 | #import "GILReusableViewAdapter.h" 48 | 49 | @implementation GILReusableView 50 | 51 | - (instancetype)initWithAdapter:(id)adapter { 52 | self = [super initWithFrame:CGRectZero]; 53 | if (self) { 54 | _adapter = adapter; 55 | [self GIL_setupManagedViews]; 56 | } 57 | return self; 58 | } 59 | 60 | - (instancetype)initWithFrame:(CGRect)frame { 61 | NSAssert(NO, @"Use the designated initializer instead."); 62 | return nil; 63 | } 64 | 65 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 66 | NSAssert(NO, @"Use the designated initializer instead."); 67 | return nil; 68 | } 69 | 70 | - (void)GIL_setupManagedViews { 71 | [_adapter.managedViews enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) { 72 | if (![obj isKindOfClass:[UIView class]]) { 73 | NSAssert(NO, @"Adapter did not create a valid view instance."); 74 | return; 75 | } 76 | [self addSubview:obj]; 77 | }]; 78 | } 79 | 80 | - (void)layoutSubviews { 81 | [super layoutSubviews]; 82 | [_adapter layoutManagedViewsForSize:CGSizeMake(CGRectGetWidth(self.bounds), 83 | CGRectGetHeight(self.bounds))]; 84 | if (_layoutCompletionBlock) { 85 | _layoutCompletionBlock(); 86 | } 87 | } 88 | 89 | - (CGSize)sizeThatFits:(CGSize)size { 90 | return [_adapter sizeThatFits:size]; 91 | } 92 | 93 | @end 94 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILWebImageView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | @interface GILWebImageView : UIImageView 48 | 49 | @property(nonatomic, readonly, copy) NSURL *imageURL; 50 | 51 | - (void)setImageURL:(NSURL *)imageURL placehoderImage:(UIImage *)placeholderImage; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Infrastructure/Views/GILWebImageView.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILWebImageView.h" 46 | 47 | @implementation GILWebImageView 48 | 49 | - (void)setImageURL:(NSURL *)imageURL placehoderImage:(UIImage *)placeholderImage { 50 | if ((_imageURL || imageURL) && ![_imageURL isEqual:imageURL]) { 51 | _imageURL = [imageURL copy]; 52 | self.image = placeholderImage; 53 | 54 | if (!imageURL) { 55 | return; 56 | } 57 | 58 | NSURL *fetchURL = [_imageURL copy]; 59 | __weak typeof(self) weakSelf = self; 60 | NSURLSessionDataTask *task = [[NSURLSession sharedSession] 61 | dataTaskWithURL:imageURL 62 | completionHandler:^(NSData *_Nullable data, NSURLResponse *_Nullable response, 63 | NSError *_Nullable error) { 64 | typeof(self) strongSelf = weakSelf; 65 | if (!strongSelf) { 66 | return; 67 | } 68 | if (![fetchURL isEqual:self->_imageURL]) { 69 | return; 70 | } 71 | 72 | if (data.length) { 73 | UIImage *image = [UIImage imageWithData:data]; 74 | dispatch_async(dispatch_get_main_queue(), ^{ 75 | strongSelf.image = image; 76 | }); 77 | } 78 | }]; 79 | [task resume]; 80 | } 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/SpeechRecognitionService.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | typedef void (^SpeechRecognitionCompletionHandler)(id object); 48 | 49 | @interface SpeechRecognitionService : NSObject 50 | 51 | + (instancetype)sharedInstance; 52 | 53 | - (void)processAudioData:(NSData *)audioData 54 | withCompletion:(SpeechRecognitionCompletionHandler)completion; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/ViewComponents/CBLoadingIndicatorMessageCellComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILCellViewComponent.h" 46 | 47 | #import "CBDefines.h" 48 | #import "GILViewComponentConstants.h" 49 | 50 | @interface CBLoadingIndicatorMessageCellComponent : NSObject 51 | 52 | - (instancetype)initWithArrowPosition:(CBChatBubbleArrowPosition)arrowPosition 53 | backgroundColor:(UIColor *)backgroundColor 54 | bubbleColor:(UIColor *)bubbleColor 55 | padding:(UIEdgeInsets)padding 56 | maxBubbleWidthPercentage:(CGFloat)maxBubbleWidthPercentage 57 | indicatorSizeBlock:(GILViewSizeBlock)imageViewSizeBlock; 58 | 59 | @property(nonatomic, readonly) CBChatBubbleArrowPosition arrowPosition; 60 | 61 | @property(nonatomic, copy, readonly) UIColor *backgroundColor; 62 | 63 | @property(nonatomic, copy, readonly) UIColor *bubbleColor; 64 | 65 | @property(nonatomic, readonly) UIEdgeInsets padding; 66 | 67 | @property(nonatomic, readonly) CGFloat maxBubbleWidthPercentage; 68 | 69 | @property(nonatomic, copy, readonly) GILViewSizeBlock indicatorSizeBlock; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/ViewComponents/CBMessageCellComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILCellViewComponent.h" 46 | 47 | #import "CBDefines.h" 48 | 49 | @class GILAttributedLabelComponent; 50 | 51 | @interface CBMessageCellComponent : NSObject 52 | 53 | - (instancetype)initWithMessageComponent:(GILAttributedLabelComponent *)messageComponent 54 | actionButtonImageName:(NSString *)actionButtonImageName 55 | actionButtonTapEventBlock:(void (^)(void))actionButtonTapEventBlock 56 | arrowPosition:(CBChatBubbleArrowPosition)arrowPosition 57 | backgroundColor:(UIColor *)backgroundColor 58 | bubbleColor:(UIColor *)bubbleColor 59 | padding:(UIEdgeInsets)padding 60 | maxBubbleWidthPercentage:(CGFloat)maxBubbleWidthPercentage; 61 | 62 | @property(nonatomic, copy, readonly) GILAttributedLabelComponent *messageComponent; 63 | 64 | @property(nonatomic, readonly) CBChatBubbleArrowPosition arrowPosition; 65 | 66 | // Nil image name hides the button. 67 | @property(nonatomic, copy, readonly) NSString *actionButtonImageName; 68 | 69 | @property (nonatomic, copy, readonly) void (^actionButtonTapEventBlock)(void); 70 | 71 | @property(nonatomic, copy, readonly) UIColor *backgroundColor; 72 | 73 | @property(nonatomic, copy, readonly) UIColor *bubbleColor; 74 | 75 | @property(nonatomic, readonly) UIEdgeInsets padding; 76 | 77 | @property(nonatomic, readonly) CGFloat maxBubbleWidthPercentage; 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/ViewComponents/CBSystemMessageCellComponent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILCellViewComponent.h" 46 | 47 | @class GILAttributedLabelComponent; 48 | 49 | @interface CBSystemMessageCellComponent : NSObject 50 | 51 | - (instancetype)initWithMessageComponent:(GILAttributedLabelComponent *)messageComponent 52 | backgroundColor:(UIColor *)backgroundColor 53 | padding:(UIEdgeInsets)padding; 54 | 55 | @property(nonatomic, copy, readonly) GILAttributedLabelComponent *messageComponent; 56 | 57 | @property(nonatomic, copy, readonly) UIColor *backgroundColor; 58 | 59 | @property(nonatomic, readonly) UIEdgeInsets padding; 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/ViewControllers/CBViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | #import "CBDefines.h" 48 | 49 | @class CBViewController; 50 | 51 | @protocol CBViewControllerDelegate 52 | 53 | - (void)chatBotController:(CBViewController *)controller 54 | didRequestUserImageWithCompletionBlock:(CBUserImageSelectedCompletionBlock)completionBlock; 55 | 56 | - (void)chatBotController:(CBViewController *)controller 57 | shouldPresentViewController:(UIViewController *)viewController; 58 | 59 | @end 60 | 61 | /** 62 | * A standalone view controller used to provide a quick ChatBot experience with api.ai backend 63 | * services. The view controller may be used as a child view controller or subclassed. 64 | */ 65 | @interface CBViewController : UIViewController 66 | 67 | /** 68 | * The delegate of the view controller. 69 | */ 70 | @property(nonatomic, weak) id delegate; 71 | 72 | /** 73 | * The api.ai access token associated with an agent. 74 | */ 75 | @property(nonatomic, copy) NSString *clientAccessToken; 76 | 77 | /** 78 | * The inset of the scroll area that can be used by a parent view controller or subclassed 79 | * view controller to adjust the message scroll area. 80 | * 81 | * Value is not in effect until @c automaticallyAdjustsScrollViewInsets is disabled. 82 | * 83 | * For simplier use cases with the out-of-the-box UINavigationController, consider relying on 84 | * @c automaticallyAdjustsScrollViewInsets bening enabled. 85 | */ 86 | @property(nonatomic) UIEdgeInsets scrollAreaInset; 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/CBChatBubbleView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "GILTitleLabelsView.h" 46 | 47 | #import "CBDefines.h" 48 | #import "GILViewComponentConstants.h" 49 | 50 | CB_EXTERN UIBezierPath *CBChatBubblePath(CGRect rect, CBChatBubbleArrowPosition position, 51 | BOOL drawArrow); 52 | 53 | @interface CBChatBubbleView : UIView 54 | 55 | @property(nonatomic) CBChatBubbleArrowPosition arrowPosition; 56 | 57 | @property(nonatomic) UIView *contentView; 58 | 59 | @property(nonatomic) GILViewSizeBlock contentViewSizeBlock; 60 | 61 | @property(nonatomic) UIEdgeInsets padding; 62 | 63 | @property(nonatomic) BOOL offsetContentViewWithArrowWidth; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBBubbleCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | #import "CBDefines.h" 48 | 49 | @class CBChatBubbleView; 50 | 51 | @interface CBBubbleCell : UICollectionViewCell 52 | 53 | @property(nonatomic, readonly) CBChatBubbleView *messageBubbleView; 54 | 55 | // Temp work. Need the make actionButton position logic 'less' hardcoded. Current button size is 56 | // hardcoded. The button is hidden upon initialization. 57 | @property(nonatomic, readonly) UIButton *actionButton; 58 | 59 | @property (nonatomic, copy) void (^actionButtonTapEventBlock)(void); 60 | 61 | @property(nonatomic) UIColor *bubbleColor; 62 | 63 | @property(nonatomic) UIEdgeInsets padding; 64 | 65 | @property(nonatomic) CBChatBubbleArrowPosition arrowPosition; 66 | 67 | @property(nonatomic) CGFloat maxBubbleWidthPercentage; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBImageMessageCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBBubbleCell.h" 46 | 47 | #import "GILViewComponentConstants.h" 48 | 49 | @class GILWebImageView; 50 | 51 | @interface CBImageMessageCell : CBBubbleCell 52 | 53 | @property(nonatomic) GILWebImageView *imageView; 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBImageMessageCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBImageMessageCell.h" 46 | 47 | #import "CBChatBubbleView.h" 48 | #import "GILWebImageView.h" 49 | 50 | @implementation CBImageMessageCell 51 | 52 | - (instancetype)initWithFrame:(CGRect)frame { 53 | self = [super initWithFrame:frame]; 54 | [self CBImageMessageCell_init]; 55 | return self; 56 | } 57 | 58 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 59 | self = [super initWithCoder:aDecoder]; 60 | [self CBImageMessageCell_init]; 61 | return self; 62 | } 63 | 64 | - (void)CBImageMessageCell_init { 65 | _imageView = [[GILWebImageView alloc] initWithFrame:self.messageBubbleView.bounds]; 66 | _imageView.contentMode = UIViewContentModeScaleAspectFill; 67 | self.messageBubbleView.contentView = _imageView; 68 | self.messageBubbleView.offsetContentViewWithArrowWidth = NO; 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBLoadingIndicatorMessageCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBBubbleCell.h" 46 | 47 | @interface CBLoadingIndicatorMessageCell : CBBubbleCell 48 | 49 | @property(nonatomic, readonly) UIActivityIndicatorView *indicator; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBLoadingIndicatorMessageCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBLoadingIndicatorMessageCell.h" 46 | 47 | #import "CBChatBubbleView.h" 48 | 49 | static const UIEdgeInsets kContentInsets = {8.0f, 8.0f, 8.0f, 8.0f}; 50 | 51 | @implementation CBLoadingIndicatorMessageCell 52 | 53 | - (instancetype)initWithFrame:(CGRect)frame { 54 | self = [super initWithFrame:frame]; 55 | [self CBLoadingIndicatorMessageCell_init]; 56 | return self; 57 | } 58 | 59 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 60 | self = [super initWithCoder:aDecoder]; 61 | [self CBLoadingIndicatorMessageCell_init]; 62 | return self; 63 | } 64 | 65 | - (void)CBLoadingIndicatorMessageCell_init { 66 | _indicator = [[UIActivityIndicatorView alloc] 67 | initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 68 | self.messageBubbleView.contentView = _indicator; 69 | self.messageBubbleView.padding = kContentInsets; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBMessageCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBBubbleCell.h" 46 | 47 | #import "CBDefines.h" 48 | 49 | @class CBChatBubbleView; 50 | 51 | @interface CBMessageCell : CBBubbleCell 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBMessageCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBMessageCell.h" 46 | 47 | #import "CBChatBubbleView.h" 48 | #import "GILAttributedLabelComponent.h" 49 | 50 | static const UIEdgeInsets kContentInsets = {8.0f, 8.0f, 8.0f, 8.0f}; 51 | 52 | @implementation CBMessageCell 53 | 54 | - (instancetype)initWithFrame:(CGRect)frame { 55 | self = [super initWithFrame:frame]; 56 | [self CBMessageCell_Init]; 57 | return self; 58 | } 59 | 60 | - (instancetype)initWithCode:(NSCoder *)aCoder { 61 | self = [super initWithCoder:aCoder]; 62 | [self CBMessageCell_Init]; 63 | return self; 64 | } 65 | 66 | - (void)CBMessageCell_Init { 67 | UILabel *messageLabel = (UILabel *)[GILAttributedLabelComponent view]; 68 | self.messageBubbleView.contentView = messageLabel; 69 | self.messageBubbleView.padding = kContentInsets; 70 | } 71 | 72 | @end 73 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBPaddingCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | @interface CBPaddingCell : UICollectionViewCell 48 | 49 | @property(nonatomic) UIView *customView; 50 | 51 | @property(nonatomic) UIEdgeInsets padding; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBPaddingCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBPaddingCell.h" 46 | 47 | @implementation CBPaddingCell 48 | 49 | - (void)layoutSubviews { 50 | [super layoutSubviews]; 51 | 52 | CGRect layoutArea = UIEdgeInsetsInsetRect(self.contentView.bounds, _padding); 53 | _customView.frame = CGRectIntegral(layoutArea); 54 | } 55 | 56 | - (CGSize)sizeThatFits:(CGSize)size { 57 | CGRect layoutArea = UIEdgeInsetsInsetRect(self.contentView.bounds, _padding); 58 | CGSize customViewSize = [_customView sizeThatFits:layoutArea.size]; 59 | CGFloat height = customViewSize.height + _padding.top + _padding.bottom; 60 | return CGSizeMake(size.width, height); 61 | } 62 | 63 | #pragma mark - Property overrides 64 | 65 | - (void)setCustomView:(UIView *)customView { 66 | [_customView removeFromSuperview]; 67 | _customView = customView; 68 | [self.contentView addSubview:customView]; 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBSystemMessageCell.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBPaddingCell.h" 46 | 47 | @interface CBSystemMessageCell : CBPaddingCell 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /ChatBot/ChatBot/Views/Cells/CBSystemMessageCell.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "CBSystemMessageCell.h" 46 | 47 | #import "GILAttributedLabelComponent.h" 48 | 49 | @implementation CBSystemMessageCell 50 | 51 | - (instancetype)initWithFrame:(CGRect)frame { 52 | self = [super initWithFrame:frame]; 53 | [self CBSystemMessageCell_commonInit]; 54 | return self; 55 | } 56 | 57 | - (instancetype)initWithCoder:(NSCoder *)aDecoder { 58 | self = [super initWithCoder:aDecoder]; 59 | [self CBSystemMessageCell_commonInit]; 60 | return self; 61 | } 62 | 63 | - (void)CBSystemMessageCell_commonInit { 64 | self.customView = [GILAttributedLabelComponent view]; 65 | } 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /ChatBot/DemoMapViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | @interface DemoMapViewController : UIViewController 48 | 49 | @property(nonatomic) UIImage *mapImage; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /ChatBot/DemoMapViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import "DemoMapViewController.h" 46 | 47 | @interface DemoMapViewController () { 48 | UIImageView *_mapImageView; 49 | } 50 | @end 51 | 52 | @implementation DemoMapViewController 53 | 54 | - (void)viewDidLoad { 55 | [super viewDidLoad]; 56 | _mapImageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; 57 | _mapImageView.autoresizingMask = 58 | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 59 | _mapImageView.image = _mapImage; 60 | [self.view addSubview:_mapImageView]; 61 | } 62 | 63 | - (void)setMapImage:(UIImage *)mapImage { 64 | _mapImage = mapImage; 65 | _mapImageView.image = mapImage; 66 | } 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /ChatBot/DemoViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | /** 48 | * A demo view controller used to load a web URL and shows a live chat button to simulate 49 | * the chat bot experience. 50 | */ 51 | @interface DemoViewController : UIViewController 52 | 53 | - (instancetype)initWithURL:(NSURL *)URL 54 | name:(NSString *)name 55 | agentAccessToken:(NSString *)agentAccessToken NS_DESIGNATED_INITIALIZER; 56 | 57 | - (instancetype)initWithNibName:(NSString *)nibNameOrNil 58 | bundle:(NSBundle *)nibBundleOrNil NS_UNAVAILABLE; 59 | 60 | - (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE; 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /ChatBot/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSApplicationCategoryType 22 | 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | NSMicrophoneUsageDescription 31 | Talk to agent 32 | NSPhotoLibraryUsageDescription 33 | For sending images during the chat. 34 | UILaunchStoryboardName 35 | LaunchScreen 36 | UIRequiredDeviceCapabilities 37 | 38 | armv7 39 | 40 | UISupportedInterfaceOrientations 41 | 42 | UIInterfaceOrientationPortrait 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | UISupportedInterfaceOrientations~ipad 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationPortraitUpsideDown 50 | UIInterfaceOrientationLandscapeLeft 51 | UIInterfaceOrientationLandscapeRight 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /ChatBot/main.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | #import "AppDelegate.h" 47 | 48 | int main(int argc, char* argv[]) { 49 | @autoreleasepool { 50 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ChatBotTests/CBTranslationServiceTests.m: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017, Google Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * * Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following disclaimer 14 | * in the documentation and/or other materials provided with the 15 | * distribution. 16 | * * Neither the name of Google Inc. nor the names of its 17 | * contributors may be used to endorse or promote products derived from 18 | * this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * Licensed under the Apache License, Version 2.0 (the "License"); 33 | * you may not use this file except in compliance with the License. 34 | * You may obtain a copy of the License at 35 | * 36 | * http://www.apache.org/licenses/LICENSE-2.0 37 | * 38 | * Unless required by applicable law or agreed to in writing, software 39 | * distributed under the License is distributed on an "AS IS" BASIS, 40 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 | * See the License for the specific language governing permissions and 42 | * limitations under the License. 43 | */ 44 | 45 | #import 46 | 47 | #import "CBTranslationService.h" 48 | 49 | @interface CBTranslationServiceTests : XCTestCase 50 | 51 | @end 52 | 53 | @implementation CBTranslationServiceTests 54 | 55 | - (void)testTranslate { 56 | CBTranslationService *translationService = [CBTranslationService sharedService]; 57 | XCTestExpectation *expectation = [self expectationWithDescription:@"Transation"]; 58 | [translationService 59 | translate:@"Golden Gate Bridge" 60 | completion:^(NSString *translatedText, NSString *sourceLangauge, NSError *error) { 61 | XCTAssertEqualObjects(translatedText, @"金门大桥"); 62 | XCTAssertEqualObjects(sourceLangauge, @"en"); 63 | [expectation fulfill]; 64 | }]; 65 | NSUInteger timeout = 5; 66 | NSString *file = [NSString stringWithUTF8String:__FILE__]; 67 | [self waitForExpectationsWithTimeout:timeout 68 | handler:^(NSError *_Nullable error) { 69 | if (error) { 70 | NSString *message = [NSString 71 | stringWithFormat:@"Failed to get a response from " 72 | @"translation service after %tu seconds", 73 | timeout]; 74 | [self recordFailureWithDescription:message 75 | inFile:file 76 | atLine:__LINE__ 77 | expected:YES]; 78 | } 79 | 80 | }]; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '8.0' 3 | 4 | # Uncomment this line if you're using Swift 5 | #use_frameworks! 6 | 7 | target ‘ChatBot’ do 8 | 9 | pod 'googleapis', :path => '.' 10 | 11 | end 12 | 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chatbot with API.AI and Google Cloud APIs 2 | 3 | This sample demonstrates how to build an iOS chatbot with Google Cloud Vision, 4 | Speech, and Translate APIs and API.AI. 5 | 6 | [![English Demo](http://img.youtube.com/vi/qDAP3ZFjO48/0.jpg)](https://youtu.be/qDAP3ZFjO48) 7 | [![The Google Assistant / Google Home Demo](http://img.youtube.com/vi/_x5rlkpZiyc/0.jpg)](https://youtu.be/_x5rlkpZiyc) 8 | 9 | ## Prerequisites 10 | - An iOS API key for the Cloud APIs (See 11 | [the docs][getting-started] to learn more) 12 | - [Xcode 7][xcode] 13 | - [Cocoapods][cocoapods] version 1.0 or later 14 | 15 | ## Quickstart 16 | - Clone this repo and `cd` into this directory. 17 | - Run `pod install` to download and build Cocoapods dependencies. 18 | - Open the project by running `open ChatBot.xcworkspace`. 19 | - In [CBDefines.m](ChatBot/ChatBot/Helpers/CBDefines.m), replace 20 | `your google API key` with the API key obtained above. 21 | - Build and run the app. 22 | 23 | 24 | ## API keys 25 | 1. Create a new project on https://console.cloud.google.com. 26 | 1. Enable Billing. 27 | 1. Go to API Manager. 28 | 1. Go to Credentials 29 | 1. Create credentials. Choose API Key. 30 | 1. Replace @"your google API key" with your google API key in [CBDefines.m](ChatBot/ChatBot/Helpers/CBDefines.m) 31 | 32 | ## API.AI 33 | Optionally, follow these steps to create your own API.AI agents. 34 | 1. Create TourGuide agent. 35 | 1. Go to Settings and import [api.ai/TourGuide.zip](api.ai/TourGuide.zip). 36 | 1. (Optional steps to support Chinese) Create TourGuideChinese agent with 37 | language set to Chinese. 38 | 1. Go to Settings and import [api.ai/TourGuideChinese.zip](api.ai/TourGuideChinese.zip) 39 | 1. Replace CBApiAiToken with your API.AI token in [CBDefines.m](ChatBot/ChatBot/Helpers/CBDefines.m). 40 | You can find your token from the API.AI agent setting page. 41 | 42 | 43 | # Chinese Demo 44 | [![Chinese Demo](http://img.youtube.com/vi/Oy4oNNd1aGw/0.jpg)](https://youtu.be/Oy4oNNd1aGw) 45 | 46 | ## License 47 | 48 | This sample is released under the [Apache 2.0 license](LICENSE). 49 | 50 | ## Disclaimer 51 | This is not an official Google product. 52 | 53 | ## Authors 54 | [Chang Luo][changluo] and [Bob Liu][bobliu] 55 | 56 | [getting-started]: https://cloud.google.com/vision/docs/getting-started 57 | [cloud-console]: https://console.cloud.google.com 58 | [git]: https://git-scm.com/ 59 | [xcode]: https://developer.apple.com/xcode/ 60 | [billing]: https://console.cloud.google.com/billing?project=_ 61 | [enable-speech]: https://console.cloud.google.com/apis/api/speech.googleapis.com/overview?project=_ 62 | [api-key]: https://console.cloud.google.com/apis/credentials?project=_ 63 | [cocoapods]: https://cocoapods.org/ 64 | [changluo]: https://www.linkedin.com/in/changluo 65 | [bobliu]: https://www.linkedin.com/in/bobyliu 66 | [google-home]: https://www.youtube.com/watch?v=_x5rlkpZiyc&feature=youtu.be 67 | -------------------------------------------------------------------------------- /api.ai/TourGuide.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/api.ai/TourGuide.zip -------------------------------------------------------------------------------- /api.ai/TourGuideChinese.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/ios-chatbot/1e37f6c35b5c4c0a70b310ac36f526ae2bb25003/api.ai/TourGuideChinese.zip -------------------------------------------------------------------------------- /api.ai/webhook-cloud-function/index.js: -------------------------------------------------------------------------------- 1 | const ApiAiAssistant = require('actions-on-google').ApiAiAssistant; 2 | function parade(assistant) { 3 | assistant.tell(`Chinese New Year Parade in Chinatown from 6pm to 9pm.`); 4 | } 5 | exports.parades = function(request, response) { 6 | var assistant = new ApiAiAssistant({request: request, response: response}); 7 | var actionMap = new Map(); 8 | actionMap.set("inquiry.parades", parade); 9 | assistant.handleRequest(actionMap); 10 | }; -------------------------------------------------------------------------------- /api.ai/webhook-cloud-function/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "parades", 3 | "version": "0.0.1", 4 | "main": "index.js", 5 | "dependencies": { 6 | "actions-on-google": "^1.1.1" 7 | } 8 | } -------------------------------------------------------------------------------- /api.ai/webhook/Procfile: -------------------------------------------------------------------------------- 1 | web: python app.py -------------------------------------------------------------------------------- /api.ai/webhook/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Tour Guide demo webhook", 3 | "description": "Webhook demonstration" 4 | } 5 | -------------------------------------------------------------------------------- /api.ai/webhook/app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from __future__ import print_function 4 | from future.standard_library import install_aliases 5 | install_aliases() 6 | 7 | from urllib.parse import urlparse, urlencode 8 | from urllib.request import urlopen, Request 9 | from urllib.error import HTTPError 10 | 11 | import json 12 | import os 13 | 14 | from flask import Flask 15 | from flask import request 16 | from flask import make_response 17 | 18 | # Flask app should start in global layout 19 | app = Flask(__name__) 20 | 21 | 22 | @app.route('/webhook', methods=['POST']) 23 | def webhook(): 24 | req = request.get_json(silent=True, force=True) 25 | 26 | print("Request:") 27 | print(json.dumps(req, indent=4)) 28 | 29 | result = req.get("result") 30 | 31 | parameters = result.get("parameters") 32 | 33 | print("Parameters:") 34 | print(parameters) 35 | 36 | action = result.get("action") 37 | 38 | print("action:") 39 | print(action) 40 | 41 | res = {} 42 | 43 | if (action == 'inquiry.parades'): 44 | res = processParadesQuery(parameters) 45 | 46 | res = json.dumps(res, indent=4) 47 | print(res) 48 | r = make_response(res) 49 | r.headers['Content-Type'] = 'application/json' 50 | return r 51 | 52 | def processParadesQuery(parameters): 53 | # Simulate a database query result 54 | speech = "Chinese New Year Parade in Chinatown from 5pm to 8pm." 55 | 56 | res = { 57 | "speech": speech, 58 | "displayText": speech, 59 | "data":"https://upload.wikimedia.org/wikipedia/commons/f/f1/Year_of_Ox_Chinese_New_Year_Parade_San_Francisco_2009.jpg", 60 | "contextOut": [], 61 | "source": "demo-tour-guide" 62 | } 63 | 64 | return res 65 | 66 | if __name__ == '__main__': 67 | port = int(os.getenv('PORT', 5000)) 68 | 69 | print("Starting app on port %d" % port) 70 | 71 | app.run(debug=False, port=port, host='0.0.0.0') 72 | -------------------------------------------------------------------------------- /api.ai/webhook/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask~>0.12.3 2 | future==0.16.0 3 | -------------------------------------------------------------------------------- /google/api/Annotations.pbobjc.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: google/api/annotations.proto 3 | 4 | // This CPP symbol can be defined to use imports that match up to the framework 5 | // imports needed when using CocoaPods. 6 | #if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) 7 | #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 8 | #endif 9 | 10 | #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 11 | #import 12 | #else 13 | #import "GPBProtocolBuffers.h" 14 | #endif 15 | 16 | #if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001 17 | #error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources. 18 | #endif 19 | 20 | // @@protoc_insertion_point(imports) 21 | 22 | #pragma clang diagnostic push 23 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 24 | 25 | CF_EXTERN_C_BEGIN 26 | 27 | NS_ASSUME_NONNULL_BEGIN 28 | 29 | #pragma mark - AnnotationsRoot 30 | 31 | /** 32 | * Exposes the extension registry for this file. 33 | * 34 | * The base class provides: 35 | * @code 36 | * + (GPBExtensionRegistry *)extensionRegistry; 37 | * @endcode 38 | * which is a @c GPBExtensionRegistry that includes all the extensions defined by 39 | * this file and all files that it depends on. 40 | **/ 41 | @interface AnnotationsRoot : GPBRootObject 42 | @end 43 | 44 | @interface AnnotationsRoot (DynamicMethods) 45 | /** See `HttpRule`. */ 46 | + (GPBExtensionDescriptor *)HTTP; 47 | @end 48 | 49 | NS_ASSUME_NONNULL_END 50 | 51 | CF_EXTERN_C_END 52 | 53 | #pragma clang diagnostic pop 54 | 55 | // @@protoc_insertion_point(global_scope) 56 | -------------------------------------------------------------------------------- /google/api/Annotations.pbobjc.m: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: google/api/annotations.proto 3 | 4 | // This CPP symbol can be defined to use imports that match up to the framework 5 | // imports needed when using CocoaPods. 6 | #if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) 7 | #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 8 | #endif 9 | 10 | #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 11 | #import 12 | #else 13 | #import "GPBProtocolBuffers_RuntimeSupport.h" 14 | #endif 15 | 16 | #import "google/api/Annotations.pbobjc.h" 17 | #import "google/api/HTTP.pbobjc.h" 18 | #import "google/protobuf/Descriptor.pbobjc.h" 19 | // @@protoc_insertion_point(imports) 20 | 21 | #pragma clang diagnostic push 22 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 23 | 24 | #pragma mark - AnnotationsRoot 25 | 26 | @implementation AnnotationsRoot 27 | 28 | + (GPBExtensionRegistry*)extensionRegistry { 29 | // This is called by +initialize so there is no need to worry 30 | // about thread safety and initialization of registry. 31 | static GPBExtensionRegistry* registry = nil; 32 | if (!registry) { 33 | GPBDebugCheckRuntimeVersion(); 34 | registry = [[GPBExtensionRegistry alloc] init]; 35 | static GPBExtensionDescription descriptions[] = { 36 | { 37 | .defaultValue.valueMessage = nil, 38 | .singletonName = GPBStringifySymbol(AnnotationsRoot_HTTP), 39 | .extendedClass = GPBStringifySymbol(GPBMethodOptions), 40 | .messageOrGroupClassName = GPBStringifySymbol(HttpRule), 41 | .enumDescriptorFunc = NULL, 42 | .fieldNumber = 72295728, 43 | .dataType = GPBDataTypeMessage, 44 | .options = 0, 45 | }, 46 | }; 47 | for (size_t i = 0; i < sizeof(descriptions) / sizeof(descriptions[0]); ++i) { 48 | GPBExtensionDescriptor *extension = 49 | [[GPBExtensionDescriptor alloc] initWithExtensionDescription:&descriptions[i]]; 50 | [registry addExtension:extension]; 51 | [self globallyRegisterExtension:extension]; 52 | [extension release]; 53 | } 54 | [registry addExtensions:[HTTPRoot extensionRegistry]]; 55 | [registry addExtensions:[GPBDescriptorRoot extensionRegistry]]; 56 | } 57 | return registry; 58 | } 59 | 60 | @end 61 | 62 | 63 | #pragma clang diagnostic pop 64 | 65 | // @@protoc_insertion_point(global_scope) 66 | -------------------------------------------------------------------------------- /google/api/Label.pbobjc.h: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: google/api/label.proto 3 | 4 | // This CPP symbol can be defined to use imports that match up to the framework 5 | // imports needed when using CocoaPods. 6 | #if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) 7 | #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 8 | #endif 9 | 10 | #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 11 | #import 12 | #else 13 | #import "GPBProtocolBuffers.h" 14 | #endif 15 | 16 | #if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != 30001 17 | #error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources. 18 | #endif 19 | 20 | // @@protoc_insertion_point(imports) 21 | 22 | #pragma clang diagnostic push 23 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 24 | 25 | CF_EXTERN_C_BEGIN 26 | 27 | NS_ASSUME_NONNULL_BEGIN 28 | 29 | #pragma mark - Enum LabelDescriptor_ValueType 30 | 31 | /** Value types that can be used as label values. */ 32 | typedef GPB_ENUM(LabelDescriptor_ValueType) { 33 | /** 34 | * Value used if any message's field encounters a value that is not defined 35 | * by this enum. The message will also have C functions to get/set the rawValue 36 | * of the field. 37 | **/ 38 | LabelDescriptor_ValueType_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue, 39 | /** A variable-length string. This is the default. */ 40 | LabelDescriptor_ValueType_String = 0, 41 | 42 | /** Boolean; true or false. */ 43 | LabelDescriptor_ValueType_Bool = 1, 44 | 45 | /** A 64-bit signed integer. */ 46 | LabelDescriptor_ValueType_Int64 = 2, 47 | }; 48 | 49 | GPBEnumDescriptor *LabelDescriptor_ValueType_EnumDescriptor(void); 50 | 51 | /** 52 | * Checks to see if the given value is defined by the enum or was not known at 53 | * the time this source was generated. 54 | **/ 55 | BOOL LabelDescriptor_ValueType_IsValidValue(int32_t value); 56 | 57 | #pragma mark - LabelRoot 58 | 59 | /** 60 | * Exposes the extension registry for this file. 61 | * 62 | * The base class provides: 63 | * @code 64 | * + (GPBExtensionRegistry *)extensionRegistry; 65 | * @endcode 66 | * which is a @c GPBExtensionRegistry that includes all the extensions defined by 67 | * this file and all files that it depends on. 68 | **/ 69 | @interface LabelRoot : GPBRootObject 70 | @end 71 | 72 | #pragma mark - LabelDescriptor 73 | 74 | typedef GPB_ENUM(LabelDescriptor_FieldNumber) { 75 | LabelDescriptor_FieldNumber_Key = 1, 76 | LabelDescriptor_FieldNumber_ValueType = 2, 77 | LabelDescriptor_FieldNumber_Description_p = 3, 78 | }; 79 | 80 | /** 81 | * A description of a label. 82 | **/ 83 | @interface LabelDescriptor : GPBMessage 84 | 85 | /** The label key. */ 86 | @property(nonatomic, readwrite, copy, null_resettable) NSString *key; 87 | 88 | /** The type of data that can be assigned to the label. */ 89 | @property(nonatomic, readwrite) LabelDescriptor_ValueType valueType; 90 | 91 | /** A human-readable description for the label. */ 92 | @property(nonatomic, readwrite, copy, null_resettable) NSString *description_p; 93 | 94 | @end 95 | 96 | /** 97 | * Fetches the raw value of a @c LabelDescriptor's @c valueType property, even 98 | * if the value was not defined by the enum at the time the code was generated. 99 | **/ 100 | int32_t LabelDescriptor_ValueType_RawValue(LabelDescriptor *message); 101 | /** 102 | * Sets the raw value of an @c LabelDescriptor's @c valueType property, allowing 103 | * it to be set to a value that was not defined by the enum at the time the code 104 | * was generated. 105 | **/ 106 | void SetLabelDescriptor_ValueType_RawValue(LabelDescriptor *message, int32_t value); 107 | 108 | NS_ASSUME_NONNULL_END 109 | 110 | CF_EXTERN_C_END 111 | 112 | #pragma clang diagnostic pop 113 | 114 | // @@protoc_insertion_point(global_scope) 115 | -------------------------------------------------------------------------------- /google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option java_multiple_files = true; 23 | option java_outer_classname = "AnnotationsProto"; 24 | option java_package = "com.google.api"; 25 | 26 | extend google.protobuf.MethodOptions { 27 | // See `HttpRule`. 28 | HttpRule http = 72295728; 29 | } 30 | -------------------------------------------------------------------------------- /google/api/label.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | option java_multiple_files = true; 20 | option java_outer_classname = "LabelProto"; 21 | option java_package = "com.google.api"; 22 | 23 | 24 | // A description of a label. 25 | message LabelDescriptor { 26 | // Value types that can be used as label values. 27 | enum ValueType { 28 | // A variable-length string. This is the default. 29 | STRING = 0; 30 | 31 | // Boolean; true or false. 32 | BOOL = 1; 33 | 34 | // A 64-bit signed integer. 35 | INT64 = 2; 36 | } 37 | 38 | // The label key. 39 | string key = 1; 40 | 41 | // The type of data that can be assigned to the label. 42 | ValueType value_type = 2; 43 | 44 | // A human-readable description for the label. 45 | string description = 3; 46 | } 47 | -------------------------------------------------------------------------------- /google/api/monitored_resource.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/label.proto"; 20 | 21 | option java_multiple_files = true; 22 | option java_outer_classname = "MonitoredResourceProto"; 23 | option java_package = "com.google.api"; 24 | 25 | 26 | // A descriptor that describes the schema of [MonitoredResource][google.api.MonitoredResource]. 27 | message MonitoredResourceDescriptor { 28 | // The monitored resource type. For example, the type `"cloudsql_database"` 29 | // represents databases in Google Cloud SQL. 30 | string type = 1; 31 | 32 | // A concise name for the monitored resource type that can be displayed in 33 | // user interfaces. For example, `"Google Cloud SQL Database"`. 34 | string display_name = 2; 35 | 36 | // A detailed description of the monitored resource type that can be used in 37 | // documentation. 38 | string description = 3; 39 | 40 | // A set of labels that can be used to describe instances of this monitored 41 | // resource type. For example, Google Cloud SQL databases can be labeled with 42 | // their `"database_id"` and their `"zone"`. 43 | repeated LabelDescriptor labels = 4; 44 | } 45 | 46 | // A monitored resource describes a resource that can be used for monitoring 47 | // purpose. It can also be used for logging, billing, and other purposes. Each 48 | // resource has a `type` and a set of `labels`. The labels contain information 49 | // that identifies the resource and describes attributes of it. For example, 50 | // you can use monitored resource to describe a normal file, where the resource 51 | // has `type` as `"file"`, the label `path` identifies the file, and the label 52 | // `size` describes the file size. The monitoring system can use a set of 53 | // monitored resources of files to generate file size distribution. 54 | message MonitoredResource { 55 | // The monitored resource type. This field must match the corresponding 56 | // [MonitoredResourceDescriptor.type][google.api.MonitoredResourceDescriptor.type] to this resource.. For example, 57 | // `"cloudsql_database"` represents Cloud SQL databases. 58 | string type = 1; 59 | 60 | // Values for some or all of the labels listed in the associated monitored 61 | // resource descriptor. For example, you specify a specific Cloud SQL database 62 | // by supplying values for both the `"database_id"` and `"zone"` labels. 63 | map labels = 2; 64 | } 65 | -------------------------------------------------------------------------------- /google/cloud/speech/v1/CloudSpeech.pbrpc.h: -------------------------------------------------------------------------------- 1 | #import "google/cloud/speech/v1/CloudSpeech.pbobjc.h" 2 | 3 | #import 4 | #import 5 | #import 6 | 7 | #import "google/api/Annotations.pbobjc.h" 8 | #import "google/longrunning/Operations.pbobjc.h" 9 | #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 10 | #import 11 | #else 12 | #import "google/protobuf/Any.pbobjc.h" 13 | #endif 14 | #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 15 | #import 16 | #else 17 | #import "google/protobuf/Duration.pbobjc.h" 18 | #endif 19 | #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 20 | #import 21 | #else 22 | #import "google/protobuf/Timestamp.pbobjc.h" 23 | #endif 24 | #import "google/rpc/Status.pbobjc.h" 25 | 26 | 27 | NS_ASSUME_NONNULL_BEGIN 28 | 29 | @protocol Speech 30 | 31 | #pragma mark Recognize(RecognizeRequest) returns (RecognizeResponse) 32 | 33 | /** 34 | * Performs synchronous speech recognition: receive results after all audio 35 | * has been sent and processed. 36 | */ 37 | - (void)recognizeWithRequest:(RecognizeRequest *)request handler:(void(^)(RecognizeResponse *_Nullable response, NSError *_Nullable error))handler; 38 | 39 | /** 40 | * Performs synchronous speech recognition: receive results after all audio 41 | * has been sent and processed. 42 | */ 43 | - (GRPCProtoCall *)RPCToRecognizeWithRequest:(RecognizeRequest *)request handler:(void(^)(RecognizeResponse *_Nullable response, NSError *_Nullable error))handler; 44 | 45 | 46 | #pragma mark LongRunningRecognize(LongRunningRecognizeRequest) returns (Operation) 47 | 48 | /** 49 | * Performs asynchronous speech recognition: receive results via the 50 | * google.longrunning.Operations interface. Returns either an 51 | * `Operation.error` or an `Operation.response` which contains 52 | * a `LongRunningRecognizeResponse` message. 53 | */ 54 | - (void)longRunningRecognizeWithRequest:(LongRunningRecognizeRequest *)request handler:(void(^)(Operation *_Nullable response, NSError *_Nullable error))handler; 55 | 56 | /** 57 | * Performs asynchronous speech recognition: receive results via the 58 | * google.longrunning.Operations interface. Returns either an 59 | * `Operation.error` or an `Operation.response` which contains 60 | * a `LongRunningRecognizeResponse` message. 61 | */ 62 | - (GRPCProtoCall *)RPCToLongRunningRecognizeWithRequest:(LongRunningRecognizeRequest *)request handler:(void(^)(Operation *_Nullable response, NSError *_Nullable error))handler; 63 | 64 | 65 | #pragma mark StreamingRecognize(stream StreamingRecognizeRequest) returns (stream StreamingRecognizeResponse) 66 | 67 | /** 68 | * Performs bidirectional streaming speech recognition: receive results while 69 | * sending audio. This method is only available via the gRPC API (not REST). 70 | */ 71 | - (void)streamingRecognizeWithRequestsWriter:(GRXWriter *)requestWriter eventHandler:(void(^)(BOOL done, StreamingRecognizeResponse *_Nullable response, NSError *_Nullable error))eventHandler; 72 | 73 | /** 74 | * Performs bidirectional streaming speech recognition: receive results while 75 | * sending audio. This method is only available via the gRPC API (not REST). 76 | */ 77 | - (GRPCProtoCall *)RPCToStreamingRecognizeWithRequestsWriter:(GRXWriter *)requestWriter eventHandler:(void(^)(BOOL done, StreamingRecognizeResponse *_Nullable response, NSError *_Nullable error))eventHandler; 78 | 79 | 80 | @end 81 | 82 | /** 83 | * Basic service implementation, over gRPC, that only does 84 | * marshalling and parsing. 85 | */ 86 | @interface Speech : GRPCProtoService 87 | - (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER; 88 | + (instancetype)serviceWithHost:(NSString *)host; 89 | @end 90 | 91 | NS_ASSUME_NONNULL_END 92 | -------------------------------------------------------------------------------- /google/cloud/speech/v1/CloudSpeech.pbrpc.m: -------------------------------------------------------------------------------- 1 | #import "google/cloud/speech/v1/CloudSpeech.pbrpc.h" 2 | 3 | #import 4 | #import 5 | 6 | @implementation Speech 7 | 8 | // Designated initializer 9 | - (instancetype)initWithHost:(NSString *)host { 10 | return (self = [super initWithHost:host packageName:@"google.cloud.speech.v1" serviceName:@"Speech"]); 11 | } 12 | 13 | // Override superclass initializer to disallow different package and service names. 14 | - (instancetype)initWithHost:(NSString *)host 15 | packageName:(NSString *)packageName 16 | serviceName:(NSString *)serviceName { 17 | return [self initWithHost:host]; 18 | } 19 | 20 | + (instancetype)serviceWithHost:(NSString *)host { 21 | return [[self alloc] initWithHost:host]; 22 | } 23 | 24 | 25 | #pragma mark Recognize(RecognizeRequest) returns (RecognizeResponse) 26 | 27 | /** 28 | * Performs synchronous speech recognition: receive results after all audio 29 | * has been sent and processed. 30 | */ 31 | - (void)recognizeWithRequest:(RecognizeRequest *)request handler:(void(^)(RecognizeResponse *_Nullable response, NSError *_Nullable error))handler{ 32 | [[self RPCToRecognizeWithRequest:request handler:handler] start]; 33 | } 34 | // Returns a not-yet-started RPC object. 35 | /** 36 | * Performs synchronous speech recognition: receive results after all audio 37 | * has been sent and processed. 38 | */ 39 | - (GRPCProtoCall *)RPCToRecognizeWithRequest:(RecognizeRequest *)request handler:(void(^)(RecognizeResponse *_Nullable response, NSError *_Nullable error))handler{ 40 | return [self RPCToMethod:@"Recognize" 41 | requestsWriter:[GRXWriter writerWithValue:request] 42 | responseClass:[RecognizeResponse class] 43 | responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]]; 44 | } 45 | #pragma mark LongRunningRecognize(LongRunningRecognizeRequest) returns (Operation) 46 | 47 | /** 48 | * Performs asynchronous speech recognition: receive results via the 49 | * google.longrunning.Operations interface. Returns either an 50 | * `Operation.error` or an `Operation.response` which contains 51 | * a `LongRunningRecognizeResponse` message. 52 | */ 53 | - (void)longRunningRecognizeWithRequest:(LongRunningRecognizeRequest *)request handler:(void(^)(Operation *_Nullable response, NSError *_Nullable error))handler{ 54 | [[self RPCToLongRunningRecognizeWithRequest:request handler:handler] start]; 55 | } 56 | // Returns a not-yet-started RPC object. 57 | /** 58 | * Performs asynchronous speech recognition: receive results via the 59 | * google.longrunning.Operations interface. Returns either an 60 | * `Operation.error` or an `Operation.response` which contains 61 | * a `LongRunningRecognizeResponse` message. 62 | */ 63 | - (GRPCProtoCall *)RPCToLongRunningRecognizeWithRequest:(LongRunningRecognizeRequest *)request handler:(void(^)(Operation *_Nullable response, NSError *_Nullable error))handler{ 64 | return [self RPCToMethod:@"LongRunningRecognize" 65 | requestsWriter:[GRXWriter writerWithValue:request] 66 | responseClass:[Operation class] 67 | responsesWriteable:[GRXWriteable writeableWithSingleHandler:handler]]; 68 | } 69 | #pragma mark StreamingRecognize(stream StreamingRecognizeRequest) returns (stream StreamingRecognizeResponse) 70 | 71 | /** 72 | * Performs bidirectional streaming speech recognition: receive results while 73 | * sending audio. This method is only available via the gRPC API (not REST). 74 | */ 75 | - (void)streamingRecognizeWithRequestsWriter:(GRXWriter *)requestWriter eventHandler:(void(^)(BOOL done, StreamingRecognizeResponse *_Nullable response, NSError *_Nullable error))eventHandler{ 76 | [[self RPCToStreamingRecognizeWithRequestsWriter:requestWriter eventHandler:eventHandler] start]; 77 | } 78 | // Returns a not-yet-started RPC object. 79 | /** 80 | * Performs bidirectional streaming speech recognition: receive results while 81 | * sending audio. This method is only available via the gRPC API (not REST). 82 | */ 83 | - (GRPCProtoCall *)RPCToStreamingRecognizeWithRequestsWriter:(GRXWriter *)requestWriter eventHandler:(void(^)(BOOL done, StreamingRecognizeResponse *_Nullable response, NSError *_Nullable error))eventHandler{ 84 | return [self RPCToMethod:@"StreamingRecognize" 85 | requestsWriter:requestWriter 86 | responseClass:[StreamingRecognizeResponse class] 87 | responsesWriteable:[GRXWriteable writeableWithEventHandler:eventHandler]]; 88 | } 89 | @end 90 | -------------------------------------------------------------------------------- /google/longrunning/README.md: -------------------------------------------------------------------------------- 1 | # Google Long Running Operations API 2 | This package contains the definition of an abstract interface that 3 | manages long running operations with API services. See 4 | [google.longrunning.Operations][] for details. 5 | -------------------------------------------------------------------------------- /google/rpc/Code.pbobjc.m: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: google/rpc/code.proto 3 | 4 | // This CPP symbol can be defined to use imports that match up to the framework 5 | // imports needed when using CocoaPods. 6 | #if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) 7 | #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 8 | #endif 9 | 10 | #if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 11 | #import 12 | #else 13 | #import "GPBProtocolBuffers_RuntimeSupport.h" 14 | #endif 15 | 16 | #import "google/rpc/Code.pbobjc.h" 17 | // @@protoc_insertion_point(imports) 18 | 19 | #pragma clang diagnostic push 20 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 21 | 22 | #pragma mark - CodeRoot 23 | 24 | @implementation CodeRoot 25 | 26 | @end 27 | 28 | #pragma mark - Enum Code 29 | 30 | GPBEnumDescriptor *Code_EnumDescriptor(void) { 31 | static GPBEnumDescriptor *descriptor = NULL; 32 | if (!descriptor) { 33 | static const char *valueNames = 34 | "Ok\000Cancelled\000Unknown\000InvalidArgument\000Dea" 35 | "dlineExceeded\000NotFound\000AlreadyExists\000Per" 36 | "missionDenied\000Unauthenticated\000ResourceEx" 37 | "hausted\000FailedPrecondition\000Aborted\000OutOf" 38 | "Range\000Unimplemented\000Internal\000Unavailable" 39 | "\000DataLoss\000"; 40 | static const int32_t values[] = { 41 | Code_Ok, 42 | Code_Cancelled, 43 | Code_Unknown, 44 | Code_InvalidArgument, 45 | Code_DeadlineExceeded, 46 | Code_NotFound, 47 | Code_AlreadyExists, 48 | Code_PermissionDenied, 49 | Code_Unauthenticated, 50 | Code_ResourceExhausted, 51 | Code_FailedPrecondition, 52 | Code_Aborted, 53 | Code_OutOfRange, 54 | Code_Unimplemented, 55 | Code_Internal, 56 | Code_Unavailable, 57 | Code_DataLoss, 58 | }; 59 | GPBEnumDescriptor *worker = 60 | [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(Code) 61 | valueNames:valueNames 62 | values:values 63 | count:(uint32_t)(sizeof(values) / sizeof(int32_t)) 64 | enumVerifier:Code_IsValidValue]; 65 | if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) { 66 | [worker release]; 67 | } 68 | } 69 | return descriptor; 70 | } 71 | 72 | BOOL Code_IsValidValue(int32_t value__) { 73 | switch (value__) { 74 | case Code_Ok: 75 | case Code_Cancelled: 76 | case Code_Unknown: 77 | case Code_InvalidArgument: 78 | case Code_DeadlineExceeded: 79 | case Code_NotFound: 80 | case Code_AlreadyExists: 81 | case Code_PermissionDenied: 82 | case Code_Unauthenticated: 83 | case Code_ResourceExhausted: 84 | case Code_FailedPrecondition: 85 | case Code_Aborted: 86 | case Code_OutOfRange: 87 | case Code_Unimplemented: 88 | case Code_Internal: 89 | case Code_Unavailable: 90 | case Code_DataLoss: 91 | return YES; 92 | default: 93 | return NO; 94 | } 95 | } 96 | 97 | 98 | #pragma clang diagnostic pop 99 | 100 | // @@protoc_insertion_point(global_scope) 101 | -------------------------------------------------------------------------------- /google/rpc/README.md: -------------------------------------------------------------------------------- 1 | # Google RPC 2 | 3 | This package contains type definitions for general RPC systems. While 4 | [gRPC](https://github.com/grpc) is using these defintions, but they 5 | are not designed specifically to support gRPC. 6 | -------------------------------------------------------------------------------- /google/rpc/status.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.rpc; 18 | 19 | import "google/protobuf/any.proto"; 20 | 21 | option java_multiple_files = true; 22 | option java_outer_classname = "StatusProto"; 23 | option java_package = "com.google.rpc"; 24 | 25 | 26 | // The `Status` type defines a logical error model that is suitable for different 27 | // programming environments, including REST APIs and RPC APIs. It is used by 28 | // [gRPC](https://github.com/grpc). The error model is designed to be: 29 | // 30 | // - Simple to use and understand for most users 31 | // - Flexible enough to meet unexpected needs 32 | // 33 | // # Overview 34 | // 35 | // The `Status` message contains three pieces of data: error code, error message, 36 | // and error details. The error code should be an enum value of 37 | // [google.rpc.Code][google.rpc.Code], but it may accept additional error codes if needed. The 38 | // error message should be a developer-facing English message that helps 39 | // developers *understand* and *resolve* the error. If a localized user-facing 40 | // error message is needed, put the localized message in the error details or 41 | // localize it in the client. The optional error details may contain arbitrary 42 | // information about the error. There is a predefined set of error detail types 43 | // in the package `google.rpc` which can be used for common error conditions. 44 | // 45 | // # Language mapping 46 | // 47 | // The `Status` message is the logical representation of the error model, but it 48 | // is not necessarily the actual wire format. When the `Status` message is 49 | // exposed in different client libraries and different wire protocols, it can be 50 | // mapped differently. For example, it will likely be mapped to some exceptions 51 | // in Java, but more likely mapped to some error codes in C. 52 | // 53 | // # Other uses 54 | // 55 | // The error model and the `Status` message can be used in a variety of 56 | // environments, either with or without APIs, to provide a 57 | // consistent developer experience across different environments. 58 | // 59 | // Example uses of this error model include: 60 | // 61 | // - Partial errors. If a service needs to return partial errors to the client, 62 | // it may embed the `Status` in the normal response to indicate the partial 63 | // errors. 64 | // 65 | // - Workflow errors. A typical workflow has multiple steps. Each step may 66 | // have a `Status` message for error reporting purpose. 67 | // 68 | // - Batch operations. If a client uses batch request and batch response, the 69 | // `Status` message should be used directly inside batch response, one for 70 | // each error sub-response. 71 | // 72 | // - Asynchronous operations. If an API call embeds asynchronous operation 73 | // results in its response, the status of those operations should be 74 | // represented directly using the `Status` message. 75 | // 76 | // - Logging. If some API errors are stored in logs, the message `Status` could 77 | // be used directly after any stripping needed for security/privacy reasons. 78 | message Status { 79 | // The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. 80 | int32 code = 1; 81 | 82 | // A developer-facing error message, which should be in English. Any 83 | // user-facing error message should be localized and sent in the 84 | // [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. 85 | string message = 2; 86 | 87 | // A list of messages that carry the error details. There will be a 88 | // common set of message types for APIs to use. 89 | repeated google.protobuf.Any details = 3; 90 | } 91 | -------------------------------------------------------------------------------- /googleapis.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'googleapis' 3 | s.version = '0.0.1' 4 | s.license = 'Apache 2.0' 5 | s.authors = { 'Google Inc.' => 'timburks@google.com'} 6 | s.homepage = 'http://github.com/GoogleCloudPlatform/ios-docs-samples' 7 | s.source = { :git => 'https://github.com/GoogleCloudPlatform/ios-docs-samples.git', 8 | :tag => '0.0.1' } 9 | s.summary = 'Service definitions for Google Cloud Platform APIs' 10 | 11 | s.ios.deployment_target = '7.1' 12 | s.osx.deployment_target = '10.9' 13 | 14 | # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients. 15 | s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1.1" 16 | 17 | # Pods directory corresponding to this app's Podfile, relative to the location of this podspec. 18 | pods_root = 'Pods' 19 | 20 | # Path where Cocoapods downloads protoc and the gRPC plugin. 21 | protoc_dir = "#{pods_root}/!ProtoCompiler" 22 | protoc = "#{protoc_dir}/protoc" 23 | plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin" 24 | 25 | # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients. 26 | # You can run this command manually if you later change your protos and need to regenerate. 27 | s.prepare_command = <<-CMD 28 | #{protoc} \ 29 | --plugin=protoc-gen-grpc=#{plugin} \ 30 | --objc_out=. \ 31 | --grpc_out=. \ 32 | -I . \ 33 | -I #{protoc_dir} \ 34 | google/*/*.proto google/*/*/*/*.proto 35 | CMD 36 | 37 | # The --objc_out plugin generates a pair of .pbobjc.h/.pbobjc.m files for each .proto file. 38 | s.subspec "Messages" do |ms| 39 | ms.source_files = "google/**/*.pbobjc.{h,m}" 40 | ms.header_mappings_dir = "." 41 | ms.requires_arc = false 42 | ms.dependency "Protobuf" 43 | end 44 | 45 | # The --objcgrpc_out plugin generates a pair of .pbrpc.h/.pbrpc.m files for each .proto file with 46 | # a service defined. 47 | s.subspec "Services" do |ss| 48 | ss.source_files = "google/**/*.pbrpc.{h,m}" 49 | ss.header_mappings_dir = "." 50 | ss.requires_arc = true 51 | ss.dependency "gRPC-ProtoRPC" 52 | ss.dependency "#{s.name}/Messages" 53 | end 54 | 55 | s.pod_target_xcconfig = { 56 | 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1', 57 | 'USER_HEADER_SEARCH_PATHS' => '$SRCROOT/..' 58 | } 59 | 60 | end 61 | 62 | --------------------------------------------------------------------------------