From 3a1ac3c80bc80f65b02ad7fc001c2fb4805b8f1b Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 14 Aug 2018 04:14:18 +0200 Subject: [PATCH] Major updates - Fix code typos - Add a 'fromSym' field in the transactions table - Fix translation in the drawer [RecordTransactionActivity rework] - New currency selection - Add Exchange selection - Add corresponding Pair selection - Add tabs to select Buy/Sell/Transaction > Buy fragment - Add note field - Add fee format selection - Limit date selection to the past (it's no longer possible to add a futur transaction) - Auto fill the price after date selection --- .idea/assetWizardSettings.xml | 4 +- .idea/caches/build_file_checksums.ser | Bin 545 -> 545 bytes app/build.gradle | 2 +- .../DetailsActivityFragments/Charts.java | 2 +- .../HomeActivityFragments/Summary.java | 2 +- .../HomeActivityFragments/Watchlist.java | 2 +- .../Activities/RecordTransactionActivity.java | 305 ++++++++---------- .../BuyFragment.java | 295 ++++++++++++++++- .../SellFragment.java | 18 +- .../TransferFragment.java | 18 +- .../CurrencyInfoUpdateNotifierInterface.java | 2 +- .../CustomLayouts/CustomRecordFragment.java | 41 +++ .../moodl/CustomLayouts/CustomTabLayout.java | 19 +- .../DataManagers/CurrencyData/Currency.java | 22 +- .../CurrencyData/CurrencyCardview.java | 2 +- .../moodl/DataManagers/DatabaseManager.java | 72 ++++- .../ExchangeManager/BinanceManager.java | 2 +- .../DataManagers/PreferencesManager.java | 25 -- .../com/herbron/moodl/PlaceholderManager.java | 13 + app/src/main/res/anim/dismiss.xml | 10 + app/src/main/res/anim/reveal.xml | 10 + .../res/drawable/disabled_tab_background.xml | 17 + .../drawable/ic_arrow_drop_up_white_24dp.xml | 5 + .../record_transaction_tab_background_buy.xml | 31 +- ...record_transaction_tab_background_sell.xml | 31 +- ...rd_transaction_tab_background_transfer.xml | 31 +- .../layout/activity_record_transaction.xml | 4 +- app/src/main/res/layout/fragment_buy.xml | 15 +- .../main/res/layout/summary_drawer_header.xml | 11 +- app/src/main/res/menu/menu_record_action.xml | 12 - app/src/main/res/values-fr/strings.xml | 4 + app/src/main/res/values/strings.xml | 4 + build.gradle | 2 +- 33 files changed, 723 insertions(+), 310 deletions(-) create mode 100644 app/src/main/java/com/herbron/moodl/CustomLayouts/CustomRecordFragment.java create mode 100644 app/src/main/res/anim/dismiss.xml create mode 100644 app/src/main/res/anim/reveal.xml create mode 100644 app/src/main/res/drawable/disabled_tab_background.xml create mode 100644 app/src/main/res/drawable/ic_arrow_drop_up_white_24dp.xml delete mode 100644 app/src/main/res/menu/menu_record_action.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index cad50d5..943e267 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -23,7 +23,7 @@ @@ -34,7 +34,7 @@ diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 083b9b606dd7bd77bba8a5a769b32d9350239cee..ade57472755c33bf79039d6ed2cf8f39c522ab98 100644 GIT binary patch delta 56 zcmV-80LTBK1fc|wm;^R1jY^T6cM$w3E^y7luZl@At__gGJ%y7a0YwlUj)#;VUxQ3r OeVEr{zV-l(cryptocompareApiManager.getCurrenciesDenomination())); + CoinRecordListAdapter adapter = new CoinRecordListAdapter(getBaseContext(), R.layout.custom_summary_coin_row, new ArrayList<>(cryptocompareApiManager.getCurrenciesDenomination())); coin_autoCompleteTextView.setThreshold(0); coin_autoCompleteTextView.setAdapter(adapter); @@ -379,6 +391,13 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr currencyIconImageView.setImageBitmap(null); exchange_autoCompleteTextView.setEnabled(false); exchange_autoCompleteTextView.setText(""); + + ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(2).setEnabled(false); + + if(isGlobalLayoutVisible && globalTabLayouts.getAnimation().hasEnded()) + { + globalTabLayouts.startAnimation(dismissAnimation); + } } @Override @@ -424,13 +443,53 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr IconDownloaderTask iconDownloaderTask = new IconDownloaderTask(); iconDownloaderTask.execute(); + + ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(0).setEnabled(false); + ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(1).setEnabled(false); + ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(2).setEnabled(true); + tabLayout.getTabAt(2).select(); + + updateCurrencyData(); + + if(globalTabLayouts.getVisibility() == View.GONE) + { + globalTabLayouts.setVisibility(View.VISIBLE); + } + + globalTabLayouts.startAnimation(revealAnimation); + + isGlobalLayoutVisible = true; } }); } + private void updateCurrencyData() + { + for(int i = 0; i < pageAdapter.getCount(); i++) + { + ((CustomRecordFragment) pageAdapter.getItem(i)).setCurrency(currency); + } + } + + private void updateExchangeData() + { + for(int i = 0; i < pageAdapter.getCount(); i++) + { + ((CustomRecordFragment) pageAdapter.getItem(i)).setExchange(exchange); + } + } + + private void updatePairData() + { + for(int i = 0; i < pageAdapter.getCount(); i++) + { + ((CustomRecordFragment) pageAdapter.getItem(i)).setPair(pair); + } + } + @Override - public void onTimestampPriveUpdated(String price) { - purchasedPriceEditText.setText(price); + public void onTimestampPriceUpdated(String price) { + //purchasedPriceEditText.setText(price); } @Override @@ -543,54 +602,6 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr activity.getCurrentFocus().getWindowToken(), 0); } - /*private void initializeButtons() - { - buyButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - buyButton.setEnabled(false); - sellButton.setEnabled(true); - transferButton.setEnabled(true); - findViewById(R.id.input_purchase_price).setVisibility(View.VISIBLE); - findViewById(R.id.input_fees).setVisibility(View.GONE); - } - }); - - sellButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - buyButton.setEnabled(true); - sellButton.setEnabled(false); - transferButton.setEnabled(true); - findViewById(R.id.input_purchase_price).setVisibility(View.GONE); - findViewById(R.id.input_fees).setVisibility(View.VISIBLE); - } - }); - - transferButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - buyButton.setEnabled(true); - sellButton.setEnabled(true); - transferButton.setEnabled(false); - // Prepare transfer interface - } - }); - } - - private void initializeViewElements() - { - symbolTxtView = findViewById(R.id.currencySymbol); - amountTxtView = findViewById(R.id.currencyAmount); - feesTxtView = findViewById(R.id.feesTextView); - purchasedDateLayout = findViewById(R.id.input_purchase_date); - purchaseDate = findViewById(R.id.purchaseDate); - purchasedPriceEditText = findViewById(R.id.purchasePrice); - buyButton = findViewById(R.id.buyButton); - sellButton = findViewById(R.id.sellButton); - transferButton = findViewById(R.id.transfertButton); - }*/ - private void setupBackButton() { ImageButton backButton = findViewById(R.id.back_button); @@ -601,44 +612,4 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr } }); } - - private void createDatePicker() - { - new android.app.DatePickerDialog( - RecordTransactionActivity.this, - new android.app.DatePickerDialog.OnDateSetListener() { - @Override - public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { - calendar.set(Calendar.YEAR, year); - calendar.set(Calendar.MONTH, month); - calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); - purchaseDate.setText(sdf.format(calendar.getTime())); - createTimePicker(); - } - }, - calendar.get(Calendar.YEAR), - calendar.get(Calendar.MONTH), - calendar.get(Calendar.DAY_OF_MONTH) - ).show(); - } - - private void createTimePicker() - { - new android.app.TimePickerDialog( - RecordTransactionActivity.this, - new android.app.TimePickerDialog.OnTimeSetListener() { - @Override - public void onTimeSet(TimePicker view, int hour, int minute) { - calendar.set(Calendar.HOUR_OF_DAY, hour); - calendar.set(Calendar.MINUTE, minute); - purchaseDate.setText(sdf.format(calendar.getTime())); - - currency.getTimestampPrice(RecordTransactionActivity.this, preferenceManager.getDefaultCurrency(),calendar.getTimeInMillis() / 1000); - } - }, - calendar.get(Calendar.HOUR_OF_DAY), - calendar.get(Calendar.MINUTE), - true - ).show(); - } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/BuyFragment.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/BuyFragment.java index 41cac85..df49f70 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/BuyFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/BuyFragment.java @@ -1,37 +1,312 @@ package com.herbron.moodl.Activities.RecordTransactionFragments; +import android.app.DatePickerDialog; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; +import android.support.design.widget.TextInputEditText; +import android.support.v7.widget.AppCompatButton; +import android.text.Editable; +import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.DatePicker; +import android.widget.Spinner; +import android.widget.TimePicker; -import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface; -import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager; +import com.herbron.moodl.Activities.HomeActivity; +import com.herbron.moodl.CustomLayouts.CustomRecordFragment; +import com.herbron.moodl.DataManagers.CurrencyData.Currency; +import com.herbron.moodl.DataManagers.DatabaseManager; +import com.herbron.moodl.DataManagers.ExchangeManager.Exchange; +import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair; +import com.herbron.moodl.DataManagers.PreferencesManager; +import com.herbron.moodl.PlaceholderManager; import com.herbron.moodl.R; -public class BuyFragment extends Fragment implements CryptocompareNotifierInterface { +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Locale; - private CryptocompareApiManager cryptocompareApiManager; +public class BuyFragment extends CustomRecordFragment { + + private TextInputEditText amoutEditText; + private TextInputEditText buyPriceEditText; + private TextInputEditText buyDateEditText; + private TextInputEditText totalValueEditText; + private TextInputEditText fees_editText; + private TextInputEditText note_editText; + private AppCompatButton saveBuyButton; + private static Spinner feesCurrencySpinner; + private static View view; + + private ArrayAdapter currencyAdapter; + + private SimpleDateFormat sdf; + private Calendar calendar; + private PreferencesManager preferenceManager; + + private static Context context; + + private static Currency fragmentCurrency; + private static Exchange fragmentExchange; + private static Pair fragmentPair; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_buy, container, false); + view = inflater.inflate(R.layout.fragment_buy, container, false); + + context = getActivity().getApplicationContext(); + + calendar = Calendar.getInstance(); + sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy", Locale.UK); + + preferenceManager = new PreferencesManager(getContext()); + + initializeViewElements(); return view; } - @Override - public void onDetailsUpdated() { + private void initializeViewElements() + { + totalValueEditText = view.findViewById(R.id.totalValue_editText); + amoutEditText = view.findViewById(R.id.amount_editText); + amoutEditText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + if(isFieldCorrectlyFilled(buyPriceEditText, false) && isFieldCorrectlyFilled(amoutEditText, false)) + { + if(Double.parseDouble(amoutEditText.getText().toString()) > 0) + { + Double totalValue = Double.parseDouble(buyPriceEditText.getText().toString()) * Double.parseDouble(s.toString()); + totalValueEditText.setText(String.format("%f", totalValue)); + } + else + { + totalValueEditText.setText("0"); + } + } + else + { + totalValueEditText.setText(""); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + buyPriceEditText = view.findViewById(R.id.buyPrice_editText); + buyDateEditText = view.findViewById(R.id.buyDate_editText); + buyDateEditText.setText(sdf.format(calendar.getTime())); + + buyDateEditText.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + createDatePicker(); + } + }); + feesCurrencySpinner = view.findViewById(R.id.feesCurrency_editText); + + currencyAdapter = new ArrayAdapter(getSecureContext(), android.R.layout.simple_spinner_item, new ArrayList<>()); + currencyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + feesCurrencySpinner.setAdapter(currencyAdapter); + + if(fragmentPair != null) + { + updateAdapter(); + } + + saveBuyButton = view.findViewById(R.id.saveBuyButton); + saveBuyButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(isFieldCorrectlyFilled(amoutEditText, true) && isFieldCorrectlyFilled(buyPriceEditText, true) && isFieldCorrectlyFilled(totalValueEditText, true)) + { + double amount = Double.parseDouble(amoutEditText.getText().toString()); + double purchasedPrice = Double.parseDouble(buyPriceEditText.getText().toString()); + double fees; + + if(fees_editText.getText().toString().equals("")) + { + fees = 0; + } + else + { + fees = Double.parseDouble(fees_editText.getText().toString()); + } + + String note = note_editText.getText().toString(); + + DatabaseManager databaseManager = new DatabaseManager(getContext()); + + databaseManager.addTransaction(fragmentCurrency.getSymbol() + , amount + , calendar.getTime() + , purchasedPrice + , fees + , note + , fragmentPair.getFrom().equals(fragmentCurrency.getSymbol()) ? fragmentPair.getTo() : fragmentPair.getFrom()); + + preferenceManager.setMustUpdateSummary(true); + Intent intent = new Intent(getActivity(), HomeActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); + getActivity().finish(); + } + } + }); + + fees_editText = view.findViewById(R.id.fees_editText); + note_editText = view.findViewById(R.id.note_editText); + } + + private boolean isFieldCorrectlyFilled(TextInputEditText editText, boolean displayError) + { + String purchasedPriceText = editText.getText().toString(); + double purchasedPrice; + + try { + purchasedPrice = Double.parseDouble(purchasedPriceText); + + if(purchasedPrice < 0) + { + if(displayError) editText.setError(getResources().getString(R.string.field_negative)); + + return false; + } + } catch (NumberFormatException e) { + if(displayError) editText.setError(getResources().getString(R.string.field_nan)); + + return false; + } + + if(purchasedPriceText.equals("")) + { + if(displayError) editText.setError(getResources().getString(R.string.field_empty)); + + return false; + } + + return true; + } + + private void updateAdapter() + { + List symbolStrings = new ArrayList<>(); + symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getFrom(), getSecureContext())); + symbolStrings.addAll(PlaceholderManager.getFeeOptionsForSymbol(fragmentPair.getTo(), getSecureContext())); + + currencyAdapter.clear(); + currencyAdapter.addAll(symbolStrings); + currencyAdapter.notifyDataSetChanged(); + } + + private void createDatePicker() + { + DatePickerDialog datePickerDialog = new DatePickerDialog( + getContext(), + new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { + calendar.set(Calendar.YEAR, year); + calendar.set(Calendar.MONTH, month); + calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); + buyDateEditText.setText(sdf.format(calendar.getTime())); + createTimePicker(); + } + }, + calendar.get(Calendar.YEAR), + calendar.get(Calendar.MONTH), + calendar.get(Calendar.DAY_OF_MONTH) + ); + + datePickerDialog.getDatePicker().setMaxDate(Calendar.getInstance().getTimeInMillis()); + datePickerDialog.show(); + } + + private void createTimePicker() + { + new android.app.TimePickerDialog( + getContext(), + new android.app.TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hour, int minute) { + calendar.set(Calendar.HOUR_OF_DAY, hour); + calendar.set(Calendar.MINUTE, minute); + buyDateEditText.setText(sdf.format(calendar.getTime())); + + if(fragmentCurrency != null) + { + fragmentCurrency.getTimestampPrice(getContext(), preferenceManager.getDefaultCurrency(),calendar.getTimeInMillis() / 1000); + } + } + }, + calendar.get(Calendar.HOUR_OF_DAY), + calendar.get(Calendar.MINUTE), + true + ).show(); + } + + private static Context getSecureContext() + { + return context; } @Override - public void onExchangesUpdated() { - + public void onCurrencyUpdated() { + fragmentCurrency = currency; } + + @Override + public void onExchangeUpdated() { + fragmentExchange = exchange; + } + + @Override + public void onPairUpdated() { + fragmentPair = pair; + + fragmentCurrency.setOnTimestampPriceUpdatedListener(new Currency.OnTimestampPriceUpdatedListener() { + @Override + public void onTimeStampPriceUpdated(String price) { + ((TextInputEditText) view.findViewById(R.id.buyPrice_editText)).setText(price); + + if(currencyAdapter != null) + { + updateAdapter(); + } + } + }); + + if(preferenceManager == null) + { + preferenceManager = new PreferencesManager(getSecureContext()); + } + + if(calendar == null) + { + calendar = Calendar.getInstance(); + } + + fragmentCurrency.getTimestampPrice(getSecureContext(), preferenceManager.getDefaultCurrency(), calendar.getTimeInMillis() / 1000); + } + } diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/SellFragment.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/SellFragment.java index fd3a83f..7faf575 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/SellFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/SellFragment.java @@ -8,9 +8,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import com.herbron.moodl.CustomLayouts.CustomRecordFragment; import com.herbron.moodl.R; -public class SellFragment extends Fragment { +public class SellFragment extends CustomRecordFragment { @Nullable @Override @@ -18,4 +19,19 @@ public class SellFragment extends Fragment { View view = inflater.inflate(R.layout.fragment_sell, container, false); return view; } + + @Override + public void onCurrencyUpdated() { + + } + + @Override + public void onExchangeUpdated() { + + } + + @Override + public void onPairUpdated() { + + } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/TransferFragment.java b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/TransferFragment.java index 49f2b2b..42121ee 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/TransferFragment.java +++ b/app/src/main/java/com/herbron/moodl/Activities/RecordTransactionFragments/TransferFragment.java @@ -8,9 +8,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import com.herbron.moodl.CustomLayouts.CustomRecordFragment; import com.herbron.moodl.R; -public class TransferFragment extends Fragment { +public class TransferFragment extends CustomRecordFragment { @Nullable @Override @@ -18,4 +19,19 @@ public class TransferFragment extends Fragment { View view = inflater.inflate(R.layout.fragment_transfer, container, false); return view; } + + @Override + public void onCurrencyUpdated() { + + } + + @Override + public void onExchangeUpdated() { + + } + + @Override + public void onPairUpdated() { + + } } diff --git a/app/src/main/java/com/herbron/moodl/CurrencyInfoUpdateNotifierInterface.java b/app/src/main/java/com/herbron/moodl/CurrencyInfoUpdateNotifierInterface.java index b8731cb..b93b101 100644 --- a/app/src/main/java/com/herbron/moodl/CurrencyInfoUpdateNotifierInterface.java +++ b/app/src/main/java/com/herbron/moodl/CurrencyInfoUpdateNotifierInterface.java @@ -4,7 +4,7 @@ import com.herbron.moodl.DataManagers.CurrencyData.Currency; public interface CurrencyInfoUpdateNotifierInterface { - void onTimestampPriveUpdated(String price); + void onTimestampPriceUpdated(String price); void onHistoryDataUpdated(); diff --git a/app/src/main/java/com/herbron/moodl/CustomLayouts/CustomRecordFragment.java b/app/src/main/java/com/herbron/moodl/CustomLayouts/CustomRecordFragment.java new file mode 100644 index 0000000..f2f5b2b --- /dev/null +++ b/app/src/main/java/com/herbron/moodl/CustomLayouts/CustomRecordFragment.java @@ -0,0 +1,41 @@ +package com.herbron.moodl.CustomLayouts; + +import android.support.v4.app.Fragment; + +import com.herbron.moodl.DataManagers.CurrencyData.Currency; +import com.herbron.moodl.DataManagers.ExchangeManager.Exchange; +import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair; + +public abstract class CustomRecordFragment extends Fragment { + + protected Currency currency; + protected Exchange exchange; + protected Pair pair; + + public void setCurrency(Currency currency) + { + this.currency = currency; + + onCurrencyUpdated(); + } + + public void setExchange(Exchange exchange) + { + this.exchange = exchange; + + onExchangeUpdated(); + } + + public void setPair(Pair pair) + { + this.pair = pair; + + onPairUpdated(); + } + + public abstract void onCurrencyUpdated(); + + public abstract void onExchangeUpdated(); + + public abstract void onPairUpdated(); +} diff --git a/app/src/main/java/com/herbron/moodl/CustomLayouts/CustomTabLayout.java b/app/src/main/java/com/herbron/moodl/CustomLayouts/CustomTabLayout.java index ccb3965..df32836 100644 --- a/app/src/main/java/com/herbron/moodl/CustomLayouts/CustomTabLayout.java +++ b/app/src/main/java/com/herbron/moodl/CustomLayouts/CustomTabLayout.java @@ -27,39 +27,44 @@ public class CustomTabLayout extends TabLayout { private StateListDrawable getSellStateListDrawable() { StateListDrawable sld = new StateListDrawable(); sld.addState(new int[] {android.R.attr.state_pressed}, - ContextCompat.getDrawable(context, R.drawable.record_transaction_tab_background_sell)); + ContextCompat.getDrawable(context, R.drawable.unselected_tab_background)); sld.addState(new int[] {android.R.attr.state_selected}, ContextCompat.getDrawable(context, R.drawable.record_transaction_tab_background_sell)); - sld.addState(new int[] { }, + sld.addState(new int[] {android.R.attr.state_enabled }, ContextCompat.getDrawable(context, R.drawable.unselected_tab_background)); + sld.addState(new int[] { }, + ContextCompat.getDrawable(context, R.drawable.disabled_tab_background)); return sld; } private StateListDrawable getBuyStateListDrawable() { StateListDrawable sld = new StateListDrawable(); sld.addState(new int[] {android.R.attr.state_pressed}, - ContextCompat.getDrawable(context, R.drawable.record_transaction_tab_background_buy)); + ContextCompat.getDrawable(context, R.drawable.unselected_tab_background)); sld.addState(new int[] {android.R.attr.state_selected}, ContextCompat.getDrawable(context, R.drawable.record_transaction_tab_background_buy)); - sld.addState(new int[] { }, + sld.addState(new int[] {android.R.attr.state_enabled }, ContextCompat.getDrawable(context, R.drawable.unselected_tab_background)); + sld.addState(new int[] { }, + ContextCompat.getDrawable(context, R.drawable.disabled_tab_background)); return sld; } private StateListDrawable getTransferStateListDrawable() { StateListDrawable sld = new StateListDrawable(); sld.addState(new int[] {android.R.attr.state_pressed}, - ContextCompat.getDrawable(context, R.drawable.record_transaction_tab_background_transfer)); + ContextCompat.getDrawable(context, R.drawable.unselected_tab_background)); sld.addState(new int[] {android.R.attr.state_selected}, ContextCompat.getDrawable(context, R.drawable.record_transaction_tab_background_transfer)); - sld.addState(new int[] { }, + sld.addState(new int[] {android.R.attr.state_enabled }, ContextCompat.getDrawable(context, R.drawable.unselected_tab_background)); + sld.addState(new int[] { }, + ContextCompat.getDrawable(context, R.drawable.disabled_tab_background)); return sld; } public void addTab(int index, String label) { TextView textView = new TextView(context); - textView.setTextColor(getResources().getColor(R.color.white)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); textView.setText(label); textView.setGravity(GRAVITY_CENTER); diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java index 5371bd9..e9e855d 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java @@ -4,13 +4,9 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.os.Parcel; import android.os.Parcelable; -import android.util.Log; import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface; -import org.json.JSONException; -import org.json.JSONObject; - import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; @@ -48,6 +44,7 @@ public class Currency implements Parcelable { private int rank; private String startDate; private List socialMediaLinks; + private OnTimestampPriceUpdatedListener onTimestampPriceUpdatedListener; //private String proofType private CurrencyInfoUpdateNotifierInterface currencyInfoUpdateNotifierInterface; @@ -97,7 +94,12 @@ public class Currency implements Parcelable { @Override public void onSuccess(String price) { - currencyInfoUpdateNotifierInterface.onTimestampPriveUpdated(price); + currencyInfoUpdateNotifierInterface.onTimestampPriceUpdated(price); + + if(onTimestampPriceUpdatedListener != null) + { + onTimestampPriceUpdatedListener.onTimeStampPriceUpdated(price); + } } }, timestamp); } @@ -534,4 +536,14 @@ public class Currency implements Parcelable { return new Currency[size]; } }; + + public interface OnTimestampPriceUpdatedListener + { + void onTimeStampPriceUpdated(String price); + } + + public void setOnTimestampPriceUpdatedListener(OnTimestampPriceUpdatedListener onTimestampPriceUpdatedListener) + { + this.onTimestampPriceUpdatedListener = onTimestampPriceUpdatedListener; + } } diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java index 1c44eeb..8e9333d 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -357,7 +357,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti } @Override - public void onTimestampPriveUpdated(String price) { + public void onTimestampPriceUpdated(String price) { } 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 a6b5297..988a3c5 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -19,6 +19,7 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -29,7 +30,7 @@ import java.util.List; public class DatabaseManager extends SQLiteOpenHelper{ - private static final int DATABASE_VERSION = 10; + private static final int DATABASE_VERSION = 13; private static final String DATABASE_NAME = "Currencies.db"; @@ -39,8 +40,9 @@ public class DatabaseManager extends SQLiteOpenHelper{ private static final String KEY_CURRENCY_ID = "idCurrency"; private static final String KEY_CURRENCY_SYMBOL = "symbol"; - private static final String KEY_CURRENCY_NAME = "name"; + private static final String KEY_CURRENCY_NOTES = "notes"; private static final String KEY_CURRENCY_BALANCE = "balance"; + private static final String KEY_CURRENCY_FROM = "symFrom"; private static final String KEY_CURRENCY_DATE = "addDate"; private static final String KEY_CURRENCY_PURCHASED_PRICE = "purchasedPrice"; private static final String KEY_CURRENCY_IS_MINED = "isMined"; @@ -73,12 +75,13 @@ public class DatabaseManager extends SQLiteOpenHelper{ db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_MANUAL_CURRENCIES + "(" + KEY_CURRENCY_ID + " INTEGER PRIMARY KEY," + KEY_CURRENCY_SYMBOL + " VARCHAR(4)," - + KEY_CURRENCY_NAME + " VARCHAR(45)," + KEY_CURRENCY_BALANCE + " TEXT," + KEY_CURRENCY_DATE + " TEXT," + KEY_CURRENCY_PURCHASED_PRICE + " REAL," + KEY_CURRENCY_IS_MINED + " INTEGER," - + KEY_CURRENCY_FEES + " REAL" + + KEY_CURRENCY_FEES + " REAL," + + KEY_CURRENCY_NOTES + " TEXT," + + KEY_CURRENCY_FROM + " VARCHAR(4)" + ");"); db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_EXCHANGE_KEYS + "(" @@ -118,6 +121,44 @@ public class DatabaseManager extends SQLiteOpenHelper{ case 9: db.execSQL("ALTER TABLE " + TABLE_EXCHANGE_KEYS + " ADD " + KEY_EXCHANGE_IS_ENABLED + " INTEGER"); + case 10: + db.execSQL("CREATE TEMPORARY TABLE " + TABLE_MANUAL_CURRENCIES + "_back(" + + KEY_CURRENCY_ID + " INTEGER PRIMARY KEY," + + KEY_CURRENCY_SYMBOL + " VARCHAR(4)," + + KEY_CURRENCY_BALANCE + " TEXT," + + KEY_CURRENCY_DATE + " TEXT," + + KEY_CURRENCY_PURCHASED_PRICE + " REAL," + + KEY_CURRENCY_IS_MINED + " INTEGER," + + KEY_CURRENCY_FEES + " REAL" + + ");"); + db.execSQL("INSERT INTO " + TABLE_MANUAL_CURRENCIES + "_back SELECT " + + KEY_CURRENCY_ID + "," + + KEY_CURRENCY_SYMBOL + "," + + KEY_CURRENCY_BALANCE + "," + + KEY_CURRENCY_DATE + "," + + KEY_CURRENCY_PURCHASED_PRICE + "," + + KEY_CURRENCY_IS_MINED + "," + + KEY_CURRENCY_FEES + " FROM " + TABLE_MANUAL_CURRENCIES); + db.execSQL("DROP TABLE " + TABLE_MANUAL_CURRENCIES); + db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_MANUAL_CURRENCIES + "(" + + KEY_CURRENCY_ID + " INTEGER PRIMARY KEY," + + KEY_CURRENCY_SYMBOL + " VARCHAR(4)," + + KEY_CURRENCY_BALANCE + " TEXT," + + KEY_CURRENCY_DATE + " TEXT," + + KEY_CURRENCY_PURCHASED_PRICE + " REAL," + + KEY_CURRENCY_IS_MINED + " INTEGER," + + KEY_CURRENCY_FEES + " REAL" + + ");"); + db.execSQL("INSERT INTO " + TABLE_MANUAL_CURRENCIES + " SELECT * FROM " + TABLE_MANUAL_CURRENCIES + "_back"); + db.execSQL("DROP TABLE " + TABLE_MANUAL_CURRENCIES + "_back"); + case 11: + db.execSQL("ALTER TABLE " + TABLE_MANUAL_CURRENCIES + + " ADD " + KEY_CURRENCY_NOTES + " TEXT"); + case 12: + db.execSQL("ALTER TABLE " + TABLE_MANUAL_CURRENCIES + + " ADD " + KEY_CURRENCY_FROM + " VARCHAR(4)"); + db.execSQL("UPDATE " + TABLE_MANUAL_CURRENCIES + + " SET " + KEY_CURRENCY_FROM + "= 'USD'"); } } @@ -152,6 +193,23 @@ public class DatabaseManager extends SQLiteOpenHelper{ return false; } + public void addTransaction(String symbol, Double amount, Date date, Double purchasedPrice, Double fees, String note, String symbolFrom) + { + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues values = new ContentValues(); + + values.put(KEY_CURRENCY_SYMBOL, symbol); + values.put(KEY_CURRENCY_BALANCE, amount); + values.put(KEY_CURRENCY_DATE, date.getTime()); + values.put(KEY_CURRENCY_PURCHASED_PRICE, purchasedPrice); + values.put(KEY_CURRENCY_FEES, fees); + values.put(KEY_CURRENCY_NOTES, note); + values.put(KEY_CURRENCY_FROM, symbolFrom); + + db.insert(TABLE_MANUAL_CURRENCIES, null, values); + db.close(); + } + public void updateWatchlistPosition(String symbol, int position) { SQLiteDatabase db = this.getWritableDatabase(); @@ -397,7 +455,6 @@ public class DatabaseManager extends SQLiteOpenHelper{ if(decrypt) { values.put(KEY_CURRENCY_SYMBOL, DataCrypter.decrypt(context, rawValues.getString(KEY_CURRENCY_SYMBOL))); - values.put(KEY_CURRENCY_NAME, DataCrypter.decrypt(context, rawValues.getString(KEY_CURRENCY_NAME))); values.put(KEY_CURRENCY_BALANCE, DataCrypter.decrypt(context, rawValues.getString(KEY_CURRENCY_BALANCE))); values.put(KEY_CURRENCY_DATE, DataCrypter.decrypt(context, rawValues.getString(KEY_CURRENCY_DATE))); values.put(KEY_CURRENCY_PURCHASED_PRICE, DataCrypter.decrypt(context, rawValues.getString(KEY_CURRENCY_PURCHASED_PRICE))); @@ -407,7 +464,6 @@ public class DatabaseManager extends SQLiteOpenHelper{ else { values.put(KEY_CURRENCY_SYMBOL, rawValues.getString(KEY_CURRENCY_SYMBOL)); - values.put(KEY_CURRENCY_NAME, rawValues.getString(KEY_CURRENCY_NAME)); values.put(KEY_CURRENCY_BALANCE, rawValues.getString(KEY_CURRENCY_BALANCE)); values.put(KEY_CURRENCY_DATE, rawValues.getString(KEY_CURRENCY_DATE)); values.put(KEY_CURRENCY_PURCHASED_PRICE, rawValues.getString(KEY_CURRENCY_PURCHASED_PRICE)); @@ -497,7 +553,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ while(resultatList.moveToNext()) { - currencyList.add(new Currency(resultatList.getString(1), resultatList.getDouble(3) - resultatList.getDouble(7))); + currencyList.add(new Currency(resultatList.getString(1), resultatList.getDouble(2) - resultatList.getDouble(6))); } resultatList.close(); @@ -551,7 +607,7 @@ public class DatabaseManager extends SQLiteOpenHelper{ while (resultatList.moveToNext()) { - transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4), resultatList.getLong(5), resultatList.getDouble(7))); + transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(2), resultatList.getLong(3), resultatList.getLong(4), resultatList.getDouble(6))); } resultatList.close(); diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/ExchangeManager/BinanceManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/ExchangeManager/BinanceManager.java index 5ecd3a6..f33d9bb 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/ExchangeManager/BinanceManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/ExchangeManager/BinanceManager.java @@ -68,7 +68,7 @@ public class BinanceManager extends Exchange { if(Double.parseDouble(assets.get(i).getFree()) > 0 || Double.parseDouble(assets.get(i).getLocked()) > 0) { //balance.add(new Currency(assets.get(i).getAsset(), Double.parseDouble(assets.get(i).getFree()) + Double.parseDouble(assets.get(i).getLocked()))); - if(!assets.get(i).getAsset().equals("VET")) + if(!assets.get(i).getAsset().equals("VEN")) { balance.add(new Currency(assets.get(i).getAsset(), Double.parseDouble(assets.get(i).getFree()) + Double.parseDouble(assets.get(i).getLocked()))); } 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 4110957..65aeca6 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java @@ -38,31 +38,6 @@ public class PreferencesManager { return settingPreferences.getString("default_currency", "USD"); } - public String getHitBTCPublicKey() - { - return settingPreferences.getString("hitbtc_publickey", null); - } - - public String getHitBTCPrivateKey() - { - 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); - } - public boolean switchBalanceHiddenState() { SharedPreferences.Editor editor = settingPreferences.edit(); diff --git a/app/src/main/java/com/herbron/moodl/PlaceholderManager.java b/app/src/main/java/com/herbron/moodl/PlaceholderManager.java index 8a2bd9a..b3ad52a 100644 --- a/app/src/main/java/com/herbron/moodl/PlaceholderManager.java +++ b/app/src/main/java/com/herbron/moodl/PlaceholderManager.java @@ -4,6 +4,9 @@ import android.content.Context; import com.herbron.moodl.DataManagers.PreferencesManager; +import java.util.ArrayList; +import java.util.List; + /** * Created by Tiji on 19/04/2018. */ @@ -34,6 +37,16 @@ public class PlaceholderManager { return formattedString; } + public static List getFeeOptionsForSymbol(String symbol, Context context) + { + List options = new ArrayList<>(); + + options.add(context.getResources().getString(R.string.fixedFee, symbol)); + options.add(context.getResources().getString(R.string.percentageFee, symbol)); + + return options; + } + public static String getPairString(String pair1, String pair2, Context context) { return context.getResources().getString(R.string.pairPlaceholder, pair1, pair2); diff --git a/app/src/main/res/anim/dismiss.xml b/app/src/main/res/anim/dismiss.xml new file mode 100644 index 0000000..2eb244c --- /dev/null +++ b/app/src/main/res/anim/dismiss.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/reveal.xml b/app/src/main/res/anim/reveal.xml new file mode 100644 index 0000000..c7eba3c --- /dev/null +++ b/app/src/main/res/anim/reveal.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/disabled_tab_background.xml b/app/src/main/res/drawable/disabled_tab_background.xml new file mode 100644 index 0000000..ce071fd --- /dev/null +++ b/app/src/main/res/drawable/disabled_tab_background.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_arrow_drop_up_white_24dp.xml b/app/src/main/res/drawable/ic_arrow_drop_up_white_24dp.xml new file mode 100644 index 0000000..1d266ce --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_drop_up_white_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/record_transaction_tab_background_buy.xml b/app/src/main/res/drawable/record_transaction_tab_background_buy.xml index d703b75..e7e477b 100644 --- a/app/src/main/res/drawable/record_transaction_tab_background_buy.xml +++ b/app/src/main/res/drawable/record_transaction_tab_background_buy.xml @@ -1,18 +1,17 @@ - - - - - - - + + + + - - - - - - - \ No newline at end of file + + + + + diff --git a/app/src/main/res/drawable/record_transaction_tab_background_sell.xml b/app/src/main/res/drawable/record_transaction_tab_background_sell.xml index 4c8dcf2..51acf4c 100644 --- a/app/src/main/res/drawable/record_transaction_tab_background_sell.xml +++ b/app/src/main/res/drawable/record_transaction_tab_background_sell.xml @@ -1,18 +1,17 @@ - - - - - - - + + + + - - - - - - - \ No newline at end of file + + + + + diff --git a/app/src/main/res/drawable/record_transaction_tab_background_transfer.xml b/app/src/main/res/drawable/record_transaction_tab_background_transfer.xml index 344c1d1..0d00149 100644 --- a/app/src/main/res/drawable/record_transaction_tab_background_transfer.xml +++ b/app/src/main/res/drawable/record_transaction_tab_background_transfer.xml @@ -1,18 +1,17 @@ - - - - - - - + + + + - - - - - - - \ No newline at end of file + + + + + diff --git a/app/src/main/res/layout/activity_record_transaction.xml b/app/src/main/res/layout/activity_record_transaction.xml index 716091c..f96a74e 100644 --- a/app/src/main/res/layout/activity_record_transaction.xml +++ b/app/src/main/res/layout/activity_record_transaction.xml @@ -111,11 +111,13 @@ + android:orientation="vertical" + android:visibility="invisible"> @@ -26,7 +27,8 @@ + android:orientation="horizontal" + android:baselineAligned="false"> @@ -68,6 +71,7 @@ android:id="@+id/totalValue_editText" android:layout_width="match_parent" android:layout_height="wrap_content" + android:inputType="numberDecimal" android:hint="@string/total_value"/> @@ -81,21 +85,22 @@ android:id="@+id/input_fees" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_weight="0.15"> + android:layout_weight="0.7"> + android:layout_weight="1"/> @@ -116,7 +121,7 @@ + android:text="@string/total_portfolio_value"/> - - - \ No newline at end of file diff --git a/app/src/main/res/menu/menu_record_action.xml b/app/src/main/res/menu/menu_record_action.xml deleted file mode 100644 index ba39a95..0000000 --- a/app/src/main/res/menu/menu_record_action.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 0bf9c38..5cca29f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -153,4 +153,8 @@ Notes Sélectionner un échange Paire + Valeur totale : + + Pourcentage de %1$s + %1$s fixe \ 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 64266be..2423a18 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -268,5 +268,9 @@ Notes Select an exchange Pair + Total portfolio value : + + %1$s percentage + %1$s fixed diff --git a/build.gradle b/build.gradle index 6c02a11..04c6bc4 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.1.4' // NOTE: Do not place your application dependencies here; they belong