From c8c0c43c49234aed8cb60e6ea68b31f85d738b83 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 12:56:56 -0400 Subject: [PATCH 01/12] Initial pass at a refreshable table. --- .../_tables/_refreshable_table.rb | 57 +++++++++++++++++++ .../_tables/_sectioned_table.rb | 3 + .../screen_helpers/_tables/grouped_table.rb | 1 + .../screen_helpers/_tables/plain_table.rb | 1 + lib/ProMotion/screens/_table_screen_module.rb | 13 +++++ 5 files changed, 75 insertions(+) create mode 100644 lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb diff --git a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb new file mode 100644 index 0000000..bb29a86 --- /dev/null +++ b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb @@ -0,0 +1,57 @@ +module ProMotion::MotionTable + module RefreshableTable + def make_refreshable + @refresh = UIRefreshControl.alloc.init + @refresh.attributedTitle = NSAttributedString.alloc.initWithString("Pull to Refresh") + @refresh.addTarget(self, action:'refreshView:', forControlEvents:UIControlEventValueChanged) + self.refreshControl = @refresh + # @on_refresh = get_refreshable_block + + + # params[:content_controller] ||= params[:contentController] + # params[:data_source] ||= params[:searchResultsDataSource] + # params[:search_results_delegate] ||= params[:searchResultsDelegate] + + # params[:frame] ||= CGRectMake(0, 0, 320, 44) # TODO: Don't hardcode this... + # params[:content_controller] ||= self + # params[:delegate] ||= self + # params[:data_source] ||= self + # params[:search_results_delegate] ||= self + + # search_bar = UISearchBar.alloc.initWithFrame(params[:frame]) + # search_bar.autoresizingMask = UIViewAutoresizingFlexibleWidth + + # if params[:search_bar] && params[:search_bar][:placeholder] + # search_bar.placeholder = params[:search_bar][:placeholder] + # end + + # @contacts_search_display_controller = UISearchDisplayController.alloc.initWithSearchBar(search_bar, contentsController: params[:content_controller]) + # @contacts_search_display_controller.delegate = params[:delegate] + # @contacts_search_display_controller.searchResultsDataSource = params[:data_source] + # @contacts_search_display_controller.searchResultsDelegate = params[:search_results_delegate] + + # self.table_view.tableHeaderView = search_bar + end + alias :makeRefreshable :make_refreshable + + ######### iOS methods, headless camel case ####### + + # UIRefreshControl Delegates + def refreshView(refresh) + refresh.attributedTitle = NSAttributedString.alloc.initWithString("Refreshing data...") + @on_refresh.call if @on_refresh + end + + def on_refresh(&block) + @on_refresh = block + end + + def end_refreshing + return unless @refresh + + @refresh.attributedTitle = NSAttributedString.alloc.initWithString("Last updated on #{Time.now.strftime("%H:%M:%S")}") + @refresh.endRefreshing + self.update_table_data + end + end +end \ No newline at end of file diff --git a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb index f514a61..990f210 100644 --- a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb @@ -7,6 +7,9 @@ module ProMotion::MotionTable if self.class.respond_to?(:get_searchable) && self.class.get_searchable self.make_searchable(content_controller: self, search_bar: self.class.get_searchable_params) end + if self.class.respond_to?(:get_refreshable) && self.class.get_refreshable + self.make_refreshable + end end # @param [Array] Array of table data diff --git a/lib/ProMotion/screen_helpers/_tables/grouped_table.rb b/lib/ProMotion/screen_helpers/_tables/grouped_table.rb index 07e877f..09fb665 100644 --- a/lib/ProMotion/screen_helpers/_tables/grouped_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/grouped_table.rb @@ -1,6 +1,7 @@ module ProMotion::MotionTable module GroupedTable include SectionedTable + include RefreshableTable def table_view @table_view ||= UITableView.alloc.initWithFrame(self.view.frame, style:UITableViewStyleGrouped) diff --git a/lib/ProMotion/screen_helpers/_tables/plain_table.rb b/lib/ProMotion/screen_helpers/_tables/plain_table.rb index 11c5534..d837ac2 100644 --- a/lib/ProMotion/screen_helpers/_tables/plain_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/plain_table.rb @@ -2,6 +2,7 @@ module ProMotion::MotionTable module PlainTable include SectionedTable include SearchableTable + include RefreshableTable def table_view @table_view ||= UITableView.alloc.initWithFrame(self.view.frame, style:UITableViewStylePlain) diff --git a/lib/ProMotion/screens/_table_screen_module.rb b/lib/ProMotion/screens/_table_screen_module.rb index 925fb56..fb79460 100644 --- a/lib/ProMotion/screens/_table_screen_module.rb +++ b/lib/ProMotion/screens/_table_screen_module.rb @@ -2,6 +2,7 @@ module ProMotion module TableScreenModule include MotionTable::PlainTable include MotionTable::SearchableTable + include MotionTable::RefreshableTable include ProMotion::ScreenModule def update_table_data @@ -9,6 +10,7 @@ module ProMotion end module TableClassMethods + # Searchable def searchable(params={}) @searchable_params = params @searchable = true @@ -21,6 +23,17 @@ module ProMotion def get_searchable @searchable ||= false end + + # Refreshable + def refreshable(&block) + @refreshable_block = block + @refreshable = true + end + + def get_refreshable + @refreshable ||= false + end + end def self.included(base) base.extend(ClassMethods) From adfe258aab4c2f62c40260b890775cfccc1b7861 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 13:03:50 -0400 Subject: [PATCH 02/12] Update readme with implementation details for refreshing a tableview. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index bc90486..4704446 100644 --- a/README.md +++ b/README.md @@ -684,6 +684,14 @@ end searchable(placeholder: "placeholder text") Class method to make the current table searchable. + + refreshable + Class method to make the current table refreshable.

