Add currency dominance bar
This commit is contained in:
parent
e7378c278b
commit
daf2f0ddc1
@ -130,13 +130,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
|
||||
((BottomNavigationView) findViewById(R.id.navigation_details)).getMenu().getItem(1).setEnabled(false);
|
||||
|
||||
setupActionBar();
|
||||
|
||||
drawTransactionList();
|
||||
|
||||
initializeButtons();
|
||||
|
||||
createCharts(DAY, 1);
|
||||
|
||||
setupActionBar();
|
||||
updateChartTab(DAY, 1);
|
||||
|
||||
BottomNavigationView navigation = findViewById(R.id.navigation_details);
|
||||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
||||
@ -218,13 +218,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
switch (interval)
|
||||
{
|
||||
case "1h":
|
||||
createCharts(HOUR, 1);
|
||||
updateChartTab(HOUR, 1);
|
||||
break;
|
||||
case "3h":
|
||||
createCharts(HOUR, 3);
|
||||
updateChartTab(HOUR, 3);
|
||||
break;
|
||||
case "1d":
|
||||
createCharts(DAY, 1);
|
||||
updateChartTab(DAY, 1);
|
||||
break;
|
||||
case "3d":
|
||||
currency.updateHistoryHours(this, new Currency.CurrencyCallBack() {
|
||||
@ -233,7 +233,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createCharts(CurrencyDetailsActivity.DAY, 3);
|
||||
updateChartTab(CurrencyDetailsActivity.DAY, 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -246,7 +246,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createCharts(CurrencyDetailsActivity.WEEK, 11);
|
||||
updateChartTab(CurrencyDetailsActivity.WEEK, 11);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -259,7 +259,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createCharts(CurrencyDetailsActivity.MONTH, 1);
|
||||
updateChartTab(CurrencyDetailsActivity.MONTH, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -272,7 +272,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createCharts(CurrencyDetailsActivity.MONTH, 3);
|
||||
updateChartTab(CurrencyDetailsActivity.MONTH, 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -285,7 +285,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createCharts(CurrencyDetailsActivity.MONTH, 6);
|
||||
updateChartTab(CurrencyDetailsActivity.MONTH, 6);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -298,7 +298,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
createCharts(CurrencyDetailsActivity.YEAR, 1);
|
||||
updateChartTab(CurrencyDetailsActivity.YEAR, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -307,7 +307,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void createCharts(int timeUnit, int amount)
|
||||
private void updateChartTab(int timeUnit, int amount)
|
||||
{
|
||||
updateChartsData(timeUnit, amount);
|
||||
drawPriceChart();
|
||||
@ -509,7 +509,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
|
||||
for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++)
|
||||
{
|
||||
values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeTo()));
|
||||
values.add(new BarEntry(j, (float) dataChartList.get(j).getVolumeTo()));
|
||||
}
|
||||
|
||||
dataSet = new BarDataSet(values, "Volume");
|
||||
@ -614,7 +614,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
||||
private void updateFluctuation(float start, float end)
|
||||
{
|
||||
float fluctuation = end - start;
|
||||
float percentageFluctuation = (float) (fluctuation / start * 100);
|
||||
float percentageFluctuation = (fluctuation / start * 100);
|
||||
|
||||
if(percentageFluctuation < 0)
|
||||
{
|
||||
|
@ -85,6 +85,7 @@ public class HomeActivity extends AppCompatActivity {
|
||||
private long lastTimestamp;
|
||||
private boolean detailsChecker;
|
||||
private boolean isDetailed;
|
||||
private float totalValue;
|
||||
|
||||
private CollapsingToolbarLayout toolbarLayout;
|
||||
private SwipeRefreshLayout refreshLayout;
|
||||
@ -97,29 +98,6 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
private HashMap<String, Integer> dominantCurrenciesColors;
|
||||
|
||||
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
||||
= new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.navigation_something:
|
||||
|
||||
//((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide();
|
||||
return true;
|
||||
case R.id.navigation_view_list:
|
||||
//((FloatingActionButton) findViewById(R.id.floatingAddButton)).show();
|
||||
//viewFlipper.setDisplayedChild(1);
|
||||
return true;
|
||||
case R.id.navigation_market_cap:
|
||||
//((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide();
|
||||
//viewFlipper.setDisplayedChild(2);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -289,11 +267,11 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onItemClick(int itemIndex, String itemName) {
|
||||
spaceNavigationItemEvent(itemIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemReselected(int itemIndex, String itemName) {
|
||||
spaceNavigationItemEvent(itemIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -437,7 +415,6 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
private void adaptView()
|
||||
{
|
||||
|
||||
currencyLayout.removeAllViews();
|
||||
|
||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
||||
@ -446,7 +423,7 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null))
|
||||
{
|
||||
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed));
|
||||
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -830,7 +807,7 @@ public class HomeActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCurrency(Currency currency, List<View> cardList)
|
||||
private void loadCurrency(Currency currency)
|
||||
{
|
||||
if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001)
|
||||
{
|
||||
@ -838,30 +815,24 @@ public class HomeActivity extends AppCompatActivity {
|
||||
currency.setId(balanceManager.getCurrencyId(currency.getSymbol()));
|
||||
totalValue += currency.getValue() * currency.getBalance();
|
||||
totalFluctuation += (currency.getValue() * currency.getBalance()) * (currency.getDayFluctuationPercentage() / 100);
|
||||
|
||||
cardList.add(layoutGenerator.getInfoLayout(currency, true));
|
||||
}
|
||||
|
||||
if(!currency.getSymbol().equals("USD") && currency.getHistoryMinutes() == null)
|
||||
{
|
||||
cardList.add(layoutGenerator.getInfoLayout(currency, true));
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshCurrencyList(final List<View> cardList)
|
||||
private void refreshCurrencyList()
|
||||
{
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
refreshLayout.setRefreshing(false);
|
||||
currencyLayout.removeAllViews();
|
||||
|
||||
for(int i = 0; i < cardList.size(); i++)
|
||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
||||
{
|
||||
currencyLayout.addView(cardList.get(i));
|
||||
}
|
||||
Currency currency = balanceManager.getTotalBalance().get(i);
|
||||
|
||||
adaptView();
|
||||
if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) {
|
||||
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed, totalValue, preferencesManager.isBalanceHidden()));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -910,8 +881,6 @@ public class HomeActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params)
|
||||
{
|
||||
final List<View> cardList = new ArrayList<>();
|
||||
|
||||
Looper.prepare();
|
||||
|
||||
balanceManager.sortCoins();
|
||||
@ -922,13 +891,11 @@ public class HomeActivity extends AppCompatActivity {
|
||||
|
||||
updateChartColor(localCurrency);
|
||||
|
||||
loadCurrency(localCurrency, cardList);
|
||||
loadCurrency(localCurrency);
|
||||
|
||||
balanceManager.getTotalBalance().set(i, localCurrency);
|
||||
}
|
||||
|
||||
refreshCurrencyList(cardList);
|
||||
|
||||
toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue));
|
||||
|
||||
updateFluctuation();
|
||||
@ -941,6 +908,9 @@ public class HomeActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onPostExecute(Void result)
|
||||
{
|
||||
refreshLayout.setRefreshing(false);
|
||||
refreshCurrencyList();
|
||||
HomeActivity.this.totalValue = totalValue;
|
||||
handler.removeCallbacks(updateRunnable);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.RingtonePreference;
|
||||
import android.preference.SwitchPreference;
|
||||
import android.security.keystore.KeyGenParameterSpec;
|
||||
import android.security.keystore.KeyPermanentlyInvalidatedException;
|
||||
import android.security.keystore.KeyProperties;
|
||||
@ -131,8 +132,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.d("coinfolio", "hello");
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@ -198,7 +197,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
*/
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
return PreferenceFragment.class.getName().equals(fragmentName)
|
||||
//|| GeneralPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| GeneralPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| DataSyncPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| NotificationPreferenceFragment.class.getName().equals(fragmentName)
|
||||
|| ExchangePreferenceFragment.class.getName().equals(fragmentName);
|
||||
@ -216,12 +215,22 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
addPreferencesFromResource(R.xml.pref_general);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
|
||||
// to their values. When their values change, their summaries are
|
||||
// updated to reflect the new value, per the Android Design
|
||||
// guidelines.
|
||||
bindPreferenceSummaryToValue(findPreference("example_text"));
|
||||
bindPreferenceSummaryToValue(findPreference("example_list"));
|
||||
((SwitchPreference) findPreference("hide_balance")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
boolean isChecked = !((SwitchPreference) findPreference("hide_balance")).isChecked();
|
||||
|
||||
((SwitchPreference) findPreference("hide_balance")).setChecked(isChecked);
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
SharedPreferences.Editor editor = preference.getEditor();
|
||||
|
||||
editor.putBoolean("hide_balance", isChecked);
|
||||
editor.apply();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,6 +58,11 @@ public class PreferencesManager {
|
||||
return settingPreferences.getBoolean("enable_hitbtc", false);
|
||||
}
|
||||
|
||||
public boolean isBalanceHidden()
|
||||
{
|
||||
return settingPreferences.getBoolean("hide_balance", false);
|
||||
}
|
||||
|
||||
public void disableHitBTC()
|
||||
{
|
||||
SharedPreferences.Editor editor = settingPreferences.edit();
|
||||
|
@ -9,6 +9,7 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.db.chart.model.ChartSet;
|
||||
@ -45,9 +46,8 @@ public class HomeLayoutGenerator {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public View getInfoLayout(final Currency currency, boolean isExtended)
|
||||
public View getInfoLayout(final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden)
|
||||
{
|
||||
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null);
|
||||
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@ -64,7 +64,7 @@ public class HomeLayoutGenerator {
|
||||
}
|
||||
});
|
||||
|
||||
updateCardViewInfos(view, currency);
|
||||
updateCardViewInfos(view, currency, totalValue, isBalanceHidden);
|
||||
|
||||
view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -120,7 +120,7 @@ public class HomeLayoutGenerator {
|
||||
});
|
||||
}
|
||||
|
||||
private void updateCardViewInfos(View view, Currency currency)
|
||||
private void updateCardViewInfos(View view, Currency currency, float totalValue, boolean isBalanceHidden)
|
||||
{
|
||||
((ImageView) view.findViewById(R.id.currencyIcon))
|
||||
.setImageBitmap(currency.getIcon());
|
||||
@ -141,6 +141,20 @@ public class HomeLayoutGenerator {
|
||||
.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation())));
|
||||
((ImageView) view.findViewById(R.id.detailsArrow))
|
||||
.getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
||||
|
||||
if(isBalanceHidden)
|
||||
{
|
||||
double value = currency.getValue() * currency.getBalance();
|
||||
double percentage = value / totalValue * 100;
|
||||
|
||||
view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.VISIBLE);
|
||||
((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage));
|
||||
((ProgressBar) view.findViewById(R.id.currencyPortfolioDominance)).getIndeterminateDrawable().setColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_ATOP);
|
||||
}
|
||||
else
|
||||
{
|
||||
view.findViewById(R.id.currencyPortfolioDominance).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void collapseView(View view)
|
||||
|
@ -13,7 +13,7 @@
|
||||
android:layout_margin="10dp"
|
||||
android:clickable="false"
|
||||
android:backgroundTint="@color/listBackground2"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardCornerRadius="2dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
@ -24,6 +24,13 @@
|
||||
android:orientation="vertical"
|
||||
android:tag="mainLinear">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/currencyPortfolioDominance"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/currencyInfoLayout"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -13,7 +13,7 @@
|
||||
android:layout_margin="10dp"
|
||||
android:clickable="false"
|
||||
android:backgroundTint="@color/listBackground2"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardCornerRadius="2dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
|
@ -2,7 +2,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/navigation_something"
|
||||
android:id="@+id/navigation_watchlist"
|
||||
android:icon="@drawable/ic_remove_red_eye_black_24dp"
|
||||
android:title="@string/title_watchlist" />
|
||||
|
||||
|
@ -12,10 +12,7 @@
|
||||
<!-- Example General settings -->
|
||||
<string name="pref_header_general">General</string>
|
||||
|
||||
<string name="pref_title_social_recommendations">Enable social recommendations</string>
|
||||
<string name="pref_description_social_recommendations">Recommendations for people to contact
|
||||
based on your message history
|
||||
</string>
|
||||
<string name="pref_title_hide_balance">Hide balance</string>
|
||||
|
||||
<string name="pref_title_display_name">Display name</string>
|
||||
<string name="pref_default_display_name">John Smith</string>
|
||||
|
@ -1,14 +1,13 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="example_switch"
|
||||
android:summary="@string/pref_description_social_recommendations"
|
||||
android:title="@string/pref_title_social_recommendations" />
|
||||
android:defaultValue="false"
|
||||
android:key="hide_balance"
|
||||
android:title="@string/pref_title_hide_balance" />
|
||||
|
||||
<!-- NOTE: EditTextPreference accepts EditText attributes. -->
|
||||
<!-- NOTE: EditTextPreference's summary should be set to its value by the activity code. -->
|
||||
<EditTextPreference
|
||||
<!--<EditTextPreference
|
||||
android:capitalize="words"
|
||||
android:defaultValue="@string/pref_default_display_name"
|
||||
android:inputType="textCapWords"
|
||||
@ -16,18 +15,18 @@
|
||||
android:maxLines="1"
|
||||
android:selectAllOnFocus="true"
|
||||
android:singleLine="true"
|
||||
android:title="@string/pref_title_display_name" />
|
||||
android:title="@string/pref_title_display_name" />-->
|
||||
|
||||
<!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog to
|
||||
dismiss it. -->
|
||||
<!-- NOTE: ListPreference's summary should be set to its value by the activity code. -->
|
||||
<ListPreference
|
||||
<!--<ListPreference
|
||||
android:defaultValue="-1"
|
||||
android:entries="@array/pref_example_list_titles"
|
||||
android:entryValues="@array/pref_example_list_values"
|
||||
android:key="example_list"
|
||||
android:negativeButtonText="@null"
|
||||
android:positiveButtonText="@null"
|
||||
android:title="@string/pref_title_add_friends_to_messages" />
|
||||
android:title="@string/pref_title_add_friends_to_messages" />-->
|
||||
|
||||
</PreferenceScreen>
|
||||
|
@ -2,6 +2,11 @@
|
||||
|
||||
<!-- These settings headers are only used on tablets. -->
|
||||
|
||||
<header
|
||||
android:fragment="com.nauk.coinfolio.Activities.SettingsActivity$GeneralPreferenceFragment"
|
||||
android:icon="@drawable/ic_info_black_24dp"
|
||||
android:title="@string/pref_header_general" />
|
||||
|
||||
<header
|
||||
android:fragment="com.nauk.coinfolio.Activities.SettingsActivity$ExchangePreferenceFragment"
|
||||
android:icon="@drawable/ic_developer_board_black_24dp"
|
||||
@ -18,3 +23,5 @@
|
||||
android:title="@string/pref_header_data_sync" />-->
|
||||
|
||||
</preference-headers>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user