<commit_before>package edu.agh.mindmap.fragment

import com.actionbarsherlock.app.SherlockFragment
import android.os.Bundle
import android.view.{View, ViewGroup, LayoutInflater}
import edu.agh.mindmap.R
import android.widget.{AdapterView, ArrayAdapter, TextView, ListView}
import com.michalrus.helper.ScalaFragment
import edu.agh.mindmap.model.MindMap
import android.widget.AdapterView.OnItemClickListener
import edu.agh.mindmap.activity.MainActivity
import android.content.Context

object MapListFragment {
  val ItemXml = R.layout.recent_list_item
}

class MapListFragment extends SherlockFragment with ScalaFragment {

  def addMap(map: MindMap) = addMaps(map :: Nil)

  def addMaps(maps: Seq[MindMap]) {
    maps foreach (m => adapter add m)
    adapter notifyDataSetChanged()
  }

  private lazy val adapter = new ArrayAdapter(getActivity, MapListFragment.ItemXml, collection.JavaConversions.bufferAsJavaList(MindMap.findAll.toBuffer)) {
    private lazy val inflater = getActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE).asInstanceOf[LayoutInflater]

    override def getView(position: Int, convertView: View, parent: ViewGroup) = {
      val v = Option(convertView) match {
        case Some(x) => x
        case _ => inflater.inflate(MapListFragment.ItemXml, parent, false)
      }

      val map = getItem(position)

      v.find[TextView](R.id.recent_list_item_name).
        setText(map.root.content.getOrElse(""))
      v.find[TextView](R.id.recent_list_item_detail).
        setText(new java.util.Date(map.lastMod).toString)

      v
    }
  }

  def withMainActivity[A](f: MainActivity => A) {
    getActivity match {
      case a: MainActivity => f(a)
      case _ =>
    }
  }

  override def onCreateView(inflater: LayoutInflater, container: ViewGroup, bundle: Bundle) = {
    val view = inflater.inflate(R.layout.recent_list, container, false)

    val listView = view.find[ListView](R.id.listview)

    listView setAdapter adapter

    listView setOnItemClickListener new OnItemClickListener {
      override def onItemClick(parent: AdapterView[_], view: View, position: Int, id: Long) {
        val map = adapter getItem position
        withMainActivity (_ viewMindMap map)
      }
    }

    view
  }

}
<commit_msg>Get rid of redundant add map method<commit_after>package edu.agh.mindmap.fragment

import com.actionbarsherlock.app.SherlockFragment
import android.os.Bundle
import android.view.{View, ViewGroup, LayoutInflater}
import edu.agh.mindmap.R
import android.widget.{AdapterView, ArrayAdapter, TextView, ListView}
import com.michalrus.helper.ScalaFragment
import edu.agh.mindmap.model.MindMap
import android.widget.AdapterView.OnItemClickListener
import edu.agh.mindmap.activity.MainActivity
import android.content.Context

object MapListFragment {
  val ItemXml = R.layout.recent_list_item
}

class MapListFragment extends SherlockFragment with ScalaFragment {

  def addMaps(maps: Seq[MindMap]) {
    maps foreach (m => adapter add m)
    adapter notifyDataSetChanged()
  }

  private lazy val adapter = new ArrayAdapter(getActivity, MapListFragment.ItemXml, collection.JavaConversions.bufferAsJavaList(MindMap.findAll.toBuffer)) {
    private lazy val inflater = getActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE).asInstanceOf[LayoutInflater]

    override def getView(position: Int, convertView: View, parent: ViewGroup) = {
      val v = Option(convertView) match {
        case Some(x) => x
        case _ => inflater.inflate(MapListFragment.ItemXml, parent, false)
      }

      val map = getItem(position)

      v.find[TextView](R.id.recent_list_item_name).
        setText(map.root.content.getOrElse(""))
      v.find[TextView](R.id.recent_list_item_detail).
        setText(new java.util.Date(map.lastMod).toString)

      v
    }
  }

  def withMainActivity[A](f: MainActivity => A) {
    getActivity match {
      case a: MainActivity => f(a)
      case _ =>
    }
  }

  override def onCreateView(inflater: LayoutInflater, container: ViewGroup, bundle: Bundle) = {
    val view = inflater.inflate(R.layout.recent_list, container, false)

    val listView = view.find[ListView](R.id.listview)

    listView setAdapter adapter

    listView setOnItemClickListener new OnItemClickListener {
      override def onItemClick(parent: AdapterView[_], view: View, position: Int, id: Long) {
        val map = adapter getItem position
        withMainActivity (_ viewMindMap map)
      }
    }

    view
  }

}

{'fraction_non_alphanumeric': 0.09579230080572963, 'fraction_numerical': 0.0, 'mean_word_length': 3.960044395116537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4643656', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1338, 'n_words': 297}