From 97c625efa78f8ee286c650de6e228c89d335d4c3 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 30 Jan 2018 00:07:45 +0100 Subject: [PATCH] Transaction deletion / Coin menu Quick add of the upcoming coin menu comporting 3 tabs Possibility to remove a manual transaction from the transaction tab in the coin menu --- app/src/main/AndroidManifest.xml | 11 +- .../Activities/CurrencyDetailsActivity.java | 102 ++++++++++++++++++ .../DataManagers/DatabaseManager.java | 30 ++++++ .../LayoutManagers/HomeLayoutGenerator.java | 10 +- .../ic_account_balance_wallet_black_24dp.xml | 9 ++ .../res/drawable/ic_dashboard_black_24dp.xml | 9 ++ .../main/res/drawable/ic_home_black_24dp.xml | 9 ++ .../res/drawable/ic_show_chart_black_24dp.xml | 9 ++ .../res/layout/activity_currency_details.xml | 91 ++++++++++++++++ app/src/main/res/menu/navigation.xml | 19 ++++ app/src/main/res/values/dimens.xml | 3 + app/src/main/res/values/strings.xml | 4 + 12 files changed, 299 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java create mode 100644 app/src/main/res/drawable/ic_account_balance_wallet_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_dashboard_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_home_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_show_chart_black_24dp.xml create mode 100644 app/src/main/res/layout/activity_currency_details.xml create mode 100644 app/src/main/res/menu/navigation.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5538d15..2c2db21 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ android:supportsRtl="true" android:theme="@style/AppTheme"> @@ -22,10 +22,13 @@ - - + + + \ No newline at end of file diff --git a/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java new file mode 100644 index 0000000..d3bfe89 --- /dev/null +++ b/app/src/main/java/com/nauk/coinfolio/Activities/CurrencyDetailsActivity.java @@ -0,0 +1,102 @@ +package com.nauk.coinfolio.Activities; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.design.widget.BottomNavigationView; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.MenuItem; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.ViewFlipper; + +import com.nauk.coinfolio.DataManagers.DatabaseManager; +import com.nauk.coinfolio.R; + +import org.w3c.dom.Text; + +import java.util.HashMap; +import java.util.Iterator; + +public class CurrencyDetailsActivity extends AppCompatActivity { + + private ViewFlipper viewFlipper; + private LinearLayout transactionLayout; + private DatabaseManager databaseManager; + private String symbol; + + private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener + = new BottomNavigationView.OnNavigationItemSelectedListener() { + + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case R.id.navigation_home: + viewFlipper.setDisplayedChild(0); + return true; + case R.id.navigation_dashboard: + viewFlipper.setDisplayedChild(1); + return true; + case R.id.navigation_notifications: + viewFlipper.setDisplayedChild(2); + return true; + } + return false; + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_currency_details); + + Intent intent = getIntent(); + + symbol = intent.getStringExtra("symbol"); + + databaseManager = new DatabaseManager(this); + + viewFlipper = findViewById(R.id.vfCurrencyDetails); + transactionLayout = findViewById(R.id.transactionsLinearLayout); + + drawTransactionList(); + + BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); + navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + } + + private void drawTransactionList() + { + transactionLayout.removeAllViews(); + + HashMap transactionList = databaseManager.getCurrencyTransactions(symbol); + + Iterator transactionsIterator = transactionList.keySet().iterator(); + + while(transactionsIterator.hasNext()) + { + final TextView txtView = new TextView(this); + Integer key = (Integer) transactionsIterator.next(); + + txtView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); + txtView.setTag(key); + txtView.setText("Amount : " + transactionList.get(key)); + + txtView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + TextView thisTxtView = (TextView) view; + databaseManager.deleteTransactionFromId(Integer.parseInt(thisTxtView.getTag().toString())); + Log.d(CurrencyDetailsActivity.this.getResources().getString(R.string.debug), "Id : " + thisTxtView.getTag()); + drawTransactionList(); + } + }); + + transactionLayout.addView(txtView); + } + + } + +} diff --git a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java index c4d6889..077a1ae 100644 --- a/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/coinfolio/DataManagers/DatabaseManager.java @@ -10,6 +10,7 @@ import android.util.Log; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; /** @@ -108,4 +109,33 @@ public class DatabaseManager extends SQLiteOpenHelper{ return currencyList; } + + public HashMap getCurrencyTransactions(String symbol) + { + String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'"; + SQLiteDatabase db = this.getWritableDatabase(); + Cursor resultatList = db.rawQuery(searchQuerry, null); + + HashMap transactionList = new HashMap<>(); + + while(resultatList.moveToNext()) + { + transactionList.put(resultatList.getInt(0), resultatList.getDouble(3)); + } + + resultatList.close(); + + db.close(); + + return transactionList; + } + + public void deleteTransactionFromId(int id) + { + SQLiteDatabase db = this.getWritableDatabase(); + + db.delete(TABLE_MANUAL_CURRENCIES, KEY_CURRENCY_ID + "=" + id, null); + + db.close(); + } } diff --git a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java index 591a9ae..77bfaa2 100644 --- a/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java +++ b/app/src/main/java/com/nauk/coinfolio/LayoutManagers/HomeLayoutGenerator.java @@ -3,6 +3,7 @@ package com.nauk.coinfolio.LayoutManagers; import android.animation.AnimatorInflater; import android.animation.StateListAnimator; import android.content.Context; +import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Color; import android.support.design.widget.Snackbar; @@ -16,6 +17,8 @@ import android.widget.TextView; import com.db.chart.model.LineSet; import com.db.chart.renderer.AxisRenderer; import com.db.chart.view.LineChartView; +import com.nauk.coinfolio.Activities.CurrencyDetailsActivity; +import com.nauk.coinfolio.Activities.HomeActivity; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.coinfolio.R; @@ -39,7 +42,7 @@ public class HomeLayoutGenerator { this.context = context; } - public CardView getInfoLayout(Currency currency, int chartColor) + public CardView getInfoLayout(final Currency currency, int chartColor) { CardView mainCard = new CardView(context); LinearLayout mainLinear = new LinearLayout(context); @@ -63,8 +66,9 @@ public class HomeLayoutGenerator { @Override public void onClick(View view) { view.animate(); - Snackbar.make(view, "This feature is not yet available...", Snackbar.LENGTH_LONG) - .show(); + Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class); + intent.putExtra("symbol", currency.getSymbol()); + context.getApplicationContext().startActivity(intent); } }); mainCard.setClickable(true); diff --git a/app/src/main/res/drawable/ic_account_balance_wallet_black_24dp.xml b/app/src/main/res/drawable/ic_account_balance_wallet_black_24dp.xml new file mode 100644 index 0000000..326c11a --- /dev/null +++ b/app/src/main/res/drawable/ic_account_balance_wallet_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_dashboard_black_24dp.xml b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml new file mode 100644 index 0000000..ae6a446 --- /dev/null +++ b/app/src/main/res/drawable/ic_dashboard_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_home_black_24dp.xml b/app/src/main/res/drawable/ic_home_black_24dp.xml new file mode 100644 index 0000000..0c36320 --- /dev/null +++ b/app/src/main/res/drawable/ic_home_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_show_chart_black_24dp.xml b/app/src/main/res/drawable/ic_show_chart_black_24dp.xml new file mode 100644 index 0000000..550bdf1 --- /dev/null +++ b/app/src/main/res/drawable/ic_show_chart_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_currency_details.xml b/app/src/main/res/layout/activity_currency_details.xml new file mode 100644 index 0000000..fad4b5f --- /dev/null +++ b/app/src/main/res/layout/activity_currency_details.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/navigation.xml b/app/src/main/res/menu/navigation.xml new file mode 100644 index 0000000..c17a03a --- /dev/null +++ b/app/src/main/res/menu/navigation.xml @@ -0,0 +1,19 @@ + + + + + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 72b40bd..2960eca 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,4 +4,7 @@ 16dp 6dp 5dp + + 16dp + 16dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6a7d52c..1796bb0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -116,4 +116,8 @@ Amount Purchased price + CurrencyDetailsActivity + Charts + Infos + Transactions