Skip to content

Commit

Permalink
Restruct. prefs, fixed MainFragment's date setting, & other edits
Browse files Browse the repository at this point in the history
[Ref]: Merged settings_info, strings_auth, update_periods into
strings_config.xml
[Mod]: Reworked the PreferenceUtil and Preference structure; no more
boxing, now only default preferences. More importantly, update interval
is now a String which can be readily parsed via the fetch method:
getUpdateInterval(Context).

[Ref][Mod]: ExchangeRateUpdateLoader restructured to appropriately:
- Use the correct JSON preference
- Moved the set/get the update time to PreferenceUtils

[Rea]: Minor simplification of CurrencyCursorAdapter output.
[Mod]: Added method CurrencyCalculator to calculate + format
conversions.

[Rea][Mod]: Update the MainFragment's flow:
- Remove some dead code/comments
- Moved calculation/formatting of conversion to CurrencyCalculator
- Fixed the date formatting
- Fixed the times the progress bar shows/hides
  • Loading branch information
iamovrhere committed May 26, 2015
1 parent 59ed41f commit ce032ef
Show file tree
Hide file tree
Showing 14 changed files with 353 additions and 287 deletions.
2 changes: 1 addition & 1 deletion res/values/currency_codes_symbols.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<!-- The code for JPY -->
<string name="currConv_JPY_code" >JPY</string>

<!-- Symbols most symbols not required. -->
<!-- Symbols have veen kept as Currency symbols is cumbersome to deal with. -->
<eat-comment />
<!-- The symbol for USD -->
<string name="currConv_USD_symbol" >$</string>
Expand Down
47 changes: 25 additions & 22 deletions res/values/default_exchange_rates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
-->
<resources>
<!-- A list of default values to populat the database with should there
be no connection at start. -->
be no connection at start.
Source: http://query.yahooapis.com/v1/public/yql/?q=select * from yahoo.finance.xchange where pair in ("USDCAD", "USDEUR", "USDGBP", "USDJPY", "CADEUR", "CADGBP", "CADJPY", "EURGBP", "EURJPY", "GBPJPY")&env=store://datatables.org/alltableswithkeys&format=json
-->
<eat-comment />

<!-- The currency update time (UTC/GMT) for default values.
Should be of the form "yyyy-mm-dd hh:mm:ss.SSS+0000" -->
<item name="currConv_defRate_updateTime"
format="string" type="string" >2014-09-08 19:08:14.000+0000</item>
format="string" type="string" >2015-05-26 04:27:27.000+0000</item>

<!-- String array. The order of the rates given for all default rates. -->
<string-array name="currConv_rateOrder" >
Expand All @@ -46,48 +49,48 @@
<!-- The rates from USD -> currencies in currConv_rateOrder -->
<array name="currConv_USD_defRates" >
<item name="USD" format="float">1.00</item>
<item name="CAD" format="float">1.0967</item>
<item name="EUR" format="float">0.7750</item>
<item name="GBP" format="float">0.6205</item>
<item name="JPY" format="float">105.9535</item>
<item name="CAD" format="float">1.2307</item>
<item name="EUR" format="float">0.9134</item>
<item name="GBP" format="float">0.6470</item>
<item name="JPY" format="float">121.7695</item>
</array>

<!-- The rates from CAD -> currencies in currConv_rateOrder -->
<array name="currConv_CAD_defRates" >
<item name="USD" format="float">0.9118</item>
<item name="USD" format="float">0.8125</item>
<item name="CAD" format="float">1.00</item>
<item name="EUR" format="float">0.7067</item>
<item name="GBP" format="float">0.5658</item>
<item name="JPY" format="float">96.6134</item>
<item name="EUR" format="float">0.7421</item>
<item name="GBP" format="float">0.5257</item>
<item name="JPY" format="float">98.9437</item>
</array>


<!-- The rates from EUR -> currencies in currConv_rateOrder -->
<array name="currConv_EUR_defRates" >
<item name="USD" format="float">1.2903</item>
<item name="CAD" format="float">1.4151</item>
<item name="USD" format="float">1.0948</item>
<item name="CAD" format="float">1.3475</item>
<item name="EUR" format="float">1.00</item>
<item name="GBP" format="float">0.8006</item>
<item name="JPY" format="float">136.7171</item>
<item name="GBP" format="float">0.7083</item>
<item name="JPY" format="float">133.3050</item>
</array>


