diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Overview.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Overview.java index c92c6a5..f56f467 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Overview.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Overview.java @@ -2,18 +2,26 @@ package com.nauk.moodl.Activities.HomeActivityFragments; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.support.v4.app.Fragment; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; import android.support.v7.graphics.Palette; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; +import android.widget.ExpandableListView; +import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.ListView; +import android.widget.ProgressBar; import com.nauk.moodl.Activities.HomeActivity; import com.nauk.moodl.DataManagers.CurrencyData.Currency; @@ -38,6 +46,8 @@ public class Overview extends Fragment { private PreferencesManager preferenceManager; private OverviewListAdapter overviewListAdapter; + private View loadingFooter; + boolean flag_loading; private ListView listLayout; @@ -75,66 +85,39 @@ public class Overview extends Fragment { } }); + flag_loading = true; + updateList(); + setupDrawerButton(fragmentView); + return fragmentView; } + private void setupDrawerButton(View view) + { + ImageButton drawerButton = view.findViewById(R.id.drawer_button); + drawerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DrawerLayout drawerLayout = getActivity().findViewById(R.id.drawer_layout); + + if(drawerLayout.isDrawerOpen(GravityCompat.START)) + { + drawerLayout.closeDrawers(); + } + else + { + drawerLayout.openDrawer(GravityCompat.START); + } + } + }); + } + private void updateList() { - new AsyncTask() { - - @Override - protected Void doInBackground(Void... voids) { - - currencyTickerList.getCurrenciesFrom(listLayout.getCount(), preferenceManager.getDefaultCurrency(), new UpdateCallBack() { - @Override - public void onSuccess(List currencyList) - { - for(Currency currency : currencyList) - { - String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), currencyDetailsList); - - if(iconUrl != null) - { - MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { - @Override - public void onSuccess(Bitmap bitmap) { - currency.setIcon(bitmap); - updateChartColor(currency); - } - }); - } - else - { - Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl); - icon = Bitmap.createScaledBitmap(icon, 50, 50, false); - - currency.setIcon(icon); - updateChartColor(currency); - } - } - - if(overviewListAdapter == null) - { - overviewListAdapter = new OverviewListAdapter(getContext(), currencyList); - - listLayout.setAdapter(overviewListAdapter); - listLayout.setTextFilterEnabled(false); - } - else - { - overviewListAdapter.addAll(currencyList); - overviewListAdapter.notifyDataSetChanged(); - } - - flag_loading = false; - } - }); - return null; - } - }.execute(); - + CurrencyLoader currencyLoader = new CurrencyLoader(); + currencyLoader.execute(); } private void updateChartColor(Currency currency) @@ -155,4 +138,101 @@ public class Overview extends Fragment { { void onSuccess(List currencyList); } + + private void loadingIndicatorGenerator() + { + loadingFooter = LayoutInflater.from(getContext()).inflate(R.layout.listview_loading_indicator, null, false); + + listLayout.addFooterView(loadingFooter); + } + + private class CurrencyLoader extends AsyncTask + { + @Override + protected void onPreExecute() { + super.onPreExecute(); + + loadingIndicatorGenerator(); + } + + @Override + protected Void doInBackground(Void... voids) { + currencyTickerList.getCurrenciesFrom(listLayout.getCount(), preferenceManager.getDefaultCurrency(), new UpdateCallBack() { + @Override + public void onSuccess(List currencyList) + { + IconDownloader iconDownloader = new IconDownloader(); + iconDownloader.execute(currencyList); + } + }); + return null; + } + } + + private class IconDownloader extends AsyncTask, Void, Void> + { + private int iconCounter; + + @Override + protected Void doInBackground(List... currencies) { + + for(Currency currency : currencies[0]) + { + String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), currencyDetailsList); + + if(iconUrl != null) + { + MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { + @Override + public void onSuccess(Bitmap bitmap) { + currency.setIcon(bitmap); + updateChartColor(currency); + countIcons(currencies[0]); + } + }); + } + else + { + Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl); + icon = Bitmap.createScaledBitmap(icon, 50, 50, false); + + currency.setIcon(icon); + updateChartColor(currency); + countIcons(currencies[0]); + } + } + + return null; + } + + private void countIcons(List currencyList) + { + iconCounter++; + + if(iconCounter == currencyList.size()) + { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + if(overviewListAdapter == null) + { + overviewListAdapter = new OverviewListAdapter(getContext(), currencyList, getActivity()); + + listLayout.setAdapter(overviewListAdapter); + listLayout.setTextFilterEnabled(false); + } + else + { + overviewListAdapter.addAll(currencyList); + overviewListAdapter.notifyDataSetChanged(); + } + + listLayout.removeFooterView(loadingFooter); + + flag_loading = false; + } + }); + } + } + } } diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java index 161ecf0..1adfdb4 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -276,11 +276,11 @@ public class Watchlist extends Fragment { private void generateCards() { - ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews(); - getActivity().runOnUiThread(new Runnable() { @Override public void run() { + ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews(); + for(Currency currency : watchlistManager.getWatchlist()) { ((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(new CurrencyCardview(getContext(), currency, getActivity())); diff --git a/app/src/main/java/com/nauk/moodl/LayoutManagers/OverviewListAdapter.java b/app/src/main/java/com/nauk/moodl/LayoutManagers/OverviewListAdapter.java index f0244e1..b45bf4d 100644 --- a/app/src/main/java/com/nauk/moodl/LayoutManagers/OverviewListAdapter.java +++ b/app/src/main/java/com/nauk/moodl/LayoutManagers/OverviewListAdapter.java @@ -1,16 +1,22 @@ package com.nauk.moodl.LayoutManagers; +import android.app.Activity; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v7.widget.CardView; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import com.nauk.moodl.DataManagers.CurrencyData.Currency; +import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview; +import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDetailsList; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; @@ -24,12 +30,15 @@ import static com.nauk.moodl.MoodlBox.numberConformer; public class OverviewListAdapter extends ArrayAdapter { - private Context context; + private Activity activity; + private CurrencyDetailsList currencyDetailsList; - public OverviewListAdapter(Context context, List currencies) + public OverviewListAdapter(Context context, List currencies, Activity activity) { - super(context, android.R.layout.simple_list_item_1, currencies); - this.context = context; + super(context, android.R.layout.simple_expandable_list_item_1, currencies); + this.activity = activity; + + currencyDetailsList = CurrencyDetailsList.getInstance(getContext()); } @NonNull @@ -38,24 +47,12 @@ public class OverviewListAdapter extends ArrayAdapter { { Currency currency = getItem(position); - if(convertView == null) - { - convertView = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, parent, false); - } + currencyDetailsList.getCurrencyDetailsFromSymbol(currency.getSymbol()); - TextView symbolTxtView = convertView.findViewById(R.id.currencySymbolTextView); - TextView nameTxtView = convertView.findViewById(R.id.currencyNameTextView); - TextView valueTxtView = convertView.findViewById(R.id.currencyValueTextView); - TextView fluctuationTxtView = convertView.findViewById(R.id.currencyFluctuationTextView); - TextView percentageTxtView = convertView.findViewById(R.id.currencyFluctuationPercentageTextView); - ImageView iconImageView = convertView.findViewById(R.id.currencyIcon); - - symbolTxtView.setText(currency.getSymbol()); - nameTxtView.setText(currency.getName()); - valueTxtView.setText(PlaceholderManager.getValueString(numberConformer(currency.getValue()), getContext())); - fluctuationTxtView.setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext())); - percentageTxtView.setText(PlaceholderManager.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext())); - iconImageView.setImageBitmap(currency.getIcon()); + CurrencyCardview currencyCardview = new CurrencyCardview(getContext(), currency, activity); + LinearLayout linearLayout = new LinearLayout(getContext()); + linearLayout.addView(currencyCardview); + convertView = linearLayout; return convertView; } diff --git a/app/src/main/res/layout/cardview_overview.xml b/app/src/main/res/layout/cardview_overview.xml new file mode 100644 index 0000000..aae1be5 --- /dev/null +++ b/app/src/main/res/layout/cardview_overview.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_overview_homeactivity.xml b/app/src/main/res/layout/fragment_overview_homeactivity.xml index e35ed17..7ccdc1f 100644 --- a/app/src/main/res/layout/fragment_overview_homeactivity.xml +++ b/app/src/main/res/layout/fragment_overview_homeactivity.xml @@ -61,7 +61,9 @@ android:layout_height="wrap_content" android:layout_marginTop="?attr/actionBarSize" android:orientation="vertical" - xmlns:android="http://schemas.android.com/apk/res/android"/> + xmlns:android="http://schemas.android.com/apk/res/android" + android:divider="@null" + android:dividerHeight="0dp"/> \ No newline at end of file diff --git a/app/src/main/res/layout/listview_loading_indicator.xml b/app/src/main/res/layout/listview_loading_indicator.xml index 587f506..16fc4b5 100644 --- a/app/src/main/res/layout/listview_loading_indicator.xml +++ b/app/src/main/res/layout/listview_loading_indicator.xml @@ -14,6 +14,6 @@ + android:text="Hodl..."/> \ No newline at end of file