Details are now accessible even when there is no chart data

This commit is contained in:
Tanguy Herbron 2018-08-03 16:17:15 +02:00
parent 92f08e00ed
commit ac3ad43775
6 changed files with 81 additions and 77 deletions

View File

@ -220,13 +220,20 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
lineChart.getLegend().setEnabled(false); lineChart.getLegend().setEnabled(false);
lineChart.getXAxis().setEnabled(false); lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0); lineChart.setViewPortOffsets(0, 0, 0, 0);
lineChart.setNoDataTextColor(currency.getChartColor());
} }
private void updateChartTab(int timeUnit, int amount) private void updateChartTab(int timeUnit, int amount)
{ {
updateChartsData(timeUnit, amount); updateChartsData(timeUnit, amount);
drawPriceLineChart();
drawPriceCandleStickChart(); if(currency.getHistoryMinutes() != null)
{
drawPriceLineChart();
drawPriceCandleStickChart();
drawVolumeChart();
updateGeneralData(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY());
}
if(displayLineChart) if(displayLineChart)
{ {
@ -238,9 +245,6 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
view.findViewById(R.id.chartCandleStickView).setVisibility(View.VISIBLE); view.findViewById(R.id.chartCandleStickView).setVisibility(View.VISIBLE);
view.findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); view.findViewById(R.id.progressLayoutChart).setVisibility(View.GONE);
} }
drawVolumeChart();
updateGeneralData(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY());
} }
private void updateGeneralData(float start, float end) private void updateGeneralData(float start, float end)
@ -559,12 +563,15 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
private void updateChartsData(int timeUnit, int amount) private void updateChartsData(int timeUnit, int amount)
{ {
dataChartList = new ArrayList<>(); dataChartList = null;
switch (timeUnit) switch (timeUnit)
{ {
case HOUR: case HOUR:
dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size()); if(currency.getHistoryMinutes() != null)
{
dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size());
}
break; break;
case DAY: case DAY:
if(amount == 1) if(amount == 1)
@ -573,11 +580,17 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
} }
else else
{ {
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size()); if(currency.getHistoryHours() != null)
{
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size());
}
} }
break; break;
case WEEK: case WEEK:
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size()); if(currency.getHistoryHours() != null)
{
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size());
}
break; break;
case MONTH: case MONTH:
switch (amount) switch (amount)
@ -586,10 +599,16 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
dataChartList = currency.getHistoryHours(); dataChartList = currency.getHistoryHours();
break; break;
case 3: case 3:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size()); if(currency.getHistoryDays() != null)
{
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size());
}
break; break;
case 6: case 6:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size()); if(currency.getHistoryDays() != null)
{
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size());
}
break; break;
} }
break; break;

View File

@ -229,7 +229,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
for(int i = 0; i < renderedCurrencies.size(); i++) for(int i = 0; i < renderedCurrencies.size(); i++)
{ {
//currencyLayout.addView(currencyView.get(i)); //currencyLayout.addView(currencyView.get(i));
currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), totalValue, preferencesManager.isBalanceHidden())); currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), totalValue, preferencesManager.isBalanceHidden()));
} }
if(loadingDialog.isShowing()) if(loadingDialog.isShowing())

View File

