<commit_before>package org.positronicnet.sample.contacts

import org.positronicnet.ui._
import org.positronicnet.content.PositronicContentResolver

import org.positronicnet.notifications.Actions._
import org.positronicnet.orm.Actions._

import android.content.{Context, Intent}
import android.util.{AttributeSet, Log}
import android.view.View
import android.widget.{TextView, ListView}

import android.accounts.{AccountManager, Account}

import scala.collection.mutable.ArrayBuffer

class ContactsActivity 
  extends android.app.ListActivity 
  with PositronicActivityHelpers
  with ActivityViewUtils
{
  onCreate {
    useAppFacility( PositronicContentResolver )
    useAppFacility( Res )               // stash a copy of the Resources
    setContentView( R.layout.contacts )
    
    useOptionsMenuResource( R.menu.contacts_menu )
    onOptionsItemSelected( R.id.dump_contacts ){ dumpToLog }
    onOptionsItemSelected( R.id.new_contact ) { newContact }
  }

  onResume {
    Contacts ! Fetch { contacts => 
      if (contacts.size > 0) {
        val sortedContacts = contacts.sortBy{ _.displayNamePrimary.toLowerCase }
        setListAdapter( new IndexedSeqAdapter( sortedContacts, 
                                               R.layout.contact_view_row ))
      }
      else {
        // android package IDs don't show up in TypedResources, so...
        val txtv = findViewById( android.R.id.empty ).asInstanceOf[ TextView ]
        txtv.setText( R.string.no_contacts )
      }
    }
  }

  override def onListItemClick( l: ListView, v: View, posn: Int, id: Long ) = {
    val contact = getListAdapter.getItem( posn ).asInstanceOf[Contact]
    RawContacts.forContact( contact ) ! Fetch { rawContacts => 
      if (rawContacts.size == 1)
        startEditingRawContact( rawContacts(0) )
      else {
        val title = R.string.edit_contact_in_account
        withChoiceFromDialog[ RawContact ]( title, rawContacts, _.accountName ){
          startEditingRawContact( _ )
        }
      }
    }<commit_msg>First trial use of "futures" syntax in sample contacts app.<commit_after>package org.positronicnet.sample.contacts

import org.positronicnet.ui._
import org.positronicnet.content.PositronicContentResolver

import org.positronicnet.notifications.Actions._
import org.positronicnet.orm.Actions._

import android.content.{Context, Intent}
import android.util.{AttributeSet, Log}
import android.view.View
import android.widget.{TextView, ListView}

import android.accounts.{AccountManager, Account}

import scala.collection.mutable.ArrayBuffer

class ContactsActivity 
  extends android.app.ListActivity 
  with PositronicActivityHelpers
  with ActivityViewUtils
{
  onCreate {
    useAppFacility( PositronicContentResolver )
    useAppFacility( Res )               // stash a copy of the Resources
    setContentView( R.layout.contacts )
    
    useOptionsMenuResource( R.menu.contacts_menu )
    onOptionsItemSelected( R.id.dump_contacts ){ dumpToLog }
    onOptionsItemSelected( R.id.new_contact ) { newContact }
  }

  onResume {
    (Contacts ? Query).onSuccess{ contacts => 
      if (contacts.size > 0) {
        val sortedContacts = contacts.sortBy{ _.displayNamePrimary.toLowerCase }
        setListAdapter( new IndexedSeqAdapter( sortedContacts, 
                                               R.layout.contact_view_row ))
      }
      else {
        // android package IDs don't show up in TypedResources, so...
        val txtv = findViewById( android.R.id.empty ).asInstanceOf[ TextView ]
        txtv.setText( R.string.no_contacts )
      }
    }
  }

  override def onListItemClick( l: ListView, v: View, posn: Int, id: Long ) = {
    val contact = getListAdapter.getItem( posn ).asInstanceOf[Contact]
    (RawContacts.forContact( contact ) ? Query).onSuccess { rawContacts => 
      if (rawContacts.size == 1)
        startEditingRawContact( rawContacts(0) )
      else {
        val title = R.string.edit_contact_in_account
        withChoiceFromDialog[ RawContact ]( title, rawContacts, _.accountName ){
          startEditingRawContact( _ )
        }
      }
    }
{'fraction_non_alphanumeric': 0.08819936476911801, 'fraction_numerical': 0.0014659174199853407, 'mean_word_length': 3.0216110019646365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561052', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1200, 'n_words': 257}