Skip to content

Commit

Permalink
Merge pull request #113 from physphil/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
physphil authored Jun 17, 2018
2 parents e113077 + 4aacf27 commit e205d96
Show file tree
Hide file tree
Showing 20 changed files with 584 additions and 334 deletions.
57 changes: 33 additions & 24 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -17,14 +17,10 @@
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
buildToolsVersion '25.0.0'
compileSdkVersion 27
buildToolsVersion '26.0.2'

signingConfigs {
release {
Expand All @@ -43,9 +39,9 @@ android {
defaultConfig {
applicationId "com.physphil.android.unitconverterultimate"
minSdkVersion 14
targetSdkVersion 24
versionCode 50300
versionName '5.3'
targetSdkVersion 27
versionCode 50301
versionName '5.3.1'
}


Expand All @@ -58,33 +54,46 @@ 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: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-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'
implementation 'io.reactivex:rxjava:1.3.0'

googleCompile 'com.google.firebase:firebase-crash:10.2.1'
googleImplementation 'com.google.firebase:firebase-crash:11.8.0'

debugCompile 'com.facebook.stetho:stetho:1.1.1'
debugImplementation 'com.facebook.stetho:stetho:1.5.0'

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'
}

// 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'
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,7 +22,7 @@
import android.support.annotation.NonNull;

import com.google.gson.Gson;
import com.physphil.android.unitconverterultimate.api.models.CurrencyResponse;
import com.physphil.android.unitconverterultimate.api.models.Currencies;
import com.physphil.android.unitconverterultimate.models.Conversion;
import com.physphil.android.unitconverterultimate.models.Language;

Expand All @@ -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;
Expand Down Expand Up @@ -114,17 +114,17 @@ public boolean showHelp() {
}

public boolean hasLatestCurrency() {
return mPrefs.contains(PREFS_CURRENCY);
return mPrefs.contains(PREFS_CURRENCY_V2);
}

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_V2, new Gson().toJson(currencies)).apply();
}

public CurrencyResponse getLatestCurrency() {
if (mPrefs.contains(PREFS_CURRENCY)) {
String currency = mPrefs.getString(PREFS_CURRENCY, null);
return new Gson().fromJson(currency, CurrencyResponse.class);
public Currencies getLatestCurrency() {
if (mPrefs.contains(PREFS_CURRENCY_V2)) {
String currencies = mPrefs.getString(PREFS_CURRENCY_V2, null);
return new Gson().fromJson(currencies, Currencies.class);
}
else {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,38 +18,37 @@

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
* 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://api.fixer.io";
private static FixerApi mInstance;
private static final String BASE_URL = "https://www.ecb.europa.eu/stats/eurofxref/";
private static CurrencyApi mInstance;

private FixerService mService;
private CurrencyService mService;

private FixerApi() {
private CurrencyApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.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;
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,16 +16,15 @@

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;

/**
* Retrofit service to consume Fixer.io API
* Created by Phizz on 16-07-26.
* Retrofit service to consume Currency API
*/
public interface FixerService {
@GET("latest")
Observable<CurrencyResponse> getLatestRates();
public interface CurrencyService {
@GET("eurofxref-daily.xml")
Observable<Envelope> getLatestRates();
}
Original file line number Diff line number Diff line change
@@ -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<Currency>) {
fun toMap(): Map<Country, Double> {
val map = mutableMapOf<Country, Double>()
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
}

This file was deleted.

Loading

0 comments on commit e205d96

Please sign in to comment.