Skip to main content

Showing the Status Detail View

Lesson 13 from: Building a Twitter App

Tony Hillerson

Showing the Status Detail View

Lesson 13 from: Building a Twitter App

Tony Hillerson

buy this class

$00

$00
Sale Ends Soon!

starting under

$13/month*

Unlock this classplus 2200+ more >

Lesson Info

13. Showing the Status Detail View

Lesson Info

Showing the Status Detail View

Okay, so let's look at the next step, which is just simply we're gonna show when ah, particular status or tweet is clicked. We're going to show a detail page that just shows that the content of that tweet. So, um, on that detail page or detailed view, we're gonna show the user name. We're going to show the text of the tweet with clickable links. If there any links in there and they're gonna show when it was created and then optionally if the tweet was in reply to someone else, it'll show who it was in reply to and optionally, if there was a location associated with a tweet will show that as well. You can see in this case on the slide, there's not so it won't show up if there's not. Um, the take away here is we're gonna go through the exercise that we've done a lot since last class, which is to add a new view and activity and then on list item click will show that new activity activity and pass along a status extra. So close up this code Clothes a week. Three close up, Week four and ope...

n a week. I'm sorry that week. Step Step five and let's go. Let's start by looking at because it's this is fairly simple. Start by looking at this running, uh, Rennes Android application. Come back. You to the emulator is it loads up. We'll be able to see, um, our progress indicator working as we set it up in last step, making us all feel warm and fuzzy that the applications actually doing something. And now, once it's loaded, we can click any one of these guys and that will jump over to a detailed view. And I show things like one has created the text of the tweet, and this one is a retweet. But I don't know if it's actually no, we don't want to retweet. We want a their reply to on and I don't see any replies. Um, so I can create a reply here in second, but let's just go look at the code for the detail view. So first thing, let's look at the view and resource is layout. We've added a status detail view, so it's open up that and look at it in XML. Um, it's just simple, relatively out. It doesn't have a custom class. It has a text view for the user name. It has a text view for the status text. Um, it has a tech savvy for created at a text, the reply to in a text V for geo text. Um, and you can see that the visibility is set to gone for the text view for the Geo text and there in reply to. And then there's one other interesting thing. Remember, we wanted to show links. So in text of you, you can say, um, the simple attributes Auto link all and that will we'll hear the options to see if I can get the options to show up. I can't get the options to show up. Try it like this. There we go. OK, so you're the options resuming on these guys because they auto link none. And then it won't put put any links on the text Otto Link Web. And then a lonely find. Links to Web Resource is like other, like somebody sent around a link inside the tweet. It would find those and then the other options or email, phone map and all. And those are all things it'll automatically try to detect inside of the text for you. So for email, try to find emails and make those link herbal. And then when you click it, it will go to mail the mail application for phone. It will go to try to make a phone call map. It will try to find addresses and show those on the map, and all will try to show all so we can just turn that on so that it will try to auto link all of those things that it finds inside the status detail of a tweet. Okay, let's go look at the activity. So inside of activities, we've now created a status detail activity activity, and that just has a reference to all those different components that we've that we just looked at inside the XML. And then it also has a link to the status or tweet that is displaying and then on create It sets the content view to that detail view that we created calls this little helper set of views. And then you can see that, um, the way that it gets a link to the status or a reference to the status that we're going to be showing on the detail views by getting it out of the extras, and this is again a little bit of review from the last class. But in case you remember and when you start open intense, you can pass along something called extras to that intent. There's extras can be some instructions, um, sort of in the form of primitive variables like, uh, passing along some string variables or manager variables, or can be dated data that you want to show, um, inside the intent. Interview on the intent, either primitive data. Or if you have more complex object data, you can either make that serialize herbal data to pass along and in this case, a statuses serialize herbal. So we can we can get that extra out of the intent that's coming into the new detail view as a serialize herbal, and we use this status. Constant, Um, which is defined appear online. 15 of status detailed list activity. Just a string. Remember, all the extras were kind of like key value Paris on the intent. And then finally we show status and then we just show status is right here online. 33. It's just a bunch of conditional to figure out if we've got a date for create when the status was created. Whether or not Thean reply to screen name is is null or not in the Geo location, whether that's no basically, whether or not the tweet was in reply to another user and whether or not we can show that and whether or not it had a location. And then we in those cases just set the text of the of those components to what we want to show and then make them visible. So that's pretty straightforward stuff. Set up views is again called in on create, and that's where we get referenced all those components. So that's pretty straightforward stuff. Let's see how this actually gets kicked off. Instead, it's list activity on on this item click, which is online 85. Um, remember these conditions that we put in before if the view that was clicked was the head of you're the foot or view we need to do those, um, load newer load older tweets, but otherwise we know that it's a status and we want to show the detail for that status. So notice that I've got a little note here. I don't want to say, as I originally said in my code and found out the wrong way that it was the wrong are found out the hard way that it was the wrong thing to do, to try to get the status that I want to pass the detail view off of the adapter Because if I get an item at a position the position position of the view that's clicked in this case, it's not gonna count for the header and footer in the adapter. So it's going to be it's gonna be basically the position that's coming in is it is accounting for the header or footer, I guess. Probably just the header. Um, but the adapter, if I said get item at position, it is not accounting for the header, so I'm gonna get an off by one error there. But if I do instead get listsview, get item at position and cast that to a status, then that will be the right status and then I can create a new intent. Nobody's seen this type of code a few times by now. Um, this is Ah, the intent where we started another activity and Then I put the status into the extra with the key value of that constant from the status detail activity and then start the activity. And then everything should work just fine. Let's see this. This one's got a link so I can click this one, and you could see that the auto link is working there. When I go to this, the winners for this week it's loading up inside the Web browser, and we got one minute left, so I'm just gonna assume that's gonna load at some point. And there we go. We've shown details of particular tweet, so to take away here is the text of you can automatically recognize this different kind. It's of data that a user can interact with so, like Web blanks, phone numbers, addresses, that kind of stuff. So what we've done today is we've shown the user their Twitter home line by loading it, Um, when the APP starts, if there are already authenticated on, we allowed him to load lure newer or older tweets with those headers off the list, and we learned about the header and footer views on a list to let them do that and then we learned how to do some work in the background with just a basic Java thread. So there you are ranges responsive, and we learned about recognizing links in text views with that auto link, a method or ah, attribute of the text view. So if you want to do some more work to kind of cement in what we've learned today, you may have noticed. And I think somebody even commented last week that authentication when we're authenticating with Twitter or are exchanging the response tokens for the request tokens for the users, um Awad token that the app kind of slows down and gets unresponsive. So where you could try to do is basically online. 28 of the authorization activity is where we do the work where we call app that authorized So you could put that in this thread and then maybe so, show some progress. Well, that's happening. And then when the threat is finished, you just need to call back with a run a ball through a handler, um, and call finish on that authorized authorization activity activity. So that would be some good homework. And then next week we'll look at how to do some simpler or more robust background task with a sink task. And along the way we will load the user avatars, and we will also tweet from the application. Cool. That sounds fun. So just two minutes over. We've got a lot of stuff in today. If anybody wants to hang around for questions, I'm game. I didn't get a couple more questions related to that last segment that I wanted to ask you. Um, we had some people interested in combining the different actionable links so that you could say support email and maps, but not Web. Perhaps. And then somebody asked if you can add your own actionable links. Um, I'm not very familiar with adding your with something like adding your own. That might be possible. Um, but I'm not sure you might. I don't know if there's really a framework for that or not. That's that's something we could take to the forums. But the answer, the earlier question. I think you can do this, Um, everybody seeing that I'm delimiting delimiting these with a pipe. So it's a straight up and down the Ford Slash, right? Yeah, it doesn't like that. It's blowing up string types not allowed at out a link with value emailed bash or email Pipe phone. Let me let me see if it doesn't like the space. Okay, that was it. It didn't like this space. So you can't put a space in there. But you delimited with a pipe symbol, which is the up and down, up and down text thing. And then just Teoh, go back to one of the questions we had earlier about the off property file. Since we did have some people who missed last week, if you wouldn't mind showing that file again so that people who get averred I never tire you, don't it? Never showing. Okay, so I'm gonna show this in week one, step one, because I don't actually have my keys in there. But what you need to do when you check out the code to every project that we have here is go to resource is the resource is directory, right? Click it and say new folder and then create a folder called Raw. You could see already have it created here. An inside of raw creative ah ah file called a law stop properties and inside off the properties. Put these keys is just a standard proper job. A properties file Put these keys consumer key and consumer Secret Key. And then the values that you put in here are the consumer keen consumer seeker key from your your Applications page on Twitter. So if you go to the detail for that application, you could grab those keys. And earlier in the class last week, I will give out a link for the screen cast that shows how to get those applications set up. So you need to do that for each one of these guys, created raw directory and create oh, author properties as a file inside of there. And that screen cast for everybody is on YouTube on the O. Reilly Channel, so it's pretty easy to find. I think the link is also in the free videos for the overview week as well, so you can find that great Thank you, Tony. Well, we know we didn't get to everybody's questions, but we're going to get to them on the forms. So thank you all so much for participating today and asking your great questions. And Tony, thank you so much. Round of applause for Tony, please do join us next week, we're gonna be able to tweet, and one more just quick mentioned. Thank you to our sponsor. Add mob. Yeah, Thanks again for everybody for showing up and we'll see you next week.

RELATED ARTICLES

RELATED ARTICLES