This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3.11 Add fully functional units setting
- Loading branch information
Showing
5 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string-array name="pref_units_options"> | ||
<item>@string/pref_units_label_metric</item> | ||
<item>@string/pref_units_label_imperial</item> | ||
</string-array> | ||
|
||
<string-array name="pref_units_values"> | ||
<item>@string/pref_units_metric</item> | ||
<item>@string/pref_units_imperial</item> | ||
</string-array> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cdd3f2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I was inattentive and missed an explanation but why should we use manual converting of temperature instead of getting already converted vlues from Openweathermap service?
cdd3f2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isupovs : you can go back and watch the video of "Temperature Units Setting" in Lesson 3 again. Katherine mentioned that the App will eventually has a database to store these data, so it's better keep internal data consistent.
cdd3f2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@isupovs Agree with you. It sounds more easy with Openweather. (reinvented the wheel).
Maybe a little issue with URL.
"http://api.openweathermap.org/data/2.5/forecast/daily?" This is for "Location instead of zip"
cdd3f2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterqz As @closer76 mentioned, this was done to maintain consistency when storing values in the database. Imagine you store 7 rows in metric units and the next 7 in imperial units. Then every time you retrieve the values from database, you will have to check for the unit type and this can lead to inconsistencies. So its better to use just one api call for metric and convert to imperial on the fly
cdd3f2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As well, why do API calls when you can already compute its result?
cdd3f2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@salogel42 @ceruleanotter Why not use a TwoStatePreference like a SwitchPreference for the temperature unit choice? That was my first instinct but I couldn't resolve an error due to setInitialValue (called automatically in the background) receiving a string when the activity starts.
cdd3f2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry , I'm still a beginner in android, someone could please explain me why we have to edit the "build.gradle" file , I saw that when I clicked in the diff for this node link, its the firs file edited but in the video doesn't say anything about that file and why we have to manually edited and add this:
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
}
cdd3f2c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@emperatorLeo The apikey will be exposed, meaning anyone can see it and steal your apikey. To prevent this you can store your apikey in
gradle.properties
for example and reference it in your buildConfigField.Also using buildConfig means you can switch between dev and prod versions if you have multiple apikeys and keep them hidden.