Welcome back.
And this video, I would like to show you two things before I will give you another challenge that you
then will finalize to set up UI function.
So the first thing I want to show you, however, is how you can get the right time.
So we're going to create a another get function here.
So private fun Unix time and that will be a long time that I get, but I want to make a string out of
it.
So the thing is, when you get the time, you get it as a long value.
So looking at our weather response.
And then in the cease file, so here in our society, you can see we have a sunrise and sunset, so
I set those Intertrust, but I think there really should be longus.
So we're going to get a long value here.
So the time when the sunrises and sunsets.
So here you can see sunrise and sunset, very long values.
So what I want to do, all of those, is I want to create a time that is relatable for us.
So if you don't take this time here, for example, and you go to the airport convertor and you enter
that.
Timestamped to human, then you can see that it was Tuesday, November 3rd, 2015, six fifty eight
a.m..
OK, so the values that we get here, they are long, but in the end they represent a specific time
and that is what I want to have.
So I want to have this specific value here instead of having this value that we get here with just huge
number, this long number.
All right.
So let's do that.
Therefore, I go back to my activity, and if this is your next time, which should return a string.
So let's go ahead and create a date object first.
Savol date will be a date object.
And now I'm going to just pass the time X, which is this long value.
And now the cool thing is time X can work with that.
So me.
Import data for this and now I want to get it in a right format, so I don't want to have it in this
weird format, but I want to have a simple data formatter to just give me the hours, minutes and seconds.
So I'm going to use this pattern here.
So simple data format, and then I can use this simple data format to set the time zone to be time zone,
get default so we get the default time zone of the device of the user, and then we return the result
of ASDF that format data.
OK, so what we have is one thing as to date, then we get the simple data format, which is the format
that we want to use and then we.
Program, our ASDF, so we changed settings of the SDF in this case, I'm just setting the time zone
of this SDF to be the default time zone of the user.
So get the default time zone for this host.
So pretty much for this device.
And then I want to return that data that we get as a long value and to dis formatted value that we have
here.
So that's what this Unix time function will return.
So what is this all for?
Well, in the end, it's for our main activity here for this sunrise and sunset.
So for those two values that I have here, I want to set this TextView to set the sunrise time and then
this one to display the sunset time.
OK, so let's just do that real quick.
TV sunrise time.
The text should be said to you next time.
And what do we get the time from?
Well, we get it from weather list.
DOT says that sunrise sources start sunrise.
So you can see sunrise is a variable in our class, which is this one here, which is this long value.
OK, so we are passing a long value here.
To our Unix time function, and then we can do the same thing with the other TV underscore sonra set
time here, that text, and that should be the same thing except for its sun set this time.
So we're getting the sun set variable, which is this other law.
Now let's quickly test that just to see if it's going to display the right value for us.
And you can see at this place the value here, zero eight 11 two, so two are probably the second.
So maybe we don't want to have the second in there.
Actually, let's rerun this with this other pattern.
So hours and minutes.
And we are so now it's us, eight o'clock, eleven minutes and sunset is at eight o'clock and 12 minutes.
So now the thing is we get that with AM and PM, so probably that's not going to be as useful.
And therefore, I just ask Stack Overflow, where I asked Google and then Stack Overflow gives me several
options.
So here how to set 24 hours format for data on Java.
And basically we're using Java, even though we're using Kotlin, but they're super close to each other.
So you can see they offer multiple different solutions here.
So what he says is that we can add the local here, for example, for a 24 hour format.
That would be this as we have it here with local UK.
So as it seems, the data is probably what we get there.
So maybe it's just a data that is corrupt.
So that is something that is not as easy to find out sometimes.
So potentially it is that.
So let's add local UK here.
By the way, for the state to work correctly, we need to add this star 1000 L to our long value in
order for it to give us useful information.
So in order for us to display correct dates.
And that is because the time stamp is in milliseconds and we need to convert that accordingly because
the data that we are getting is not in the same format as they'd expected.
So that's why we need to add a thousand here or multiplied with a thousand.
So if we now test our application and we look at the Lockette and we can see here at the coordinates
here in the sunrise.
Our response result, you can see we get this weather response and pretty far to what's the right,
you can see we get the sunrise here and the sunset.
So now let's take this sunrise and let's go over to Époque Convertor.
And here, paystub value.
And you could see we get this seven fifty six a.m. GMT plus one, which is my time zone.
And now if I go to my application, I can see that it's exactly this time and now and now let's have
a look at the sunset.
Which is this value here?
So let's put that in there as well.
You can see it's five, 12, all right.
And that's exactly what we get here.
So now we, of course, need to display it in the right format.
And therefore, we need to change the pattern to capital ratios in my case, because to capitalize,
this gives me the 24 hour format.
All right.
So not just 17 and 12, which is five p.m..
All right, so now a little challenge for you, please go ahead and add all of the rest of the UI elements
that we still have here to all of those textures at the relevant information from the weather response
that you get.
So you need to look at the different classes.
For example, you can see and Maine, you get the minimum temperature and the maximum temperature,
as well as the humidity and pressure.
So this would be an information that we would have here as well as this percent would be interesting.
OK, so we're not displaying pressure here, but you can see we displayed the wind.
So that's something that you get from another class.
So you need to look up the different classes and see which data you want to display.
All right, so I hope you post the video and tried it.
So basically what we need to set is, for example, here, the humidity is going to be so-and-so to
string percent.
Then our minimum temperature will be Tammin, which comes from Maine, so here in Maine, we have to
bend and we have to Max.
Then the speed comes from the wind class.
So we have the speed of the wind.
We use that.
Then the weather at least has also the name.
So here it's the string.
It's the weather response class.
So it completely has the whole name here already as well as our country, which is inside of this.
So you can see here in this class, we have the country, which is the string here that we get from
our variable there.
All right.
So after having set all of that up, let's test it.
Let's see how that's going to look in our application.
All right, so this is the data that we get can see zero point zero, a minimum zero point zero maximum,
87 percent.
Centennial Park is the city apparently the country code is D.C., The wind is one, so the temperature
seems to be all around zero point zero, even though we have five point eight Celsius.
So let's see what's wrong there.
Let's look at our Lockette.
And let's see the response.
So Tembin tarmac's.
So as it seems, that is the.
Whether we get so that's the data that we get and, well, that's a problem with the API, it's not
really an issue of our application, as it seems.
So there's nothing we can do about it.
You can see the wind is just going to be speed one and then.
Yeah, I think it's fine so far, except for I don't like the fact that it's just 0.01, so it's not
really super valuable there.
But well, that's how it is sometimes sometimes you just get bad data and you have to work with it,
especially when you work with an API.
So either you use another API then or you ask the API creator, what's wrong there or whatever.
All right.
OK, so I hope you managed to get this right here to get this running and then in the next video we
are going to set up the icons.
So we're going to get to the point where we display the correct icon here at the very top, because
currently it says clouds.
But we see our.
Snowflake here.
So we want to change that, of course.
All right.
So see you in the next video.