Marketp cap activity improvements

- Add icon review
- Add "global" and "others" info
- Add dominance percentage
This commit is contained in:
Tanguy Herbron 2018-05-26 17:01:36 +02:00
parent 9845edd8cb
commit 2cfb2df9d3
3 changed files with 74 additions and 57 deletions

View File

@ -42,7 +42,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static com.nauk.moodl.MoodlBox.numberConformer;
import static java.lang.Math.abs;
/**
@ -213,8 +212,6 @@ public class MarketCapitalization extends Fragment {
private void refreshDisplayedData()
{
setupTextViewMarketCap();
view.findViewById(R.id.progressBarMarketCap).setVisibility(View.GONE);
view.findViewById(R.id.layoutProgressMarketCap).setVisibility(View.VISIBLE);
@ -252,7 +249,7 @@ public class MarketCapitalization extends Fragment {
colors.add(dominantCurrenciesColors.get(topCurrencies.get(i).getSymbol()));
}
entries.add(new PieEntry(100-topCurrenciesDominance, "Others"));
entries.add(new PieEntry(100-topCurrenciesDominance, "Others", "others"));
colors.add(-12369084);
PieDataSet set = new PieDataSet(entries, "Market Cap Dominance");
@ -323,6 +320,8 @@ public class MarketCapitalization extends Fragment {
pieChart.setTouchEnabled(true);
pieChart.setEntryLabelColor(Color.WHITE);
updateDetails(marketCapManager.getMarketCap(), marketCapManager.getDayVolume(), "Global", 0);
pieChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
@ -350,19 +349,15 @@ public class MarketCapitalization extends Fragment {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if(e.getData() != null)
if(!e.getData().equals("others"))
{
view.findViewById(R.id.layoutMarketDetails).setVisibility(View.VISIBLE);
view.findViewById(R.id.currencyIcon).setVisibility(View.VISIBLE);
Currency currency = marketCapManager.getCurrencyFromSymbol((String) e.getData());
view.findViewById(R.id.currencyIcon).setVisibility(View.VISIBLE);
view.findViewById(R.id.layoutPercentageDominance).setVisibility(View.VISIBLE);
updateDetails(currency.getMarketCapitalization(), currency.getVolume24h(), currency.getName() + " (" + currency.getSymbol() + ")", h.getY());
((TextView) view.findViewById(R.id.textViewMarketCap))
.setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(currency.getMarketCapitalization()), getContext()));
((TextView) view.findViewById(R.id.textViewVolume))
.setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(currency.getVolume24h()), getContext()));
((TextView) view.findViewById(R.id.textViewNameSymbol))
.setText(currency.getName() + " (" + currency.getSymbol() + ")");
((ImageView) view.findViewById(R.id.currencyIcon))
.setImageBitmap(currency.getIcon());
@ -370,8 +365,20 @@ public class MarketCapitalization extends Fragment {
}
else
{
double othersMarketCap = marketCapManager.getMarketCap();
double othersVolume = marketCapManager.getDayVolume();
for(int i = 0; i < marketCapManager.getTopCurrencies().size(); i++)
{
othersMarketCap -= marketCapManager.getTopCurrencies().get(i).getMarketCapitalization();
othersVolume -= marketCapManager.getTopCurrencies().get(i).getVolume24h();
}
view.findViewById(R.id.currencyIcon).setVisibility(View.GONE);
view.findViewById(R.id.layoutMarketDetails).setVisibility(View.GONE);
view.findViewById(R.id.layoutPercentageDominance).setVisibility(View.VISIBLE);
updateDetails(othersMarketCap, othersVolume, "Other coins", h.getY());
pieChart.setDrawCenterText(true);
}
}
@ -381,7 +388,10 @@ public class MarketCapitalization extends Fragment {
@Override
public void onNothingSelected() {
view.findViewById(R.id.currencyIcon).setVisibility(View.GONE);
view.findViewById(R.id.layoutMarketDetails).setVisibility(View.GONE);
view.findViewById(R.id.layoutPercentageDominance).setVisibility(View.GONE);
updateDetails(marketCapManager.getMarketCap(), marketCapManager.getDayVolume(), "Global", 0);
pieChart.setDrawCenterText(true);
}
});
@ -392,17 +402,21 @@ public class MarketCapitalization extends Fragment {
pieChart.invalidate();
}
private void updateDetails(double marketCap, double volume, String title, double percentage)
{
((TextView) view.findViewById(R.id.textViewMarketCap))
.setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(marketCap), getContext()));
((TextView) view.findViewById(R.id.textViewVolume))
.setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(volume), getContext()));
((TextView) view.findViewById(R.id.textViewTitle))
.setText(title);
((TextView) view.findViewById(R.id.textViewDominancePercentage))
.setText(PlaceholderManager.getPercentageString(MoodlBox.numberConformer(percentage), getContext()));
}
private SpannableString generateCenterSpannableText() {
SpannableString spannableString = new SpannableString("Market Capitalization Dominance");
return spannableString;
}
private void setupTextViewMarketCap()
{
((TextView) view.findViewById(R.id.marketCapTextView))
.setText(PlaceholderManager.getValueString(numberConformer(marketCapManager.getMarketCap()), getActivity()));
((TextView) view.findViewById(R.id.dayVolumeTotalMarketCap))
.setText(PlaceholderManager.getValueString(numberConformer(marketCapManager.getDayVolume()), getActivity()));
}
}

View File

@ -403,12 +403,16 @@ public class Summary extends Fragment implements HideBalanceSwitch {
loadingDialog.dismiss();
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateTitle();
}
});
try {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
updateTitle();
}
});
} catch (NullPointerException e) {
e.printStackTrace();
}
}
protected void updateTitle()

View File

@ -78,31 +78,10 @@
android:visibility="gone"
android:orientation="vertical">
<TextView
android:id="@+id/marketCapTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:textSize="20dp"
android:gravity="center_horizontal"/>
<TextView
android:id="@+id/dayVolumeTotalMarketCap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:textSize="18dp"
android:gravity="center_horizontal"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="350dp">
android:layout_height="350dp"
android:layout_marginTop="5dp">
<com.nauk.moodl.LayoutManagers.CustomPieChart
android:id="@+id/marketCapPieChart"
@ -128,13 +107,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
android:visibility="gone">
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textViewNameSymbol"
android:id="@+id/textViewTitle"
android:textStyle="bold"
android:textSize="20sp"/>
@ -168,6 +146,27 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/layoutPercentageDominance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
android:layout_marginTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dominance percentage"
android:textStyle="bold"/>
<TextView
android:id="@+id/textViewDominancePercentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout