Skip to content

Commit

Permalink
FIX for issue #3: Hyperlinks fail to appear unless they are the last …
Browse files Browse the repository at this point in the history
…in the textblock
  • Loading branch information
zahndy committed Mar 20, 2012
1 parent f23d6cb commit 68b50f8
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ o3o is a C# WPF Twitter client
as of now it works but still needs a lot of tweaks and features added.

TODO:
- detection of hashtags and @user and turn them into links

- streaming or polling tweets
- preferences tab
- smooth draggable listbox?
Binary file modified o3o.suo
Binary file not shown.
3 changes: 2 additions & 1 deletion o3o/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void Window1_Loaded(object sender, RoutedEventArgs e)

void get_tweets()
{
TweetElements.Items.Clear();
Twitterizer.TwitterStatusCollection response = o3o.Twitter.GetTweets();
foreach (Twitterizer.TwitterStatus tweet in response)
{
Expand All @@ -71,7 +72,7 @@ void get_mentions()
{
Twitterizer.TwitterStatusCollection menstruations = o3o.Twitter.GetMentions();


TweetMentions.Items.Clear();
foreach (Twitterizer.TwitterStatus drama in menstruations)
{
FillMentions(drama.Text, drama.User.ScreenName, drama.CreatedDate.ToString(), drama.User.ProfileImageLocation, drama.Id.ToString());
Expand Down
158 changes: 71 additions & 87 deletions o3o/TweetElement.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,111 +33,95 @@ public partial class TweetElement : UserControl
public string Date;
public string imagelocation;
public string ID;

public bool loaded = false;
public TweetElement()
{

InitializeComponent();
TweetBlock.Text = Tweet;
datelabel.Text = Date;
}
public Hyperlink Username(string x)
{
string username = x.Replace("@", "");
username.Replace(":", "");
Hyperlink uname = new Hyperlink();
uname.NavigateUri = new Uri("http://twitter.com/" + username);
uname.RequestNavigate += new RequestNavigateEventHandler(Hyperlink_RequestNavigateEvent);
uname.Inlines.Add(x);
uname.TextDecorations = null;
uname.Foreground = new SolidColorBrush(Colors.SkyBlue);
return uname;

}

public Hyperlink Hashtag(string x)
{
string hastag = x.Replace("#", "");
Hyperlink hash = new Hyperlink();
hash.NavigateUri = new Uri("http://search.twitter.com/search?q=" + hastag);
hash.RequestNavigate += new RequestNavigateEventHandler(Hyperlink_RequestNavigateEvent);
hash.Inlines.Add(x);
hash.TextDecorations = null;
hash.Foreground = new SolidColorBrush(Colors.SkyBlue);
return hash;

}

public Hyperlink http(string x)
{
string url = x.Replace("http://", "");
Hyperlink link = new Hyperlink();
link.NavigateUri = new Uri(x);
link.RequestNavigate += new RequestNavigateEventHandler(Hyperlink_RequestNavigateEvent);
link.Inlines.Add(url);
link.TextDecorations = null;
link.Foreground = new SolidColorBrush(Colors.SkyBlue);
return link;

}

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
var kaas = Tweet.Split(' ');
foreach (string a in kaas)
if (loaded == false)
{
if (a.StartsWith("@"))
{
TweetBlock.Inlines.Add(Username(a));
TweetBlock.Inlines.Add(" ");
}
else if (a.StartsWith("#"))
var kaas = Tweet.Split(' ');
foreach (string a in kaas)
{
TweetBlock.Inlines.Add(Hashtag(a));
TweetBlock.Inlines.Add(" ");
if (a.StartsWith("@"))
{
string username = a.Replace("@", "");
username.Replace(":", "");
Hyperlink uname = new Hyperlink( new Run(a)) { NavigateUri = new Uri("http://twitter.com/" + username) };
//uname.Inlines.Add(a);
uname.RequestNavigate += Hyperlink_RequestNavigateEvent;
uname.TextDecorations = null;
uname.Foreground = new SolidColorBrush(Colors.SkyBlue);
TweetBlock.Inlines.Add(uname);
TweetBlock.Inlines.Add(new Run(" "));

}
else if (a.StartsWith("#"))
{
string hashtag = a.Replace("#", "");
Hyperlink hash = new Hyperlink() { NavigateUri = new Uri("http://search.twitter.com/search?q=" + hashtag) };
hash.Inlines.Add(a);
hash.RequestNavigate += Hyperlink_RequestNavigateEvent;
hash.TextDecorations = null;
hash.Foreground = new SolidColorBrush(Colors.SkyBlue);
TweetBlock.Inlines.Add(hash);
TweetBlock.Inlines.Add(new Run(" "));
}
else if (a.StartsWith("http"))
{
string url = a.Replace("http://", "");
Hyperlink link = new Hyperlink() { NavigateUri = new Uri(a) };
link.Inlines.Add(url);
link.RequestNavigate += Hyperlink_RequestNavigateEvent;
link.TextDecorations = null;
link.Foreground = new SolidColorBrush(Colors.SkyBlue);
TweetBlock.Inlines.Add(link);
TweetBlock.Inlines.Add(new Run(" "));
}
else
{
TweetBlock.Inlines.Add( new Run(a+ " "));
}
}
else if (a.StartsWith("http"))
{
TweetBlock.Inlines.Add(http(a));
TweetBlock.Inlines.Add(" ");
}
else
{
TweetBlock.Text += a+" ";
}
}

// find hashtags and @user in Tweet
//TweetBlock.Text = Tweet.ParseURL().ParseUsername().ParseHashtag();

datelabel.Text = Date;
label1.Text = name;
var image = new BitmapImage();
int BytesToRead=100;
WebRequest request = WebRequest.Create(new Uri(imagelocation));
request.Timeout = -1;
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
BinaryReader reader = new BinaryReader(responseStream);
MemoryStream memoryStream = new MemoryStream();

byte[] bytebuffer = new byte[BytesToRead];
int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);

while (bytesRead > 0)
{
memoryStream.Write(bytebuffer, 0, bytesRead);
bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
}
// find hashtags and @user in Tweet
//TweetBlock.Text = Tweet.ParseURL().ParseUsername().ParseHashtag();

image.BeginInit();
memoryStream.Seek(0, SeekOrigin.Begin);
datelabel.Text = Date;
label1.Text = name;
var image = new BitmapImage();
int BytesToRead = 100;
WebRequest request = WebRequest.Create(new Uri(imagelocation));
request.Timeout = -1;
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
BinaryReader reader = new BinaryReader(responseStream);
MemoryStream memoryStream = new MemoryStream();

image.StreamSource = memoryStream;
image.EndInit();
byte[] bytebuffer = new byte[BytesToRead];
int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);

tweetImg.Source = image;
while (bytesRead > 0)
{
memoryStream.Write(bytebuffer, 0, bytesRead);
bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
}

image.BeginInit();
memoryStream.Seek(0, SeekOrigin.Begin);

image.StreamSource = memoryStream;
image.EndInit();

tweetImg.Source = image;
loaded = true;
}
}
private void Hyperlink_RequestNavigateEvent(object sender, RequestNavigateEventArgs e)
{
Expand Down
Binary file modified o3o/bin/Debug/o3o.exe
Binary file not shown.
Binary file modified o3o/bin/Debug/o3o.pdb
Binary file not shown.
Binary file modified o3o/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
Binary file modified o3o/obj/x86/Debug/o3o.exe
Binary file not shown.
Binary file modified o3o/obj/x86/Debug/o3o.pdb
Binary file not shown.

1 comment on commit 68b50f8

@xarinatan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FFFFFFFFFFFFF finally D8

Please sign in to comment.