<commit_before>module ProMotion::MotionTable
  module SectionedTable
    # @param [Array] Array of table data
    # @returns [UITableView] delegated to self
    def createTableViewFromData(data)
      setTableViewData data
      return tableView
    end

    def updateTableViewData(data)
      setTableViewData data
      self.tableView.reloadData
    end

    def setTableViewData(data)
      @mt_table_view_groups = data
    end

    def numberOfSectionsInTableView(tableView)
      if @mt_filtered
        return @mt_filtered_data.length if @mt_filtered_data
      else
        return @mt_table_view_groups.length if @mt_table_view_groups
      end
      0
    end

    # Number of cells
    def tableView(tableView, numberOfRowsInSection:section)
      return sectionAtIndex(section)[:cells].length if sectionAtIndex(section) && sectionAtIndex(section)[:cells]
      0
    end

    def tableView(tableView, titleForHeaderInSection:section)
      return sectionAtIndex(section)[:title] if sectionAtIndex(section) && sectionAtIndex(section)[:title]
    end

    # Set table_data_index if you want the right hand index column (jumplist)
    def sectionIndexTitlesForTableView(tableView)
      if self.respond_to?(:table_data_index)
        self.table_data_index 
      end
    end

    def tableView(tableView, cellForRowAtIndexPath:indexPath)
      # Aah, magic happens here...

      dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
      return UITableViewCell.alloc.init unless dataCell
      dataCell[:cellStyle] ||= UITableViewCellStyleDefault
      dataCell[:cellIdentifier] ||= "Cell"
      cellIdentifier = dataCell[:cellIdentifier]
      dataCell[:cellClass] ||= UITableViewCell

      tableCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
      unless tableCell
        tableCell = dataCell[:cellClass].alloc.initWithStyle(dataCell[:cellStyle], reuseIdentifier:cellIdentifier)
        
        # Add optimizations here
        tableCell.layer.masksToBounds = true if dataCell[:masksToBounds]
        tableCell.backgroundColor = dataCell[:backgroundColor] if dataCell[:backgroundColor]
        tableCell.selectionStyle = dataCell[:selectionStyle] if dataCell[:selectionStyle]
        tableCell.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin
      end

      if dataCell[:cellClassAttributes]
        set_cell_attributes tableCell, dataCell[:cellClassAttributes]
      end
      
      if dataCell[:accessoryView]
        tableCell.accessoryView = dataCell[:accessoryView]
        tableCell.accessoryView.autoresizingMask = UIViewAutoresizingFlexibleWidth
      end

      if dataCell[:accessory] && dataCell[:accessory] == :switch
        switchView = UISwitch.alloc.initWithFrame(CGRectZero)
        switchView.addTarget(self, action: "accessoryToggledSwitch:", forControlEvents:UIControlEventValueChanged);
        switchView.on = true if dataCell[:accessoryDefault]
        tableCell.accessoryView = switchView
      end

      if dataCell[:subtitle]
        tableCell.detailTextLabel.text = dataCell[:subtitle]
        tableCell.detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth
      end

      tableCell.selectionStyle = UITableViewCellSelectionStyleNone if dataCell[:no_select]

      if dataCell[:remoteImage]
        if tableCell.imageView.respond_to?("setImageWithURL:placeholderImage:")
          url = dataCell[:remoteImage][:url]
          url = NSURL.URLWithString(url) unless url.is_a?(NSURL)
          placeholder = dataCell[:remoteImage][:placeholder]
          placeholder = UIImage.imageNamed(placeholder) if placeholder.is_a?(String)

          tableCell.imageView.setImageWithURL(url, placeholderImage: placeholder)
          tableCell.imageView.layer.masksToBounds = true
          tableCell.imageView.layer.cornerRadius = dataCell[:remoteImage][:radius]
        else
          ProMotion::MotionTable::Console.log("ProMotion Warning: to use remoteImage with TableScreen you need to include the CocoaPod 'SDWebImage'.", withColor: MotionTable::Console::RED_COLOR)
        end
      elsif dataCell[:image]
        tableCell.imageView.layer.masksToBounds = true
        tableCell.imageView.image = dataCell[:image][:image]
        tableCell.imageView.layer.cornerRadius = dataCell[:image][:radius] if dataCell[:image][:radius]
      end

      if dataCell[:subViews]
        tag_number = 0
        dataCell[:subViews].each do |view|
          # Remove an existing view at that tag number
          tag_number += 1
          existing_view = tableCell.viewWithTag(tag_number)<commit_msg>Size issue<commit_after>module ProMotion::MotionTable
  module SectionedTable
    # @param [Array] Array of table data
    # @returns [UITableView] delegated to self
    def createTableViewFromData(data)
      setTableViewData data
      return tableView
    end

    def updateTableViewData(data)
      setTableViewData data
      self.tableView.reloadData
    end

    def setTableViewData(data)
      @mt_table_view_groups = data
    end

    def numberOfSectionsInTableView(tableView)
      if @mt_filtered
        return @mt_filtered_data.length if @mt_filtered_data
      else
        return @mt_table_view_groups.length if @mt_table_view_groups
      end
      0
    end

    # Number of cells
    def tableView(tableView, numberOfRowsInSection:section)
      return sectionAtIndex(section)[:cells].length if sectionAtIndex(section) && sectionAtIndex(section)[:cells]
      0
    end

    def tableView(tableView, titleForHeaderInSection:section)
      return sectionAtIndex(section)[:title] if sectionAtIndex(section) && sectionAtIndex(section)[:title]
    end

    # Set table_data_index if you want the right hand index column (jumplist)
    def sectionIndexTitlesForTableView(tableView)
      if self.respond_to?(:table_data_index)
        self.table_data_index 
      end
    end

    def tableView(tableView, cellForRowAtIndexPath:indexPath)
      # Aah, magic happens here...

      dataCell = cellAtSectionAndIndex(indexPath.section, indexPath.row)
      return UITableViewCell.alloc.init unless dataCell
      dataCell[:cellStyle] ||= UITableViewCellStyleDefault
      dataCell[:cellIdentifier] ||= "Cell"
      cellIdentifier = dataCell[:cellIdentifier]
      dataCell[:cellClass] ||= UITableViewCell

      tableCell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
      unless tableCell
        tableCell = dataCell[:cellClass].alloc.initWithStyle(dataCell[:cellStyle], reuseIdentifier:cellIdentifier)
        
        # Add optimizations here
        tableCell.layer.masksToBounds = true if dataCell[:masksToBounds]
        tableCell.backgroundColor = dataCell[:backgroundColor] if dataCell[:backgroundColor]
        tableCell.selectionStyle = dataCell[:selectionStyle] if dataCell[:selectionStyle]
        tableCell.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin
      end

      if dataCell[:cellClassAttributes]
        set_cell_attributes tableCell, dataCell[:cellClassAttributes]
      end
      
      if dataCell[:accessoryView]
        tableCell.accessoryView = dataCell[:accessoryView]
        tableCell.accessoryView.autoresizingMask = UIViewAutoresizingFlexibleWidth
      end

      if dataCell[:accessory] && dataCell[:accessory] == :switch
        switchView = UISwitch.alloc.initWithFrame(CGRectZero)
        switchView.addTarget(self, action: "accessoryToggledSwitch:", forControlEvents:UIControlEventValueChanged);
        switchView.on = true if dataCell[:accessoryDefault]
        tableCell.accessoryView = switchView
      end

      if dataCell[:subtitle]
        tableCell.detailTextLabel.text = dataCell[:subtitle]
        tableCell.detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth
      end

      tableCell.selectionStyle = UITableViewCellSelectionStyleNone if dataCell[:no_select]

      if dataCell[:remoteImage]
        if tableCell.imageView.respond_to?("setImageWithURL:placeholderImage:")
          url = dataCell[:remoteImage][:url]
          url = NSURL.URLWithString(url) unless url.is_a?(NSURL)
          placeholder = dataCell[:remoteImage][:placeholder]
          placeholder = UIImage.imageNamed(placeholder) if placeholder.is_a?(String)

          tableCell.imageView.setImageWithURL(url, placeholderImage: placeholder)
          tableCell.imageView.layer.masksToBounds = true
          tableCell.imageView.layer.cornerRadius = dataCell[:remoteImage][:radius]
          if dataCell[:remoteImage][:size]
            f = tableCell.imageView.frame
            size_inset_x = tableCell.imageView.image.size.width - dataCell[:remoteImage][:size]
            size_inset_y = tableCell.imageView.image.size.height - dataCell[:remoteImage][:size]
            tableCell.imageView.frame = CGRectInset(f, size_inset_x, size_inset_y)
          end
        else
          ProMotion::MotionTable::Console.log("ProMotion Warning: to use remoteImage with TableScreen you need to include the CocoaPod 'SDWebImage'.", withColor: MotionTable::Console::RED_COLOR)
        end
      elsif dataCell[:image]
        tableCell.imageView.layer.masksToBounds = true
        tableCell.imageView.image = dataCell[:image][:image]
        tableCell.imageView.layer.cornerRadius = dataCell[:image][:radius] if dataCell[:image][:radius]
      end

      if dataCell[:subViews]
        tag_number = 0
        dataCell[:subViews].each do |view|
          # Remove an existing view at that tag number
          tag_number += 1
          existing_view = tableCell.viewWithTag(tag_number)
{'fraction_non_alphanumeric': 0.07964418700868846, 'fraction_numerical': 0.0008274720728175424, 'mean_word_length': 3.584637268847795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5997627', 'n_tokens_mistral': 2756, 'n_tokens_neox': 2637, 'n_words': 511}