You must also specify the following block in your will_appear method:

+ on_refresh do
+ # Code to start the refresh
+ end
+

And after you're done refreshing everything, call end_refreshing and your tableview will refresh the data automatically.

+

table_data

From f46aeea0d8190d32a2df1ad8a3c1d390ecdff77e Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 13:41:19 -0400 Subject: [PATCH 03/12] Make sure that we're running on ios6 or higher --- .../_tables/_refreshable_table.rb | 26 ------------------- .../_tables/_sectioned_table.rb | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb index bb29a86..c2fa041 100644 --- a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb @@ -5,32 +5,6 @@ module ProMotion::MotionTable @refresh.attributedTitle = NSAttributedString.alloc.initWithString("Pull to Refresh") @refresh.addTarget(self, action:'refreshView:', forControlEvents:UIControlEventValueChanged) self.refreshControl = @refresh - # @on_refresh = get_refreshable_block - - - # params[:content_controller] ||= params[:contentController] - # params[:data_source] ||= params[:searchResultsDataSource] - # params[:search_results_delegate] ||= params[:searchResultsDelegate] - - # params[:frame] ||= CGRectMake(0, 0, 320, 44) # TODO: Don't hardcode this... - # params[:content_controller] ||= self - # params[:delegate] ||= self - # params[:data_source] ||= self - # params[:search_results_delegate] ||= self - - # search_bar = UISearchBar.alloc.initWithFrame(params[:frame]) - # search_bar.autoresizingMask = UIViewAutoresizingFlexibleWidth - - # if params[:search_bar] && params[:search_bar][:placeholder] - # search_bar.placeholder = params[:search_bar][:placeholder] - # end - - # @contacts_search_display_controller = UISearchDisplayController.alloc.initWithSearchBar(search_bar, contentsController: params[:content_controller]) - # @contacts_search_display_controller.delegate = params[:delegate] - # @contacts_search_display_controller.searchResultsDataSource = params[:data_source] - # @contacts_search_display_controller.searchResultsDelegate = params[:search_results_delegate] - - # self.table_view.tableHeaderView = search_bar end alias :makeRefreshable :make_refreshable diff --git a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb index 990f210..b0ef431 100644 --- a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb @@ -7,7 +7,7 @@ module ProMotion::MotionTable if self.class.respond_to?(:get_searchable) && self.class.get_searchable self.make_searchable(content_controller: self, search_bar: self.class.get_searchable_params) end - if self.class.respond_to?(:get_refreshable) && self.class.get_refreshable + if ios_version_greater_eq?("6.0") && self.class.respond_to?(:get_refreshable) && self.class.get_refreshable self.make_refreshable end end From c96a4a537d0ebca38a4ee535fa3b48e45eef1b58 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 13:43:14 -0400 Subject: [PATCH 04/12] fix readme typo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4704446..99be9f7 100644 --- a/README.md +++ b/README.md @@ -688,7 +688,7 @@ end refreshable Class method to make the current table refreshable.

You must also specify the following block in your will_appear method:

on_refresh do
- # Code to start the refresh
+ # Code to start the refresh
end

And after you're done refreshing everything, call end_refreshing and your tableview will refresh the data automatically.

From 0d6cd7227e05a74d6ea58fd10160fd6ef4f2c42a Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 13:44:26 -0400 Subject: [PATCH 05/12] Better readme formatting for refreshable. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 99be9f7..b5b6f9b 100644 --- a/README.md +++ b/README.md @@ -687,9 +687,9 @@ end refreshable Class method to make the current table refreshable.

