<commit_before>package com.mapswithme.maps.maplayer;

import android.app.Activity;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.mapswithme.maps.maplayer.subway.DefaultMapLayerController;
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButton;
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButtonController;
import com.mapswithme.maps.tips.Tutorial;
import com.mapswithme.maps.tips.TutorialClickListener;
import com.mapswithme.util.InputUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MapLayerCompositeController implements MapLayerController
{
  @NonNull
  private final AppCompatActivity mActivity;
  @NonNull
  private final List<ControllerAndMode> mChildrenEntries;
  @NonNull
  private ControllerAndMode mMasterEntry;
  @NonNull
  private final TutorialClickListener mOpenBottomDialogClickListener;

  public MapLayerCompositeController(@NonNull TrafficButton traffic, @NonNull View subway,
                                     @NonNull View isoLines, @NonNull AppCompatActivity activity)
  {
    mOpenBottomDialogClickListener = new OpenBottomDialogClickListener(activity);
    mActivity = activity;
    mChildrenEntries = createEntries(traffic, subway, isoLines, activity, mOpenBottomDialogClickListener);
    mMasterEntry = getCurrentLayer();
    toggleMode(mMasterEntry.getMode());
  }

  @NonNull
  private static List<ControllerAndMode> createEntries(@NonNull TrafficButton traffic,
                                                             @NonNull View subway,
                                                             @NonNull View isoLinesView,
                                                             @NonNull AppCompatActivity activity,
                                                             @NonNull View.OnClickListener dialogClickListener)
  {
    traffic.setOnclickListener(dialogClickListener);
    TrafficButtonController trafficButtonController = new TrafficButtonController(traffic,
                                                                                  activity);
    subway.setOnClickListener(dialogClickListener);
    DefaultMapLayerController subwayMapLayerController = new DefaultMapLayerController(subway);

    isoLinesView.setOnClickListener(dialogClickListener);
    DefaultMapLayerController isoLinesController = new DefaultMapLayerController(isoLinesView);

    ControllerAndMode subwayEntry = new ControllerAndMode(Mode.SUBWAY, Tutorial.SUBWAY,
                                                          subwayMapLayerController);
    ControllerAndMode trafficEntry = new ControllerAndMode(Mode.TRAFFIC, null,
                                                           trafficButtonController);
    ControllerAndMode isoLineEntry = new ControllerAndMode(Mode.ISOLINES, Tutorial.ISOLINES,
                                                           isoLinesController);

    List<ControllerAndMode> entries = new ArrayList<>();
    entries.add(subwayEntry);
    entries.add(isoLineEntry);
    entries.add(trafficEntry);

    return entries;
  }

  public void setTutorial(@NonNull Tutorial tutorial)
  {
    mOpenBottomDialogClickListener.setTutorial(tutorial);

    // The sorting is needed to put the controller mode corresponding to the specified tutorial
    // at the first place in the list. It allows to enable the map layer ignoring the opening the
    // bottom dialog when user taps on the pulsating map layer button.
    Collections.sort(mChildrenEntries, (lhs, rhs) ->
    {
      if (tutorial.equals(lhs.getTutorial()))
        return -1;
      if (tutorial.equals(rhs.getTutorial()))
        return 1;
      return 0;
    });
  }

  public void toggleMode(@NonNull Mode mode)
  {
    toggleMode(mode, false);
  }

  private void toggleMode(@NonNull Mode mode, boolean animate)
  {
    setMasterController(mode);
    showMasterController(animate);

    boolean enabled = mode.isEnabled(mActivity);
    if (enabled)
    {
      turnOn();<commit_msg>[android] Added updating of current layer field after the layer controllers are sorted.<commit_after>package com.mapswithme.maps.maplayer;

import android.app.Activity;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.mapswithme.maps.maplayer.subway.DefaultMapLayerController;
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButton;
import com.mapswithme.maps.maplayer.traffic.widget.TrafficButtonController;
import com.mapswithme.maps.tips.Tutorial;
import com.mapswithme.maps.tips.TutorialClickListener;
import com.mapswithme.util.InputUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MapLayerCompositeController implements MapLayerController
{
  @NonNull
  private final AppCompatActivity mActivity;
  @NonNull
  private final List<ControllerAndMode> mChildrenEntries;
  @NonNull
  private ControllerAndMode mMasterEntry;
  @NonNull
  private final TutorialClickListener mOpenBottomDialogClickListener;

  public MapLayerCompositeController(@NonNull TrafficButton traffic, @NonNull View subway,
                                     @NonNull View isoLines, @NonNull AppCompatActivity activity)
  {
    mOpenBottomDialogClickListener = new OpenBottomDialogClickListener(activity);
    mActivity = activity;
    mChildrenEntries = createEntries(traffic, subway, isoLines, activity, mOpenBottomDialogClickListener);
    mMasterEntry = getCurrentLayer();
    toggleMode(mMasterEntry.getMode());
  }

  @NonNull
  private static List<ControllerAndMode> createEntries(@NonNull TrafficButton traffic,
                                                             @NonNull View subway,
                                                             @NonNull View isoLinesView,
                                                             @NonNull AppCompatActivity activity,
                                                             @NonNull View.OnClickListener dialogClickListener)
  {
    traffic.setOnclickListener(dialogClickListener);
    TrafficButtonController trafficButtonController = new TrafficButtonController(traffic,
                                                                                  activity);
    subway.setOnClickListener(dialogClickListener);
    DefaultMapLayerController subwayMapLayerController = new DefaultMapLayerController(subway);

    isoLinesView.setOnClickListener(dialogClickListener);
    DefaultMapLayerController isoLinesController = new DefaultMapLayerController(isoLinesView);

    ControllerAndMode subwayEntry = new ControllerAndMode(Mode.SUBWAY, Tutorial.SUBWAY,
                                                          subwayMapLayerController);
    ControllerAndMode trafficEntry = new ControllerAndMode(Mode.TRAFFIC, null,
                                                           trafficButtonController);
    ControllerAndMode isoLineEntry = new ControllerAndMode(Mode.ISOLINES, Tutorial.ISOLINES,
                                                           isoLinesController);

    List<ControllerAndMode> entries = new ArrayList<>();
    entries.add(subwayEntry);
    entries.add(isoLineEntry);
    entries.add(trafficEntry);

    return entries;
  }

  public void setTutorial(@NonNull Tutorial tutorial)
  {
    mOpenBottomDialogClickListener.setTutorial(tutorial);

    // The sorting is needed to put the controller mode corresponding to the specified tutorial
    // at the first place in the list. It allows to enable the map layer ignoring the opening the
    // bottom dialog when user taps on the pulsating map layer button.
    Collections.sort(mChildrenEntries, (lhs, rhs) ->
    {
      if (tutorial.equals(lhs.getTutorial()))
        return -1;
      if (tutorial.equals(rhs.getTutorial()))
        return 1;
      return 0;
    });

    // The current layer must be updated after the layer controllers are sorted.
    mMasterEntry = getCurrentLayer();
    toggleMode(mMasterEntry.getMode());
  }

  public void toggleMode(@NonNull Mode mode)
  {
    toggleMode(mode, false);
  }

  private void toggleMode(@NonNull Mode mode, boolean animate)
  {
    setMasterController(mode);
    showMasterController(animate);

    boolean enabled = mode.isEnabled(mActivity);
    if (enabled)
    {
      turnOn();
{'fraction_non_alphanumeric': 0.06761229314420804, 'fraction_numerical': 0.0007092198581560284, 'mean_word_length': 2.7604444444444445, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5327247', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1963, 'n_words': 480}