Add remove option on watchlist
This commit is contained in:
parent
c431b18d36
commit
9976109472
@ -8,18 +8,17 @@ import android.graphics.PorterDuff;
|
|||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.support.design.widget.AppBarLayout;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.view.ViewPager;
|
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.graphics.Palette;
|
import android.support.v7.graphics.Palette;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -28,7 +27,6 @@ import android.widget.ImageView;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
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;
|
||||||
@ -43,6 +41,7 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
|
|||||||
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
|
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
|
||||||
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDetailsList;
|
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDetailsList;
|
||||||
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyTickerList;
|
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyTickerList;
|
||||||
|
import com.nauk.coinfolio.DataManagers.DatabaseManager;
|
||||||
import com.nauk.coinfolio.DataManagers.PreferencesManager;
|
import com.nauk.coinfolio.DataManagers.PreferencesManager;
|
||||||
import com.nauk.coinfolio.DataManagers.WatchlistManager;
|
import com.nauk.coinfolio.DataManagers.WatchlistManager;
|
||||||
import com.nauk.coinfolio.PlaceholderManager;
|
import com.nauk.coinfolio.PlaceholderManager;
|
||||||
@ -77,6 +76,7 @@ public class Watchlist extends Fragment {
|
|||||||
private CurrencyTickerList currencyTickerList;
|
private CurrencyTickerList currencyTickerList;
|
||||||
private boolean tickerUpdated;
|
private boolean tickerUpdated;
|
||||||
private boolean detailsUpdated;
|
private boolean detailsUpdated;
|
||||||
|
private boolean editModeEnabled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||||
@ -99,6 +99,8 @@ public class Watchlist extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
editModeEnabled = false;
|
||||||
|
|
||||||
watchlistManager = new WatchlistManager(getContext());
|
watchlistManager = new WatchlistManager(getContext());
|
||||||
|
|
||||||
updateWatchlist(true);
|
updateWatchlist(true);
|
||||||
@ -121,7 +123,6 @@ public class Watchlist extends Fragment {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ImageButton settingsButton = view.findViewById(R.id.settings_button);
|
ImageButton settingsButton = view.findViewById(R.id.settings_button);
|
||||||
|
|
||||||
settingsButton.setOnClickListener(new View.OnClickListener() {
|
settingsButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
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;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +200,31 @@ public class Watchlist extends Fragment {
|
|||||||
v.startAnimation(a);
|
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) {
|
private static void collapse(final View v) {
|
||||||
final int initialHeight = v.getMeasuredHeight();
|
final int initialHeight = v.getMeasuredHeight();
|
||||||
|
|
||||||
@ -198,6 +251,30 @@ public class Watchlist extends Fragment {
|
|||||||
v.startAnimation(a);
|
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
|
@Override
|
||||||
public void onResume()
|
public void onResume()
|
||||||
@ -301,7 +378,9 @@ public class Watchlist extends Fragment {
|
|||||||
|
|
||||||
private View getCurrencyCardFor(final Currency currency)
|
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))
|
((TextView) card.findViewById(R.id.currencyFluctuationTextView))
|
||||||
.setText(PlaceholderManager.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getActivity()));
|
.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.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
||||||
progressDrawable.invalidateSelf();
|
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);
|
updateColor(card, currency);
|
||||||
|
|
||||||
card.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() {
|
card.findViewById(R.id.LineChartView).setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -103,6 +103,13 @@ public class DatabaseManager extends SQLiteOpenHelper{
|
|||||||
db.close();
|
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()
|
public List<Currency> getAllCurrenciesFromWatchlist()
|
||||||
{
|
{
|
||||||
String searchQuerry = "SELECT * FROM " + TABLE_WATCHLIST;
|
String searchQuerry = "SELECT * FROM " + TABLE_WATCHLIST;
|
||||||
|
9
app/src/main/res/drawable/ic_mode_edit_white_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_mode_edit_white_24dp.xml
Normal 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>
|
@ -5,7 +5,8 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:paddingBottom="4dp">
|
android:paddingBottom="4dp"
|
||||||
|
android:tag="ParentCon">
|
||||||
|
|
||||||
<android.support.v7.widget.CardView
|
<android.support.v7.widget.CardView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -14,7 +15,13 @@
|
|||||||
android:clickable="false"
|
android:clickable="false"
|
||||||
android:backgroundTint="@color/listBackground2"
|
android:backgroundTint="@color/listBackground2"
|
||||||
app:cardCornerRadius="2dp"
|
app:cardCornerRadius="2dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent">
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
android:tag="Parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/mainLinear"
|
android:id="@+id/mainLinear"
|
||||||
@ -25,11 +32,18 @@
|
|||||||
android:tag="mainLinear">
|
android:tag="mainLinear">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/currencyInfoLayout"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:baselineAligned="false">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/currencyInfoLayout"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:layout_weight="0.92">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/topLayout"
|
android:id="@+id/topLayout"
|
||||||
@ -105,6 +119,28 @@
|
|||||||
|
|
||||||
</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:background="@drawable/ic_delete_white_24dp"
|
||||||
|
android:clickable="false"
|
||||||
|
android:focusable="false"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/collapsableLayout"
|
android:id="@+id/collapsableLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -179,6 +215,8 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</android.support.v7.widget.CardView>
|
</android.support.v7.widget.CardView>
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
@ -6,8 +6,8 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal">
|
||||||
>
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -22,6 +22,16 @@
|
|||||||
app:layout_collapseMode="pin"
|
app:layout_collapseMode="pin"
|
||||||
android:layout_margin="10dp">
|
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
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Coinfolio</string>
|
<string name="app_name">Coinfolio</string>
|
||||||
<string name="action_settings">Settings</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="donation">Fais un don wallah</string>
|
||||||
<string name="debug">Coinfolio_debug</string>
|
<string name="debug">Coinfolio_debug</string>
|
||||||
<string name="debug_volley">Coinfolio_debugVolley</string>
|
<string name="debug_volley">Coinfolio_debugVolley</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user