Performance improvements
- New data refreshing method | avoid soft freezing the app - Update fragment titles - Update background color for a better visibility of summary and watchlist cards
This commit is contained in:
parent
eab8ff14bf
commit
78adcd5485
@ -86,14 +86,12 @@ public class HomeActivity extends AppCompatActivity {
|
|||||||
switch (item.getItemId())
|
switch (item.getItemId())
|
||||||
{
|
{
|
||||||
case R.id.navigation_watchlist:
|
case R.id.navigation_watchlist:
|
||||||
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true);
|
|
||||||
viewPager.setCurrentItem(0);
|
viewPager.setCurrentItem(0);
|
||||||
break;
|
break;
|
||||||
case R.id.navigation_currencies_list:
|
case R.id.navigation_currencies_list:
|
||||||
viewPager.setCurrentItem(1);
|
viewPager.setCurrentItem(1);
|
||||||
break;
|
break;
|
||||||
case R.id.navigation_market_cap:
|
case R.id.navigation_market_cap:
|
||||||
((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true);
|
|
||||||
viewPager.setCurrentItem(2);
|
viewPager.setCurrentItem(2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import com.nauk.coinfolio.R;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,18 +138,6 @@ public class Summary extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ImageButton detailsButton = view.findViewById(R.id.switch_button);
|
|
||||||
detailsButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
preferencesManager.setDetailOption(!preferencesManager.getDetailOption());
|
|
||||||
updateViewButtonIcon();
|
|
||||||
switchView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//updateTitle();
|
|
||||||
|
|
||||||
updateAll(true);
|
updateAll(true);
|
||||||
|
|
||||||
generateSplashScreen();
|
generateSplashScreen();
|
||||||
@ -189,8 +178,6 @@ public class Summary extends Fragment {
|
|||||||
|
|
||||||
updateAll(preferencesManager.mustUpdateSummary());
|
updateAll(preferencesManager.mustUpdateSummary());
|
||||||
|
|
||||||
updateViewButtonIcon();
|
|
||||||
|
|
||||||
displayBalance(preferencesManager.isBalanceHidden());
|
displayBalance(preferencesManager.isBalanceHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,31 +230,38 @@ public class Summary extends Fragment {
|
|||||||
totalFluctuation = 0;
|
totalFluctuation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void switchView()
|
|
||||||
{
|
|
||||||
if(preferencesManager.getDetailOption())
|
|
||||||
{
|
|
||||||
adaptView();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
adaptView();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void adaptView()
|
private void adaptView()
|
||||||
{
|
{
|
||||||
currencyLayout.removeAllViews();
|
currencyLayout.removeAllViews();
|
||||||
|
|
||||||
|
final List<View> currencyView = new ArrayList<>();
|
||||||
|
|
||||||
|
Runnable newRunnabmle = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
||||||
{
|
{
|
||||||
final Currency currency = balanceManager.getTotalBalance().get(i);
|
final Currency currency = balanceManager.getTotalBalance().get(i);
|
||||||
|
|
||||||
if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001))
|
if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001))
|
||||||
{
|
{
|
||||||
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, preferencesManager.getDetailOption(), totalValue, preferencesManager.isBalanceHidden()));
|
currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for(int i = 0; i < currencyView.size(); i++)
|
||||||
|
{
|
||||||
|
currencyLayout.addView(currencyView.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
newRunnabmle.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void countCoins(boolean isCoin, boolean isDetails)
|
private void countCoins(boolean isCoin, boolean isDetails)
|
||||||
@ -357,6 +351,8 @@ public class Summary extends Fragment {
|
|||||||
{
|
{
|
||||||
float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) * 100;
|
float totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) * 100;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(preferencesManager.isBalanceHidden())
|
if(preferencesManager.isBalanceHidden())
|
||||||
{
|
{
|
||||||
toolbarLayout.setTitle(getResources().getString(R.string.currencyPercentagePlaceholder, String.format("%.2f", totalFluctuationPercentage)));
|
toolbarLayout.setTitle(getResources().getString(R.string.currencyPercentagePlaceholder, String.format("%.2f", totalFluctuationPercentage)));
|
||||||
@ -446,27 +442,6 @@ public class Summary extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshCurrencyList()
|
|
||||||
{
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
currencyLayout.removeAllViews();
|
|
||||||
|
|
||||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
|
||||||
{
|
|
||||||
Currency currency = balanceManager.getTotalBalance().get(i);
|
|
||||||
|
|
||||||
if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001) {
|
|
||||||
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, preferencesManager.getDetailOption(), totalValue, preferencesManager.isBalanceHidden()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adaptView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params)
|
protected Void doInBackground(Void... params)
|
||||||
{
|
{
|
||||||
@ -534,22 +509,6 @@ public class Summary extends Fragment {
|
|||||||
callBack.onSuccess(result);
|
callBack.onSuccess(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateViewButtonIcon()
|
|
||||||
{
|
|
||||||
ImageButton imgButton = getActivity().findViewById(R.id.switch_button);
|
|
||||||
|
|
||||||
imgButton.setBackgroundColor(this.getResources().getColor(R.color.buttonColor));
|
|
||||||
|
|
||||||
if(preferencesManager.getDetailOption())
|
|
||||||
{
|
|
||||||
imgButton.setBackground(this.getResources().getDrawable(R.drawable.ic_unfold_less_black_24dp));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
imgButton.setBackground(this.getResources().getDrawable(R.drawable.ic_details_black_24dp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayBalance(boolean hideBalance)
|
private void displayBalance(boolean hideBalance)
|
||||||
{
|
{
|
||||||
updateTitle();
|
updateTitle();
|
||||||
|
@ -27,6 +27,7 @@ import android.widget.ImageButton;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.support.v7.widget.Toolbar;
|
||||||
|
|
||||||
import com.github.mikephil.charting.charts.LineChart;
|
import com.github.mikephil.charting.charts.LineChart;
|
||||||
import com.github.mikephil.charting.data.Entry;
|
import com.github.mikephil.charting.data.Entry;
|
||||||
@ -69,6 +70,7 @@ public class Watchlist extends Fragment {
|
|||||||
private SwipeRefreshLayout refreshLayout;
|
private SwipeRefreshLayout refreshLayout;
|
||||||
private long lastTimestamp;
|
private long lastTimestamp;
|
||||||
private PreferencesManager preferencesManager;
|
private PreferencesManager preferencesManager;
|
||||||
|
private Toolbar toolbar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||||
@ -91,6 +93,7 @@ public class Watchlist extends Fragment {
|
|||||||
updateWatchlist(false);
|
updateWatchlist(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
toolbar = view.findViewById(R.id.toolbar);
|
||||||
|
|
||||||
Button addWatchlistButton = view.findViewById(R.id.buttonAddWatchlist);
|
Button addWatchlistButton = view.findViewById(R.id.buttonAddWatchlist);
|
||||||
addWatchlistButton.setOnClickListener(new View.OnClickListener() {
|
addWatchlistButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@ -225,8 +228,13 @@ public class Watchlist extends Fragment {
|
|||||||
|
|
||||||
if(watchlistCounter >= watchlistManager.getWatchlist().size())
|
if(watchlistCounter >= watchlistManager.getWatchlist().size())
|
||||||
{
|
{
|
||||||
|
final List<View> watchlistViews = new ArrayList<View>();
|
||||||
|
|
||||||
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews();
|
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews();
|
||||||
|
|
||||||
|
Runnable newRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
for(final Currency currency : watchlistManager.getWatchlist())
|
for(final Currency currency : watchlistManager.getWatchlist())
|
||||||
{
|
{
|
||||||
View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null);
|
View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null);
|
||||||
@ -286,9 +294,23 @@ public class Watchlist extends Fragment {
|
|||||||
setupLineChart(card, currency);
|
setupLineChart(card, currency);
|
||||||
}
|
}
|
||||||
|
|
||||||
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(card, 0);
|
watchlistViews.add(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for(int i = 0; i < watchlistViews.size(); i++)
|
||||||
|
{
|
||||||
|
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(watchlistViews.get(i), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
newRunnable.run();
|
||||||
|
|
||||||
if(refreshLayout.isRefreshing())
|
if(refreshLayout.isRefreshing())
|
||||||
{
|
{
|
||||||
refreshLayout.setRefreshing(false);
|
refreshLayout.setRefreshing(false);
|
||||||
|
@ -46,7 +46,7 @@ public class HomeLayoutGenerator {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getInfoLayout(final Currency currency, boolean isExtended, float totalValue, boolean isBalanceHidden)
|
public View getInfoLayout(final Currency currency, float totalValue, boolean isBalanceHidden)
|
||||||
{
|
{
|
||||||
View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null, true);
|
View view = LayoutInflater.from(context).inflate(R.layout.cardview_currency, null, true);
|
||||||
|
|
||||||
@ -85,15 +85,6 @@ public class HomeLayoutGenerator {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(isExtended)
|
|
||||||
{
|
|
||||||
extendView(view);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
collapseView(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateColor(view, currency);
|
updateColor(view, currency);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
app:title="Test"
|
||||||
app:layout_collapseMode="pin">
|
app:layout_collapseMode="pin">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
@ -22,6 +23,16 @@
|
|||||||
app:layout_collapseMode="pin"
|
app:layout_collapseMode="pin"
|
||||||
android:layout_margin="10dp">
|
android:layout_margin="10dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="Market Capitalization"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/settings_button"
|
android:id="@+id/settings_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -54,15 +54,6 @@
|
|||||||
app:layout_collapseMode="pin"
|
app:layout_collapseMode="pin"
|
||||||
android:layout_margin="10dp">
|
android:layout_margin="10dp">
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/switch_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/quick_button"
|
|
||||||
android:visibility="visible"
|
|
||||||
android:layout_gravity="start"
|
|
||||||
android:contentDescription="Switch view"/>
|
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/settings_button"
|
android:id="@+id/settings_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -22,6 +22,16 @@
|
|||||||
app:layout_collapseMode="pin"
|
app:layout_collapseMode="pin"
|
||||||
android:layout_margin="10dp">
|
android:layout_margin="10dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="Watchlist"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textStyle="bold"/>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/settings_button"
|
android:id="@+id/settings_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -48,7 +58,8 @@
|
|||||||
|
|
||||||
<android.support.v4.widget.NestedScrollView
|
<android.support.v4.widget.NestedScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:overScrollMode="never">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -58,7 +69,8 @@
|
|||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:overScrollMode="never">
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/linearLayoutWatchlist"
|
<LinearLayout android:id="@+id/linearLayoutWatchlist"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<color name="green">#FF4CAF50</color>
|
<color name="green">#FF4CAF50</color>
|
||||||
<color name="white">#FFFFFFFF</color>
|
<color name="white">#FFFFFFFF</color>
|
||||||
<color name="cardview_background">#FFFFFFFF</color>
|
<color name="cardview_background">#FFFFFFFF</color>
|
||||||
<color name="summary_background">#FBFCFF</color>
|
<color name="summary_background">#F5F7FA</color>
|
||||||
<color name="decreaseCandle">#FFFF5754</color>
|
<color name="decreaseCandle">#FFFF5754</color>
|
||||||
<color name="increaseCandle">#FF45B64A</color>
|
<color name="increaseCandle">#FF45B64A</color>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user