Permalink
Browse files

nio changes...

  • Loading branch information...
1 parent 1af552d commit 304248f63da52c56ea54466564c6e85a950a02d9 @n8han n8han committed Jan 24, 2011
@@ -9,81 +9,26 @@ class SnapupProject(info: ProjectInfo) extends AndroidProject(info: ProjectInfo)
val databinder_net = "databinder.net repository" at "http://databinder.net/repo"
lazy val dmeet = "net.databinder" %% "dispatch-meetup" % "0.8.0.Beta3-SNAPSHOT"
lazy val dnio = "net.databinder" %% "dispatch-nio" % "0.8.0.Beta3-SNAPSHOT"
- lazy val dhttp = "net.databinder" %% "dispatch-http" % "0.8.0.Beta3-SNAPSHOT"
override def proguardOption = """
|-keep class dispatch.** {
| public scala.Function1 *();
|}
+ |-keep class org.apache.http.protocol.ImmutableHttpProcessor {
+ | public ** *();
+ |}
|-keep class snapup.** {
| public scala.Function1 *();
|}
|-keep class ** extends dispatch.Builder {
| public ** product();
|}
""".stripMargin
-}
-trait TypedResources extends AndroidProject {
- import scala.xml._
- def managedScalaPath = "src_managed" / "main" / "scala"
- def typedResource = managedScalaPath / "TR.scala"
- abstract override def mainSourceRoots = super.mainSourceRoots +++ managedScalaPath
- def xmlResources = mainResPath ** "*.xml"
- override def compileAction = super.compileAction dependsOn generateTypedResources
- override def cleanAction = super.cleanAction dependsOn cleanTask(managedScalaPath)
- override def watchPaths = super.watchPaths +++ xmlResources
-
- lazy val generateTypedResources = fileTask(typedResource from xmlResources) {
- val Id = """@\+id/(.*)""".r
- val resources = xmlResources.get.flatMap { path =>
- val xml = XML.loadFile(path.asFile)
- xml.descendant flatMap { node =>
- // all nodes
- node.attribute("http://schemas.android.com/apk/res/android", "id") flatMap {
- // with android:id attribute
- _.firstOption map { _.text } flatMap {
- case Id(id) => try { Some(id,
- // whre ids start with @+id/
- ClasspathUtilities.toLoader(androidJarPath).loadClass(
- // where the label is a widget in the android jar
- "android.widget." + node.label
- ).getName)
- } catch { case _ => None }
- case _ => None
- }
- }
- }
- }.foldLeft(Map.empty[String, String]) { case (m, (k, v)) => m + (k -> v) }
- FileUtilities.write(typedResource.asFile,
- """ |package %s
- |import android.app.Activity
- |import android.view.View
- |
- |case class TypedResource[T](id: Int)
- |object TR {
- |%s
- |}
- |trait TypedViewHolder {
- | def view: View
- | def findView[T](tr: TypedResource[T]) = view.findViewById(tr.id).asInstanceOf[T]
- |}
- |trait TypedView extends View { def view = this }
- |trait TypedActivityHolder {
- | def activity: Activity
- | def findView[T](tr: TypedResource[T]) = activity.findViewById(tr.id).asInstanceOf[T]
- |}
- |trait TypedActivity extends Activity with TypedActivityHolder { def activity = this }
- |object TypedResource {
- | implicit def view2typed(v: View) = new TypedViewHolder { def view = v }
- | implicit def view2typed(act: Activity) = new TypedActivityHolder { def activity = act }
- |}
- |""".stripMargin.format(
- manifestPackage, resources map { case (id, classname) =>
- " val %s = TypedResource[%s](R.id.%s)".format(id, classname, id)
- } mkString "\n"
- ), log
- )
- None
- }
+ override def ivyXML =
+ <dependencies>
+ <exclude module="commons-logging" conf="compile"/>
+ <exclude module="commons-codec" conf="compile"/>
+ <exclude module="scala-library" conf="compile"/>
+ </dependencies>
}
View
@@ -11,7 +11,6 @@ import dispatch._
import oauth._
import meetup._
import dispatch.liftjson.Js._
-import Http._
import net.liftweb.json._
import net.liftweb.json.JsonAST._
@@ -44,7 +43,7 @@ class Main extends ScalaActivity {
else {
prefs.meetups.editor { _.clear() }
val cli = Account.client(at)
- future { http(cli(Members.self) ># { json =>
+ http(cli(Members.self) ># { json =>
val List(id) = Response.results(json) >>= Member.id
http(cli(Events.member_id(id).status(Event.Past, Event.Upcoming)) >- { json =>
post {
@@ -55,7 +54,7 @@ class Main extends ScalaActivity {
proceed()
}
})
- }) }
+ })
}
}
override def onCreate(savedInstanceState: Bundle) {
@@ -72,17 +71,17 @@ class Main extends ScalaActivity {
case None =>
getIntent.getData match {
case null =>
- future { http(Auth.request_token(Account.consumer, "snapup:///") ~> { token =>
+ http(Auth.request_token(Account.consumer, "snapup:///") ~> { token =>
authorize(write(prefs.request, token))
- }) }
+ })
case uri =>
Account.tokens(prefs.request) filter {
_.value == uri.getQueryParameter("oauth_token")
- } foreach { rt => future { http(
+ } foreach { rt => http(
Auth.access_token(Account.consumer, rt, uri.getQueryParameter("oauth_verifier")) ~> { token: oauth.Token =>
fetch_meetups(write(prefs.access, token))
}
- ) } }
+ ) }
}
case Some(at) => fetch_meetups(at)
}
@@ -106,4 +105,4 @@ class Main extends ScalaActivity {
}
}
}
-}
+}
@@ -12,8 +12,6 @@ import android.content.{Intent, DialogInterface}
import android.util.Log
import dispatch.meetup._
-import dispatch.Http
-import dispatch.Http._
import java.io.{File,FileOutputStream}
import net.liftweb.json._
@@ -79,4 +77,4 @@ class Meetups extends ListActivity with ScalaActivity {
true
case _ => false
}
-}
+}
@@ -15,17 +15,13 @@ import android.graphics.drawable.ColorDrawable
import android.util.Log
import dispatch.meetup._
-import dispatch.Http
-import dispatch.Http._
import dispatch.liftjson.Js._
import dispatch.mime.Mime._
import java.io.{File,FileOutputStream}
import net.liftweb.json._
import net.liftweb.json.JsonAST._
-import dispatch.futures.DefaultFuture.future
-
object RsvpCache extends HttpCache[Array[JValue]] {
def apply(prefs: Prefs) = load { event_id =>
val Some(cli) = Account.client(prefs)
@@ -108,24 +104,22 @@ class Members extends ListActivity with ScalaActivity {
loading.setTitle("Posting Photo to Meetup")
loading.show()
val Some(cli) = Account.client(prefs)
- future {
- try {
- http(cli(PhotoUpload.event_id(event_id).caption(caption).photo(image_f)) >?> { total =>
- post { loading.setMax(total.toInt) }
- (bytes) => { post { loading.setProgress(bytes.toInt) } }
- } >> { stm =>
- image_f.delete()
- post {
- loading.dismiss()
- Toast.makeText(this, R.string.photo_uploaded, Toast.LENGTH_LONG).show()
- }
- })
- } catch { case e =>
- Log.e("Meetups", "Error uploading photo", e)
- post {
- loading.dismiss()
- failed_dialog(event_id, caption)
+ try {
+ http(cli(PhotoUpload.event_id(event_id).caption(caption).photo(image_f)) >?> { total =>
+ post { loading.setMax(total.toInt) }
+ (bytes) => { post { loading.setProgress(bytes.toInt) } }
+ } >> { stm =>
+ image_f.delete()
+ post {
+ loading.dismiss()
+ Toast.makeText(this, R.string.photo_uploaded, Toast.LENGTH_LONG).show()
}
+ })
+ } catch { case e =>
+ Log.e("Meetups", "Error uploading photo", e)
+ post {
+ loading.dismiss()
+ failed_dialog(event_id, caption)
}
}
}
@@ -154,4 +148,4 @@ class Members extends ListActivity with ScalaActivity {
.create()
.show()
}
-}
+}
@@ -39,12 +39,12 @@ object Account {
def client(access: Token) = OAuthClient(consumer, access)
def client(prefs: Prefs) = tokens(prefs.access) map { access => OAuthClient(consumer, access) }
}
-class AndroidHttp extends Http {
- override lazy val log = new Logger {
+class AndroidHttp extends nio.Http {
+ /* override def make_logger = new Logger {
def info(msg: String, items: Any*) {
Log.i("Main", "INF: [android logger] dispatch: " + msg.format(items: _*))
}
- }
+ } */
}
trait Cache[T] {
import java.lang.ref.SoftReference
@@ -58,10 +58,9 @@ trait Cache[T] {
}
}
class HttpCache[T] extends Cache[T] {
- import dispatch.futures.DefaultFuture.future
def load(retrieve: String => Handler[T])(key: String)(use: T => Unit) { get(key) match {
case Some(item) => use(item)
- case None => future { (new AndroidHttp)(retrieve(key) ~> put(key) ~> use) }
+ case None => (new AndroidHttp)(retrieve(key) ~> put(key) ~> use)
} }
}
object ImageCache extends HttpCache[android.graphics.Bitmap] {

0 comments on commit 304248f

Please sign in to comment.