From aa10defb03dd9ce1834a246af097d4a6d7f09391 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 17 Jul 2018 00:33:29 +0200 Subject: [PATCH] Major detail activity fix - Fix details activity chart loading error - Fix some non translated strings --- .../{Home.java => Charts.java} | 341 ++++++++--------- .../moodl/Activities/SettingsActivity.java | 12 +- .../DataManagers/CurrencyData/Currency.java | 19 - .../DataManagers/PreferencesManager.java | 39 -- .../moodl/DetailsActivityPagerAdapter.java | 4 +- .../fragment_charts_detailsactivity.xml | 278 ++++++++++++++ .../layout/fragment_home_detailsactivity.xml | 358 ------------------ app/src/main/res/values-fr/strings.xml | 33 +- app/src/main/res/values/strings.xml | 95 +---- app/src/main/res/values/styles.xml | 6 + 10 files changed, 494 insertions(+), 691 deletions(-) rename app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/{Home.java => Charts.java} (91%) create mode 100644 app/src/main/res/layout/fragment_charts_detailsactivity.xml delete mode 100644 app/src/main/res/layout/fragment_home_detailsactivity.xml diff --git a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Home.java b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Charts.java similarity index 91% rename from app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Home.java rename to app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Charts.java index 0c03a30..e140042 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Home.java +++ b/app/src/main/java/com/herbron/moodl/Activities/DetailsActivityFragments/Charts.java @@ -7,12 +7,16 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.LinearLayout; +import android.widget.Spinner; import android.widget.TextView; import com.github.mikephil.charting.charts.BarChart; @@ -47,7 +51,7 @@ import static com.herbron.moodl.MoodlBox.numberConformer; * Created by Tiji on 13/05/2018. */ -public class Home extends Fragment { +public class Charts extends Fragment { private final static int HOUR = 0; private final static int DAY = 1; @@ -72,7 +76,7 @@ public class Home extends Fragment { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - view = inflater.inflate(R.layout.fragment_home_detailsactivity, container, false); + view = inflater.inflate(R.layout.fragment_charts_detailsactivity, container, false); currency = getActivity().getIntent().getParcelableExtra("currency"); @@ -111,15 +115,168 @@ public class Home extends Fragment { } }); - initializeButtons(); initializeLineChart(lineChart); initializeCandleStickChart(candleStickChart); - updateChartTab(DAY, 1); + initializeSpinners(); return view; } + private void initializeSpinners() + { + Spinner spinner = view.findViewById(R.id.timeIntervalSinner); + + ArrayAdapter adapter = ArrayAdapter.createFromResource(getContext(), + R.array.time_interval_string_array, android.R.layout.simple_spinner_item); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + + spinner.setAdapter(adapter); + + spinner.setSelection(2); + + spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + updateCharts(i); + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + } + + private void updateCharts(int index) + { + view.findViewById(R.id.chartPriceView).setVisibility(View.GONE); + view.findViewById(R.id.chartCandleStickView).setVisibility(View.GONE); + view.findViewById(R.id.chartVolumeView).setVisibility(View.GONE); + view.findViewById(R.id.progressLayoutChart).setVisibility(View.VISIBLE); + + switch (index) + { + case 0: + currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.HOUR, 1); + } + }); + } + }); + break; + case 1: + currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.HOUR, 3); + } + }); + } + }); + break; + case 2: + currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.DAY, 1); + } + }); + } + }); + break; + case 3: + currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.DAY, 3); + } + }); + } + }); + break; + case 4: + currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.WEEK, 11); + } + }); + } + }); + break; + case 5: + currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.MONTH, 1); + } + }); + } + }); + break; + case 6: + currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.MONTH, 3); + } + }); + } + }); + break; + case 7: + currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.MONTH, 6); + } + }); + } + }); + break; + case 8: + currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { + @Override + public void onSuccess(Currency currency) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + updateChartTab(Charts.YEAR, 1); + } + }); + } + }); + break; + } + } + private void initializeCandleStickChart(CandleStickChart candleStickChart) { candleStickChart.setDrawGridBackground(false); @@ -150,182 +307,6 @@ public class Home extends Fragment { lineChart.setViewPortOffsets(0, 0, 0, 0); } - private void initializeButtons() - { - LinearLayout buttonLayout = view.findViewById(R.id.layoutChartButtons); - - for(int i = 0; i < buttonLayout.getChildCount(); i++) - { - final Button button = (Button) buttonLayout.getChildAt(i); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - buttonEvent(v); - } - }); - } - } - - private void buttonEvent(View v) - { - v.setEnabled(false); - - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - { - v.setElevation(MoodlBox.convertDpToPx(8, getResources())); - } - - LinearLayout buttonLayout = (LinearLayout) v.getParent(); - - for(int i = 0; i < buttonLayout.getChildCount(); i++) - { - Button button = (Button) buttonLayout.getChildAt(i); - - if(button != v) - { - button.setEnabled(true); - - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - { - button.setElevation(MoodlBox.convertDpToPx(2, getResources())); - } - } - } - - updateCharts((Button) v); - } - - private void updateCharts(Button button) - { - view.findViewById(R.id.chartPriceView).setVisibility(View.GONE); - view.findViewById(R.id.chartCandleStickView).setVisibility(View.GONE); - view.findViewById(R.id.chartVolumeView).setVisibility(View.GONE); - view.findViewById(R.id.progressLayoutChart).setVisibility(View.VISIBLE); - - String interval = button.getText().toString().substring(button.getText().toString().length()-2); - - switch (interval) - { - case "1h": - currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.HOUR, 1); - } - }); - } - }); - break; - case "3h": - currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.HOUR, 3); - } - }); - } - }); - break; - case "1d": - currency.updateHistoryMinutes(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.DAY, 1); - } - }); - } - }); - break; - case "3d": - currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.DAY, 3); - } - }); - } - }); - break; - case "1w": - currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.WEEK, 11); - } - }); - } - }); - break; - case "1M": - currency.updateHistoryHours(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.MONTH, 1); - } - }); - } - }); - break; - case "3M": - currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.MONTH, 3); - } - }); - } - }); - break; - case "6M": - currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.MONTH, 6); - } - }); - } - }); - break; - case "1y": - currency.updateHistoryDays(getContext(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { - @Override - public void onSuccess(Currency currency) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - updateChartTab(Home.YEAR, 1); - } - }); - } - }); - break; - } - } - private void updateChartTab(int timeUnit, int amount) { updateChartsData(timeUnit, amount); diff --git a/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java b/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java index 415b106..df1dceb 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java @@ -227,7 +227,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { findPreference("enable_fingerprint").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object o) { - + return false; } }); @@ -542,8 +542,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } }); - dialogBuilder.setTitle("Restore backup"); - dialogBuilder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() { + dialogBuilder.setTitle(getString(R.string.restoreBackup)); + dialogBuilder.setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int whichButton) { @@ -579,7 +579,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } }); - dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + dialogBuilder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); @@ -594,8 +594,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { }); EditTextPreference editTextPreference = (EditTextPreference) findPreference("minimum_value_displayed"); - editTextPreference.setPositiveButtonText("Save"); - editTextPreference.setNegativeButtonText("Cancel"); + editTextPreference.setPositiveButtonText(getString(R.string.save)); + editTextPreference.setNegativeButtonText(getString(R.string.cancel)); } private boolean checkPermissions() { diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java index eedafb0..b1c9d9c 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/Currency.java @@ -93,25 +93,6 @@ public class Currency implements Parcelable { }, timestamp); } - public static String getIconUrl(String currencyDetails) - { - String url; - - try { - JSONObject jsonObject = new JSONObject(currencyDetails); - url = "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=50"; - - } catch (NullPointerException e) { - //Log.d(context.getResources().getString(R.string.debug), symbol + " has no icon URL"); - url = null; - } catch (JSONException e) { - //Log.d(context.getResources().getString(R.string.debug), "Url parsing error for " + symbol); - url = null; - } - - return url; - } - public void updatePrice(android.content.Context context, String toSymbol, final CurrencyCallBack callBack) { dataRetriver = new CurrencyDataRetriever(context); diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java index c5b58c9..0a6d95d 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/PreferencesManager.java @@ -9,43 +9,11 @@ import android.preference.PreferenceManager; public class PreferencesManager { - private static int fragmentUpdated = 0; - private static final String currencyListFile = "CustomCurrencies"; - private static final String preferencesFile = "Preferences"; private SharedPreferences settingPreferences; - private SharedPreferences currencyList; - private SharedPreferences preferencesList; public PreferencesManager(android.content.Context context) { settingPreferences = PreferenceManager.getDefaultSharedPreferences(context); - currencyList = context.getSharedPreferences(currencyListFile, 0); - preferencesList = context.getSharedPreferences(preferencesFile, 0); - } - - public void setDetailOption(boolean isExtended) - { - SharedPreferences.Editor editor = preferencesList.edit(); - editor.putBoolean("DetailOption", isExtended); - editor.apply(); - } - - public boolean getDetailOption() - { - return preferencesList.getBoolean("DetailOption", true); - } - - public boolean mustRefreshDefaultCurrency() - { - fragmentUpdated++; - - if(fragmentUpdated == 3) - { - disableRefreshDefaultCurrency(); - fragmentUpdated = 0; - } - - return settingPreferences.getBoolean("refresh_default_currency", false); } public float getMinimumAmount() @@ -65,13 +33,6 @@ public class PreferencesManager { return ret; } - private void disableRefreshDefaultCurrency() - { - SharedPreferences.Editor editor = settingPreferences.edit(); - editor.putBoolean("refresh_default_currency", false); - editor.apply(); - } - public String getDefaultCurrency() { return settingPreferences.getString("default_currency", "USD"); diff --git a/app/src/main/java/com/herbron/moodl/DetailsActivityPagerAdapter.java b/app/src/main/java/com/herbron/moodl/DetailsActivityPagerAdapter.java index 08a5794..da76aec 100644 --- a/app/src/main/java/com/herbron/moodl/DetailsActivityPagerAdapter.java +++ b/app/src/main/java/com/herbron/moodl/DetailsActivityPagerAdapter.java @@ -4,7 +4,7 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; -import com.herbron.moodl.Activities.DetailsActivityFragments.Home; +import com.herbron.moodl.Activities.DetailsActivityFragments.Charts; import com.herbron.moodl.Activities.DetailsActivityFragments.Informations; import com.herbron.moodl.Activities.DetailsActivityFragments.Transactions; @@ -27,7 +27,7 @@ public class DetailsActivityPagerAdapter extends FragmentStatePagerAdapter { switch (position) { case 0: - return new Home(); + return new Charts(); case 1: return new Informations(); case 2: diff --git a/app/src/main/res/layout/fragment_charts_detailsactivity.xml b/app/src/main/res/layout/fragment_charts_detailsactivity.xml new file mode 100644 index 0000000..7b83b9e --- /dev/null +++ b/app/src/main/res/layout/fragment_charts_detailsactivity.xml @@ -0,0 +1,278 @@ + + + + + + + + + + + + + +