Sha256: 435e382114ef3dcbf102e28c0d1c0780f95d1b40269af0bf09c36e63caf24474

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

module ProMotion::MotionTable
  module RefreshableTable
    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]|| :on_refresh

      @refresh_control = UIRefreshControl.alloc.init
      @refresh_control.attributedTitle = NSAttributedString.alloc.initWithString(pull_message)
      @refresh_control.addTarget(self, action:'refreshView:', forControlEvents:UIControlEventValueChanged)
      self.refreshControl = @refresh_control
    end
    alias :makeRefreshable :make_refreshable

    ######### iOS methods, headless camel case #######

    # UIRefreshControl Delegates
    def refreshView(refresh)
      refresh.attributedTitle = NSAttributedString.alloc.initWithString(@refreshing)
      if @refreshable_callback && self.respond_to?(@refreshable_callback)
        self.send(@refreshable_callback)
      else
        PM.logger.warn "You must implement the '#{@refreshable_callback}' method in your TableScreen."
      end
    end

    def start_refreshing
      return unless @refresh_control

      @refresh_control.beginRefreshing
    end

    def end_refreshing
      return unless @refresh_control

      @refresh_control.attributedTitle = NSAttributedString.alloc.initWithString(sprintf(@updated_format, Time.now.strftime(@updated_time_format)))
      @refresh_control.endRefreshing
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ProMotion-0.6.5 lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb
ProMotion-0.6.4 lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb
ProMotion-0.6.3 lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb
ProMotion-0.6.2 lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb
ProMotion-0.6.1 lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb
ProMotion-0.6.0 lib/ProMotion/screen_helpers/_tables/_refreshable_table.rb