Skip to content

Instantly share code, notes, and snippets.

@martinbowling
Forked from migueldeicaza/gist:312933
Created February 24, 2010 01:57
Show Gist options
  • Save martinbowling/312980 to your computer and use it in GitHub Desktop.
Save martinbowling/312980 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.Dialog;
using System.Net;
namespace MIX10
{
public partial class HomeViewController
{
enum Activity {
Passed,
HadDinnerWith,
TookMyPictureWith,
EavesdroppedOn,
Fanboyed
}
[Preserve (AllMembers=true)]
class CelebForm {
[Section ("Spotted a Mix10 Celebrity?\nYou can now share it with the world!")]
[Entry ("Your twitter name")]
public string Name = "";
[Section ("I just...")]
public Activity activity = Activity.Passed;
[Section ("Mix Celebrity")]
[Checkbox] public bool TheGu;
[Checkbox] public bool CodingHorror;
[Entry ("Celebrity name")]
public string Other = "";
[Entry ("At...")]
public string At;
[Section (null, "This post will appear as @mixcelebs")]
[Caption ("Tweet it!"), OnTap ("Post")]
public string post;
}
CelebForm celeb;
BindingContext context;
void CelebSpot ()
{
celeb = new CelebForm ();
context = new BindingContext (this, celeb, "Celeb Spot");
var dc = new DialogViewController (context.Root, true);
ActivateController (dc);
}
public void Post ()
{
context.Fetch ();
if (celeb.Name == ""){
using (var alert = new UIAlertView ("Name missing", "You must give us your twitter name", null, "OK")){
alert.Show ();
}
return;
}
if (celeb.At == ""){
using (var alert = new UIAlertView ("Location missing", "Where did you spot this awesome celebrity? Let us know", null, "OK")){
alert.Show ();
}
return;
}
// trim @ from name; may have been input, maybe not
celeb.Name = celeb.Name.Trim('@',' ');
var sb = new StringBuilder ();
sb.Append ("I @" + celeb.Name + " just ");
switch (celeb.activity){
case Activity.Passed:
sb.Append ("passed "); break;
case Activity.HadDinnerWith:
sb.Append ("had dinner with "); break;
case Activity.TookMyPictureWith:
sb.Append ("took my picture with "); break;
case Activity.EavesdroppedOn:
sb.Append ("eavesdropped on "); break;
case Activity.Fanboyed:
sb.Append ("fanboyed "); break;
}
if (celeb.TheGu)
sb.Append ("TheGu ");
if (celeb.CodingHorror)
sb.Append ("Atwood ");
if (celeb.Other != "")
sb.Append ("@" + celeb.Other.Trim() + " (minor celebrity) ");
sb.Append ("at ");
sb.Append (celeb.At);
sb.Append (" ");
if (celeb.TheGu == false && celeb.CodingHorror == false && celeb.Other == ""){
using (var alert = new UIAlertView ("Celeb Missing", "You must specify a celeb", null, "OK")){
alert.Show ();
}
return;
}
string tags = String.IsNullOrEmpty(AppDelegate.ConferenceData.CelebTwitterTags)?"#Mix10 #monotouch":AppDelegate.ConferenceData.CelebTwitterTags;
sb.Append (tags); // allow tags to be changed from server
try {
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
using (var wc = new WebClient ()){
wc.Credentials = new NetworkCredential ("mixcelebs", "Dingus");
ServicePointManager.Expect100Continue = false;
wc.UploadString ("http://twitter.com/statuses/update.xml", "status=" + sb.ToString ());
}
} catch {
using (var alert = new UIAlertView ("Network error", "There was a problem connecting to the network", null, "OK")){
alert.Show ();
}
}
UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
var nav = ParentViewController as UINavigationController;
nav.PopViewControllerAnimated (true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment