lib/ProMotion/table/table.rb in ProMotion-2.4.0 vs lib/ProMotion/table/table.rb in ProMotion-2.4.1
- old
+ new
@@ -19,15 +19,14 @@
set_up_header_footer_views
set_up_searchable
set_up_refreshable
set_up_longpressable
set_up_row_height
- set_up_accessibility
end
def check_table_data
- PM.logger.error "Missing #table_data method in TableScreen #{self.class.to_s}." unless self.respond_to?(:table_data)
+ mp("Missing #table_data method in TableScreen #{self.class.to_s}.", force_color: :red) unless self.respond_to?(:table_data)
end
def promotion_table_data
@promotion_table_data ||= TableData.new(table_data, table_view, setup_search_method)
end
@@ -37,11 +36,11 @@
if self.respond_to?("table_#{hf_view}_view".to_sym)
view = self.send("table_#{hf_view}_view")
if view.is_a? UIView
self.tableView.send(camelize("set_table_#{hf_view}_view:"), view)
else
- PM.logger.warn "Table #{hf_view} view must be a UIView."
+ mp "Table #{hf_view} view must be a UIView.", force_color: :yellow
end
end
end
end
@@ -71,11 +70,11 @@
def set_up_refreshable
if self.class.respond_to?(:get_refreshable) && self.class.get_refreshable
if defined?(UIRefreshControl)
self.make_refreshable(self.class.get_refreshable_params)
else
- PM.logger.warn "To use the refresh control on < iOS 6, you need to include the CocoaPod 'CKRefreshControl'."
+ mp "To use the refresh control on < iOS 6, you need to include the CocoaPod 'CKRefreshControl'.", force_color: :yellow
end
end
end
def set_up_longpressable
@@ -89,23 +88,10 @@
self.view.rowHeight = params[:height]
self.view.estimatedRowHeight = params[:estimated]
end
end
- def editable?
- self.promotion_table_data.sections.each do |section|
- section[:cells].each do |cell|
- return true if [:insert,:delete].include?(cell[:editing_style])
- end
- end
- false
- end
-
- def set_up_accessibility
- self.extend(Editable) if editable?
- end
-
def searching?
self.promotion_table_data.filtered
end
def original_search_string
@@ -133,21 +119,21 @@
def accessory_toggled_switch(switch)
table_cell = closest_parent(UITableViewCell, switch)
index_path = closest_parent(UITableView, table_cell).indexPathForCell(table_cell)
if index_path
- data_cell = promotion_table_data.cell(section: index_path.section, index: index_path.row)
+ data_cell = cell_at(index_path: index_path)
data_cell[:accessory][:arguments][:value] = switch.isOn if data_cell[:accessory][:arguments].is_a?(Hash)
trigger_action(data_cell[:accessory][:action], data_cell[:accessory][:arguments], index_path) if data_cell[:accessory][:action]
end
end
def delete_row(index_paths, animation = nil)
deletable_index_paths = []
Array(index_paths).each do |index_path|
delete_cell = false
- delete_cell = send(:on_cell_deleted, self.promotion_table_data.cell(index_path: index_path)) if self.respond_to?("on_cell_deleted:")
+ delete_cell = send(:on_cell_deleted, cell_at(index_path: index_path)) if self.respond_to?("on_cell_deleted:")
unless delete_cell == false
self.promotion_table_data.delete_cell(index_path: index_path)
deletable_index_paths << index_path
end
end
@@ -174,10 +160,15 @@
def edit_mode?
!!isEditing
end
+ # Returns the data cell
+ def cell_at(args = {})
+ self.promotion_table_data.cell(args)
+ end
+
########## Cocoa touch methods #################
def numberOfSectionsInTableView(_)
self.promotion_table_data.sections.length
end
@@ -198,56 +189,60 @@
nil
end
def tableView(_, cellForRowAtIndexPath: index_path)
params = index_path_to_section_index(index_path: index_path)
- data_cell = self.promotion_table_data.cell(section: params[:section], index: params[:index])
+ data_cell = cell_at(index: params[:index], section: params[:section])
return UITableViewCell.alloc.init unless data_cell
create_table_cell(data_cell)
end
def tableView(_, willDisplayCell: table_cell, forRowAtIndexPath: index_path)
- data_cell = self.promotion_table_data.cell(index_path: index_path)
+ data_cell = cell_at(index_path: index_path)
+ try :will_display_cell, table_cell, index_path
table_cell.send(:will_display) if table_cell.respond_to?(:will_display)
table_cell.send(:restyle!) if table_cell.respond_to?(:restyle!) # Teacup compatibility
end
def tableView(_, heightForRowAtIndexPath: index_path)
- (self.promotion_table_data.cell(index_path: index_path)[:height] || tableView.rowHeight).to_f
+ (cell_at(index_path: index_path)[:height] || tableView.rowHeight).to_f
end
def tableView(table_view, didSelectRowAtIndexPath: index_path)
- data_cell = self.promotion_table_data.cell(index_path: index_path)
+ data_cell = cell_at(index_path: index_path)
table_view.deselectRowAtIndexPath(index_path, animated: true) unless data_cell[:keep_selection] == true
trigger_action(data_cell[:action], data_cell[:arguments], index_path) if data_cell[:action]
end
- def tableView(_, editingStyleForRowAtIndexPath: index_path)
+ def tableView(_, canEditRowAtIndexPath:index_path)
data_cell = self.promotion_table_data.cell(index_path: index_path, unfiltered: true)
+ [:insert,:delete].include?(data_cell[:editing_style])
+ end
+
+ def tableView(_, editingStyleForRowAtIndexPath: index_path)
+ data_cell = cell_at(index_path: index_path, unfiltered: true)
map_cell_editing_style(data_cell[:editing_style])
end
- module Editable
- def tableView(_, commitEditingStyle: editing_style, forRowAtIndexPath: index_path)
- if editing_style == UITableViewCellEditingStyleDelete
- delete_row(index_path)
- end
+ def tableView(_, commitEditingStyle: editing_style, forRowAtIndexPath: index_path)
+ if editing_style == UITableViewCellEditingStyleDelete
+ delete_row(index_path)
end
end
def tableView(_, canMoveRowAtIndexPath:index_path)
- data_cell = self.promotion_table_data.cell(index_path: index_path, unfiltered: true)
+ data_cell = cell_at(index_path: index_path, unfiltered: true)
if (!data_cell[:moveable].nil? || data_cell[:moveable].is_a?(Symbol)) && data_cell[:moveable] != false
true
else
false
end
end
def tableView(_, targetIndexPathForMoveFromRowAtIndexPath:source_index_path, toProposedIndexPath:proposed_destination_index_path)
- data_cell = self.promotion_table_data.cell(index_path: source_index_path, unfiltered: true)
+ data_cell = cell_at(index_path: source_index_path, unfiltered: true)
if data_cell[:moveable] == :section && source_index_path.section != proposed_destination_index_path.section
source_index_path
else
proposed_destination_index_path
@@ -265,11 +260,11 @@
},
cell: self.promotion_table_data.section(to_index_path.section)[:cells][to_index_path.row]
}
send(:on_cell_moved, args)
else
- PM.logger.warn "Implement the on_cell_moved method in your PM::TableScreen to be notified when a user moves a cell."
+ mp "Implement the on_cell_moved method in your PM::TableScreen to be notified when a user moves a cell.", force_color: :yellow
end
end
def tableView(table_view, sectionForSectionIndexTitle: title, atIndex: index)
return index unless ["{search}", UITableViewIndexSearch].include?(self.table_data_index[0])
@@ -281,11 +276,11 @@
index - 1
end
end
def deleteRowsAtIndexPaths(index_paths, withRowAnimation: animation)
- PM.logger.warn "ProMotion expects you to use 'delete_cell(index_paths, animation)'' instead of 'deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)'."
+ mp "ProMotion expects you to use 'delete_cell(index_paths, animation)'' instead of 'deleteRowsAtIndexPaths(index_paths, withRowAnimation:animation)'.", force_color: :yellow
delete_row(index_paths, animation)
end
# Section view methods
def tableView(_, viewForHeaderInSection: index)
@@ -341,8 +336,7 @@
end
def self.included(base)
base.extend(TableClassMethods)
end
-
end
end