Update graddle | Display marketcap details | Fix marketcap piechart click crash

This commit is contained in:
Tanguy Herbron 2018-05-18 12:24:10 +02:00
parent 44333e55f7
commit 984956e535
6 changed files with 107 additions and 6 deletions

Binary file not shown.

4
.idea/gradle.xml generated
View File

@ -3,9 +3,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-4.1" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-4.7" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View File

@ -14,6 +14,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.Entry;
@ -27,6 +28,7 @@ import com.nauk.moodl.Activities.SettingsActivity;
import com.nauk.moodl.DataManagers.CurrencyData.Currency;
import com.nauk.moodl.DataManagers.MarketCapManager;
import com.nauk.moodl.DataManagers.PreferencesManager;
import com.nauk.moodl.LayoutManagers.CustomPieChart;
import com.nauk.moodl.LayoutManagers.CustomViewPager;
import com.nauk.moodl.PlaceholderManager;
import com.nauk.moodl.R;
@ -246,7 +248,7 @@ public class MarketCapitalization extends Fragment {
private void setupPieChart(PieData data)
{
PieChart pieChart = view.findViewById(R.id.marketCapPieChart);
CustomPieChart pieChart = view.findViewById(R.id.marketCapPieChart);
pieChart.setData(data);
pieChart.setDrawSlicesUnderHole(false);
@ -270,6 +272,9 @@ public class MarketCapitalization extends Fragment {
((CustomViewPager) view.getParent().getParent().getParent().getParent().getParent()).setPagingEnabled(true);
break;
}
view.performClick();
return false;
}
});
@ -277,8 +282,23 @@ public class MarketCapitalization extends Fragment {
pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
Currency currency = marketCapManager.getCurrencyFromSymbol((String) e.getData());
Log.d("moodl", "> " + currency.getSymbol() + " " + currency.getMarketCapitalization() + " " + currency.getVolume24h());
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if(e.getData() != null)
{
Currency currency = marketCapManager.getCurrencyFromSymbol((String) e.getData());
//view.findViewById(R.id.layoutMarketDetails).setVisibility();
((TextView) view.findViewById(R.id.textViewMarketCap))
.setText(PlaceholderManager.getValueString(String.valueOf(currency.getMarketCapitalization()), getContext()));
((TextView) view.findViewById(R.id.textViewVolume))
.setText(PlaceholderManager.getValueString(String.valueOf(currency.getVolume24h()), getContext()));
((TextView) view.findViewById(R.id.textViewSymbol))
.setText(currency.getName());
}
}
});
}
@Override

View File

@ -155,6 +155,8 @@ public class MarketCapManager {
{
returnedCurrency = topCurrencies.get(index);
}
index++;
} while(index < topCurrencies.size() && returnedCurrency == null);

View File

@ -0,0 +1,28 @@
package com.nauk.moodl.LayoutManagers;
import android.content.Context;
import android.util.AttributeSet;
import com.github.mikephil.charting.charts.PieChart;
public class CustomPieChart extends PieChart {
public CustomPieChart(Context context) {
super(context);
}
public CustomPieChart(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomPieChart(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean performClick() {
super.performClick();
return true;
}
}

View File

@ -101,11 +101,62 @@
android:textSize="18dp"
android:gravity="center_horizontal"/>
<com.github.mikephil.charting.charts.PieChart
<com.nauk.moodl.LayoutManagers.CustomPieChart
android:id="@+id/marketCapPieChart"
android:layout_width="match_parent"
android:layout_height="350dp"/>
<LinearLayout
android:id="@+id/layoutMarketDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textViewSymbol"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Market capitalization"
android:textStyle="bold"/>
<TextView
android:id="@+id/textViewMarketCap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="24h volume"
android:textStyle="bold"/>
<TextView
android:id="@+id/textViewVolume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>