Details are now accessible even when there is no chart data
This commit is contained in:
parent
92f08e00ed
commit
ac3ad43775
@ -220,13 +220,20 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
|
||||
lineChart.getLegend().setEnabled(false);
|
||||
lineChart.getXAxis().setEnabled(false);
|
||||
lineChart.setViewPortOffsets(0, 0, 0, 0);
|
||||
lineChart.setNoDataTextColor(currency.getChartColor());
|
||||
}
|
||||
|
||||
private void updateChartTab(int timeUnit, int 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)
|
||||
{
|
||||
@ -238,9 +245,6 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
|
||||
view.findViewById(R.id.chartCandleStickView).setVisibility(View.VISIBLE);
|
||||
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)
|
||||
@ -559,12 +563,15 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
|
||||
|
||||
private void updateChartsData(int timeUnit, int amount)
|
||||
{
|
||||
dataChartList = new ArrayList<>();
|
||||
dataChartList = null;
|
||||
|
||||
switch (timeUnit)
|
||||
{
|
||||
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;
|
||||
case DAY:
|
||||
if(amount == 1)
|
||||
@ -573,11 +580,17 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
|
||||
}
|
||||
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;
|
||||
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;
|
||||
case MONTH:
|
||||
switch (amount)
|
||||
@ -586,10 +599,16 @@ public class Charts extends Fragment implements CurrencyInfoUpdateNotifierInterf
|
||||
dataChartList = currency.getHistoryHours();
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
|
@ -229,7 +229,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
||||
for(int i = 0; i < renderedCurrencies.size(); 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())
|
||||
|
@ -12,7 +12,6 @@ import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
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.expandH;
|
||||
import static com.herbron.moodl.MoodlBox.getColor;
|
||||
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 {
|
||||
|
||||
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) {
|
||||
super(context);
|
||||
@ -59,6 +76,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
||||
currency.setListener(this);
|
||||
|
||||
this.currency = currency;
|
||||
this.parentActivity = activity;
|
||||
|
||||
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) {
|
||||
collapseH(view.findViewById(R.id.collapsableLayout));
|
||||
} 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);
|
||||
expandH(view.findViewById(R.id.collapsableLayout));
|
||||
|
||||
@ -85,7 +103,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
||||
{
|
||||
expandH(view.findViewById(R.id.collapsableLayout));
|
||||
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() {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
|
||||
findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
|
||||
|
||||
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);
|
||||
|
||||
currency.setListener(this);
|
||||
|
||||
this.currency = currency;
|
||||
this.parentActivity = activity;
|
||||
|
||||
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) {
|
||||
collapseH(view.findViewById(R.id.collapsableLayout));
|
||||
} 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);
|
||||
expandH(view.findViewById(R.id.collapsableLayout));
|
||||
|
||||
@ -158,7 +160,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
||||
{
|
||||
expandH(view.findViewById(R.id.collapsableLayout));
|
||||
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);
|
||||
|
||||
findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
});
|
||||
findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
|
||||
findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
|
||||
|
||||
updateColor(currency);
|
||||
}
|
||||
@ -367,7 +362,6 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
||||
|
||||
@Override
|
||||
public void onHistoryDataUpdated() {
|
||||
setupLineChart(currency);
|
||||
|
||||
View progressWatchlistView = findViewById(R.id.progressBarLinechartWatchlist);
|
||||
View progressSummaryView = findViewById(R.id.progressBarLinechartSummary);
|
||||
@ -382,11 +376,11 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import com.android.volley.toolbox.StringRequest;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
import com.herbron.moodl.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -267,35 +268,25 @@ public class CurrencyDataRetriever {
|
||||
{
|
||||
List<CurrencyDataChart> dataChart = new ArrayList<>();
|
||||
|
||||
if(response.length() > 250)
|
||||
{
|
||||
response = response.substring(response.indexOf("Data\":[{") + 7, response.lastIndexOf("}],\"TimeTo"));
|
||||
String[] tab = response.split(Pattern.quote("},{"));
|
||||
for(int i = 0; i < tab.length; i++)
|
||||
try {
|
||||
JSONObject mainJsonObject = new JSONObject(response);
|
||||
|
||||
if(mainJsonObject.getString("Response").equals("Success"))
|
||||
{
|
||||
JSONArray dataJsonArray = mainJsonObject.getJSONArray("Data");
|
||||
|
||||
if(i == 0)
|
||||
for(int i = 0; i < dataJsonArray.length(); i++)
|
||||
{
|
||||
tab[i] = tab[i] + "}";
|
||||
}
|
||||
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);
|
||||
JSONObject timeJsonObject = dataJsonArray.getJSONObject(i);
|
||||
dataChart.add(parseJSON(timeJsonObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataChart = null;
|
||||
else
|
||||
{
|
||||
dataChart = null;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.d("moodl", "API Request error : " + e);
|
||||
}
|
||||
|
||||
return dataChart;
|
||||
|
@ -174,7 +174,7 @@
|
||||
android:visibility="visible"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/linearLayoutSubLayout"
|
||||
android:id="@+id/linearLayoutSubCharts"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
|
@ -186,7 +186,7 @@
|
||||
android:visibility="visible"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/linearLayoutSubLayout"
|
||||
android:id="@+id/linearLayoutSubCharts"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
|
Loading…
Reference in New Issue
Block a user