diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index cf8f721..4083388 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -40,6 +40,7 @@ import com.daasuu.ei.Ease; import com.daasuu.ei.EasingInterpolator; import com.herbron.moodl.Activities.CurrencySelectionActivity; import com.herbron.moodl.Activities.HomeActivity; +import com.herbron.moodl.Activities.RecordTransactionActivity; import com.herbron.moodl.BalanceUpdateInterface; import com.herbron.moodl.DataManagers.BalanceManager; import com.herbron.moodl.DataManagers.CurrencyData.Currency; @@ -180,6 +181,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, refreshLayout.setRefreshing(false); showErrorSnackbar(); + Log.d("moodl", "Error > Refresh out of time"); } if (loadingDialog.isShowing()) @@ -187,6 +189,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, loadingDialog.dismiss(); showErrorSnackbar(); + Log.d("moodl", "Error > Refresh out of time"); } } }; @@ -242,7 +245,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, addCurrencyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Intent addIntent = new Intent(getActivity(), CurrencySelectionActivity.class); + Intent addIntent = new Intent(getActivity(), RecordTransactionActivity.class); startActivity(addIntent); } diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java index a278e9d..b904cee 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionActivity.java @@ -4,6 +4,8 @@ import android.content.Intent; import android.os.Bundle; import android.support.design.widget.TextInputLayout; import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.SearchView; +import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; @@ -47,6 +49,8 @@ public class RecordTransactionActivity extends AppCompatActivity { private Currency currency; private int transactionId; + private SearchView mainSearchView; + @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); @@ -54,7 +58,7 @@ public class RecordTransactionActivity extends AppCompatActivity { return true; } - @Override + /*@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_record: @@ -94,7 +98,7 @@ public class RecordTransactionActivity extends AppCompatActivity { break; } return true; - } + }*/ private boolean checkPriceText() { @@ -160,14 +164,18 @@ public class RecordTransactionActivity extends AppCompatActivity { databaseManager = new DatabaseManager(this); preferenceManager = new PreferencesManager(this); - initializeViewElements(); + //initializeViewElements(); coin = intent.getStringExtra("coin"); symbol = intent.getStringExtra("symbol"); transactionId = intent.getIntExtra("transactionId", -1); - if(transactionId != -1) + Toolbar toolbar = findViewById(R.id.searchCurrencyToolbar); + + setSupportActionBar(toolbar); + + /*if(transactionId != -1) { setTitle(PlaceholderManager.getEditTransactionString(coin, getBaseContext())); @@ -206,17 +214,17 @@ public class RecordTransactionActivity extends AppCompatActivity { } }); - initializeButtons(); + //initializeButtons(); currency.getTimestampPrice(this, preferenceManager.getDefaultCurrency(), new Currency.PriceCallBack() { @Override public void onSuccess(String price) { purchasedPriceEditText.setText(price); } - }, calendar.getTimeInMillis() / 1000); + }, calendar.getTimeInMillis() / 1000);*/ } - private void initializeButtons() + /*private void initializeButtons() { buyButton.setOnClickListener(new View.OnClickListener() { @Override @@ -262,7 +270,7 @@ public class RecordTransactionActivity extends AppCompatActivity { buyButton = findViewById(R.id.buyButton); sellButton = findViewById(R.id.sellButton); transferButton = findViewById(R.id.transfertButton); - } + }*/ private void createDatePicker() { diff --git a/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java b/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java index b920683..a08fd4f 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java @@ -288,57 +288,58 @@ public class SettingsActivity extends AppCompatPreferenceActivity { { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getContext()); FingerprintDialogFragment newFragment = FingerprintDialogFragment.newInstance(); + SwitchPreference touchdIdSwitch = (SwitchPreference) findPreference("enable_fingerprint"); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + { + keyguardManager = (KeyguardManager) this.getActivity().getSystemService(KEYGUARD_SERVICE); + fingerprintManager = (FingerprintManager) this.getActivity().getSystemService(FINGERPRINT_SERVICE); + + try { + if(!fingerprintManager.isHardwareDetected()) + { + touchdIdSwitch.setEnabled(false); + } + + if(ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) + { + touchdIdSwitch.setEnabled(false); + } + + if(!fingerprintManager.hasEnrolledFingerprints()) + { + touchdIdSwitch.setEnabled(false); + } + + if(!keyguardManager.isKeyguardSecure()) + { + touchdIdSwitch.setEnabled(false); + } + else + { + try { + generateKey(); + } catch (FingerprintException e) { + e.printStackTrace(); + } + + if(initCipher()) + { + cryptoObject = new FingerprintManager.CryptoObject(cipher); + + FingerprintHandler helper = new FingerprintHandler(this.getContext(), newFragment); + helper.startAuth(fingerprintManager, cryptoObject); + } + } + } catch (NullPointerException e) { + e.printStackTrace(); + } + } if(preferences.getBoolean("enable_fingerprint", false)) { newFragment.setCancelable(false); newFragment.show(getFragmentManager(), "dialog"); - - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - { - keyguardManager = (KeyguardManager) this.getActivity().getSystemService(KEYGUARD_SERVICE); - fingerprintManager = (FingerprintManager) this.getActivity().getSystemService(FINGERPRINT_SERVICE); - - try { - if(!fingerprintManager.isHardwareDetected()) - { - this.getActivity().findViewById(R.id.fingerprint_switch).setVisibility(View.GONE); - } - - if(ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) - { - this.getActivity().findViewById(R.id.fingerprint_switch).setVisibility(View.GONE); - } - - if(!fingerprintManager.hasEnrolledFingerprints()) - { - this.getActivity().findViewById(R.id.fingerprint_switch).setVisibility(View.GONE); - } - - if(!keyguardManager.isKeyguardSecure()) - { - this.getActivity().findViewById(R.id.fingerprint_switch).setVisibility(View.GONE); - } - else - { - try { - generateKey(); - } catch (FingerprintException e) { - e.printStackTrace(); - } - - if(initCipher()) - { - cryptoObject = new FingerprintManager.CryptoObject(cipher); - - FingerprintHandler helper = new FingerprintHandler(this.getContext(), newFragment); - helper.startAuth(fingerprintManager, cryptoObject); - } - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - } } } @@ -720,9 +721,29 @@ public class SettingsActivity extends AppCompatPreferenceActivity { for(int i = 0; i < watchlistArray.length(); i++) { - JSONObject transactionObject = watchlistArray.getJSONObject(i); + JSONObject watchlistObject = watchlistArray.getJSONObject(i); - databaseManager.addRowWatchlist(transactionObject, getContext(), enterPasswordCheckbox.isChecked()); + databaseManager.addRowWatchlist(watchlistObject, getContext(), enterPasswordCheckbox.isChecked()); + } + } + } + + if(restoreApiKeysCheckbox.isChecked()) + { + if(wipeApiKeyxCheckbox.isChecked()) + { + databaseManager.wipeData(DatabaseManager.TABLE_EXCHANGE_KEYS); + } + + if(backupJson.has("apiKeys")) + { + JSONArray apiArray = backupJson.getJSONArray("apiKeys"); + + for(int i = 0; i < apiArray.length(); i++) + { + JSONObject apiKeysObject = apiArray.getJSONObject(i); + + databaseManager.addRowApiKeys(apiKeysObject, getContext(), enterPasswordCheckbox.isChecked()); } } } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java index 398db93..2d5018d 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/BalanceManager.java @@ -96,25 +96,13 @@ public class BalanceManager { public void updateExchangeKeys() { - String publicKey = preferenceManager.getHitBTCPublicKey(); - String privateKey = preferenceManager.getHitBTCPrivateKey(); - hitBtcManagers.clear(); - if(preferenceManager.isHitBTCActivated() && publicKey != null && privateKey != null) - { - hitBtcManagers.add(new HitBtcManager(context, publicKey, privateKey)); - } - - publicKey = preferenceManager.getBinancePublicKey(); - privateKey = preferenceManager.getBinancePrivateKey(); + hitBtcManagers = databaseManager.getHitBtcAccounts(context); binanceManagers.clear(); - if(preferenceManager.isBinanceActivated() && publicKey != null && privateKey != null) - { - binanceManagers.add(new BinanceManager(publicKey, privateKey)); - } + binanceManagers = databaseManager.getBinanceAccounts(); } public List getTotalBalance() diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java index 9d53637..c3d9aab 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java @@ -71,6 +71,11 @@ public class CurrencyDetailsList { public boolean isUpToDate() { + if(coinInfosHashmap == null) + { + upToDate = false; + } + return upToDate; } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyTickerList.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyTickerList.java index 4658027..8769dfd 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyTickerList.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyTickerList.java @@ -49,6 +49,11 @@ public class CurrencyTickerList { public boolean isUpToDate() { + if(currencyTickerList == null) + { + upToDate = false; + } + return upToDate; } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java index d33df71..a66fddc 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -9,13 +9,17 @@ import android.util.Log; import com.herbron.moodl.DataManagers.CurrencyData.Currency; import com.herbron.moodl.DataManagers.CurrencyData.Transaction; +import com.herbron.moodl.DataManagers.ExchangeManager.BinanceManager; +import com.herbron.moodl.DataManagers.ExchangeManager.HitBtcManager; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; +import java.util.Iterator; import java.util.List; /** @@ -24,7 +28,7 @@ import java.util.List; public class DatabaseManager extends SQLiteOpenHelper{ - private static final int DATABASE_VERSION = 7; + private static final int DATABASE_VERSION = 8; private static final String DATABASE_NAME = "Currencies.db"; @@ -43,6 +47,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ private static final String KEY_EXCHANGE_ID = "idExchange"; private static final String KEY_EXCHANGE_NAME = "name"; + private static final String KEY_EXCHANGE_TYPE = "type"; private static final String KEY_EXCHANGE_DESCRIPTION = "description"; private static final String KEY_EXCHANGE_PUBLIC_KEY = "publicKey"; private static final String KEY_EXCHANGE_SECRET_KEY = "secretKey"; @@ -52,6 +57,9 @@ public class DatabaseManager extends SQLiteOpenHelper{ private static final String KEY_WATCHLIST_NAME = "name"; private static final String KEY_WATCHLIST_POSITION = "position"; + private static final int BINANCE_TYPE = 0; + private static final int HITBTC_TYPE = 1; + public DatabaseManager(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); @@ -73,6 +81,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_EXCHANGE_KEYS + "(" + KEY_EXCHANGE_ID + " INTEGER PRIMARY KEY," + + KEY_EXCHANGE_TYPE + " INTEGER," + KEY_EXCHANGE_NAME + " TEXT," + KEY_EXCHANGE_DESCRIPTION + " TEXT," + KEY_EXCHANGE_PUBLIC_KEY + " TEXT," @@ -96,7 +105,10 @@ public class DatabaseManager extends SQLiteOpenHelper{ { case 6: db.execSQL("ALTER TABLE " + TABLE_EXCHANGE_KEYS - + " ADD " + KEY_EXCHANGE_DESCRIPTION+ " VARCHAR"); + + " ADD " + KEY_EXCHANGE_DESCRIPTION + " TEXT"); + case 7: + db.execSQL("ALTER TABLE " + TABLE_EXCHANGE_KEYS + + " ADD " + KEY_EXCHANGE_TYPE + " INTEGER"); } } @@ -198,6 +210,9 @@ public class DatabaseManager extends SQLiteOpenHelper{ backupArray.put(backupObject); } + result.close(); + db.close(); + return backupArray; } @@ -207,6 +222,49 @@ public class DatabaseManager extends SQLiteOpenHelper{ db.execSQL("DELETE FROM "+ table); } + public void addRawData(Context context, JSONObject rawValues, String table, boolean decrypt) + { + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues values = new ContentValues(); + + while(rawValues.keys().hasNext()) + { + String key = rawValues.keys().next(); + + try { + if(decrypt) + { + values.put(key, DataCrypter.decrypt(context, rawValues.getString(key))); + } + else + { + values.put(key, rawValues.getString(key)); + } + } catch (JSONException e) { + Log.d("moodl", "Error while inserting " + key + " " + e.getMessage()); + } + } + + db.insert(table, null, values); + db.close(); + } + + public void addRowApiKeys(JSONObject rawValues, Context context, boolean decrypt) + { + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues values = new ContentValues(); + + try { + + if(decrypt) + { + values.put(KEY_EXCHANGE_NAME, DataCrypter.decrypt(context, rawValues.getString(KEY_WATCHLIST_SYMBOL))); + } + } catch (JSONException e) { + Log.d("moodl", "Error while inserting api key " + e.getMessage()); + } + } + public void addRowWatchlist(JSONObject rawValues, Context context, boolean decrypt) { SQLiteDatabase db = this.getWritableDatabase(); @@ -226,10 +284,10 @@ public class DatabaseManager extends SQLiteOpenHelper{ values.put(KEY_WATCHLIST_POSITION, rawValues.getString(KEY_WATCHLIST_POSITION)); } } catch (JSONException e) { - Log.d("moodl", "Error while inserting transaction"); + Log.d("moodl", "Error while inserting watchlist " + e.getMessage()); } - db.insert(TABLE_MANUAL_CURRENCIES, null, values); + db.insert(TABLE_WATCHLIST, null, values); db.close(); } @@ -260,7 +318,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ values.put(KEY_CURRENCY_FEES, rawValues.getString(KEY_CURRENCY_FEES)); } } catch (JSONException e) { - Log.d("moodl", "Error while inserting transaction"); + Log.d("moodl", "Error while inserting transaction " + e.getMessage()); } db.insert(TABLE_MANUAL_CURRENCIES, null, values); @@ -280,22 +338,48 @@ public class DatabaseManager extends SQLiteOpenHelper{ currencyList.add(new Currency(resultList.getString(2), resultList.getString(1))); } + resultList.close(); + db.close(); + return currencyList; } - public void addCurrencyToManualCurrency(String symbol, double balance, Date date, double purchasedPrice, double fees) + public List getHitBtcAccounts(Context context) { + String searchQuerry = "SELECT * FROM " + TABLE_EXCHANGE_KEYS + " WHERE " + KEY_EXCHANGE_TYPE + "='" + HITBTC_TYPE + "'"; SQLiteDatabase db = this.getWritableDatabase(); - ContentValues values = new ContentValues(); + Cursor resultList = db.rawQuery(searchQuerry, null); - values.put(KEY_CURRENCY_SYMBOL, symbol); - values.put(KEY_CURRENCY_BALANCE, balance); - values.put(KEY_CURRENCY_DATE, date.getTime()); - values.put(KEY_CURRENCY_PURCHASED_PRICE, purchasedPrice); - values.put(KEY_CURRENCY_FEES, fees); + List accountList = new ArrayList<>(); - db.insert(TABLE_MANUAL_CURRENCIES, null, values); + while(resultList.moveToNext()) + { + accountList.add(new HitBtcManager(context, resultList.getString(4), resultList.getString(5))); + } + + resultList.close(); db.close(); + + return accountList; + } + + public List getBinanceAccounts() + { + String searchQuerry = "SELECT * FROM " + TABLE_EXCHANGE_KEYS + " WHERE " + KEY_EXCHANGE_TYPE + "='" + BINANCE_TYPE + "'"; + SQLiteDatabase db = this.getWritableDatabase(); + Cursor resultList = db.rawQuery(searchQuerry, null); + + List accountList = new ArrayList<>(); + + while(resultList.moveToNext()) + { + accountList.add(new BinanceManager(resultList.getString(4), resultList.getString(5))); + } + + resultList.close(); + db.close(); + + return accountList; } public List getAllCurrenciesFromManualCurrency() diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java index 0a6d95d..4110957 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java @@ -48,6 +48,16 @@ public class PreferencesManager { return settingPreferences.getString("hitbtc_privatekey", null); } + public String getBinancePublicKey() + { + return settingPreferences.getString("binance_publickey", null); + } + + public String getBinancePrivateKey() + { + return settingPreferences.getString("binance_privatekey", null); + } + public boolean isHitBTCActivated() { return settingPreferences.getBoolean("enable_hitbtc", false); @@ -74,16 +84,6 @@ public class PreferencesManager { editor.apply(); } - public String getBinancePublicKey() - { - return settingPreferences.getString("binance_publickey", null); - } - - public String getBinancePrivateKey() - { - return settingPreferences.getString("binance_privatekey", null); - } - public boolean isBinanceActivated() { return settingPreferences.getBoolean("enable_binance", false); diff --git a/app/src/main/res/layout/activity_record_transaction.xml b/app/src/main/res/layout/activity_record_transaction.xml index 28fc376..998c41a 100644 --- a/app/src/main/res/layout/activity_record_transaction.xml +++ b/app/src/main/res/layout/activity_record_transaction.xml @@ -3,15 +3,24 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" tools:context="com.herbron.moodl.Activities.RecordTransactionActivity"> - + android:layout_height="wrap_content" + android:background="@color/colorPrimary" + android:minHeight="?attr/actionBarSize" + app:theme="@style/ThemeOverlay.AppCompat.Dark" /> - + - - + --> diff --git a/app/src/main/res/menu/menu_record_action.xml b/app/src/main/res/menu/menu_record_action.xml index 59275d4..ba39a95 100644 --- a/app/src/main/res/menu/menu_record_action.xml +++ b/app/src/main/res/menu/menu_record_action.xml @@ -2,9 +2,11 @@ - + \ No newline at end of file