You must also specify the following block in your will_appear method:

- on_refresh do
- # Code to start the refresh
- end
+
on_refresh do
+  # Code to start the refresh
+end

And after you're done refreshing everything, call end_refreshing and your tableview will refresh the data automatically.

From 5a57ab6005d15d77b5e81ec4943719556a381e6b Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 19:30:07 -0400 Subject: [PATCH 06/12] Made callback pattern more consistent. Made all strings configurable. Updated documentation. --- README.md | 15 ++++++++---- .../_tables/_refreshable_table.rb | 23 ++++++++++++------- .../_tables/_sectioned_table.rb | 2 +- lib/ProMotion/screens/_table_screen_module.rb | 10 ++++++-- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b5b6f9b..6d33ed7 100644 --- a/README.md +++ b/README.md @@ -685,12 +685,19 @@ end Class method to make the current table searchable. - refreshable - Class method to make the current table refreshable.

You must also specify the following block in your will_appear method:

-
on_refresh do
+    
refreshable(
+  callback: :on_refresh,
+  pull_message: "Pull to refresh", 
+  refreshing: "Refreshing data…", 
+  updated_format: "Last updated at %s", 
+  updated_time_format: "%l:%M %p"
+)
+ Class method to make the current table refreshable. +

All parameters are optional. If you do not specify a a callback, it will assume you've implemented an on_refresh method in your tableview.

+
def on_refresh
   # Code to start the refresh
 end
-

And after you're done refreshing everything, call end_refreshing and your tableview will refresh the data automatically.

+

And after you're done with your asyncronous process, call end_refreshing to collapse the refresh view and update the last refreshed time and then update_table_data.