@ -12,7 +12,6 @@ import android.os.Build;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -37,7 +36,6 @@ import java.util.List;
import static com.herbron.moodl.MoodlBox.collapseH; import static com.herbron.moodl.MoodlBox.collapseH;
import static com.herbron.moodl.MoodlBox.expandH; import static com.herbron.moodl.MoodlBox.expandH;
import static com.herbron.moodl.MoodlBox.getColor;
import static com.herbron.moodl.MoodlBox.numberConformer; import static com.herbron.moodl.MoodlBox.numberConformer;
/** /**
@ -47,6 +45,25 @@ import static com.herbron.moodl.MoodlBox.numberConformer;
public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNotifierInterface { public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNotifierInterface {
private Currency currency; private Currency currency;
private Activity parentActivity;
private OnClickListener detailsClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(parentActivity, CurrencyDetailsActivity.class);
intent.putExtra(getContext().getString(R.string.currency), currency);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation(parentActivity, findViewById(R.id.LineChartView), "chart");
parentActivity.startActivity(intent, activityOptions.toBundle());
}
else {
parentActivity.startActivity(intent);
}
}
};
public CurrencyCardview(@NonNull Context context) { public CurrencyCardview(@NonNull Context context) {
super(context); super(context);
@ -59,6 +76,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
currency.setListener(this); currency.setListener(this);
this.currency = currency; this.currency = currency;
this.parentActivity = activity;
LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true); LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true);
@ -74,7 +92,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) {
collapseH(view.findViewById(R.id.collapsableLayout)); collapseH(view.findViewById(R.id.collapsableLayout));
} else { } else {
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE);
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE); view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE);
expandH(view.findViewById(R.id.collapsableLayout)); expandH(view.findViewById(R.id.collapsableLayout));
@ -85,7 +103,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
{ {
expandH(view.findViewById(R.id.collapsableLayout)); expandH(view.findViewById(R.id.collapsableLayout));
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE);
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
} }
} }
} }
@ -102,36 +120,20 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
} }
}); });
findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() { findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
@Override findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
public void onClick(View view) {
Intent intent = new Intent(activity, CurrencyDetailsActivity.class);
intent.putExtra("currency", currency);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
ActivityOptions activityOptions = ActivityOptions.makeSceneTransitionAnimation(activity, findViewById(R.id.LineChartView), "chart");
activity.startActivity(intent, activityOptions.toBundle());
}
else
{
activity.startActivity(intent);
}
}
});
updateColor(currency); updateColor(currency);
} }
public CurrencyCardview(@NonNull final Context context, final Currency currency, float totalValue, boolean isBalanceHidden) public CurrencyCardview(@NonNull final Context context, final Currency currency, Activity activity, float totalValue, boolean isBalanceHidden)
{ {
super(context); super(context);
currency.setListener(this); currency.setListener(this);
this.currency = currency; this.currency = currency;
this.parentActivity = activity;
LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true); LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true);
@ -147,7 +149,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) { if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) {
collapseH(view.findViewById(R.id.collapsableLayout)); collapseH(view.findViewById(R.id.collapsableLayout));
} else { } else {
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.GONE); view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE);
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE); view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE);
expandH(view.findViewById(R.id.collapsableLayout)); expandH(view.findViewById(R.id.collapsableLayout));
@ -158,7 +160,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
{ {
expandH(view.findViewById(R.id.collapsableLayout)); expandH(view.findViewById(R.id.collapsableLayout));
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE);
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
} }
} }
} }
@ -166,15 +168,8 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
updateCardViewInfos(currency, totalValue, isBalanceHidden); updateCardViewInfos(currency, totalValue, isBalanceHidden);
findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() { findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
@Override findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
public void onClick(View view) {
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
intent.putExtra(getContext().getString(R.string.currency), currency);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.getApplicationContext().startActivity(intent);
}
});
updateColor(currency); updateColor(currency);
} }
@ -367,7 +362,6 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
@Override @Override
public void onHistoryDataUpdated() { public void onHistoryDataUpdated() {
setupLineChart(currency);
View progressWatchlistView = findViewById(R.id.progressBarLinechartWatchlist); View progressWatchlistView = findViewById(R.id.progressBarLinechartWatchlist);
View progressSummaryView = findViewById(R.id.progressBarLinechartSummary); View progressSummaryView = findViewById(R.id.progressBarLinechartSummary);
@ -382,11 +376,11 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
progressSummaryView.setVisibility(View.GONE); progressSummaryView.setVisibility(View.GONE);
} }
findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
if(currency.getHistoryMinutes() == null) if(currency.getHistoryMinutes() != null)
{ {
findViewById(R.id.linearLayoutSubLayout).findViewById(R.id.detailsArrow).setVisibility(View.GONE); setupLineChart(currency);
} }
} }

View File

@ -10,6 +10,7 @@ import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley; import com.android.volley.toolbox.Volley;
import com.herbron.moodl.R; import com.herbron.moodl.R;
import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -267,35 +268,25 @@ public class CurrencyDataRetriever {
{ {
List<CurrencyDataChart> dataChart = new ArrayList<>(); List<CurrencyDataChart> dataChart = new ArrayList<>();
if(response.length() > 250) try {
{ JSONObject mainJsonObject = new JSONObject(response);
response = response.substring(response.indexOf("Data\":[{") + 7, response.lastIndexOf("}],\"TimeTo"));
String[] tab = response.split(Pattern.quote("},{")); if(mainJsonObject.getString("Response").equals("Success"))
for(int i = 0; i < tab.length; i++)
{ {
JSONArray dataJsonArray = mainJsonObject.getJSONArray("Data");
if(i == 0) for(int i = 0; i < dataJsonArray.length(); i++)
{ {
tab[i] = tab[i] + "}"; JSONObject timeJsonObject = dataJsonArray.getJSONObject(i);
} dataChart.add(parseJSON(timeJsonObject));
else
{
tab[i] = "{" + tab[i] + "}";
}
try {
JSONObject jsonObject = new JSONObject(tab[i]);
dataChart.add(parseJSON(jsonObject));
} catch (JSONException e) {
Log.d(context.getResources().getString(R.string.debug_volley), "API Request error: " + e + " index: " + i);
} }
} }
} else
else {
{ dataChart = null;
dataChart = null; }
} catch (JSONException e) {
Log.d("moodl", "API Request error : " + e);
} }
return dataChart; return dataChart;

View File

@ -174,7 +174,7 @@
android:visibility="visible"/> android:visibility="visible"/>
<FrameLayout <FrameLayout
android:id="@+id/linearLayoutSubLayout" android:id="@+id/linearLayoutSubCharts"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clickable="true" android:clickable="true"

View File

@ -186,7 +186,7 @@
android:visibility="visible"/> android:visibility="visible"/>
<FrameLayout <FrameLayout
android:id="@+id/linearLayoutSubLayout" android:id="@+id/linearLayoutSubCharts"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clickable="true" android:clickable="true"