<!-- The rates from GBP -> currencies in currConv_rateOrder -->
<array name="currConv_GBP_defRates" >
<item name="USD" format="float">1.6116</item>
<item name="CAD" format="float">1.7675</item>
<item name="EUR" format="float">1.2490</item>
<item name="USD" format="float">1.5456</item>
<item name="CAD" format="float">1.9022</item>
<item name="EUR" format="float">1.4118</item>
<item name="GBP" format="float">1.00</item>
<item name="JPY" format="float">170.7594</item>
<item name="JPY" format="float">188.2150</item>
</array>


<!-- The rates from JPY -> currencies in currConv_rateOrder -->
<array name="currConv_JPY_defRates" >
<item name="USD" format="float">0.0094</item>
<item name="CAD" format="float">0.0104</item>
<item name="EUR" format="float">0.0073</item>
<item name="GBP" format="float">0.0059</item>
<item name="USD" format="float">0.0082</item>
<item name="CAD" format="float">0.0101</item>
<item name="EUR" format="float">0.0075</item>
<item name="GBP" format="float">0.0053</item>
<item name="JPY" format="float">1.00</item>
</array>
</resources>
49 changes: 33 additions & 16 deletions res/values/preference_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,25 @@
<resources>
<!-- Version 0.4.0-20150525 -->
<eat-comment />
<!-- The string used as the preference file name. -->
<string name="preferenceutil_PREFERENCE_FILE_KEY" >
com_ovrhere_currConv_PREFERENCE_FILE_KEY
</string> <!-- Cannot change internal values -->


<!-- Cannot change internal values -->
<!-- Preference keys:
BE WARY OF CHANGING KEY **VALUES** HERE. -->
<eat-comment />

<!-- Int key. The index of the source currency to show. -->
<!-- Int key. The index of the source currency to show -->
<string name="currConv_pref_KEY_SOURCE_CURRENCY_INDEX" >
com_ovrhere_currConv_pref_KEY_SOURCE_CURRENCY_INDEX
currConv_pref_KEY_SOURCE_CURRENCY_INDEX
</string>
<!-- Int key. The index of the dest currency to show -->
<string name="currConv_pref_KEY_DEST_CURRENCY_INDEX" >
com_ovrhere_currConv_pref_KEY_DEST_CURRENCY_INDEX
currConv_pref_KEY_DEST_CURRENCY_INDEX
</string>

<!-- Long key. The number of milliseconds before rechecking is necessary. -->
<!-- String (parsed as a long) key. The number of milliseconds before rechecking is necessary. -->
<string name="currConv_pref_KEY_UPDATE_CURRENCY_INTERVAL" >
com_ovrhere_currConv_pref_KEY_UPDATE_CURRENCY_INTERVAL
</string>
currConv_pref_KEY_UPDATE_CURRENCY_INTERVAL
</string>

<!-- Long key. The number of milliseconds since the epoch GMT. Default is 0. -->
<string name="currConv_pref_KEY_LAST_UPDATE" >
Expand All @@ -59,15 +56,35 @@
<!-- Default Value to currConv_pref_KEY_DEST_CURRENCY_INDEX -->
<item name="currConv_pref_DEF_VALUE_DEST_CURRENCY_INDEX"
type="integer">0</item>

<!-- Default Value to currConv_pref_KEY_UPDATE_CURRENCY_INTERVAL;
currently 1 hour -->
<item name="currConv_pref_DEF_VALUE_UPDATE_CURRENCY_INTERVAL"
type="integer">3600000</item>
<string name="currConv_pref_DEF_VALUE_UPDATE_CURRENCY_INTERVAL"
type="integer" >3600000</string>

<!-- Default value of currConv_pref_KEY_USE_JSON_REQUEST. -->
<item name="currConv_pref_DEF_VALUE_USE_JSON_REQUEST"
type="bool">
1
</item>
type="bool">1</item>

<!-- Old string keys which may/may not be removed in the future -->
<eat-comment />
<!-- The string used as the preference file name. -->
<string name="preferenceutil_OLDPREFERENCE_FILE_KEY" >
com_ovrhere_currConv_PREFERENCE_FILE_KEY
</string>

<!-- Int key. The index of the source currency to show. -->
<string name="currConv_pref_OLDKEY_SOURCE_CURRENCY_INDEX" >
com_ovrhere_currConv_pref_KEY_SOURCE_CURRENCY_INDEX
</string>
<!-- Int key. The index of the dest currency to show -->
<string name="currConv_pref_OLDKEY_DEST_CURRENCY_INDEX" >
com_ovrhere_currConv_pref_KEY_DEST_CURRENCY_INDEX
</string>

