<commit_before>package x7c1.linen.modern.init.settings.source

import android.support.v4.app.FragmentActivity
import android.support.v7.app.AlertDialog
import android.support.v7.widget.PopupMenu
import android.support.v7.widget.PopupMenu.OnMenuItemClickListener
import android.view.{MenuItem, Menu}
import x7c1.linen.glue.res.layout.{SettingSourceAttachRowItem, SettingSourceAttach}
import x7c1.linen.modern.display.settings.SourceMenuSelected
import x7c1.linen.modern.init.settings.preset.AttachSourceDialog
import x7c1.wheat.ancient.context.ContextualFactory
import x7c1.wheat.ancient.resource.ViewHolderProviderFactory
import x7c1.wheat.macros.fragment.FragmentFactory


class OnSourceMenuSelected(
  activity: FragmentActivity,
  dialogFactory: ContextualFactory[AlertDialog.Builder],
  attachLayoutFactory: ViewHolderProviderFactory[SettingSourceAttach],
  attachRowFactory: ViewHolderProviderFactory[SettingSourceAttachRowItem]
){
  def showMenu(event: SourceMenuSelected): Unit = {
    val menu = new PopupMenu(activity, event.targetView)
    menu.getMenu.add(Menu.NONE, 123, 1, "Attached channels")
    menu setOnMenuItemClickListener new OnMenuItemClickListener {
      override def onMenuItemClick(item: MenuItem): Boolean = {
        if (item.getItemId == 123){
          createAttachSourceDialog(event) showIn activity
        }
        true
      }
    }
    menu.show()
  }
  def createAttachSourceDialog(event: SourceMenuSelected) = {
    FragmentFactory.create[AttachSourceDialog] by<commit_msg>add menu to load source<commit_after>package x7c1.linen.modern.init.settings.source

import android.support.v4.app.FragmentActivity
import android.support.v7.app.AlertDialog
import android.support.v7.widget.PopupMenu
import android.support.v7.widget.PopupMenu.OnMenuItemClickListener
import android.view.{Menu, MenuItem}
import x7c1.linen.glue.res.layout.{SettingSourceAttach, SettingSourceAttachRowItem}
import x7c1.linen.glue.service.ServiceControl
import x7c1.linen.glue.service.ServiceLabel.Updater
import x7c1.linen.modern.display.settings.SourceMenuSelected
import x7c1.linen.modern.init.settings.preset.AttachSourceDialog
import x7c1.linen.modern.init.updater.UpdaterMethods
import x7c1.wheat.ancient.context.ContextualFactory
import x7c1.wheat.ancient.resource.ViewHolderProviderFactory
import x7c1.wheat.macros.fragment.FragmentFactory
import x7c1.wheat.macros.intent.ServiceCaller
import x7c1.wheat.macros.logger.Log


class OnSourceMenuSelected(
  activity: FragmentActivity with ServiceControl,
  dialogFactory: ContextualFactory[AlertDialog.Builder],
  attachLayoutFactory: ViewHolderProviderFactory[SettingSourceAttach],
  attachRowFactory: ViewHolderProviderFactory[SettingSourceAttachRowItem]
){
  def showMenu(event: SourceMenuSelected): Unit = {
    val menu = new PopupMenu(activity, event.targetView)
    menu.getMenu.add(Menu.NONE, 123, 1, "Attached channels")
    menu.getMenu.add(1, 234, 1, "Load now")
    menu setOnMenuItemClickListener new OnMenuItemClickListener {
      override def onMenuItemClick(item: MenuItem): Boolean = {
        item.getItemId match {
          case 123 =>
            createAttachSourceDialog(event) showIn activity
          case 234 =>
            ServiceCaller.using[UpdaterMethods].
              startService(activity, activity getClassOf Updater){
                _ loadSource event.selectedSourceId
              }
          case x => Log error s"unknown menu-id:$x"
        }
        true
      }
    }
    menu.show()
  }
  def createAttachSourceDialog(event: SourceMenuSelected) = {
    FragmentFactory.create[AttachSourceDialog] by
{'fraction_non_alphanumeric': 0.08485856905158069, 'fraction_numerical': 0.018857459789240156, 'mean_word_length': 4.752791068580542, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '987962', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1071, 'n_words': 180}