From: Damyan Ivanov Date: Fri, 30 Nov 2018 21:04:15 +0000 (+0000) Subject: remove account lines by swiping left X-Git-Tag: v0.3~365 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;ds=inline;h=0ebd3063793b5951b3c651f23b289762df798439;hp=5aac42428e1d0ef0d1e6a9d6289b1a6347ef4c33;p=mobile-ledger.git remove account lines by swiping left --- diff --git a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java index 0c67506f..1ff9431b 100644 --- a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java @@ -9,6 +9,7 @@ import android.support.v7.widget.Toolbar; import android.text.InputType; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.View; import android.widget.AutoCompleteTextView; import android.widget.EditText; @@ -18,6 +19,7 @@ import android.widget.TableRow; import java.util.Objects; public class NewTransactionActivity extends AppCompatActivity { + private TableLayout table; @Override protected void onCreate(Bundle savedInstanceState) { @@ -35,6 +37,34 @@ public class NewTransactionActivity extends AppCompatActivity { } }); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + table = findViewById(R.id.new_transaction_accounts_table); + for (int i = 0; i < table.getChildCount(); i++) { + hook_swipe_listener((TableRow)table.getChildAt(i)); +// Log.d("swipe", "hooked to row "+i); + } + } + + private void hook_swipe_listener(final TableRow row) { + row.getChildAt(0).setOnTouchListener(new OnSwipeTouchListener(this) { + public void onSwipeLeft() { +// Log.d("swipe", "LEFT" + row.getId()); + if (table.getChildCount() > 2) { + table.removeView(row); +// Toast.makeText(NewTransactionActivity.this, "LEFT", Toast.LENGTH_LONG).show(); + } + else { + Snackbar.make(table, R.string.msg_at_least_two_accounts_are_required, Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + } + } +// @Override +// public boolean performClick(View view, MotionEvent m) { +// return true; +// } + public boolean onTouch(View view, MotionEvent m) { + return gestureDetector.onTouchEvent(m); + } + }); } public boolean onCreateOptionsMenu(Menu menu) { @@ -65,7 +95,6 @@ public class NewTransactionActivity extends AppCompatActivity { amt.setMinWidth(64); amt.setTextAlignment(EditText.TEXT_ALIGNMENT_VIEW_END); - final TableLayout table = findViewById(R.id.new_transaction_accounts_table); final TableRow row = new TableRow(this); row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); row.addView(acc); @@ -73,6 +102,8 @@ public class NewTransactionActivity extends AppCompatActivity { table.addView(row); acc.requestFocus(); + + hook_swipe_listener(row); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4f6ba17e..211c7109 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,4 +59,5 @@ Transaction date amount Add another acount + At least two accounts are required