<!-- Int key. The number of milliseconds before rechecking is necessary. -->
<string name="currConv_pref_OLDKEY_UPDATE_CURRENCY_INTERVAL" >
com_ovrhere_currConv_pref_KEY_UPDATE_CURRENCY_INTERVAL
</string>

</resources>
4 changes: 0 additions & 4 deletions res/values/strings_auth.xml

This file was deleted.

24 changes: 23 additions & 1 deletion res/values/settings_info.xml → res/values/strings_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@
limitations under the License.
-->
<resources>
<!-- A list of non-translatable string for use in configuration -->

<!-- Content provider authority used in the manifest -->
<string name="content_provider_authority">com.ovrhere.android.currencyconverter</string>


<!-- The values for the spinner of update times (in milliseconds!)
Parallel to currConv_spinner_updatePeriod_labels.
These will be parsed to longs at run time. -->
<string-array name="currConv_spinner_updatePeriod_values">
<item>300000</item><!-- 5 minutes -->
<item>900000</item><!-- 15 minutes -->
<item>1800000</item><!-- 30 minutes -->
<item>3600000</item><!-- 1 hour -->
<item>7200000</item><!-- 2 hours -->
<item>21600000</item><!-- 6 hours -->
<item>43200000</item><!-- 12 hours -->
<item>86400000</item><!-- 24 hours -->
<item>172800000</item><!--2 days -->
<item>604800000</item><!-- 1 week -->
</string-array>

<!-- Keys that are not settings actually but it's just easier to use them -->
<eat-comment />
<!-- Key for update interval handle -->
Expand All @@ -31,5 +53,5 @@
>currConv_settings_KEY_CLEAR_SETTINGS</string>
<!-- Key for app version -->
<string name="currConv_settings_KEY_SOFTWARE_VERSION"
>currConv_settings_KEY_SOFTWARE_VERSION</string>
>currConv_settings_KEY_SOFTWARE_VERSION</string>
</resources>
39 changes: 0 additions & 39 deletions res/values/update_periods.xml

This file was deleted.

23 changes: 10 additions & 13 deletions res/xml/preference_defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >

<!-- These will not "work" for my current implementation as I'm using
getInt(). The solutions are:
1. Use Integer.parseInt(getString(key) - which is ugly and unsafe
2. Override the perference classes to allow for integers
such as done here:
http://stackoverflow.com/questions/3721358/preferenceactivity-save-value-as-integer/3755608#3755608 -->
<!--
<ListPreference
<!-- See:
http://stackoverflow.com/questions/3721358/preferenceactivity-save-value-as-integer/3755608#3755608 -->

<com.ovrhere.android.currencyconverter.utils.IntEditTextPreference
android:key="@string/currConv_pref_KEY_SOURCE_CURRENCY_INDEX"
android:defaultValue="@integer/currConv_pref_DEF_VALUE_SOURCE_CURRENCY_INDEX"/>

<ListPreference
<com.ovrhere.android.currencyconverter.utils.IntEditTextPreference
android:key="@string/currConv_pref_KEY_DEST_CURRENCY_INDEX"
android:defaultValue="@integer/currConv_pref_DEF_VALUE_DEST_CURRENCY_INDEX"/>

<ListPreference
<EditTextPreference
android:key="@string/currConv_pref_KEY_UPDATE_CURRENCY_INTERVAL"
android:defaultValue="@integer/currConv_pref_DEF_VALUE_UPDATE_CURRENCY_INTERVAL"/>
-->
android:defaultValue="@string/currConv_pref_DEF_VALUE_UPDATE_CURRENCY_INTERVAL" />


<CheckBoxPreference
android:key="@string/currConv_pref_KEY_USE_JSON_REQUEST"
Expand Down
4 changes: 2 additions & 2 deletions res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
>

<ListPreference
android:key="@string/currConv_settings_KEY_UPDATE_INTERVAL"
android:key="@string/currConv_pref_KEY_UPDATE_CURRENCY_INTERVAL"
android:title="@string/currConv_settings_updateInterval_title"
android:entries="@array/currConv_spinner_updatePeriod_labels"
android:entryValues="@array/currConv_spinner_updatePeriod_values"
android:dialogTitle="@string/currConv_settings_updateInterval_title"
android:persistent="false"

/>

<CheckBoxPreference
Expand Down
Loading

0 comments on commit ce032ef

Please sign in to comment.