Add exchange/pair selection after each parent choice in the RecordTransactionActivity

This commit is contained in:
Tanguy Herbron 2018-08-04 03:04:07 +02:00
parent ac3ad43775
commit cf8cc29329
40 changed files with 615 additions and 141 deletions

2
.idea/gradle.xml generated
View File

@ -5,7 +5,7 @@
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-4.9" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-4.4" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View File

@ -2,7 +2,6 @@ package com.herbron.moodl.Activities;
import android.content.Intent;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
@ -46,7 +45,7 @@ public class AddExchangeActivity extends AppCompatActivity {
exchangeSpinner = findViewById(R.id.exchange_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.supported_exchanges, R.layout.exchange_spinner_item);
R.array.supported_exchanges, R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

View File

@ -21,7 +21,7 @@ import com.herbron.moodl.DataManagers.CurrencyData.Currency;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
import com.herbron.moodl.DataManagers.DatabaseManager;
import com.herbron.moodl.DataManagers.PreferencesManager;
import com.herbron.moodl.LayoutManagers.CoinWatchlistAdapter;
import com.herbron.moodl.CustomAdapters.CoinWatchlistAdapter;
import com.herbron.moodl.R;
import java.util.ArrayList;

View File

@ -2,12 +2,10 @@ package com.herbron.moodl.Activities.DetailsActivityFragments;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -15,7 +13,6 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
@ -37,7 +34,7 @@ import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDataChart;
import com.herbron.moodl.DataManagers.PreferencesManager;
import com.herbron.moodl.LayoutManagers.CustomViewPager;
import com.herbron.moodl.CustomLayouts.CustomViewPager;
import com.herbron.moodl.MoodlBox;
import com.herbron.moodl.PlaceholderManager;
import com.herbron.moodl.R;

View File

@ -23,8 +23,8 @@ import com.herbron.moodl.DataManagers.CurrencyData.Transaction;
import com.herbron.moodl.DataManagers.DatabaseManager;
import com.herbron.moodl.DataManagers.ExchangeManager.BinanceManager;
import com.herbron.moodl.DataManagers.PreferencesManager;
import com.herbron.moodl.LayoutManagers.TradeListAdapter;
import com.herbron.moodl.LayoutManagers.TransactionListAdapter;
import com.herbron.moodl.CustomAdapters.TradeListAdapter;
import com.herbron.moodl.CustomAdapters.TransactionListAdapter;
import com.herbron.moodl.R;
import java.util.ArrayList;

View File

@ -3,30 +3,21 @@ package com.herbron.moodl.Activities;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import com.herbron.moodl.DataManagers.DatabaseManager;
import com.herbron.moodl.DataManagers.ExchangeManager.Exchange;
import com.herbron.moodl.LayoutManagers.ExchangeListAdapter;
import com.herbron.moodl.CustomAdapters.ExchangeDescriptionListAdapter;
import com.herbron.moodl.R;
import java.util.ArrayList;
import java.util.List;
import static com.herbron.moodl.DataManagers.DatabaseManager.BINANCE_TYPE;
import static com.herbron.moodl.DataManagers.DatabaseManager.HITBTC_TYPE;
public class ExchangeListActivity extends AppCompatActivity {
private DatabaseManager databaseManager;
private ListView exchangeListView;
private ExchangeListAdapter exchangeListAdapter;
private ExchangeDescriptionListAdapter exchangeDescriptionListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -55,10 +46,10 @@ public class ExchangeListActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
exchangeListAdapter = new ExchangeListAdapter(getApplicationContext(), databaseManager.getExchanges());
exchangeDescriptionListAdapter = new ExchangeDescriptionListAdapter(getApplicationContext(), databaseManager.getExchanges());
exchangeListView.setAdapter(exchangeListAdapter);
exchangeListAdapter.notifyDataSetChanged();
exchangeListView.setAdapter(exchangeDescriptionListAdapter);
exchangeDescriptionListAdapter.notifyDataSetChanged();
}
@Override

View File

@ -33,7 +33,7 @@ import com.herbron.moodl.DataManagers.CurrencyData.Currency;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CoinmarketCapAPIManager;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
import com.herbron.moodl.DataManagers.PreferencesManager;
import com.herbron.moodl.LayoutManagers.CustomPieChart;
import com.herbron.moodl.CustomLayouts.CustomPieChart;
import com.herbron.moodl.MoodlBox;
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
import com.herbron.moodl.PlaceholderManager;

View File

@ -22,7 +22,7 @@ import com.herbron.moodl.DataManagers.CurrencyData.Currency;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CoinmarketCapAPIManager;
import com.herbron.moodl.DataManagers.PreferencesManager;
import com.herbron.moodl.LayoutManagers.OverviewListAdapter;
import com.herbron.moodl.CustomAdapters.OverviewListAdapter;
import com.herbron.moodl.MoodlBox;
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
import com.herbron.moodl.R;

View File

@ -13,6 +13,7 @@ import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
@ -26,13 +27,18 @@ import android.widget.TextView;
import android.widget.TimePicker;
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
import com.herbron.moodl.CustomAdapters.PairRecordListAdapter;
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
import com.herbron.moodl.DataManagers.ExchangeManager.Exchange;
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
import com.herbron.moodl.DataManagers.DatabaseManager;
import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair;
import com.herbron.moodl.DataManagers.PreferencesManager;
import com.herbron.moodl.LayoutManagers.CoinSummaryListAdapter;
import com.herbron.moodl.LayoutManagers.CustomTabLayout;
import com.herbron.moodl.LayoutManagers.RecordTransactionPageAdapter;
import com.herbron.moodl.DataNotifiers.CryptocompareNotifierInterface;
import com.herbron.moodl.CustomAdapters.CoinRecordListAdapter;
import com.herbron.moodl.CustomLayouts.CustomTabLayout;
import com.herbron.moodl.CustomAdapters.ExchangeRecordListAdapter;
import com.herbron.moodl.CustomAdapters.RecordTransactionPageAdapter;
import com.herbron.moodl.MoodlBox;
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
import com.herbron.moodl.PlaceholderManager;
@ -43,7 +49,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
public class RecordTransactionActivity extends AppCompatActivity implements CurrencyInfoUpdateNotifierInterface {
public class RecordTransactionActivity extends AppCompatActivity implements CurrencyInfoUpdateNotifierInterface, CryptocompareNotifierInterface {
private String coin;
private String symbol;
@ -60,14 +66,21 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
private SimpleDateFormat sdf;
private PreferencesManager preferenceManager;
private EditText purchasedPriceEditText;
private Currency currency;
private int transactionId;
private Toolbar toolbar;
private ImageView currencyIconImageView;
private Currency currency;
private Exchange exchange;
private Pair pair;
private CryptocompareApiManager cryptocompareApiManager;
private AutoCompleteTextView coin_autoCompleteTextView;
private AutoCompleteTextView exchange_autoCompleteTextView;
private AutoCompleteTextView pair_autoCompleteTextView;
private SearchView mainSearchView;
/*@Override
@ -176,8 +189,6 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
databaseManager = new DatabaseManager(this);
preferenceManager = new PreferencesManager(this);
//initializeViewElements();
coin = intent.getStringExtra("coin");
symbol = intent.getStringExtra("symbol");
@ -186,13 +197,31 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
toolbar = findViewById(R.id.toolbar);
currencyIconImageView = findViewById(R.id.currencyIconImageView);
cryptocompareApiManager = CryptocompareApiManager.getInstance(this);
cryptocompareApiManager.addListener(this);
cryptocompareApiManager.updateExchangeList();
coin_autoCompleteTextView = findViewById(R.id.coin_autoCompleteTextView);
exchange_autoCompleteTextView = findViewById(R.id.exchange_autoCompleteTextView);
pair_autoCompleteTextView = findViewById(R.id.pair_autoCompleteTextView);
setSupportActionBar(toolbar);
setupAutoCompleteTextView();
setupTabLayout();
setupCoinAutoCompleteTextView();
setupExchangeAutoCompleteTextView();
setupPairAutoCompleteTextView();
setupBackButton();
}
private void setupTabLayout()
{
CustomTabLayout tabLayout = findViewById(R.id.transactionsTabLayout);
tabLayout.addTab(0, "Buy");
tabLayout.addTab(1, "Sell");
@ -219,17 +248,123 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
}
});
cryptocompareApiManager.updateExchangeList();
}
private void setupAutoCompleteTextView()
private void setupPairAutoCompleteTextView()
{
cryptocompareApiManager = CryptocompareApiManager.getInstance(this);
pair_autoCompleteTextView.setThreshold(0);
pair_autoCompleteTextView.setTextColor(getResources().getColor(R.color.white));
CoinSummaryListAdapter adapter = new CoinSummaryListAdapter(this, R.layout.custom_summary_coin_row, new ArrayList<>(cryptocompareApiManager.getCurrenciesDenomination()));
pair_autoCompleteTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pair_autoCompleteTextView.showDropDown();
}
});
pair_autoCompleteTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
{
pair_autoCompleteTextView.showDropDown();
}
else
{
pair_autoCompleteTextView.dismissDropDown();
}
}
});
pair_autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
pair = (Pair) pair_autoCompleteTextView.getAdapter().getItem(position);
pair_autoCompleteTextView.setText(PlaceholderManager.getPairString(pair.getFrom(), pair.getTo(), getBaseContext()));
toolbar.requestFocus();
hideSoftKeyboard(RecordTransactionActivity.this);
}
});
}
private void setupExchangeAutoCompleteTextView()
{
exchange_autoCompleteTextView.setThreshold(0);
exchange_autoCompleteTextView.setTextColor(getResources().getColor(R.color.white));
exchange_autoCompleteTextView.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) {
pair_autoCompleteTextView.setEnabled(false);
pair_autoCompleteTextView.setText("");
}
@Override
public void afterTextChanged(Editable s) {
}
});
exchange_autoCompleteTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
exchange_autoCompleteTextView.showDropDown();
}
});
exchange_autoCompleteTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
{
exchange_autoCompleteTextView.showDropDown();
}
else
{
exchange_autoCompleteTextView.dismissDropDown();
}
}
});
exchange_autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
exchange = (Exchange) exchange_autoCompleteTextView.getAdapter().getItem(position);
exchange_autoCompleteTextView.setText(exchange.getName());
toolbar.requestFocus();
hideSoftKeyboard(RecordTransactionActivity.this);
updatePairAdapter();
pair_autoCompleteTextView.setEnabled(true);
}
});
}
private void updatePairAdapter()
{
PairRecordListAdapter pairAdapter = new PairRecordListAdapter(this, android.R.layout.simple_list_item_1, new ArrayList<>(exchange.getPairsFor(currency.getSymbol())));
pair_autoCompleteTextView.setAdapter(pairAdapter);
}
private void updateExchangeAdapter(String symbol)
{
ExchangeRecordListAdapter exchangeAdapter = new ExchangeRecordListAdapter(this, android.R.layout.simple_list_item_1, new ArrayList<>(cryptocompareApiManager.getExchangeList(symbol)));
exchange_autoCompleteTextView.setAdapter(exchangeAdapter);
}
private void setupCoinAutoCompleteTextView()
{
CoinRecordListAdapter adapter = new CoinRecordListAdapter(this, R.layout.custom_summary_coin_row, new ArrayList<>(cryptocompareApiManager.getCurrenciesDenomination()));
AutoCompleteTextView coin_autoCompleteTextView = findViewById(R.id.coin_autoCompleteTextView);
coin_autoCompleteTextView.setThreshold(0);
coin_autoCompleteTextView.setAdapter(adapter);
coin_autoCompleteTextView.setTextColor(getResources().getColor(R.color.white));
@ -242,6 +377,8 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
currencyIconImageView.setImageBitmap(null);
exchange_autoCompleteTextView.setEnabled(false);
exchange_autoCompleteTextView.setText("");
}
@Override
@ -249,6 +386,14 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
}
});
coin_autoCompleteTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
coin_autoCompleteTextView.showDropDown();
}
});
coin_autoCompleteTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
@ -266,7 +411,7 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
coin_autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Currency currency = (Currency) coin_autoCompleteTextView.getAdapter().getItem(position);
currency = (Currency) coin_autoCompleteTextView.getAdapter().getItem(position);
coin_autoCompleteTextView.setText(PlaceholderManager.getDenomination(currency.getName(), currency.getSymbol(), getBaseContext()));
toolbar.requestFocus();
@ -274,7 +419,8 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
currency.setListener(RecordTransactionActivity.this);
RecordTransactionActivity.this.currency = currency;
updateExchangeAdapter(currency.getSymbol());
exchange_autoCompleteTextView.setEnabled(true);
IconDownloaderTask iconDownloaderTask = new IconDownloaderTask();
iconDownloaderTask.execute();
@ -297,6 +443,16 @@ public class RecordTransactionActivity extends AppCompatActivity implements Curr
}
@Override
public void onDetailsUpdated() {
}
@Override
public void onExchangesUpdated() {
}
private class IconDownloaderTask extends AsyncTask<Void, Void, Void> {
@Override

View File

@ -22,12 +22,6 @@ public class BuyFragment extends Fragment implements CryptocompareNotifierInterf
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_buy, container, false);
cryptocompareApiManager = CryptocompareApiManager.getInstance(getContext());
cryptocompareApiManager.addListener(this);
cryptocompareApiManager.updateExchangeList();
return view;
}
@ -38,6 +32,6 @@ public class BuyFragment extends Fragment implements CryptocompareNotifierInterf
@Override
public void onExchangesUpdated() {
Log.d("moodl", "Received ! " + cryptocompareApiManager.getExchangeList().get(0).getName());
}
}

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomAdapters;
import android.content.Context;
import android.support.annotation.NonNull;
@ -15,12 +15,12 @@ import com.herbron.moodl.R;
import java.util.ArrayList;
public class CoinSummaryListAdapter extends ArrayAdapter<Currency> {
public class CoinRecordListAdapter extends ArrayAdapter<Currency> {
private CustomFilter filter;
private ArrayList<Currency> currencies, suggestions;
public CoinSummaryListAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Currency> currencies) {
public CoinRecordListAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Currency> currencies) {
super(context, resource, currencies);
this.currencies = currencies;
@ -72,7 +72,7 @@ public class CoinSummaryListAdapter extends ArrayAdapter<Currency> {
return filter;
}
class CustomFilter extends Filter
private class CustomFilter extends Filter
{
@Override

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomAdapters;
import android.content.Context;
import android.support.annotation.NonNull;

View File

@ -1,42 +1,28 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomAdapters;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.herbron.moodl.Activities.AddExchangeActivity;
import com.herbron.moodl.Activities.ExchangeListActivity;
import com.herbron.moodl.DataManagers.CurrencyData.Currency;
import com.herbron.moodl.DataManagers.CurrencyData.Trade;
import com.herbron.moodl.DataManagers.DatabaseManager;
import com.herbron.moodl.DataManagers.ExchangeManager.Exchange;
import com.herbron.moodl.MoodlBox;
import com.herbron.moodl.R;
import java.util.ArrayList;
import static com.herbron.moodl.MoodlBox.getDateFromTimestamp;
public class ExchangeListAdapter extends ArrayAdapter<Exchange> {
public class ExchangeDescriptionListAdapter extends ArrayAdapter<Exchange> {
private Context context;
public ExchangeListAdapter(Context context, ArrayList<Exchange> exchanges)
public ExchangeDescriptionListAdapter(Context context, ArrayList<Exchange> exchanges)
{
super(context, android.R.layout.simple_list_item_1, exchanges);

View File

@ -0,0 +1,120 @@
package com.herbron.moodl.CustomAdapters;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.TextView;
import com.herbron.moodl.DataManagers.ExchangeManager.Exchange;
import com.herbron.moodl.R;
import java.util.ArrayList;
public class ExchangeRecordListAdapter extends ArrayAdapter<Exchange> {
private CustomFilter filter;
private ArrayList<Exchange> exchanges, suggestions;
public ExchangeRecordListAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Exchange> exchanges) {
super(context, resource, exchanges);
this.exchanges = exchanges;
this.suggestions = exchanges;
}
@NonNull
@Override
public Filter getFilter() {
if(filter == null)
{
filter = new CustomFilter();
}
return filter;
}
@Override
public int getCount() {
return exchanges.size();
}
@Nullable
@Override
public Exchange getItem(int position) {
return exchanges.get(position);
}
@Override
public long getItemId(int position) {
return exchanges.indexOf(getItem(position));
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
Exchange exchange = getItem(position);
if(convertView == null)
{
convertView = LayoutInflater.from(getContext()).inflate(R.layout.simple_spinner_item, parent, false);
}
TextView nameTxtview = convertView.findViewById(R.id.textView);
nameTxtview.setTextColor(getContext().getResources().getColor(android.R.color.tab_indicator_text));
nameTxtview.setText(exchange.getName());
return convertView;
}
private class CustomFilter extends Filter
{
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if(constraint != null && constraint.length() > 0)
{
constraint = constraint.toString().toLowerCase();
ArrayList<Exchange> filters = new ArrayList<>();
for(int i = 0; i < suggestions.size(); i++)
{
if(suggestions.get(i).getName().toLowerCase().contains(constraint))
{
Exchange exchange = new Exchange(suggestions.get(i));
filters.add(exchange);
}
}
results.count = filters.size();
results.values = filters;
}
else
{
results.count = suggestions.size();
results.values = suggestions;
}
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if(results != null)
{
exchanges = (ArrayList<Exchange>) results.values;
}
notifyDataSetChanged();
}
}
}

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomAdapters;
import android.app.Activity;
import android.content.Context;

View File

@ -0,0 +1,121 @@
package com.herbron.moodl.CustomAdapters;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.TextView;
import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair;
import com.herbron.moodl.PlaceholderManager;
import com.herbron.moodl.R;
import java.util.ArrayList;
public class PairRecordListAdapter extends ArrayAdapter<Pair> {
private CustomFilter filter;
private ArrayList<Pair> pairs, suggestions;
public PairRecordListAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Pair> pairs) {
super(context, resource, pairs);
this.pairs = pairs;
this.suggestions = pairs;
}
@NonNull
@Override
public Filter getFilter() {
if(filter == null)
{
filter = new CustomFilter();
}
return filter;
}
@Override
public int getCount() {
return pairs.size();
}
@Nullable
@Override
public Pair getItem(int position) {
return pairs.get(position);
}
@Override
public long getItemId(int position) {
return pairs.indexOf(getItem(position));
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
Pair pair = getItem(position);
if(convertView == null)
{
convertView = LayoutInflater.from(getContext()).inflate(R.layout.simple_spinner_item, parent, false);
}
TextView pairTxtView = convertView.findViewById(R.id.textView);
pairTxtView.setTextColor(getContext().getResources().getColor(android.R.color.tab_indicator_text));
pairTxtView.setText(PlaceholderManager.getPairString(pair.getFrom(), pair.getTo(), getContext()));
return convertView;
}
private class CustomFilter extends Filter
{
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if(constraint != null && constraint.length() > 0)
{
constraint = constraint.toString().toUpperCase();
ArrayList<Pair> filters = new ArrayList<>();
for(int i = 0; i < suggestions.size(); i++)
{
if(suggestions.get(i).getFrom().contains(constraint) || suggestions.get(i).getTo().contains(constraint))
{
Pair pair = new Pair(suggestions.get(i));
filters.add(pair);
}
}
results.count = filters.size();
results.values = filters;
}
else
{
results.count = suggestions.size();
results.values = suggestions;
}
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if(results != null)
{
pairs = (ArrayList<Pair>) results.values;
}
notifyDataSetChanged();
}
}
}

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomAdapters;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomAdapters;
import android.content.Context;
import android.support.annotation.NonNull;

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomAdapters;
import android.app.Activity;
import android.content.Context;

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomLayouts;
import android.content.Context;
import android.util.AttributeSet;

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomLayouts;
import android.content.Context;
import android.graphics.drawable.StateListDrawable;

View File

@ -1,4 +1,4 @@
package com.herbron.moodl.LayoutManagers;
package com.herbron.moodl.CustomLayouts;
import android.content.Context;
import android.support.v4.view.ViewPager;

View File

@ -2,6 +2,7 @@ package com.herbron.moodl.DataManagers.ExchangeManager;
import com.herbron.moodl.DataManagers.InfoAPIManagers.Pair;
import java.util.ArrayList;
import java.util.List;
public class Exchange {
@ -32,6 +33,17 @@ public class Exchange {
this.pairs = pairs;
}
public Exchange(Exchange exchange)
{
this.name = exchange.name;
this.pairs = exchange.pairs;
}
public List<Pair> getPairs()
{
return pairs;
}
public boolean isEnabled()
{
return isEnabled;
@ -66,4 +78,19 @@ public class Exchange {
{
return id;
}
public List<Pair> getPairsFor(String symbol)
{
List<Pair> compatiblePairs = new ArrayList<>();
for(Pair pair : pairs)
{
if(pair.contains(symbol))
{
compatiblePairs.add(pair);
}
}
return compatiblePairs;
}
}

View File

@ -141,21 +141,21 @@ public class CryptocompareApiManager {
JSONObject exchangeJsonObject = mainJsonObject.getJSONObject(exchangeKey);
Iterator<String> pairIterator = exchangeJsonObject.keys();
List<Pair> pairList = new ArrayList<>();
while(pairIterator.hasNext())
{
String pairKey = pairIterator.next();
JSONArray pairJsonArray = exchangeJsonObject.getJSONArray(pairKey);
List<Pair> pairList = new ArrayList<>();
for(int i = 0; i < pairJsonArray.length(); i++)
{
pairList.add(new Pair(pairKey, pairJsonArray.get(i).toString()));
}
}
exchangeList.add(new Exchange(exchangeKey, pairList));
}
}
for(CryptocompareNotifierInterface cryptocompareNotifierInterface : cryptocompareNotifierInterfaceList)
{
@ -167,9 +167,28 @@ public class CryptocompareApiManager {
}
}
public List<Exchange> getExchangeList()
public List<Exchange> getExchangeList(String symbol)
{
return exchangeList;
List<Exchange> compatibleExchanges = new ArrayList<>();
for(Exchange exchange : exchangeList)
{
int i = 0;
boolean isSymbolTraded = false;
while(i < exchange.getPairs().size() && !isSymbolTraded)
{
if(exchange.getPairs().get(i).contains(symbol))
{
compatibleExchanges.add(exchange);
isSymbolTraded = true;
}
i++;
}
}
return compatibleExchanges;
}
private void processDetailResult(String response)

View File

@ -11,8 +11,26 @@ public class Pair {
this.to = to;
}
public Pair(Pair pair)
{
this.from = pair.from;
this.to = pair.to;
}
public boolean contains(String symbol)
{
symbol = symbol.toUpperCase();
return symbol.equals(from) || symbol.equals(to);
}
public String getFrom()
{
return from;
}
public String getTo()
{
return to;
}
}

View File

@ -34,6 +34,11 @@ public class PlaceholderManager {
return formattedString;
}
public static String getPairString(String pair1, String pair2, Context context)
{
return context.getResources().getString(R.string.pairPlaceholder, pair1, pair2);
}
public static String getDenomination(String coinName, String coinSymbol, Context context)
{
return context.getResources().getString(R.string.denomincationPlaceholder, coinName, coinSymbol);

View File

@ -12,7 +12,7 @@
<shape>
<corners android:topRightRadius="5dp"
android:topLeftRadius="5dp"/>
<solid android:color="@color/captionColor"/>
<solid android:color="@color/hardWhite"/>
</shape>
</item>
</selector>

View File

@ -7,11 +7,12 @@
<solid android:color="@color/decreaseCandle"/>
</shape>
</item>
<item android:state_selected="false" android:state_focused="false" android:state_pressed="false">
<shape>
<corners android:topRightRadius="5dp"
android:topLeftRadius="5dp"/>
<solid android:color="@color/captionColor"/>
<solid android:color="@color/hardWhite"/>
</shape>
</item>
</selector>

View File

@ -7,11 +7,12 @@
<solid android:color="@color/blue"/>
</shape>
</item>
<item android:state_selected="false" android:state_focused="false" android:state_pressed="false">
<shape>
<corners android:topRightRadius="5dp"
android:topLeftRadius="5dp"/>
<solid android:color="@color/captionColor"/>
<solid android:color="@color/hardWhite"/>
</shape>
</item>
</selector>

View File

@ -1,5 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/hardWhite"/>
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
<padding
android:left="3dp"
android:right="3dp"
android:top="3dp"
android:bottom="3dp"/>
</shape>
</item>
<item
android:gravity="center_vertical|right"
android:drawable="@drawable/ic_arrow_drop_down_white_24dp"/>
</layer-list>
</item>
<item android:state_enabled="false">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/softWhite"/>
@ -17,4 +41,6 @@
<item
android:gravity="center_vertical|right"
android:drawable="@drawable/ic_arrow_drop_down_white_24dp"/>
</layer-list>
</layer-list>
</item>
</selector>

View File

@ -2,7 +2,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/softWhite"/>
<solid android:color="@color/hardWhite"/>
<corners
android:topLeftRadius="5dp"

View File

@ -6,7 +6,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.herbron.moodl.Activities.CurrencyDetailsActivity">
<com.herbron.moodl.LayoutManagers.CustomViewPager
<com.herbron.moodl.CustomLayouts.CustomViewPager
android:id="@+id/vfCurrencyDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -9,7 +9,7 @@
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="125dp"
android:layout_height="@dimen/double_toolbarSpinner_size"
app:layout_collapseMode="pin"
app:elevation="0dp"
app:contentInsetLeft="0dp"
@ -49,8 +49,7 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="22dp"
android:layout_height="@dimen/spinner_toolbar_height"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp">
@ -63,7 +62,6 @@
android:textSize="18sp"
android:hint="@string/select_coin"
android:inputType="textNoSuggestions"
android:layout_gravity="center"
android:gravity="center"/>
<ImageView
@ -75,6 +73,39 @@
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/spinner_toolbar_height"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp">
<AutoCompleteTextView
android:id="@+id/exchange_autoCompleteTextView"
android:layout_width="0dp"
android:layout_weight="1.7"
android:layout_marginEnd="12dp"
android:layout_height="@dimen/spinner_toolbar_height"
android:background="@drawable/spinner_background"
android:hint="@string/select_exchange"
android:inputType="textNoSuggestions"
android:gravity="center"
android:enabled="false"/>
<AutoCompleteTextView
android:id="@+id/pair_autoCompleteTextView"
android:layout_width="0dp"
android:layout_height="@dimen/spinner_toolbar_height"
android:layout_weight="1.2"
android:background="@drawable/spinner_background"
android:hint="@string/select_pair"
android:inputType="textNoSuggestions"
android:gravity="center"
android:enabled="false"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
@ -82,16 +113,15 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="125dp"
android:layout_marginTop="@dimen/double_toolbarSpinner_size"
android:paddingTop="5dp"
android:orientation="vertical">
<com.herbron.moodl.LayoutManagers.CustomTabLayout
<com.herbron.moodl.CustomLayouts.CustomTabLayout
android:id="@+id/transactionsTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabBackground="@drawable/record_transaction_tab_background_buy"
app:tabIndicatorColor="@color/transparent"/>
<android.support.v4.view.ViewPager

View File

@ -23,7 +23,6 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:gravity="center_vertical|center_horizontal"
android:text=""
android:textColor="@color/captionColor"
android:textSize="12sp" />
</LinearLayout>

View File

@ -11,32 +11,6 @@
android:layout_margin="@dimen/margin"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_exchangeName"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/exchangeName_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/exchange"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_exchangePair"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/exchangePair_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/pair"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_amount"
android:layout_width="match_parent"

View File

@ -77,7 +77,7 @@
android:layout_height="350dp"
android:layout_marginTop="5dp">
<com.herbron.moodl.LayoutManagers.CustomPieChart
<com.herbron.moodl.CustomLayouts.CustomPieChart
android:id="@+id/marketCapPieChart"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"

View File

@ -42,6 +42,7 @@
<color name="default_color">#FFAAAAAA</color>
<color name="captionColor">#FF898989</color>
<color name="softWhite">#66FFFFFF</color>
<color name="hardWhite">#88FFFFFF</color>
<color name="binance">#FFF5BC00</color>
</resources>

View File

@ -16,4 +16,9 @@
<dimen name="fragment_padding">15dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="simple_toolbarSpinner_size">125dp</dimen>
<dimen name="double_toolbarSpinner_size">180dp</dimen>
<dimen name="spinner_toolbar_height">50dp</dimen>
</resources>

View File

@ -179,6 +179,7 @@
<string name="fluctuationYenPercentagePlaceholder" translatable="false">%1$s¥ (%2$s%%)</string>
<string name="denomincationPlaceholder" translatable="false">%1$s (%2$s)</string>
<string name="pairPlaceholder" translatable="false">%1$s/%2$s</string>
<!--DetailsActivity placeholders-->
<string name="timestampPlaceholder">Date\n%1$s</string>
@ -265,5 +266,7 @@
<string name="pair">Pair</string>
<string name="total_value">Total value</string>
<string name="notes">Notes</string>
<string name="select_exchange">Select an exchange</string>
<string name="select_pair">Pair</string>
</resources>