Add remove option on watchlist

This commit is contained in:
Tanguy Herbron 2018-04-22 22:57:16 +02:00
parent c431b18d36
commit 9976109472
7 changed files with 286 additions and 133 deletions

View File

@ -8,18 +8,17 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.CardView;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.Button;
@ -28,7 +27,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.support.v7.widget.Toolbar;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
@ -43,6 +41,7 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDetailsList;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyTickerList;
import com.nauk.coinfolio.DataManagers.DatabaseManager;
import com.nauk.coinfolio.DataManagers.PreferencesManager;
import com.nauk.coinfolio.DataManagers.WatchlistManager;
import com.nauk.coinfolio.PlaceholderManager;
@ -77,6 +76,7 @@ public class Watchlist extends Fragment {
private CurrencyTickerList currencyTickerList;
private boolean tickerUpdated;
private boolean detailsUpdated;
private boolean editModeEnabled;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
@ -99,6 +99,8 @@ public class Watchlist extends Fragment {
}
});
editModeEnabled = false;
watchlistManager = new WatchlistManager(getContext());
updateWatchlist(true);
@ -121,7 +123,6 @@ public class Watchlist extends Fragment {
});
ImageButton settingsButton = view.findViewById(R.id.settings_button);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -130,6 +131,33 @@ public class Watchlist extends Fragment {
}
});
ImageButton editButton = view.findViewById(R.id.edit_button);
editButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(editModeEnabled)
{
editModeEnabled = false;
for(int i = 0; i < ((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildCount(); i++)
{
((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildAt(i).setClickable(true);
collapseW(((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildAt(i).findViewById(R.id.deleteCardWatchlist));
}
}
else
{
editModeEnabled = true;
for(int i = 0; i < ((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildCount(); i++)
{
((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildAt(i).setClickable(false);
expandW(((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildAt(i).findViewById(R.id.deleteCardWatchlist));
}
}
}
});
return view;
}
@ -172,6 +200,31 @@ public class Watchlist extends Fragment {
v.startAnimation(a);
}
private static void expandW(final View v) {
v.measure(CardView.LayoutParams.MATCH_PARENT, CardView.LayoutParams.WRAP_CONTENT);
final int targetWidth = v.getMeasuredWidth();
v.getLayoutParams().width = 1;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().width = interpolatedTime == 1
? CardView.LayoutParams.WRAP_CONTENT
: (int)(targetWidth * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration((int)(targetWidth / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
private static void collapse(final View v) {
final int initialHeight = v.getMeasuredHeight();
@ -198,6 +251,30 @@ public class Watchlist extends Fragment {
v.startAnimation(a);
}
private static void collapseW(final View v) {
final int initialWidth = v.getMeasuredWidth();
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if(interpolatedTime == 1) {
v.setVisibility(View.GONE);
} else {
v.getLayoutParams().width = initialWidth - (int)(initialWidth * interpolatedTime);
v.requestLayout();
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration((int)(initialWidth / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
@Override
public void onResume()
@ -301,7 +378,9 @@ public class Watchlist extends Fragment {
private View getCurrencyCardFor(final Currency currency)
{
View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null);
final View card = LayoutInflater.from(getContext()).inflate(R.layout.cardview_watchlist, null);
card.setTag(currency.getSymbol());
((TextView) card.findViewById(R.id.currencyFluctuationTextView))
.setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getActivity()));
@ -328,6 +407,15 @@ public class Watchlist extends Fragment {
progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
progressDrawable.invalidateSelf();
card.findViewById(R.id.deleteCardWatchlist).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
collapse(card);
DatabaseManager databaseManager = new DatabaseManager(getActivity());
databaseManager.deleteCurrencyFromWatchlist(currency.getSymbol());
}
});
updateColor(card, currency);
card.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() {

View File

@ -103,6 +103,13 @@ public class DatabaseManager extends SQLiteOpenHelper{
db.close();
}
public int deleteCurrencyFromWatchlist(String symbol)
{
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_WATCHLIST, KEY_WATCHLIST_SYMBOL + " = '" + symbol + "'", null);
}
public List<Currency> getAllCurrenciesFromWatchlist()
{
String searchQuerry = "SELECT * FROM " + TABLE_WATCHLIST;

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

View File

@ -5,7 +5,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:focusable="true"
android:paddingBottom="4dp">
android:paddingBottom="4dp"
android:tag="ParentCon">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
@ -14,166 +15,203 @@
android:clickable="false"
android:backgroundTint="@color/listBackground2"
app:cardCornerRadius="2dp"
app:layout_constraintBottom_toBottomOf="parent">
app:layout_constraintBottom_toBottomOf="parent"
android:tag="Parent">
<LinearLayout
android:id="@+id/mainLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:orientation="vertical"
android:tag="mainLinear">
android:orientation="horizontal">
<LinearLayout
android:id="@+id/currencyInfoLayout"
android:id="@+id/mainLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
android:clickable="false"
android:orientation="vertical"
android:tag="mainLinear">
<LinearLayout
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="@+id/currencyIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp" />
<TextView
android:id="@+id/currencyNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="start"
android:textColor="@color/mainTextViewColor"
android:textSize="@dimen/cardViewMainText" />
<TextView
android:id="@+id/currencySymbolTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:gravity="left"
android:textColor="@color/secondaryTextViewColor"
android:textSize="@dimen/cardViewSecondaryText" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/currencyValueTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:textColor="@color/secondaryTextViewColor"
android:textSize="@dimen/cardViewMainText"
android:layout_weight="0.5"/>
android:baselineAligned="false">
<LinearLayout
android:id="@+id/secondaryLayout"
android:layout_width="match_parent"
android:id="@+id/currencyInfoLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal"
android:layout_weight="0.5">
android:layout_margin="5dp"
android:orientation="vertical"
android:layout_weight="0.92">
<TextView
android:id="@+id/currencyFluctuationPercentageTextView"
<LinearLayout
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="@+id/currencyIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp" />
<TextView
android:id="@+id/currencyNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="start"
android:textColor="@color/mainTextViewColor"
android:textSize="@dimen/cardViewMainText" />
<TextView
android:id="@+id/currencySymbolTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:gravity="left"
android:textColor="@color/secondaryTextViewColor"
android:textSize="@dimen/cardViewSecondaryText" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/currencyValueTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:textColor="@color/secondaryTextViewColor"
android:textSize="@dimen/cardViewMainText"
android:layout_weight="0.5"/>
<LinearLayout
android:id="@+id/secondaryLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal"
android:layout_weight="0.5">
<TextView
android:id="@+id/currencyFluctuationPercentageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/cardViewMainText" />
<TextView
android:id="@+id/currencyFluctuationTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/cardViewSecondaryText" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/deleteCardWatchlist"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/decreaseCandle"
android:gravity="center"
android:layout_gravity="end"
android:visibility="gone"
android:layout_weight="0.08"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/cardViewMainText" />
<TextView
android:id="@+id/currencyFluctuationTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/cardViewSecondaryText" />
android:background="@drawable/ic_delete_white_24dp"
android:clickable="false"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/collapsableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical">
<LinearLayout
android:id="@+id/separationLayout"
android:id="@+id/collapsableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
android:visibility="gone"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Day history"
android:textSize="@dimen/cardViewSecondaryText" />
<View
<LinearLayout
android:id="@+id/separationLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/separationColor" />
</LinearLayout>
<FrameLayout
android:id="@+id/frameLayoutChart"
android:layout_width="match_parent"
android:layout_height="@dimen/cardViewChartSize"
android:clickable="true"
android:focusable="true"
android:visibility="visible">
<ProgressBar
android:id="@+id/progressBarLinechartWatchlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:visibility="visible"/>
android:layout_margin="5dp">
<FrameLayout
android:id="@+id/linearLayoutSubLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:visibility="gone">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/LineChartView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/detailsArrow"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_keyboard_arrow_right_grey_48dp"
android:layout_gravity="center_vertical|end"/>
android:text="Day history"
android:textSize="@dimen/cardViewSecondaryText" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/separationLineSize"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/separationColor" />
</LinearLayout>
<FrameLayout
android:id="@+id/frameLayoutChart"
android:layout_width="match_parent"
android:layout_height="@dimen/cardViewChartSize"
android:clickable="true"
android:focusable="true"
android:visibility="visible">
<ProgressBar
android:id="@+id/progressBarLinechartWatchlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"
android:visibility="visible"/>
<FrameLayout
android:id="@+id/linearLayoutSubLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:visibility="gone">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/LineChartView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/detailsArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_keyboard_arrow_right_grey_48dp"
android:layout_gravity="center_vertical|end"/>
</FrameLayout>
</FrameLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>

View File

@ -6,8 +6,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -22,6 +22,16 @@
app:layout_collapseMode="pin"
android:layout_margin="10dp">
<ImageButton
android:id="@+id/edit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_edit_mode"
android:background="@drawable/ic_mode_edit_white_24dp"
android:visibility="visible"
android:layout_gravity="start"
android:contentDescription="Edit mode"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -1,6 +1,7 @@
<resources>
<string name="app_name">Coinfolio</string>
<string name="action_settings">Settings</string>
<string name="action_edit_mode">Edit mode</string>
<string name="donation">Fais un don wallah</string>
<string name="debug">Coinfolio_debug</string>
<string name="debug_volley">Coinfolio_debugVolley</string>