Add reorder option for Watchlist currencies | New edit buttons
This commit is contained in:
parent
856bce59ac
commit
142b00aff5
@ -46,6 +46,7 @@ dependencies {
|
||||
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
|
||||
implementation 'com.mattprecious.swirl:swirl:1.1.0'
|
||||
implementation 'com.wdullaer:materialdatetimepicker:3.5.2'
|
||||
implementation 'com.jmedeisis:draglinearlayout:1.1.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
|
@ -17,6 +17,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.herbron.moodl.Activities.CurrencySelectionActivity;
|
||||
@ -26,10 +27,12 @@ import com.herbron.moodl.DataManagers.CurrencyData.Currency;
|
||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
||||
import com.herbron.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
||||
import com.herbron.moodl.DataManagers.DatabaseManager;
|
||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||
import com.herbron.moodl.DataManagers.WatchlistManager;
|
||||
import com.herbron.moodl.MoodlBox;
|
||||
import com.herbron.moodl.R;
|
||||
import com.jmedeisis.draglinearlayout.DragLinearLayout;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@ -49,6 +52,7 @@ public class Watchlist extends Fragment {
|
||||
private int watchlistCounter;
|
||||
private CurrencyDetailsList currencyDetailsList;
|
||||
private SwipeRefreshLayout refreshLayout;
|
||||
private DragLinearLayout dragLinearLayout;
|
||||
private long lastTimestamp;
|
||||
private PreferencesManager preferencesManager;
|
||||
private String defaultCurrency;
|
||||
@ -56,6 +60,7 @@ public class Watchlist extends Fragment {
|
||||
private boolean tickerUpdated;
|
||||
private boolean detailsUpdated;
|
||||
private boolean editModeEnabled;
|
||||
private DatabaseManager databaseManager;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
|
||||
@ -63,8 +68,10 @@ public class Watchlist extends Fragment {
|
||||
view = inflater.inflate(R.layout.fragment_watchlist_homeactivity, container, false);
|
||||
|
||||
refreshLayout = view.findViewById(R.id.swiperefreshwatchlist);
|
||||
dragLinearLayout = view.findViewById(R.id.linearLayoutWatchlist);
|
||||
currencyDetailsList = CurrencyDetailsList.getInstance(getContext());
|
||||
preferencesManager = new PreferencesManager(getContext());
|
||||
databaseManager = new DatabaseManager(getContext());
|
||||
|
||||
lastTimestamp = 0;
|
||||
defaultCurrency = preferencesManager.getDefaultCurrency();
|
||||
@ -72,6 +79,17 @@ public class Watchlist extends Fragment {
|
||||
tickerUpdated = false;
|
||||
updateTickerList();
|
||||
|
||||
dragLinearLayout.setOnViewSwapListener(new DragLinearLayout.OnViewSwapListener() {
|
||||
@Override
|
||||
public void onSwap(View firstView, int firstPosition, View secondView, int secondPosition) {
|
||||
CurrencyCardview currencyCardviewMoved = (CurrencyCardview) firstView;
|
||||
CurrencyCardview currencyCardviewSwaped = (CurrencyCardview) secondView;
|
||||
|
||||
databaseManager.updateWatchlistPosition(currencyCardviewMoved.getCurrency().getSymbol(), secondPosition);
|
||||
databaseManager.updateWatchlistPosition(currencyCardviewSwaped.getCurrency().getSymbol(), firstPosition);
|
||||
}
|
||||
});
|
||||
|
||||
editModeEnabled = false;
|
||||
|
||||
watchlistManager = new WatchlistManager(getContext());
|
||||
@ -128,35 +146,40 @@ public class Watchlist extends Fragment {
|
||||
editButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
LinearLayout watchlistLayout = Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist);
|
||||
|
||||
if(editModeEnabled)
|
||||
{
|
||||
((ImageView) view.findViewById(R.id.edit_button)).setBackground(MoodlBox.getDrawable(R.drawable.ic_mode_edit_white_24dp, getContext()));
|
||||
|
||||
editModeEnabled = false;
|
||||
|
||||
for(int i = 0; i < watchlistLayout.getChildCount(); i++)
|
||||
for(int i = 0; i < dragLinearLayout.getChildCount(); i++)
|
||||
{
|
||||
View watchlistElement = watchlistLayout.getChildAt(i);
|
||||
View watchlistElement = dragLinearLayout.getChildAt(i);
|
||||
|
||||
if(watchlistElement instanceof CurrencyCardview)
|
||||
{
|
||||
watchlistElement.setClickable(true);
|
||||
collapseW(watchlistElement.findViewById(R.id.deleteCardWatchlist));
|
||||
collapseW(watchlistElement.findViewById(R.id.dragCardWatchlist));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
((ImageView) view.findViewById(R.id.edit_button)).setBackground(MoodlBox.getDrawable(R.drawable.ic_check_white_24dp, getContext()));
|
||||
|
||||
editModeEnabled = true;
|
||||
|
||||
for(int i = 0; i < watchlistLayout.getChildCount(); i++)
|
||||
for(int i = 0; i < dragLinearLayout.getChildCount(); i++)
|
||||
{
|
||||
View watchlistElement = watchlistLayout.getChildAt(i);
|
||||
View watchlistElement = dragLinearLayout.getChildAt(i);
|
||||
|
||||
if(watchlistElement instanceof CurrencyCardview)
|
||||
{
|
||||
watchlistElement.setClickable(false);
|
||||
expandW(watchlistElement.findViewById(R.id.deleteCardWatchlist));
|
||||
expandW(watchlistElement.findViewById(R.id.dragCardWatchlist));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -279,11 +302,14 @@ public class Watchlist extends Fragment {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).removeAllViews();
|
||||
dragLinearLayout.removeAllViews();
|
||||
view.findViewById(R.id.progressBarWatchlist).setVisibility(View.GONE);
|
||||
|
||||
for(Currency currency : watchlistManager.getWatchlist())
|
||||
{
|
||||
((LinearLayout) view.findViewById(R.id.linearLayoutWatchlist)).addView(new CurrencyCardview(getContext(), currency, getActivity()));
|
||||
View addedView = new CurrencyCardview(getContext(), currency, getActivity());
|
||||
|
||||
dragLinearLayout.addDragView(addedView, addedView.findViewById(R.id.dragCardWatchlist));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -43,6 +43,8 @@ import static com.herbron.moodl.MoodlBox.numberConformer;
|
||||
|
||||
public class CurrencyCardview extends CardView {
|
||||
|
||||
private Currency currency;
|
||||
|
||||
public CurrencyCardview(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
@ -51,6 +53,8 @@ public class CurrencyCardview extends CardView {
|
||||
{
|
||||
super (context);
|
||||
|
||||
this.currency = currency;
|
||||
|
||||
LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true);
|
||||
|
||||
((LineChart) findViewById(R.id.LineChartView)).setNoDataTextColor(currency.getChartColor());
|
||||
@ -136,6 +140,8 @@ public class CurrencyCardview extends CardView {
|
||||
{
|
||||
super(context);
|
||||
|
||||
this.currency = currency;
|
||||
|
||||
LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true);
|
||||
|
||||
((LineChart) findViewById(R.id.LineChartView)).setNoDataTextColor(currency.getChartColor());
|
||||
@ -198,6 +204,11 @@ public class CurrencyCardview extends CardView {
|
||||
updateColor(currency);
|
||||
}
|
||||
|
||||
public Currency getCurrency()
|
||||
{
|
||||
return currency;
|
||||
}
|
||||
|
||||
private void setupCardView()
|
||||
{
|
||||
ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT);
|
||||
|
@ -99,11 +99,33 @@ public class DatabaseManager extends SQLiteOpenHelper{
|
||||
|
||||
values.put(KEY_WATCHLIST_SYMBOL, currency.getSymbol());
|
||||
values.put(KEY_WATCHLIST_NAME, currency.getName());
|
||||
values.put(KEY_WATCHLIST_POSITION, getWatchlistRowCount(db));
|
||||
|
||||
db.insert(TABLE_WATCHLIST, null, values);
|
||||
db.close();
|
||||
}
|
||||
|
||||
public void updateWatchlistPosition(String symbol, int position)
|
||||
{
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
ContentValues cv = new ContentValues();
|
||||
|
||||
cv.put(KEY_WATCHLIST_POSITION, position);
|
||||
|
||||
db.update(TABLE_WATCHLIST, cv, KEY_WATCHLIST_SYMBOL + "='" + symbol + "'", null);
|
||||
|
||||
}
|
||||
|
||||
private int getWatchlistRowCount(SQLiteDatabase db)
|
||||
{
|
||||
String countQuerry = "SELECT COUNT() FROM " + TABLE_WATCHLIST;
|
||||
Cursor result = db.rawQuery(countQuerry, null);
|
||||
|
||||
result.moveToFirst();
|
||||
|
||||
return result.getInt(0);
|
||||
}
|
||||
|
||||
public int deleteCurrencyFromWatchlist(String symbol)
|
||||
{
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
@ -113,15 +135,15 @@ public class DatabaseManager extends SQLiteOpenHelper{
|
||||
|
||||
public List<Currency> getAllCurrenciesFromWatchlist()
|
||||
{
|
||||
String searchQuerry = "SELECT * FROM " + TABLE_WATCHLIST;
|
||||
String searchQuerry = "SELECT * FROM " + TABLE_WATCHLIST + " ORDER BY " + KEY_WATCHLIST_POSITION + " ASC";
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
Cursor resultatList = db.rawQuery(searchQuerry, null);
|
||||
Cursor resultList = db.rawQuery(searchQuerry, null);
|
||||
|
||||
List<Currency> currencyList = new ArrayList<>();
|
||||
|
||||
while(resultatList.moveToNext())
|
||||
while(resultList.moveToNext())
|
||||
{
|
||||
currencyList.add(new Currency(resultatList.getString(2), resultatList.getString(1)));
|
||||
currencyList.add(new Currency(resultList.getString(2), resultList.getString(1)));
|
||||
}
|
||||
|
||||
return currencyList;
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.util.Log;
|
||||
@ -257,6 +258,22 @@ public class MoodlBox {
|
||||
return color;
|
||||
}
|
||||
|
||||
public static Drawable getDrawable(int id, Context context)
|
||||
{
|
||||
Drawable drawable;
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
{
|
||||
drawable = context.getDrawable(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawable = context.getResources().getDrawable(id);
|
||||
}
|
||||
|
||||
return drawable;
|
||||
}
|
||||
|
||||
public static String getIconUrl(String symbol, CurrencyDetailsList currencyDetailsList)
|
||||
{
|
||||
return getIconUrl(symbol, 50, currencyDetailsList);
|
||||
|
9
app/src/main/res/drawable/ic_check_white_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_check_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="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
|
||||
</vector>
|
9
app/src/main/res/drawable/ic_drag_handle_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_drag_handle_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="#66999999"
|
||||
android:pathData="M20,9H4v2h16V9zM4,15h16v-2H4v2z"/>
|
||||
</vector>
|
@ -13,6 +13,25 @@
|
||||
android:orientation="horizontal"
|
||||
android:baselineAligned="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/dragCardWatchlist"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="start"
|
||||
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_drag_handle_24dp"
|
||||
android:clickable="false"
|
||||
android:focusable="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/currencyInfoLayout"
|
||||
android:layout_width="0dp"
|
||||
|
@ -78,11 +78,10 @@
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="25dp">
|
||||
|
||||
<LinearLayout android:id="@+id/linearLayoutWatchlist"
|
||||
<com.jmedeisis.draglinearlayout.DragLinearLayout android:id="@+id/linearLayoutWatchlist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
android:orientation="vertical"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBarWatchlist"
|
||||
@ -93,8 +92,6 @@
|
||||
android:background="@drawable/circular_progress_bar"
|
||||
android:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonAddWatchlist"
|
||||
android:text="@string/add_watchlist"
|
||||
|
Loading…
Reference in New Issue
Block a user