Commit f5882a48 authored by cfabio's avatar cfabio

Add Iconomi API support

parent 74f64342
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
......@@ -7,8 +7,8 @@ android {
applicationId "eu.uwot.fabio.altcoinprices"
minSdkVersion 14
targetSdkVersion 28
versionCode 77
versionName '1.6.21'
versionCode 78
versionName '1.7.0'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
......
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":77,"versionName":"1.6.21","enabled":true,"outputFile":"AltcoinPrices-fdroid-release.apk","fullName":"fdroidRelease","baseName":"fdroid-release"},"path":"AltcoinPrices-fdroid-release.apk","properties":{}}]
\ No newline at end of file
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":78,"versionName":"1.7.0","enabled":true,"outputFile":"AltcoinPrices-fdroid-release.apk","fullName":"fdroidRelease","baseName":"fdroid-release"},"path":"AltcoinPrices-fdroid-release.apk","properties":{}}]
\ No newline at end of file
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":77,"versionName":"1.6.21","enabled":true,"outputFile":"AltcoinPrices-googlePlayStore-release.apk","fullName":"googlePlayStoreRelease","baseName":"googlePlayStore-release"},"path":"AltcoinPrices-googlePlayStore-release.apk","properties":{}}]
\ No newline at end of file
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":78,"versionName":"1.7.0","enabled":true,"outputFile":"AltcoinPrices-googlePlayStore-release.apk","fullName":"googlePlayStoreRelease","baseName":"googlePlayStore-release"},"path":"AltcoinPrices-googlePlayStore-release.apk","properties":{}}]
\ No newline at end of file
......@@ -171,7 +171,7 @@ public class AddNewPortfolioItemActivity extends AppCompatActivity implements Ad
public void run() {
SharedPreferences prefs = getApplicationContext().getSharedPreferences("Settings", 0);
SharedPreferences.Editor editor = prefs.edit();
new Coin(getApplicationContext(), false).addItem(altcoinDesc, amountBought, unitPrice, currency, unixTimestamp);
new Coin(getApplicationContext(), true).addItem(altcoinDesc, amountBought, unitPrice, currency, unixTimestamp);
editor.putBoolean("initCoinsLogos", true);
editor.apply();
startActivity(new Intent(getApplicationContext(), LoadingActivity.class));
......
......@@ -190,11 +190,6 @@ public class EditCustomCoinActivity extends AppCompatActivity {
tradingviewTradingPair = "na";
}
Log.d("DEBUG", "altcoinSymbol: " + altcoinSymbol);
Log.d("DEBUG", "altcoinDescription: " + altcoinDescription);
Log.d("DEBUG", "tradingviewExchangeName: " + tradingviewExchangeName);
Log.d("DEBUG", "tradingviewTradingPair: " + tradingviewTradingPair);
// Create new coin JSON array
try {
newCustomCoin.put("altcoinSymbol", altcoinSymbol);
......
......@@ -7,6 +7,7 @@ import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
......
......@@ -4,6 +4,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
......@@ -54,7 +55,7 @@ public class LoadingActivity extends AppCompatActivity {
private void setPortfolioData () {
prefs = getApplicationContext().getSharedPreferences("Settings", 0);
editor = prefs.edit();
coin = new Coin(getApplicationContext(), false);
coin = new Coin(getApplicationContext(), true);
CoinLogo coinLogo = new CoinLogo(getApplicationContext());
boolean initCoinsLogos = prefs.getBoolean("initCoinsLogos", true);
......@@ -78,20 +79,34 @@ public class LoadingActivity extends AppCompatActivity {
float amountBought = prefs.getFloat(coin.coins[i] + "_a", -1f);
if (amountBought != -1f) {
String altcoinCurrency = prefs.getString(coin.coins[i] + "_currency", "EUR");
float currentUnitValue = coin.getCoinValue(coin.coins[i], altcoinCurrency, 0L);
editor.putFloat(coin.coins[i] + "_currentUnitValue", currentUnitValue);
float lastDayUnitValue = coin.getCoinValue(coin.coins[i], altcoinCurrency, new UnixTimestamp().getYesterdayUnixTimestamp());
editor.putFloat(coin.coins[i] + "_lastDayUnitValue", lastDayUnitValue);
float lastDayUnitValue_btc, currentUnitValue_btc;
if (coin.coins[i].equals("BTC")) {
currentUnitValue_btc = 1f;
lastDayUnitValue_btc = 1f;
if (coin.getCoinExchange(coin.coins[i]).equals("cryptocompare_icndaa")) {
String altcoinCurrency = prefs.getString(coin.coins[i] + "_currency", "EUR");
float currentUnitValue = coin.getCoinValue(coin.coins[i], altcoinCurrency, 0L);
editor.putFloat(coin.coins[i] + "_currentUnitValue", currentUnitValue);
editor.putFloat(coin.coins[i] + "_lastDayUnitValue", currentUnitValue);
float unitValue_btc = coin.currencyToCurrency(currentUnitValue, altcoinCurrency, "BTC");
editor.putFloat(coin.coins[i] + "_currentUnitValue_btc", unitValue_btc);
editor.putFloat(coin.coins[i] + "_lastDayUnitValue_btc", unitValue_btc);
} else {
currentUnitValue_btc = coin.getCoinValue(coin.coins[i], "BTC", 0L);
lastDayUnitValue_btc = coin.getCoinValue(coin.coins[i], "BTC", new UnixTimestamp().getYesterdayUnixTimestamp());
String altcoinCurrency = prefs.getString(coin.coins[i] + "_currency", "EUR");
float currentUnitValue = coin.getCoinValue(coin.coins[i], altcoinCurrency, 0L);
editor.putFloat(coin.coins[i] + "_currentUnitValue", currentUnitValue);
float lastDayUnitValue = coin.getCoinValue(coin.coins[i], altcoinCurrency, new UnixTimestamp().getYesterdayUnixTimestamp());
editor.putFloat(coin.coins[i] + "_lastDayUnitValue", lastDayUnitValue);
float lastDayUnitValue_btc, currentUnitValue_btc;
if (coin.coins[i].equals("BTC")) {
currentUnitValue_btc = 1f;
lastDayUnitValue_btc = 1f;
} else {
currentUnitValue_btc = coin.getCoinValue(coin.coins[i], "BTC", 0L);
lastDayUnitValue_btc = coin.getCoinValue(coin.coins[i], "BTC", new UnixTimestamp().getYesterdayUnixTimestamp());
}
editor.putFloat(coin.coins[i] + "_currentUnitValue_btc", currentUnitValue_btc);
editor.putFloat(coin.coins[i] + "_lastDayUnitValue_btc", lastDayUnitValue_btc);
}
if (initCoinsLogos) {
......@@ -100,10 +115,6 @@ public class LoadingActivity extends AppCompatActivity {
}
}
editor.putFloat(coin.coins[i] + "_currentUnitValue_btc", currentUnitValue_btc);
editor.putFloat(coin.coins[i] + "_lastDayUnitValue_btc", lastDayUnitValue_btc);
editor.apply();
progressBarProgess += progressBarSlotTime;
progressBar.setProgress(progressBarProgess);
}
......
......@@ -16,6 +16,7 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
......
......@@ -2,6 +2,7 @@ package eu.uwot.fabio.altcoinprices.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;
import org.json.JSONException;
......@@ -299,7 +300,7 @@ public class Coin {
put("ZIL", "binance");
put("ZRX", "binance");
put("BLX", "cryptocompare");
put("BLX", "cryptocompare_icndaa");
put("CCC", "cryptocompare_icndaa");
put("SOPR", "cryptocompare_icndaa");
put("FCI", "cryptocompare_icndaa");
......@@ -585,10 +586,10 @@ public class Coin {
public float getCoinValue(String altcoinName, String currency, long unixTimestamp) {
float coinValue;
if (!getCoinExchange(altcoinName).equals("cryptocompare_icndaa")) {
coinValue = getCoinQuoteCryptoCompare(altcoinName, currency, unixTimestamp);
if (getCoinExchange(altcoinName).equals("cryptocompare_icndaa")) {
coinValue = getCoinQuoteIconomiDDA(altcoinName, currency);
} else {
coinValue = -1f;
coinValue = getCoinQuoteCryptoCompare(altcoinName, currency, unixTimestamp);
}
// Exchange API are down or reporting broken values
......@@ -606,6 +607,59 @@ public class Coin {
return coinValue;
}
// Get coin change in _currency_ from https://api.iconomi.com //
// CURRENT REQUEST: https://api.iconomi.com/v1/daa/BLX/price
// CURRENT RESPONSE: {"ticker":"BLX","currency":"USD","price":"1.18766689"}
private float getCoinQuoteIconomiDDA(String altcoinSymbol, String currency) {
URL url = null;
HttpURLConnection urlConnection = null;
StringBuilder dataSTR = new StringBuilder();
float coinQuote = -1f;
try {
url = new URL("https://api.iconomi.com/v1/daa/" + altcoinSymbol + "/price");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
assert url != null;
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(5000); // 5 seconds timeout
InputStream in = urlConnection.getInputStream();
InputStreamReader isw = new InputStreamReader(in);
int data = isw.read();
while (data != -1) {
char current = (char) data;
data = isw.read();
dataSTR.append(Character.toString(current));
}
} catch (SocketTimeoutException e) {
dataSTR = new StringBuilder("0");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
assert urlConnection != null;
urlConnection.disconnect();
}
JSONObject json;
try {
json = new JSONObject(dataSTR.toString());
coinQuote = (float) json.getDouble("price");
} catch (JSONException e) {
e.printStackTrace();
}
coinQuote = currencyToCurrency(coinQuote, "USD", currency);
return coinQuote;
}
// Get coin change in _currency_ from cryptocompare.com //
// CURRENT REQUEST: https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD
// CURRENT RESPONSE: {"USD":6945.12}
......
......@@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:3.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
#Mon Oct 22 15:03:05 CEST 2018
#Fri Apr 19 22:24:18 CEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment