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

import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ListView;

import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmListFragment;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
import com.mapswithme.maps.dialog.EditTextDialogFragment;
import com.mapswithme.util.statistics.Statistics;

public class ChooseBookmarkCategoryFragment extends BaseMwmListFragment implements EditTextDialogFragment.OnTextSaveListener
{
  private ChooseBookmarkCategoryAdapter mAdapter;
  private Bookmark mBookmark;

  @Override
  public void onViewCreated(View view, Bundle savedInstanceState)
  {
    super.onViewCreated(view, savedInstanceState);

    mAdapter = new ChooseBookmarkCategoryAdapter(getActivity(), getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_SET, 0));
    setListAdapter(mAdapter);
    mBookmark = getBookmarkFromIntent();
  }

  @Override
  public void onListItemClick(ListView l, View v, int position, long id)
  {
    if (mAdapter.getItemViewType(position) == ChooseBookmarkCategoryAdapter.VIEW_TYPE_ADD_NEW)
      showCreateCategoryDialog();
    else
    {
      mAdapter.chooseItem(position);

      mBookmark.setCategoryId(position);
      getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK,
          new ParcelablePoint(mBookmark.getCategoryId(), mBookmark.getBookmarkId()));

      getActivity().onBackPressed();
    }
  }

  private Bookmark getBookmarkFromIntent()
  {
    // Note that Point result from the intent is actually a pair
    // of (category index, bookmark index in category).
    final Point cab = ((ParcelablePoint) getArguments().getParcelable(ChooseBookmarkCategoryActivity.BOOKMARK)).getPoint();
    return BookmarkManager.INSTANCE.getBookmark(cab.x, cab.y);
  }

  private void showCreateCategoryDialog()
  {
    final Bundle args = new Bundle();
    args.putString(EditTextDialogFragment.EXTRA_TITLE, getString(R.string.new_group));
    final EditTextDialogFragment fragment = (EditTextDialogFragment) Fragment.instantiate(getActivity(), EditTextDialogFragment.class.getName());
    fragment.setOnTextSaveListener(this);
    fragment.setArguments(args);
    fragment.show(getActivity().getSupportFragmentManager(), EditTextDialogFragment.class.getName());
  }

  private void createCategory(String name)
  {
    final int category = BookmarkManager.INSTANCE.createCategory(name);
    mBookmark.setCategoryId(category);

    getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, category)
        .putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(category, 0));

    mAdapter.chooseItem(category);
<commit_msg>Fixed new set creation.<commit_after>package com.mapswithme.maps.bookmarks;

import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ListView;

import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmListFragment;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
import com.mapswithme.maps.dialog.EditTextDialogFragment;
import com.mapswithme.util.statistics.Statistics;

public class ChooseBookmarkCategoryFragment extends BaseMwmListFragment implements EditTextDialogFragment.OnTextSaveListener
{
  private ChooseBookmarkCategoryAdapter mAdapter;
  private Bookmark mBookmark;

  @Override
  public void onViewCreated(View view, Bundle savedInstanceState)
  {
    super.onViewCreated(view, savedInstanceState);

    mAdapter = new ChooseBookmarkCategoryAdapter(getActivity(), getArguments().getInt(ChooseBookmarkCategoryActivity.BOOKMARK_SET, 0));
    setListAdapter(mAdapter);
    mBookmark = getBookmarkFromIntent();
  }

  @Override
  public void onListItemClick(ListView l, View v, int position, long id)
  {
    if (mAdapter.getItemViewType(position) == ChooseBookmarkCategoryAdapter.VIEW_TYPE_ADD_NEW)
      showCreateCategoryDialog();
    else
    {
      mAdapter.chooseItem(position);

      mBookmark.setCategoryId(position);
      getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK,
          new ParcelablePoint(mBookmark.getCategoryId(), mBookmark.getBookmarkId()));

      getActivity().onBackPressed();
    }
  }

  private Bookmark getBookmarkFromIntent()
  {
    // Note that Point result from the intent is actually a pair
    // of (category index, bookmark index in category).
    final Point cab = ((ParcelablePoint) getArguments().getParcelable(ChooseBookmarkCategoryActivity.BOOKMARK)).getPoint();
    return BookmarkManager.INSTANCE.getBookmark(cab.x, cab.y);
  }

  private void showCreateCategoryDialog()
  {
    final Bundle args = new Bundle();
    args.putString(EditTextDialogFragment.EXTRA_TITLE, getString(R.string.new_group));
    args.putString(EditTextDialogFragment.EXTRA_POSITIVE_BUTTON, getString(R.string.ok));
    final EditTextDialogFragment fragment = (EditTextDialogFragment) Fragment.instantiate(getActivity(), EditTextDialogFragment.class.getName());
    fragment.setOnTextSaveListener(this);
    fragment.setArguments(args);
    fragment.show(getActivity().getSupportFragmentManager(), EditTextDialogFragment.class.getName());
  }

  private void createCategory(String name)
  {
    final int category = BookmarkManager.INSTANCE.createCategory(name);
    mBookmark.setCategoryId(category);

    getActivity().getIntent().putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, category)
        .putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(category, 0));

    mAdapter.chooseItem(category);

{'fraction_non_alphanumeric': 0.09543918918918919, 'fraction_numerical': 0.0010135135135135136, 'mean_word_length': 5.571587125416205, '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': '6650182', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1666, 'n_words': 293}