From d3caa6e84eb5b664cbf26d56fe911fa76f81b495 Mon Sep 17 00:00:00 2001 From: Arregi Date: Sun, 21 May 2017 14:56:40 +0200 Subject: [PATCH 01/14] Update strings.xml Corrected as arielrcr suggested. --- app/src/main/res/values-es/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 22e93b9a..4a4903fc 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -201,8 +201,8 @@ Semana Día Hora - Minuta - Segunda + Minuto + Segundo Millisegundo Nanosegundo From 677e980a89116c4959233c813474ce434230cf82 Mon Sep 17 00:00:00 2001 From: Arregi Date: Sun, 21 May 2017 14:59:38 +0200 Subject: [PATCH 02/14] Update strings.xml Also added the correct spelling for milliseconds in spanish ;) --- app/src/main/res/values-es/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4a4903fc..07c6634d 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -203,7 +203,7 @@ Hora Minuto Segundo - Millisegundo + Milisegundo Nanosegundo From ef2e91a876d549e76a1452015cebf8da41e10a2e Mon Sep 17 00:00:00 2001 From: ilmonco Date: Wed, 7 Jun 2017 15:51:27 +0200 Subject: [PATCH 03/14] Create it config.xml --- app/src/main/res/values-it/config.xml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/src/main/res/values-it/config.xml diff --git a/app/src/main/res/values-it/config.xml b/app/src/main/res/values-it/config.xml new file mode 100644 index 00000000..859b5223 --- /dev/null +++ b/app/src/main/res/values-it/config.xml @@ -0,0 +1,23 @@ + + + + + 4 + . + , + 15 + From 71b60e16f9273188eb695fa97d76eb31131c1c02 Mon Sep 17 00:00:00 2001 From: ilmonco Date: Wed, 7 Jun 2017 16:39:56 +0200 Subject: [PATCH 04/14] Update es config.xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With "Ninguna" instead of "Ninguno" (please check strings.xml) "N" was default group separator. "," is the most used decimal separator in spanish speaking countries (Argentina, Bolivia, Chile, Colombia, Ecuador, España, Paraguay, Peru, Uruguay, Venezuela) whereas "." is used in Bolivia, Mexico and Central America countries. --- app/src/main/res/values-es/config.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/values-es/config.xml b/app/src/main/res/values-es/config.xml index b3a96f56..76e5bb52 100644 --- a/app/src/main/res/values-es/config.xml +++ b/app/src/main/res/values-es/config.xml @@ -17,7 +17,7 @@ 4 - Ninguna - . + Ninguno + , 15 - \ No newline at end of file + From a382da1779ff5723022dac892adf966c351b08d0 Mon Sep 17 00:00:00 2001 From: ilmonco Date: Wed, 7 Jun 2017 16:47:22 +0200 Subject: [PATCH 05/14] Update fr config.xml With "None" instead of "Acun", default group separator is "A" or "N". --- app/src/main/res/values-fr/config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-fr/config.xml b/app/src/main/res/values-fr/config.xml index 0293870c..a16f15a9 100644 --- a/app/src/main/res/values-fr/config.xml +++ b/app/src/main/res/values-fr/config.xml @@ -17,7 +17,7 @@ 4 - None + Aucun , 15 From 5ab7c6ce2f3b902557beb8f94fc1f34078309b6e Mon Sep 17 00:00:00 2001 From: ilmonco Date: Wed, 7 Jun 2017 16:52:01 +0200 Subject: [PATCH 06/14] Update hr strings.xml "Nijedno" (None) in config.xml --- app/src/main/res/values-hr/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 9dfbf04b..5c85d7d2 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -27,7 +27,7 @@ Pomoć Postavke Preuzimanje - Nijedan + Nijedno Unit Converter Ultimate: Zahtjev nove jedinice Ostale stvari Učitavanje… @@ -265,4 +265,4 @@ Američki dolar Južnoafrički rand - \ No newline at end of file + From aba66f8cd208f1e042f2c26b6ff000f1ff94866a Mon Sep 17 00:00:00 2001 From: physphil Date: Fri, 22 Dec 2017 17:01:19 -0500 Subject: [PATCH 07/14] GH-97 Update gradle plugin --- app/build.gradle | 34 +++++++++++++----------- build.gradle | 7 +++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3e95f526..7eb66337 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,7 +24,7 @@ if (file('google-services.json').exists()) { android { compileSdkVersion 24 - buildToolsVersion '25.0.0' + buildToolsVersion '26.0.2' signingConfigs { release { @@ -58,33 +58,37 @@ android { } } + flavorDimensions "distribution" + productFlavors { base { // Basic build + dimension "distribution" } google { // Adds the option to donate to the developer // Adds Firebase crash analytics + dimension "distribution" } } } dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - compile 'com.android.support:appcompat-v7:24.2.0' - compile 'com.android.support:recyclerview-v7:24.2.0' - compile 'com.android.support:design:24.2.0' - compile 'com.squareup.retrofit2:retrofit:2.1.0' - compile 'com.squareup.retrofit2:converter-gson:2.1.0' - compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0' - compile 'com.google.code.gson:gson:2.7' - compile 'io.reactivex:rxandroid:1.2.1' - compile 'io.reactivex:rxjava:1.2.3' + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'com.android.support:appcompat-v7:24.2.0' + implementation 'com.android.support:recyclerview-v7:24.2.0' + implementation 'com.android.support:design:24.2.0' + implementation 'com.squareup.retrofit2:retrofit:2.1.0' + implementation 'com.squareup.retrofit2:converter-gson:2.1.0' + implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0' + implementation 'com.google.code.gson:gson:2.7' + implementation 'io.reactivex:rxandroid:1.2.1' + implementation 'io.reactivex:rxjava:1.2.3' - googleCompile 'com.google.firebase:firebase-crash:10.2.1' + googleImplementation 'com.google.firebase:firebase-crash:10.2.1' - debugCompile 'com.facebook.stetho:stetho:1.1.1' + debugImplementation 'com.facebook.stetho:stetho:1.1.1' - testCompile 'junit:junit:4.12' - testCompile 'org.mockito:mockito-core:1.9.0' + testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-core:1.9.0' } diff --git a/build.gradle b/build.gradle index 28c0e248..300ba588 100644 --- a/build.gradle +++ b/build.gradle @@ -16,13 +16,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.0.0' + ext.kotlin_version = '1.1.51' repositories { mavenCentral() jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.2' + classpath 'com.android.tools.build:gradle:3.0.1' classpath 'com.google.gms:google-services:3.0.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } @@ -31,6 +32,8 @@ buildscript { allprojects { repositories { mavenCentral() + jcenter() + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 88bf803d..e841870e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -19,4 +19,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip From 532289ad61b6b94e6563c0c1147ddefc249c6640 Mon Sep 17 00:00:00 2001 From: physphil Date: Fri, 22 Dec 2017 17:13:20 -0500 Subject: [PATCH 08/14] GH-97 Increase SDK level to 27 and update all libraries --- app/build.gradle | 34 ++++++++++++++++++---------------- build.gradle | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7eb66337..542714eb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,13 +17,9 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -// Only apply the google-service plugin if the config file exists -if (file('google-services.json').exists()) { - apply plugin: 'com.google.gms.google-services' -} android { - compileSdkVersion 24 + compileSdkVersion 27 buildToolsVersion '26.0.2' signingConfigs { @@ -43,7 +39,7 @@ android { defaultConfig { applicationId "com.physphil.android.unitconverterultimate" minSdkVersion 14 - targetSdkVersion 24 + targetSdkVersion 27 versionCode 50300 versionName '5.3' } @@ -75,20 +71,26 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'com.android.support:appcompat-v7:24.2.0' - implementation 'com.android.support:recyclerview-v7:24.2.0' - implementation 'com.android.support:design:24.2.0' - implementation 'com.squareup.retrofit2:retrofit:2.1.0' - implementation 'com.squareup.retrofit2:converter-gson:2.1.0' - implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0' - implementation 'com.google.code.gson:gson:2.7' + implementation 'com.android.support:appcompat-v7:27.0.2' + implementation 'com.android.support:recyclerview-v7:27.0.2' + implementation 'com.android.support:design:27.0.2' + implementation 'com.squareup.retrofit2:retrofit:2.3.0' + implementation 'com.squareup.retrofit2:converter-gson:2.3.0' + implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0' + implementation 'com.google.code.gson:gson:2.8.0' implementation 'io.reactivex:rxandroid:1.2.1' - implementation 'io.reactivex:rxjava:1.2.3' + implementation 'io.reactivex:rxjava:1.3.0' - googleImplementation 'com.google.firebase:firebase-crash:10.2.1' + googleImplementation 'com.google.firebase:firebase-crash:11.8.0' - debugImplementation 'com.facebook.stetho:stetho:1.1.1' + debugImplementation 'com.facebook.stetho:stetho:1.5.0' testImplementation 'junit:junit:4.12' testImplementation 'org.mockito:mockito-core:1.9.0' } + +// According to setup, this needs to be at bottom of file - https://firebase.google.com/docs/android/setup +// Only apply the google-service plugin if the config file exists. +if (file('google-services.json').exists()) { + apply plugin: 'com.google.gms.google-services' +} diff --git a/build.gradle b/build.gradle index 300ba588..dc7a2025 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' - classpath 'com.google.gms:google-services:3.0.0' + classpath 'com.google.gms:google-services:3.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } From 5c47a30f0760ccb4a7aafda688e3f27efe6bd173 Mon Sep 17 00:00:00 2001 From: physphil Date: Sun, 24 Dec 2017 23:11:35 -0500 Subject: [PATCH 09/14] GH-96 Add Italian language --- .../unitconverterultimate/models/Language.kt | 3 + app/src/main/res/values-it/strings.xml | 270 ++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 274 insertions(+) create mode 100644 app/src/main/res/values-it/strings.xml diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/models/Language.kt b/app/src/main/java/com/physphil/android/unitconverterultimate/models/Language.kt index 8f215741..a9c1a68f 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/models/Language.kt +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/models/Language.kt @@ -26,6 +26,7 @@ private const val LANG_FARSI = "fa" private const val LANG_FRENCH = "fr" private const val LANG_GERMAN = "de" private const val LANG_HUNGARIAN = "hu" +private const val LANG_ITALIAN = "it" private const val LANG_JAPANESE = "ja" private const val LANG_PORTUGUESE_BR = "pt_BR" private const val LANG_RUSSIAN = "ru" @@ -44,6 +45,7 @@ enum class Language(val id: String) { FRENCH(LANG_FRENCH), GERMAN(LANG_GERMAN), HUNGARIAN(LANG_HUNGARIAN), + ITALIAN(LANG_ITALIAN), JAPANESE(LANG_JAPANESE), PORTUGUESE_BR(LANG_PORTUGUESE_BR), RUSSIAN(LANG_RUSSIAN), @@ -57,6 +59,7 @@ enum class Language(val id: String) { LANG_FRENCH -> R.string.language_french LANG_GERMAN -> R.string.language_german LANG_HUNGARIAN -> R.string.language_hungarian + LANG_ITALIAN -> R.string.language_italian LANG_JAPANESE -> R.string.language_japanese LANG_PORTUGUESE_BR -> R.string.language_portuguese_brazil LANG_RUSSIAN -> R.string.language_russian diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml new file mode 100644 index 00000000..6e8b3deb --- /dev/null +++ b/app/src/main/res/values-it/strings.xml @@ -0,0 +1,270 @@ + + + + + + Unit Converter Ultimate + Vuoi Donare? + Impostazioni + Da + A + 1 + Scarica + Azzera + Aiuto + Impostazioni + Nessuno + Unit Converter Ultimate: Richiedi un\'unità di misura + Altro + Caricamento… + C\'è stato un errore durante l\'aggiornamento dei tassi di cambio.\n\nControlla la tua connessione e riprova. + + Oops, c\'è stato un problema. Controlla se la connessione è attiva e riprova. + Oops, c\'è stato un problema. Per favore, prova di nuovo. + Grazie per la donazione! + Nessun browser trovato + Nessuna app email installata + Errore all\'apertura di Google Play Store, prova di nuovo + Testo copiato negli appunti + Tassi di cambio aggiornati + C\'è stato un errore durante l\'aggiornamento dei tassi di cambio. + + Formattazione + Imposta il numero di posizioni decimali preferito per la conversione della valuta + Numero di Decimali + Imposta il tipo di simbolo di raggruppamento preferito per la conversione della valuta + Simbolo di Raggruppamento + Imposta il separatore decimale preferito per la conversione della valuta + Separatore Decimale + Aspetto + Usa Tema Chiaro + Linguaggio + Scegli la lingua da utilizzare in tutta l\'app + Altro + Controlla Codice Sorgente + Unit Converter Ultimate è open source! Dai un\'occhiata al codice su GitHub. + Richiedi Unità Mancante + Vorresti aggiungere altre unità di misura? Inviami una email. + Vota su Google Play + Ti piace Unit Converter Ultimate? Allora perché non ci dai 5 stelle? + Dona + Regalaci un sorriso sostenendo il team di sviluppo :) + Trovato un Bug? + Inviaci una segnalazione su GitHub. + + OK + Aiuto + Usa il menu a comparsa per navigare fra le varie tipologie di conversione e seleziona quella che ti interessa.\n\nIl valore convertito è completamente personalizzabile. Usa il menu delle impostazioni per selezionare il numero di posizioni decimali, il simbolo di ragruppamento e il separatore decimale.\n\nTieni premuto sul valore convertito per copiarlo. + Vedi Sorgente + + + Area + Cucina + Valuta + Dimensione Dati + Energia + Carburante + Lunghezza / Distanza + Massa / Peso + Potenza + Pressione + Velocità + Temperatura + Tempo + Coppia + Volume + + + Chilometro Quadrato + Metro Quadrato + Centimetro Quadrato + Ettaro + Miglio Quadrato + Iarda Quadrata + Piede Quadrato + Pollice Quadrato + Acro + + + Bit + Byte + Kilobit + Kilobyte + Megabit + Megabyte + Gigabit + Gigabyte + Terabit + Terabyte + + + Joule + Chilojoule + Caloria + Chilocaloria + BTU + Piede per libbra + Pollice per libbra + Chilowattora + Elettronvolt + + + Miglio/gallone (USA) + Miglio/gallone (GB) + Litro/100km + Chilometro/litro + Miglio/litro + + + Chilometro + Miglio + Metro + Centimetro + Millimetro + Micrometro + Nanometro + Iarda + Piede + Pollice + Miglio Nautico + Furlong + Anno Luce + + + Chilogrammo + Libbra + Grammo + Milligrammo + Oncia + Grano + Stone + Tonnellata + Tonnellata Corta + Tonnellata Lunga + + + Watt + Chilowatt + Megawatt + HP (metrico) + HP (mecccanico) + Piede per libbra/sec + Caloria/sec + BTU/second + Kilovolt-ampere + + + Megapascal + Chilopascal + Pascal + Bar + PSI + PSF + Atmosfera + Atmosfera Tecnica + mm Hg + Torr + + + Km/h + mph + m/s + ft/s + Nodo + + + Celsius + Fahrenheit + Kelvin + Rankine + Delisle + Newton + Réaumur + Rømer + Gas Mark + + + Anno + Mese + Settimana + Giorno + Ora + Minuto + Secondo + Millisecondo + Nanosecondo + + + N-m + + + Cucchiaino + Cucchiaio + Tazza + Oncia Fluida Americana + Quarto Americano + Pinta Americana + Gallone Americano + Barile Americano + Oncia Fluida Inglese + Quarto Inglese + Pinta Inglese + Gallone Inglese + Barile Inglese + Millilitro + Litro + Centimetro Cubo + Metro Cubo + Piede Cubo + Pollice Cubo + Iarda Cubica + + + Dollaro Australiano + Lev Bulgaro + Real Brasiliano + Dollaro Canadese + Franco Svizzero + Yuan Cinese + Corona Ceca + Corona Danese + Euro + Sterlina Inglese + Dollaro Hong Kong + Kuna Croata + Fiorino Ungherese + Rupia Indonesiana + Siclo Israeliano + Rupia Indiana + Yen Giapponese + Won Sudcoreano + Peso Messicano + Ringgit Malese + Corona Norvegese + Dollaro Neozelandese + Peso Filippino + Zloty Polacco + Leu Romeno + Rublo Russo + Corona Svedese + Dollaro Singapore + Baht Thailandese + Lira Turca + Dollaro Americano + Rand Sudafricano + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a5dd0637..64e3bf57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,6 +79,7 @@ French German Hungarian + Italian Japanese Portuguese (Brazil) Russian From 67d00b2044b945da64253d567e0874da0b46da72 Mon Sep 17 00:00:00 2001 From: physphil Date: Sat, 9 Jun 2018 16:06:47 -0400 Subject: [PATCH 10/14] GH-110 use new service to get currency, as Fixer.io requirements have changed --- app/build.gradle | 3 +- .../unitconverterultimate/Preferences.java | 23 ++++- .../unitconverterultimate/api/FixerApi.java | 8 +- .../api/FixerService.java | 8 +- .../api/models/Currencies.kt | 68 +++++++++++++++ .../api/models/Envelope.java | 85 +++++++++++++++++++ .../presenters/ConversionPresenter.java | 49 +++++++++-- .../util/Conversions.java | 76 +++++++++-------- 8 files changed, 265 insertions(+), 55 deletions(-) create mode 100644 app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Currencies.kt create mode 100644 app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Envelope.java diff --git a/app/build.gradle b/app/build.gradle index 542714eb..f360a264 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2017 Phil Shadlyn + * Copyright 2018 Phil Shadlyn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,6 +76,7 @@ dependencies { implementation 'com.android.support:design:27.0.2' implementation 'com.squareup.retrofit2:retrofit:2.3.0' implementation 'com.squareup.retrofit2:converter-gson:2.3.0' + implementation 'com.squareup.retrofit2:converter-simplexml:2.3.0' implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0' implementation 'com.google.code.gson:gson:2.8.0' implementation 'io.reactivex:rxandroid:1.2.1' diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java b/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java index f120172e..1b825390 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Phil Shadlyn + * Copyright 2018 Phil Shadlyn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import android.support.annotation.NonNull; import com.google.gson.Gson; +import com.physphil.android.unitconverterultimate.api.models.Currencies; import com.physphil.android.unitconverterultimate.api.models.CurrencyResponse; import com.physphil.android.unitconverterultimate.models.Conversion; import com.physphil.android.unitconverterultimate.models.Language; @@ -121,16 +122,30 @@ public void saveLatestCurrency(CurrencyResponse latestCurrency) { mPrefs.edit().putString(PREFS_CURRENCY, new Gson().toJson(latestCurrency)).apply(); } - public CurrencyResponse getLatestCurrency() { + public void saveLatestCurrency(Currencies currencies) { + mPrefs.edit().putString(PREFS_CURRENCY, new Gson().toJson(currencies)).apply(); + } + + public Currencies getLatestCurrency() { if (mPrefs.contains(PREFS_CURRENCY)) { - String currency = mPrefs.getString(PREFS_CURRENCY, null); - return new Gson().fromJson(currency, CurrencyResponse.class); + String currencies = mPrefs.getString(PREFS_CURRENCY, null); + return new Gson().fromJson(currencies, Currencies.class); } else { return null; } } +// public CurrencyResponse getLatestCurrency() { +// if (mPrefs.contains(PREFS_CURRENCY)) { +// String currency = mPrefs.getString(PREFS_CURRENCY, null); +// return new Gson().fromJson(currency, CurrencyResponse.class); +// } +// else { +// return null; +// } +// } + public void setLanguage(final Language language) { mPrefs.edit().putString(PREFS_LANGUAGE, language.getId()).apply(); } diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerApi.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerApi.java index d26ec769..577f525b 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerApi.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerApi.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Phil Shadlyn + * Copyright 2018 Phil Shadlyn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ import retrofit2.Retrofit; import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; -import retrofit2.converter.gson.GsonConverterFactory; +import retrofit2.converter.simplexml.SimpleXmlConverterFactory; /** * Singleton to access the Fixer.io API @@ -26,7 +26,7 @@ */ public class FixerApi { - private static final String BASE_URL = "http://api.fixer.io"; + private static final String BASE_URL = "http://www.ecb.europa.eu/stats/eurofxref/"; private static FixerApi mInstance; private FixerService mService; @@ -34,7 +34,7 @@ public class FixerApi { private FixerApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) - .addConverterFactory(GsonConverterFactory.create()) + .addConverterFactory(SimpleXmlConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerService.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerService.java index b810fef9..28ef6bd0 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerService.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerService.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Phil Shadlyn + * Copyright 2018 Phil Shadlyn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.physphil.android.unitconverterultimate.api; -import com.physphil.android.unitconverterultimate.api.models.CurrencyResponse; +import com.physphil.android.unitconverterultimate.api.models.Envelope; import retrofit2.http.GET; import rx.Observable; @@ -26,6 +26,6 @@ * Created by Phizz on 16-07-26. */ public interface FixerService { - @GET("latest") - Observable getLatestRates(); + @GET("eurofxref-daily.xml") + Observable getLatestRates(); } diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Currencies.kt b/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Currencies.kt new file mode 100644 index 00000000..d9492d59 --- /dev/null +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Currencies.kt @@ -0,0 +1,68 @@ +/* + * Copyright 2018 Phil Shadlyn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.physphil.android.unitconverterultimate.api.models + +/** + * Copyright (c) 2018 Phil Shadlyn + */ +data class Currencies(val currencies: List) { + fun toMap(): Map { + val map = mutableMapOf() + currencies.forEach { + try { + map.put(Country.valueOf(it.currency), it.rate) + } catch (ignored: IllegalArgumentException) {} + } + return map + } +} + +data class Currency(val currency: String, val rate: Double) + +enum class Country { + AUD, + BGN, + BRL, + CAD, + CHF, + CNY, + CZK, + DKK, + GBP, + HKD, + HRK, + HUF, + IDR, + ILS, + INR, + JPY, + KRW, + MXN, + MYR, + NOK, + NZD, + PHP, + PLN, + RON, + RUB, + SEK, + SGD, + THB, + TRY, + USD, + ZAR +} \ No newline at end of file diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Envelope.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Envelope.java new file mode 100644 index 00000000..929e230d --- /dev/null +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Envelope.java @@ -0,0 +1,85 @@ +/* + * Copyright 2018 Phil Shadlyn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.physphil.android.unitconverterultimate.api.models; + +import org.simpleframework.xml.Attribute; +import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; + +import java.util.List; + +@Root(name="Envelope") +public class Envelope { + + @Element(name="Sender", required=false) + Sender sender; + + @Element(name="Cube", required=false) + Cube cube; + + @Element(name="subject", required=false) + String subject; + + public Sender getSender() {return this.sender;} + public void setSender(Sender value) {this.sender = value;} + + public Cube getCube() {return this.cube;} + public void setCube(Cube value) {this.cube = value;} + + public String getSubject() {return this.subject;} + public void setSubject(String value) {this.subject = value;} + + public static class Sender { + + @Element(name="name", required=false) + String name; + + public String getName() {return this.name;} + public void setName(String value) {this.name = value;} + + } + + public static class Cube { + + @ElementList(name="Cube", required=false, entry="Cube", inline=true) + List cube; + + @Attribute(name="rate", required=false) + Double rate; + + @Attribute(name="currency", required=false) + String currency; + + @Attribute(name="time", required=false) + String time; + + public List getCube() {return this.cube;} + public void setCube(List value) {this.cube = value;} + + public Double getRate() {return this.rate;} + public void setRate(Double value) {this.rate = value;} + + public String getCurrency() {return this.currency;} + public void setCurrency(String value) {this.currency = value;} + + public String getTime() {return this.time;} + public void setTime(String value) {this.time = value;} + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/presenters/ConversionPresenter.java b/app/src/main/java/com/physphil/android/unitconverterultimate/presenters/ConversionPresenter.java index 66a42b77..144fdf6d 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/presenters/ConversionPresenter.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/presenters/ConversionPresenter.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Phil Shadlyn + * Copyright 2018 Phil Shadlyn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,9 @@ import com.physphil.android.unitconverterultimate.Preferences; import com.physphil.android.unitconverterultimate.R; import com.physphil.android.unitconverterultimate.api.FixerApi; -import com.physphil.android.unitconverterultimate.api.models.CurrencyResponse; +import com.physphil.android.unitconverterultimate.api.models.Currencies; +import com.physphil.android.unitconverterultimate.api.models.Currency; +import com.physphil.android.unitconverterultimate.api.models.Envelope; import com.physphil.android.unitconverterultimate.data.DataAccess; import com.physphil.android.unitconverterultimate.models.Conversion; import com.physphil.android.unitconverterultimate.models.ConversionState; @@ -28,6 +30,8 @@ import java.math.BigDecimal; import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.List; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; @@ -91,11 +95,16 @@ public void onUpdateCurrencyConversions() { .getLatestRates() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new Action1() { + .subscribe(new Action1() { @Override - public void call(CurrencyResponse response) { + public void call(Envelope envelope) { + List currencies = new ArrayList<>(); + for (Envelope.Cube cube : envelope.getCube().getCube().get(0).getCube()) { + currencies.add(new Currency(cube.getCurrency(), cube.getRate())); + } + boolean hadCurrency = Conversions.getInstance().hasCurrency(); - Preferences.getInstance(mView.getContext()).saveLatestCurrency(response); + Preferences.getInstance(mView.getContext()).saveLatestCurrency(new Currencies(currencies)); Conversions.getInstance().updateCurrencyConversions(mView.getContext()); Conversions.getInstance().setCurrencyUpdated(true); mView.showToast(R.string.toast_currency_updated); @@ -117,6 +126,36 @@ public void call(Throwable throwable) { } } })); +// mCompositeSubscription.add(FixerApi.getInstance().getService() +// .getLatestRates() +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new Action1() { +// @Override +// public void call(CurrencyResponse response) { +// boolean hadCurrency = Conversions.getInstance().hasCurrency(); +// Preferences.getInstance(mView.getContext()).saveLatestCurrency(response); +// Conversions.getInstance().updateCurrencyConversions(mView.getContext()); +// Conversions.getInstance().setCurrencyUpdated(true); +// mView.showToast(R.string.toast_currency_updated); +// if (hadCurrency) { +// mView.updateCurrencyConversion(); +// } +// else { +// mView.showUnitsList(Conversions.getInstance().getById(Conversion.CURRENCY)); +// } +// } +// }, new Action1() { +// @Override +// public void call(Throwable throwable) { +// if (!Conversions.getInstance().hasCurrency()) { +// mView.showLoadingError(R.string.error_loading_currency); +// } +// else { +// mView.showToastError(R.string.toast_error_updating_currency); +// } +// } +// })); } public void onGetUnitsToDisplay(@Conversion.id int conversionId) { diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/util/Conversions.java b/app/src/main/java/com/physphil/android/unitconverterultimate/util/Conversions.java index bc3856f5..86212832 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/util/Conversions.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/util/Conversions.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Phil Shadlyn + * Copyright 2018 Phil Shadlyn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,8 @@ import com.physphil.android.unitconverterultimate.Preferences; import com.physphil.android.unitconverterultimate.R; -import com.physphil.android.unitconverterultimate.api.models.CurrencyResponse; -import com.physphil.android.unitconverterultimate.api.models.Rates; +import com.physphil.android.unitconverterultimate.api.models.Country; +import com.physphil.android.unitconverterultimate.api.models.Currencies; import com.physphil.android.unitconverterultimate.models.Conversion; import com.physphil.android.unitconverterultimate.models.TemperatureUnit; import com.physphil.android.unitconverterultimate.models.Unit; @@ -132,41 +132,43 @@ private void getCookingConversions() { public void updateCurrencyConversions(Context context) { // Base unit - Euro final List units = new ArrayList<>(); - final CurrencyResponse response = Preferences.getInstance(context).getLatestCurrency(); - if (Preferences.getInstance(context).hasLatestCurrency() && response != null) { - Rates currency = response.getRates(); - units.add(new Unit(USD, R.string.usd, 1 / currency.getUsd(), currency.getUsd())); - units.add(new Unit(AUD, R.string.aud, 1 / currency.getAud(), currency.getAud())); - units.add(new Unit(GBP, R.string.gbp, 1 / currency.getGbp(), currency.getGbp())); - units.add(new Unit(BRL, R.string.brl, 1 / currency.getBrl(), currency.getBrl())); - units.add(new Unit(BGN, R.string.bgn, 1 / currency.getBgn(), currency.getBgn())); - units.add(new Unit(CDN, R.string.cdn, 1 / currency.getCad(), currency.getCad())); - units.add(new Unit(CNY, R.string.cny, 1 / currency.getCny(), currency.getCny())); - units.add(new Unit(HRK, R.string.hrk, 1 / currency.getHrk(), currency.getHrk())); - units.add(new Unit(CZK, R.string.czk, 1 / currency.getCzk(), currency.getCzk())); - units.add(new Unit(DKK, R.string.dkk, 1 / currency.getDkk(), currency.getDkk())); +// final CurrencyResponse response = Preferences.getInstance(context).getLatestCurrency(); + final Currencies currencies = Preferences.getInstance(context).getLatestCurrency(); + if (Preferences.getInstance(context).hasLatestCurrency() && currencies != null) { +// Rates currency = response.getRates(); + Map map = currencies.toMap(); + units.add(new Unit(USD, R.string.usd, 1 / map.get(Country.USD), map.get(Country.USD))); + units.add(new Unit(AUD, R.string.aud, 1 / map.get(Country.AUD), map.get(Country.AUD))); + units.add(new Unit(GBP, R.string.gbp, 1 / map.get(Country.GBP), map.get(Country.GBP))); + units.add(new Unit(BRL, R.string.brl, 1 / map.get(Country.BRL), map.get(Country.BRL))); + units.add(new Unit(BGN, R.string.bgn, 1 / map.get(Country.BGN), map.get(Country.BGN))); + units.add(new Unit(CDN, R.string.cdn, 1 / map.get(Country.CAD), map.get(Country.CAD))); + units.add(new Unit(CNY, R.string.cny, 1 / map.get(Country.CNY), map.get(Country.CNY))); + units.add(new Unit(HRK, R.string.hrk, 1 / map.get(Country.HRK), map.get(Country.HRK))); + units.add(new Unit(CZK, R.string.czk, 1 / map.get(Country.CZK), map.get(Country.CZK))); + units.add(new Unit(DKK, R.string.dkk, 1 / map.get(Country.DKK), map.get(Country.DKK))); units.add(new Unit(EUR, R.string.eur, 1.0, 1.0)); - units.add(new Unit(HKD, R.string.hkd, 1 / currency.getHkd(), currency.getHkd())); - units.add(new Unit(HUF, R.string.huf, 1 / currency.getHuf(), currency.getHuf())); - units.add(new Unit(INR, R.string.inr, 1 / currency.getInr(), currency.getInr())); - units.add(new Unit(IDR, R.string.idr, 1 / currency.getIdr(), currency.getIdr())); - units.add(new Unit(ILS, R.string.ils, 1 / currency.getIls(), currency.getIls())); - units.add(new Unit(JPY, R.string.jpy, 1 / currency.getJpy(), currency.getJpy())); - units.add(new Unit(KRW, R.string.krw, 1 / currency.getKrw(), currency.getKrw())); - units.add(new Unit(MYR, R.string.myr, 1 / currency.getMyr(), currency.getMyr())); - units.add(new Unit(MXN, R.string.mxn, 1 / currency.getMxn(), currency.getMxn())); - units.add(new Unit(NZD, R.string.nzd, 1 / currency.getNzd(), currency.getNzd())); - units.add(new Unit(NOK, R.string.nok, 1 / currency.getNok(), currency.getNok())); - units.add(new Unit(PHP, R.string.php, 1 / currency.getPhp(), currency.getPhp())); - units.add(new Unit(PLN, R.string.pln, 1 / currency.getPln(), currency.getPln())); - units.add(new Unit(RON, R.string.ron, 1 / currency.getRon(), currency.getRon())); - units.add(new Unit(RUB, R.string.rub, 1 / currency.getRub(), currency.getRub())); - units.add(new Unit(SGD, R.string.sgd, 1 / currency.getSgd(), currency.getSgd())); - units.add(new Unit(ZAR, R.string.zar, 1 / currency.getZar(), currency.getZar())); - units.add(new Unit(SEK, R.string.sek, 1 / currency.getSek(), currency.getSek())); - units.add(new Unit(CHF, R.string.chf, 1 / currency.getChf(), currency.getChf())); - units.add(new Unit(THB, R.string.thb, 1 / currency.getThb(), currency.getThb())); - units.add(new Unit(LIRA, R.string.lira, 1 / currency.getLira(), currency.getLira())); + units.add(new Unit(HKD, R.string.hkd, 1 / map.get(Country.HKD), map.get(Country.HKD))); + units.add(new Unit(HUF, R.string.huf, 1 / map.get(Country.HUF), map.get(Country.HUF))); + units.add(new Unit(INR, R.string.inr, 1 / map.get(Country.INR), map.get(Country.INR))); + units.add(new Unit(IDR, R.string.idr, 1 / map.get(Country.IDR), map.get(Country.IDR))); + units.add(new Unit(ILS, R.string.ils, 1 / map.get(Country.ILS), map.get(Country.ILS))); + units.add(new Unit(JPY, R.string.jpy, 1 / map.get(Country.JPY), map.get(Country.JPY))); + units.add(new Unit(KRW, R.string.krw, 1 / map.get(Country.KRW), map.get(Country.KRW))); + units.add(new Unit(MYR, R.string.myr, 1 / map.get(Country.MYR), MYR)); + units.add(new Unit(MXN, R.string.mxn, 1 / map.get(Country.MXN), map.get(Country.MXN))); + units.add(new Unit(NZD, R.string.nzd, 1 / map.get(Country.NZD), map.get(Country.NZD))); + units.add(new Unit(NOK, R.string.nok, 1 / map.get(Country.NOK), map.get(Country.NOK))); + units.add(new Unit(PHP, R.string.php, 1 / map.get(Country.PHP), map.get(Country.PHP))); + units.add(new Unit(PLN, R.string.pln, 1 / map.get(Country.PLN), map.get(Country.PLN))); + units.add(new Unit(RON, R.string.ron, 1 / map.get(Country.RON), map.get(Country.RON))); + units.add(new Unit(RUB, R.string.rub, 1 / map.get(Country.RUB), map.get(Country.RUB))); + units.add(new Unit(SGD, R.string.sgd, 1 / map.get(Country.SGD), map.get(Country.SGD))); + units.add(new Unit(ZAR, R.string.zar, 1 / map.get(Country.ZAR), map.get(Country.ZAR))); + units.add(new Unit(SEK, R.string.sek, 1 / map.get(Country.SEK), map.get(Country.SEK))); + units.add(new Unit(CHF, R.string.chf, 1 / map.get(Country.CHF), map.get(Country.CHF))); + units.add(new Unit(THB, R.string.thb, 1 / map.get(Country.THB), map.get(Country.THB))); + units.add(new Unit(LIRA, R.string.lira, 1 / map.get(Country.TRY), map.get(Country.TRY))); } addConversion(Conversion.CURRENCY, new Conversion(Conversion.CURRENCY, R.string.currency, units)); From a52561e8907e3dc66432799794b7b4b229713139 Mon Sep 17 00:00:00 2001 From: physphil Date: Sat, 9 Jun 2018 16:49:49 -0400 Subject: [PATCH 11/14] GH-110 refactoring and cleanup for fix --- app/build.gradle | 5 +- .../unitconverterultimate/Preferences.java | 15 -- .../api/{FixerApi.java => CurrencyApi.java} | 19 +- ...FixerService.java => CurrencyService.java} | 5 +- .../api/models/CurrencyResponse.java | 40 ---- .../api/models/Envelope.java | 3 + .../api/models/Rates.java | 182 ------------------ .../presenters/ConversionPresenter.java | 34 +--- 8 files changed, 18 insertions(+), 285 deletions(-) rename app/src/main/java/com/physphil/android/unitconverterultimate/api/{FixerApi.java => CurrencyApi.java} (77%) rename app/src/main/java/com/physphil/android/unitconverterultimate/api/{FixerService.java => CurrencyService.java} (88%) delete mode 100644 app/src/main/java/com/physphil/android/unitconverterultimate/api/models/CurrencyResponse.java delete mode 100644 app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Rates.java diff --git a/app/build.gradle b/app/build.gradle index f360a264..74273f20 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -40,8 +40,8 @@ android { applicationId "com.physphil.android.unitconverterultimate" minSdkVersion 14 targetSdkVersion 27 - versionCode 50300 - versionName '5.3' + versionCode 50301 + versionName '5.3.1' } @@ -75,7 +75,6 @@ dependencies { implementation 'com.android.support:recyclerview-v7:27.0.2' implementation 'com.android.support:design:27.0.2' implementation 'com.squareup.retrofit2:retrofit:2.3.0' - implementation 'com.squareup.retrofit2:converter-gson:2.3.0' implementation 'com.squareup.retrofit2:converter-simplexml:2.3.0' implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0' implementation 'com.google.code.gson:gson:2.8.0' diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java b/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java index 1b825390..7e02476a 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java @@ -23,7 +23,6 @@ import com.google.gson.Gson; import com.physphil.android.unitconverterultimate.api.models.Currencies; -import com.physphil.android.unitconverterultimate.api.models.CurrencyResponse; import com.physphil.android.unitconverterultimate.models.Conversion; import com.physphil.android.unitconverterultimate.models.Language; @@ -118,10 +117,6 @@ public boolean hasLatestCurrency() { return mPrefs.contains(PREFS_CURRENCY); } - public void saveLatestCurrency(CurrencyResponse latestCurrency) { - mPrefs.edit().putString(PREFS_CURRENCY, new Gson().toJson(latestCurrency)).apply(); - } - public void saveLatestCurrency(Currencies currencies) { mPrefs.edit().putString(PREFS_CURRENCY, new Gson().toJson(currencies)).apply(); } @@ -136,16 +131,6 @@ public Currencies getLatestCurrency() { } } -// public CurrencyResponse getLatestCurrency() { -// if (mPrefs.contains(PREFS_CURRENCY)) { -// String currency = mPrefs.getString(PREFS_CURRENCY, null); -// return new Gson().fromJson(currency, CurrencyResponse.class); -// } -// else { -// return null; -// } -// } - public void setLanguage(final Language language) { mPrefs.edit().putString(PREFS_LANGUAGE, language.getId()).apply(); } diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerApi.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyApi.java similarity index 77% rename from app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerApi.java rename to app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyApi.java index 577f525b..861ceb55 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerApi.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyApi.java @@ -21,35 +21,34 @@ import retrofit2.converter.simplexml.SimpleXmlConverterFactory; /** - * Singleton to access the Fixer.io API - * Created by Phizz on 16-07-26. + * Singleton to access the Currency API */ -public class FixerApi { +public class CurrencyApi { private static final String BASE_URL = "http://www.ecb.europa.eu/stats/eurofxref/"; - private static FixerApi mInstance; + private static CurrencyApi mInstance; - private FixerService mService; + private CurrencyService mService; - private FixerApi() { + private CurrencyApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(SimpleXmlConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); - mService = retrofit.create(FixerService.class); + mService = retrofit.create(CurrencyService.class); } - public static FixerApi getInstance() { + public static CurrencyApi getInstance() { if (mInstance == null) { - mInstance = new FixerApi(); + mInstance = new CurrencyApi(); } return mInstance; } - public FixerService getService() { + public CurrencyService getService() { return mService; } } diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerService.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyService.java similarity index 88% rename from app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerService.java rename to app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyService.java index 28ef6bd0..9334f050 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/api/FixerService.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyService.java @@ -22,10 +22,9 @@ import rx.Observable; /** - * Retrofit service to consume Fixer.io API - * Created by Phizz on 16-07-26. + * Retrofit service to consume Currency API */ -public interface FixerService { +public interface CurrencyService { @GET("eurofxref-daily.xml") Observable getLatestRates(); } diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/CurrencyResponse.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/CurrencyResponse.java deleted file mode 100644 index bd2b6c0e..00000000 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/CurrencyResponse.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2016 Phil Shadlyn - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.physphil.android.unitconverterultimate.api.models; - -/** - * Response object sent from Fixer.io API - * Created by Phizz on 16-07-26. - */ -public class CurrencyResponse { - - private String base; - private String date; - private Rates rates; - - public String getBase() { - return base; - } - - public String getDate() { - return date; - } - - public Rates getRates() { - return rates; - } -} diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Envelope.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Envelope.java index 929e230d..1d5d35ae 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Envelope.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Envelope.java @@ -23,6 +23,9 @@ import java.util.List; +/** + * Model for XML returned from currency API + */ @Root(name="Envelope") public class Envelope { diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Rates.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Rates.java deleted file mode 100644 index 046fb73c..00000000 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/api/models/Rates.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2016 Phil Shadlyn - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.physphil.android.unitconverterultimate.api.models; - -import com.google.gson.annotations.SerializedName; - -/** - * List of currency rates from Fixer.io API - * Created by Phizz on 16-07-26. - */ -public class Rates { - - @SerializedName("AUD") double aud; - @SerializedName("BGN") double bgn; - @SerializedName("BRL") double brl; - @SerializedName("CAD") double cad; - @SerializedName("CHF") double chf; - @SerializedName("CNY") double cny; - @SerializedName("CZK") double czk; - @SerializedName("DKK") double dkk; - @SerializedName("GBP") double gbp; - @SerializedName("HKD") double hkd; - @SerializedName("HRK") double hrk; - @SerializedName("HUF") double huf; - @SerializedName("IDR") double idr; - @SerializedName("ILS") double ils; - @SerializedName("INR") double inr; - @SerializedName("JPY") double jpy; - @SerializedName("KRW") double krw; - @SerializedName("MXN") double mxn; - @SerializedName("MYR") double myr; - @SerializedName("NOK") double nok; - @SerializedName("NZD") double nzd; - @SerializedName("PHP") double php; - @SerializedName("PLN") double pln; - @SerializedName("RON") double ron; - @SerializedName("RUB") double rub; - @SerializedName("SEK") double sek; - @SerializedName("SGD") double sgd; - @SerializedName("THB") double thb; - @SerializedName("TRY") double lira; - @SerializedName("USD") double usd; - @SerializedName("ZAR") double zar; - - public double getAud() { - return aud; - } - - public double getBgn() { - return bgn; - } - - public double getBrl() { - return brl; - } - - public double getCad() { - return cad; - } - - public double getChf() { - return chf; - } - - public double getCny() { - return cny; - } - - public double getCzk() { - return czk; - } - - public double getDkk() { - return dkk; - } - - public double getGbp() { - return gbp; - } - - public double getHkd() { - return hkd; - } - - public double getHrk() { - return hrk; - } - - public double getHuf() { - return huf; - } - - public double getIdr() { - return idr; - } - - public double getIls() { - return ils; - } - - public double getInr() { - return inr; - } - - public double getJpy() { - return jpy; - } - - public double getKrw() { - return krw; - } - - public double getMxn() { - return mxn; - } - - public double getMyr() { - return myr; - } - - public double getNok() { - return nok; - } - - public double getNzd() { - return nzd; - } - - public double getPhp() { - return php; - } - - public double getPln() { - return pln; - } - - public double getRon() { - return ron; - } - - public double getRub() { - return rub; - } - - public double getSek() { - return sek; - } - - public double getSgd() { - return sgd; - } - - public double getThb() { - return thb; - } - - public double getLira() { - return lira; - } - - public double getUsd() { - return usd; - } - - public double getZar() { - return zar; - } -} diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/presenters/ConversionPresenter.java b/app/src/main/java/com/physphil/android/unitconverterultimate/presenters/ConversionPresenter.java index 144fdf6d..d6cd743d 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/presenters/ConversionPresenter.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/presenters/ConversionPresenter.java @@ -18,7 +18,7 @@ import com.physphil.android.unitconverterultimate.Preferences; import com.physphil.android.unitconverterultimate.R; -import com.physphil.android.unitconverterultimate.api.FixerApi; +import com.physphil.android.unitconverterultimate.api.CurrencyApi; import com.physphil.android.unitconverterultimate.api.models.Currencies; import com.physphil.android.unitconverterultimate.api.models.Currency; import com.physphil.android.unitconverterultimate.api.models.Envelope; @@ -91,7 +91,7 @@ public Observable call() { } public void onUpdateCurrencyConversions() { - mCompositeSubscription.add(FixerApi.getInstance().getService() + mCompositeSubscription.add(CurrencyApi.getInstance().getService() .getLatestRates() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -126,36 +126,6 @@ public void call(Throwable throwable) { } } })); -// mCompositeSubscription.add(FixerApi.getInstance().getService() -// .getLatestRates() -// .subscribeOn(Schedulers.io()) -// .observeOn(AndroidSchedulers.mainThread()) -// .subscribe(new Action1() { -// @Override -// public void call(CurrencyResponse response) { -// boolean hadCurrency = Conversions.getInstance().hasCurrency(); -// Preferences.getInstance(mView.getContext()).saveLatestCurrency(response); -// Conversions.getInstance().updateCurrencyConversions(mView.getContext()); -// Conversions.getInstance().setCurrencyUpdated(true); -// mView.showToast(R.string.toast_currency_updated); -// if (hadCurrency) { -// mView.updateCurrencyConversion(); -// } -// else { -// mView.showUnitsList(Conversions.getInstance().getById(Conversion.CURRENCY)); -// } -// } -// }, new Action1() { -// @Override -// public void call(Throwable throwable) { -// if (!Conversions.getInstance().hasCurrency()) { -// mView.showLoadingError(R.string.error_loading_currency); -// } -// else { -// mView.showToastError(R.string.toast_error_updating_currency); -// } -// } -// })); } public void onGetUnitsToDisplay(@Conversion.id int conversionId) { From 219b9cdd6017f289d904559338b54833a82c7ac2 Mon Sep 17 00:00:00 2001 From: physphil Date: Sat, 9 Jun 2018 17:01:38 -0400 Subject: [PATCH 12/14] GH-110 More refactoring, version currency preference name to avoid upgrade conflicts --- .../android/unitconverterultimate/Preferences.java | 10 +++++----- .../unitconverterultimate/util/Conversions.java | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java b/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java index 7e02476a..887a26d7 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/Preferences.java @@ -41,7 +41,7 @@ public class Preferences { public static final String PREFS_APP_OPEN_COUNT = "app_open_count"; public static final String PREFS_SHOW_HELP = "show_help"; private static final String PREFS_CONVERSION = "conversion"; - private static final String PREFS_CURRENCY = "currency"; + private static final String PREFS_CURRENCY_V2 = "currency_v2"; public static final String PREFS_LANGUAGE = "language"; private static Preferences mInstance; @@ -114,16 +114,16 @@ public boolean showHelp() { } public boolean hasLatestCurrency() { - return mPrefs.contains(PREFS_CURRENCY); + return mPrefs.contains(PREFS_CURRENCY_V2); } public void saveLatestCurrency(Currencies currencies) { - mPrefs.edit().putString(PREFS_CURRENCY, new Gson().toJson(currencies)).apply(); + mPrefs.edit().putString(PREFS_CURRENCY_V2, new Gson().toJson(currencies)).apply(); } public Currencies getLatestCurrency() { - if (mPrefs.contains(PREFS_CURRENCY)) { - String currencies = mPrefs.getString(PREFS_CURRENCY, null); + if (mPrefs.contains(PREFS_CURRENCY_V2)) { + String currencies = mPrefs.getString(PREFS_CURRENCY_V2, null); return new Gson().fromJson(currencies, Currencies.class); } else { diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/util/Conversions.java b/app/src/main/java/com/physphil/android/unitconverterultimate/util/Conversions.java index 86212832..568965f1 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/util/Conversions.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/util/Conversions.java @@ -132,10 +132,8 @@ private void getCookingConversions() { public void updateCurrencyConversions(Context context) { // Base unit - Euro final List units = new ArrayList<>(); -// final CurrencyResponse response = Preferences.getInstance(context).getLatestCurrency(); final Currencies currencies = Preferences.getInstance(context).getLatestCurrency(); if (Preferences.getInstance(context).hasLatestCurrency() && currencies != null) { -// Rates currency = response.getRates(); Map map = currencies.toMap(); units.add(new Unit(USD, R.string.usd, 1 / map.get(Country.USD), map.get(Country.USD))); units.add(new Unit(AUD, R.string.aud, 1 / map.get(Country.AUD), map.get(Country.AUD))); From 04e7cf3a92ba8f2f48462fffb6eb74eb197ac5bd Mon Sep 17 00:00:00 2001 From: physphil Date: Sat, 9 Jun 2018 17:23:56 -0400 Subject: [PATCH 13/14] GH-110 Add exclusions to SimpleXML converter to avoid clashes with Android --- app/build.gradle | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 74273f20..bc1ad43b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,7 +75,10 @@ dependencies { implementation 'com.android.support:recyclerview-v7:27.0.2' implementation 'com.android.support:design:27.0.2' implementation 'com.squareup.retrofit2:retrofit:2.3.0' - implementation 'com.squareup.retrofit2:converter-simplexml:2.3.0' + implementation ('com.squareup.retrofit2:converter-simplexml:2.3.0') { + exclude module: 'xpp3' + exclude module: 'stax-api' + } implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0' implementation 'com.google.code.gson:gson:2.8.0' implementation 'io.reactivex:rxandroid:1.2.1' From ef86e01b00d8d3c1aa0b2ca258a03f1fccf8f256 Mon Sep 17 00:00:00 2001 From: tacsipacsi Date: Sun, 10 Jun 2018 10:21:23 +0200 Subject: [PATCH 14/14] Use HTTPS in currency API Using HTTPS is always a good thing. The ECB website seems to be available using HTTPS, although I was just too lazy to build and test the app. ;) --- .../physphil/android/unitconverterultimate/api/CurrencyApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyApi.java b/app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyApi.java index 861ceb55..5155bb64 100644 --- a/app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyApi.java +++ b/app/src/main/java/com/physphil/android/unitconverterultimate/api/CurrencyApi.java @@ -25,7 +25,7 @@ */ public class CurrencyApi { - private static final String BASE_URL = "http://www.ecb.europa.eu/stats/eurofxref/"; + private static final String BASE_URL = "https://www.ecb.europa.eu/stats/eurofxref/"; private static CurrencyApi mInstance; private CurrencyService mService;