Skip to content

Commit

Permalink
Initial commit for data, domain and presentation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rendecano authored and rendecano committed Aug 25, 2016
1 parent c91ac11 commit 1c53520
Show file tree
Hide file tree
Showing 55 changed files with 1,333 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
30 changes: 30 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.rendecano.cashmoney"
minSdkVersion 22
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/frascellaclaudio/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.rendecano.cashmoney;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.rendecano.cashmoney", appContext.getPackageName());
}
}
28 changes: 28 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rendecano.cashmoney">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".presentation.AndroidApplication">
<activity
android:name=".presentation.activity.CashMoneyActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
39 changes: 39 additions & 0 deletions app/src/main/java/com/rendecano/cashmoney/data/entity/Base.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.rendecano.cashmoney.data.entity;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Ren Decano.
*/

public class Base {

private String base;
private String date;
private List<Rate> rates = new ArrayList<>();

public String getBase() {
return base;
}

public void setBase(String base) {
this.base = base;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public List<Rate> getRates() {
return rates;
}

public void setRates(List<Rate> rates) {
this.rates = rates;
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/rendecano/cashmoney/data/entity/Rate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.rendecano.cashmoney.data.entity;

/**
* Created by Ren Decano.
*/

public class Rate {

private String currency;
private double conversion;

public double getConversion() {
return conversion;
}

public void setConversion(double conversion) {
this.conversion = conversion;
}

public String getCurrency() {
return currency;
}

public void setCurrency(String currency) {
this.currency = currency;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.rendecano.cashmoney.data.entity.mapper;

import com.rendecano.cashmoney.data.entity.Base;
import com.rendecano.cashmoney.data.entity.Rate;

import org.json.JSONException;
import org.json.JSONObject;

public class BaseEntityJsonMapper {

public Base transformBaseEntity(String jsonResponse) throws JSONException {

Base entity = new Base();

JSONObject jsonObject = new JSONObject(jsonResponse);

String base = jsonObject.optString("base");
String date = jsonObject.optString("date");

entity.setBase(base);
entity.setDate(date);

// Get rates
JSONObject rates = jsonObject.getJSONObject("rates");

Rate rateCad = new Rate();
rateCad.setCurrency("CAD");
rateCad.setConversion(rates.optDouble("CAD"));

Rate rateGbp = new Rate();
rateGbp.setCurrency("GBP");
rateGbp.setConversion(rates.optDouble("GBP"));

Rate rateJpy = new Rate();
rateJpy.setCurrency("JPY");
rateJpy.setConversion(rates.optDouble("JPY"));

Rate rateUsd = new Rate();
rateUsd.setCurrency("USD");
rateUsd.setConversion(rates.optDouble("USD"));

Rate rateEur = new Rate();
rateEur.setCurrency("EUR");
rateEur.setConversion(rates.optDouble("EUR"));

entity.getRates().add(rateCad);
entity.getRates().add(rateGbp);
entity.getRates().add(rateJpy);
entity.getRates().add(rateUsd);
entity.getRates().add(rateEur);

return entity;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.rendecano.cashmoney.data.local;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.rendecano.cashmoney.data.entity.Base;
import com.rendecano.cashmoney.data.entity.Rate;
import com.rendecano.cashmoney.presentation.AndroidApplication;

public class SharedPrefStorage {

public static final String PREFS_NAME = "CASH_MONEY_PREFS";
SharedPreferences prefs;

public SharedPrefStorage(Context pContext) {
prefs = pContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
}

public void saveCurrencyConversions(Base pBase) {

savePreference("BASE", pBase.getBase());
savePreference("DATE", pBase.getDate());

if (pBase.getRates().size() > 0) {
for (Rate rate : pBase.getRates()) {
savePreference(rate.getCurrency(), String.valueOf(rate.getConversion()));
}
}
}

public double getConversion(String pCurrency) {
String conversion = prefs.getString(pCurrency, "");
return Double.valueOf(conversion);
}

private void savePreference(String key, String value) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString(key, value);
editor.commit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.rendecano.cashmoney.data.network;

import android.os.AsyncTask;
import android.text.TextUtils;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class ApiConnection {

private static final String CONTENT_TYPE_LABEL = "Content-Type";
private static final String CONTENT_TYPE_VALUE_JSON = "application/json;charset=utf-8";

private URL url;
private JsonResponseListener mListener;

public static ApiConnection createGET(String url, JsonResponseListener listener) throws MalformedURLException {
return new ApiConnection(url, listener);
}

private ApiConnection(String url, JsonResponseListener listener) throws MalformedURLException {
this.url = new URL(url);
this.mListener = listener;
}

public void call() {
new RestConnectionTask().execute(url);
}

class RestConnectionTask extends AsyncTask<URL, Void, String> {

@Override
protected String doInBackground(URL... params) {
String currencies = "";
HttpURLConnection urlConnection;
try {

urlConnection = (HttpURLConnection) params[0].openConnection();

InputStream stream = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
StringBuilder builder = new StringBuilder();

String inputString;
while ((inputString = bufferedReader.readLine()) != null) {
builder.append(inputString);
}

currencies = builder.toString();
urlConnection.disconnect();

} catch (IOException e) {
e.printStackTrace();
mListener.onError("Error in getting response");
}
return currencies;
}

@Override
protected void onPostExecute(String response) {

// Check if response is not empty
if (!TextUtils.isEmpty(response)) {
mListener.onSuccess(response);
} else {
mListener.onError("Error in getting response");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.rendecano.cashmoney.data.network;

public interface JsonResponseListener {

void onSuccess(String response);

void onError(String message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.rendecano.cashmoney.data.network;

public interface RestApi {

String API_BASE_URL = "http://api.fixer.io/latest";

void getExchangeRate(String baseCurrency, String[] symbols, JsonResponseListener listener);
}
Loading

0 comments on commit 1c53520

Please sign in to comment.