<commit_before>class FlowUIFragmentBackStackListener
  # Android doesn't call onResume when doing popBackStack
  # so we listhen to this event to call it ourselves
  def onBackStackChanged
    @previous_stack_entry_count ||= 0
    fragment_manager = UI.context.fragmentManager
    fragments_count = fragment_manager.backStackEntryCount

    # This is used to prevent to call onResume two times when pushing
    if @previous_stack_entry_count < fragment_manager.backStackEntryCount
      @previous_stack_entry_count = fragment_manager.backStackEntryCount
      return
    end

    if fragments_count > 0
      back_stack_entry = fragment_manager.getBackStackEntryAt(fragments_count - 1)
      fragment_tag = back_stack_entry.getName
      fragment = fragment_manager.findFragmentByTag(fragment_tag)
      fragment.onResume
      @previous_stack_entry_count = fragment_manager.backStackEntryCount
    end
  end
end

class UI::Navigation
  attr_reader :root_screen

  def initialize(root_screen)
    @root_screen = root_screen
    @root_screen.navigation = self
    container.addOnBackStackChangedListener(FlowUIFragmentBackStackListener.new)
  end

  def hide_bar
    UI.context.supportActionBar.hide
  end

  def show_bar
    UI.context.supportActionBar.show
  end

  def title=(title)
    UI.context.supportActionBar.title = title
  end

  def bar_color=(color)
    UI.context.supportActionBar.backgroundDrawable = Android::Graphics::Drawable::ColorDrawable.new(UI::Color(color).container) 
  end

  def push(screen, animated=true)
    screen.navigation = self
    fragment = screen.container
    transaction = container.beginTransaction
    if animated
      transaction.transition = Android::App::FragmentTransaction::TRANSIT_FRAGMENT_OPEN
    end
    content_view = UI.context.findViewById(Android::R::Id::Content)
    transaction.add(content_view.id, fragment, "screen-#{fragment.object_id}")
    transaction.addToBackStack("screen-#{fragment.object_id}")
    transaction.commit
  end

  def pop(animated=true)
    # TODO implement immediate pop without poping animation
    container.popBackStack
  end

  def container
    @container ||= UI.context.fragmentManager
  end
end
<commit_msg>properly resize the current screen’s view when the action bar is displayed/hidden<commit_after>class FlowUIFragmentBackStackListener
  # Android doesn't call onResume when doing popBackStack
  # so we listhen to this event to call it ourselves
  def onBackStackChanged
    @previous_stack_entry_count ||= 0
    fragment_manager = UI.context.fragmentManager
    fragments_count = fragment_manager.backStackEntryCount

    # This is used to prevent to call onResume two times when pushing
    if @previous_stack_entry_count < fragment_manager.backStackEntryCount
      @previous_stack_entry_count = fragment_manager.backStackEntryCount
      return
    end

    if fragments_count > 0
      back_stack_entry = fragment_manager.getBackStackEntryAt(fragments_count - 1)
      fragment_tag = back_stack_entry.getName
      fragment = fragment_manager.findFragmentByTag(fragment_tag)
      fragment.onResume
      @previous_stack_entry_count = fragment_manager.backStackEntryCount
    end
  end
end

class UI::Navigation
  attr_reader :root_screen

  def initialize(root_screen)
    @root_screen = root_screen
    @root_screen.navigation = self
    container.addOnBackStackChangedListener(FlowUIFragmentBackStackListener.new)
    @current_screens = [@root_screen]
  end

  def hide_bar
    bar = UI.context.supportActionBar
    if bar.isShowing
      bar.hide
      Task.after 0.05 do
        screen = @current_screens.last
        screen.view.height += (bar.height / UI.density)
        screen.view.update_layout
      end
    end
  end

  def show_bar
    bar = UI.context.supportActionBar
    if !bar.isShowing
      bar.show
      Task.after 0.05 do
        screen = @current_screens.last
        screen.view.height -= (bar.height / UI.density)
        screen.view.update_layout
      end
    end
  end

  def title=(title)
    UI.context.supportActionBar.title = title
  end

  def bar_color=(color)
    UI.context.supportActionBar.backgroundDrawable = Android::Graphics::Drawable::ColorDrawable.new(UI::Color(color).container) 
  end

  def push(screen, animated=true)
    screen.navigation = self
    @current_screens << screen
    fragment = screen.container
    transaction = container.beginTransaction
    if animated
      transaction.transition = Android::App::FragmentTransaction::TRANSIT_FRAGMENT_OPEN
    end
    content_view = UI.context.findViewById(Android::R::Id::Content)
    transaction.add(content_view.id, fragment, "screen-#{fragment.object_id}")
    transaction.addToBackStack("screen-#{fragment.object_id}")
    transaction.commit
  end

  def pop(animated=true)
    screen = @current_screens.pop
    # TODO implement immediate pop without poping animation
    container.popBackStack
    screen
  end

  def container
    @container ||= UI.context.fragmentManager
  end
end

{'fraction_non_alphanumeric': 0.07018247443352717, 'fraction_numerical': 0.00240625626629236, 'mean_word_length': 3.875855327468231, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1437806', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1423, 'n_words': 310}