diff --git a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb index c2fa041..ee9792a 100644 --- a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb @@ -1,8 +1,14 @@ module ProMotion::MotionTable module RefreshableTable - def make_refreshable + def make_refreshable(params={}) + pull_message = params[:pull_message] || "Pull to refresh" + @refreshing = params[:refreshing] || "Refreshing data..." + @updated_format = params[:updated_format] || "Last updated at %s" + @updated_time_format = params[:updated_time_format] || "%l:%M %p" + @refreshable_callback = params[:callback] + @refresh = UIRefreshControl.alloc.init - @refresh.attributedTitle = NSAttributedString.alloc.initWithString("Pull to Refresh") + @refresh.attributedTitle = NSAttributedString.alloc.initWithString(pull_message) @refresh.addTarget(self, action:'refreshView:', forControlEvents:UIControlEventValueChanged) self.refreshControl = @refresh end @@ -12,20 +18,21 @@ module ProMotion::MotionTable # UIRefreshControl Delegates def refreshView(refresh) - refresh.attributedTitle = NSAttributedString.alloc.initWithString("Refreshing data...") - @on_refresh.call if @on_refresh + refresh.attributedTitle = NSAttributedString.alloc.initWithString(@refreshing) + self.send(@refreshable_callback) if @refreshable_callback end - def on_refresh(&block) - @on_refresh = block + def start_refreshing + return unless @refresh + + @refresh.beginRefreshing end def end_refreshing return unless @refresh - @refresh.attributedTitle = NSAttributedString.alloc.initWithString("Last updated on #{Time.now.strftime("%H:%M:%S")}") + @refresh.attributedTitle = NSAttributedString.alloc.initWithString(sprintf(@updated_format, Time.now.strftime(@updated_time_format))) @refresh.endRefreshing - self.update_table_data end end end \ No newline at end of file diff --git a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb index b0ef431..8f296b1 100644 --- a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb @@ -8,7 +8,7 @@ module ProMotion::MotionTable self.make_searchable(content_controller: self, search_bar: self.class.get_searchable_params) end if ios_version_greater_eq?("6.0") && self.class.respond_to?(:get_refreshable) && self.class.get_refreshable - self.make_refreshable + self.make_refreshable(self.class.get_refreshable_params) end end diff --git a/lib/ProMotion/screens/_table_screen_module.rb b/lib/ProMotion/screens/_table_screen_module.rb index fb79460..b88862c 100644 --- a/lib/ProMotion/screens/_table_screen_module.rb +++ b/lib/ProMotion/screens/_table_screen_module.rb @@ -25,8 +25,10 @@ module ProMotion end # Refreshable - def refreshable(&block) - @refreshable_block = block + def refreshable(params = {}) + params[:callback] = :on_refresh unless params[:callback] + + @refreshable_params = params @refreshable = true end @@ -34,6 +36,10 @@ module ProMotion @refreshable ||= false end + def get_refreshable_params + @refreshable_params ||= nil + end + end def self.included(base) base.extend(ClassMethods) From 45d726133cb6e9527d587b383b4f0eac4cd670b9 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 19:38:18 -0400 Subject: [PATCH 07/12] Add a warning if the user didn't implement the on_refresh method or they specified a callback method but didn't implement it. --- lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb index ee9792a..3dcce4b 100644 --- a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb @@ -19,7 +19,11 @@ module ProMotion::MotionTable # UIRefreshControl Delegates def refreshView(refresh) refresh.attributedTitle = NSAttributedString.alloc.initWithString(@refreshing) - self.send(@refreshable_callback) if @refreshable_callback + if @refreshable_callback && self.respondsToSelector(@refreshable_callback) + self.send(@refreshable_callback) + else + ProMotion::Console.log("ProMotion Warning: you must implement an on_refresh method in your TableScreen.", with_color: ProMotion::Console::RED_COLOR) + end end def start_refreshing From 7df301e20dd9acc0d85a6329bd7bc8f5232c0eb9 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 22:03:55 -0400 Subject: [PATCH 08/12] Use more ruby syntax instead of Obj-C syntax. --- lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb index 3dcce4b..d892ddb 100644 --- a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb @@ -19,7 +19,7 @@ module ProMotion::MotionTable # UIRefreshControl Delegates def refreshView(refresh) refresh.attributedTitle = NSAttributedString.alloc.initWithString(@refreshing) - if @refreshable_callback && self.respondsToSelector(@refreshable_callback) + if @refreshable_callback && self.respond_to?(@refreshable_callback) self.send(@refreshable_callback) else ProMotion::Console.log("ProMotion Warning: you must implement an on_refresh method in your TableScreen.", with_color: ProMotion::Console::RED_COLOR) From c6707f938b97c83387cf1372e53672e73c65f1a2 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 22:04:29 -0400 Subject: [PATCH 09/12] Modify console log to name the actual on_refresh method they need to implement if they defined a different callback. --- lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb index d892ddb..e8eca83 100644 --- a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb @@ -22,7 +22,7 @@ module ProMotion::MotionTable if @refreshable_callback && self.respond_to?(@refreshable_callback) self.send(@refreshable_callback) else - ProMotion::Console.log("ProMotion Warning: you must implement an on_refresh method in your TableScreen.", with_color: ProMotion::Console::RED_COLOR) + ProMotion::Console.log("ProMotion Warning: you must implement the '#{@refreshable_callback}' method in your TableScreen.", with_color: ProMotion::Console::RED_COLOR) end end From 1a1918eb12fdeea3f2f39fd6636af179395b35d9 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 22:07:42 -0400 Subject: [PATCH 10/12] Better handling of the callback param. --- lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb | 2 +- lib/ProMotion/screens/_table_screen_module.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb index e8eca83..a8fc438 100644 --- a/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb @@ -5,7 +5,7 @@ module ProMotion::MotionTable @refreshing = params[:refreshing] || "Refreshing data..." @updated_format = params[:updated_format] || "Last updated at %s" @updated_time_format = params[:updated_time_format] || "%l:%M %p" - @refreshable_callback = params[:callback] + @refreshable_callback = params[:callback]|| :on_refresh @refresh = UIRefreshControl.alloc.init @refresh.attributedTitle = NSAttributedString.alloc.initWithString(pull_message) diff --git a/lib/ProMotion/screens/_table_screen_module.rb b/lib/ProMotion/screens/_table_screen_module.rb index b88862c..890182c 100644 --- a/lib/ProMotion/screens/_table_screen_module.rb +++ b/lib/ProMotion/screens/_table_screen_module.rb @@ -26,8 +26,6 @@ module ProMotion # Refreshable def refreshable(params = {}) - params[:callback] = :on_refresh unless params[:callback] - @refreshable_params = params @refreshable = true end From d514555de65a969e88ded860dfc52ee7b5332397 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Mon, 6 May 2013 22:26:10 -0400 Subject: [PATCH 11/12] Huzzah! Works brilliantly in ios 6 and ios 5 now! --- lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb index 8f296b1..3de4875 100644 --- a/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb +++ b/lib/ProMotion/screen_helpers/_tables/_sectioned_table.rb @@ -7,8 +7,10 @@ module ProMotion::MotionTable if self.class.respond_to?(:get_searchable) && self.class.get_searchable self.make_searchable(content_controller: self, search_bar: self.class.get_searchable_params) end - if ios_version_greater_eq?("6.0") && self.class.respond_to?(:get_refreshable) && self.class.get_refreshable + if defined?(UIRefreshControl) && self.class.respond_to?(:get_refreshable) && self.class.get_refreshable self.make_refreshable(self.class.get_refreshable_params) + else + ProMotion::Console.log("ProMotion Warning: to use the refresh control on < iOS 6, you need to include the Cocoapod 'CKRefreshControl'.", with_color: ProMotion::Console::RED_COLOR) end end From 7d065510e3e846042caac253c2add8b4a6edb628 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Tue, 7 May 2013 00:21:58 -0400 Subject: [PATCH 12/12] Initial stab at tablescreen tests --- spec/helpers/.gitkeep | 0 spec/helpers/table_screen.rb | 44 ++++++++++++++++++++++++ spec/helpers/table_screen_refreshable.rb | 9 +++++ spec/helpers/table_screen_searchable.rb | 5 +++ spec/table_screen_spec.rb | 38 ++++++++++++++++++++ 5 files changed, 96 insertions(+) delete mode 100644 spec/helpers/.gitkeep create mode 100644 spec/helpers/table_screen.rb create mode 100644 spec/helpers/table_screen_refreshable.rb create mode 100644 spec/helpers/table_screen_searchable.rb create mode 100644 spec/table_screen_spec.rb diff --git a/spec/helpers/.gitkeep b/spec/helpers/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/helpers/table_screen.rb b/spec/helpers/table_screen.rb new file mode 100644 index 0000000..f16c3f8 --- /dev/null +++ b/spec/helpers/table_screen.rb @@ -0,0 +1,44 @@ +class TableScreen < ProMotion::SectionedTableScreen + + def on_load + @tap_counter ||= 0 + end + + def table_data + [{ + title: "Your Account", + cells: [ + { title: "Increment", action: :increment_counter_by, arguments: { number: 3 } }, + { title: "Add New Row", action: :add_tableview_row, accessibilityLabel: "Add New Row" }, + { title: "Just another blank row" } + ] + }, { + title: "App Stuff", + cells: [ + { title: "Increment One", action: :increment_counter }, + { title: "Feedback", remote_image: { url: "http://placekitten.com/100/100", placeholder: "some-local-image", size: 50, radius: 15 } } + ] + }] + end + + def edit_profile(args={}) + args[:id] + end + + def add_tableview_row + @data[0][:cells] << { + title: "Dynamically Added" + } + update_table_data + end + + def increment_counter + @tap_counter = @tap_counter + 1 + end + + def increment_counter_by(args) + @tap_counter = @tap_counter + args[:number] + end + + +end \ No newline at end of file diff --git a/spec/helpers/table_screen_refreshable.rb b/spec/helpers/table_screen_refreshable.rb new file mode 100644 index 0000000..74f1cb4 --- /dev/null +++ b/spec/helpers/table_screen_refreshable.rb @@ -0,0 +1,9 @@ +class TableScreenRefreshable < TableScreen + + refreshable + + def on_refresh + #do stuff + end + +end \ No newline at end of file diff --git a/spec/helpers/table_screen_searchable.rb b/spec/helpers/table_screen_searchable.rb new file mode 100644 index 0000000..13c282a --- /dev/null +++ b/spec/helpers/table_screen_searchable.rb @@ -0,0 +1,5 @@ +class TableScreenSearchable < TableScreen + + searchable + +end \ No newline at end of file diff --git a/spec/table_screen_spec.rb b/spec/table_screen_spec.rb new file mode 100644 index 0000000..0e8140a --- /dev/null +++ b/spec/table_screen_spec.rb @@ -0,0 +1,38 @@ +describe "table screen basic functionality" do + + before do + @screen = TableScreen.new + @screen.on_load + end + + tests TableScreen + + it "should display have 2 sections" do + @screen.tableView.numberOfSections.should == 2 + end + + it "should have prope r cell numbers" do + @screen.tableView.numberOfRowsInSection(0).should == 3 + @screen.tableView.numberOfRowsInSection(1).should == 2 + end + + # it "should run methods without arguments when tapping cell" do + # #cell = @screen.cell_at_section_and_index(0, 0) + # [1..10].each do |index| + # @screen.instance_variable_get("@tap_counter").should == index + # tap view("Increment") + # end + # end + + # it "should have a placeholder image in the last cell" do + # @screen.cell_at_section_and_index(1,1).imageView.should.be.a UIImage + # end + + # it "should add a new cell to first section" do + # tap "Add New Row" + # wait 0.2 do + # @screen.tableView.numberOfRowsInSection(0).should == 4 + # end + # end + +end