]> git.ktnx.net Git - mobile-ledger.git/commitdiff
remove account lines by swiping left
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 30 Nov 2018 21:04:15 +0000 (21:04 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 30 Nov 2018 21:04:15 +0000 (21:04 +0000)
app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java
app/src/main/res/values/strings.xml

index 0c67506f565f3f61f6cacf88ff02c75132f549df..1ff9431b8f8cd2e25364dd3112097585e2fef98d 100644 (file)
@@ -9,6 +9,7 @@ import android.support.v7.widget.Toolbar;
 import android.text.InputType;
 import android.view.Menu;
 import android.view.MenuItem;
 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;
 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 {
 import java.util.Objects;
 
 public class NewTransactionActivity extends AppCompatActivity {
+    private TableLayout table;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -35,6 +37,34 @@ public class NewTransactionActivity extends AppCompatActivity {
             }
         });
         Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
             }
         });
         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) {
     }
 
     public boolean onCreateOptionsMenu(Menu menu) {
@@ -65,7 +95,6 @@ public class NewTransactionActivity extends AppCompatActivity {
         amt.setMinWidth(64);
         amt.setTextAlignment(EditText.TEXT_ALIGNMENT_VIEW_END);
 
         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);
         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();
         table.addView(row);
 
         acc.requestFocus();
+
+        hook_swipe_listener(row);
     }
 
 }
     }
 
 }
index 4f6ba17ed6281b20954c64602e8a01f5ea2c75be..211c7109f6301c059eda571d0b2649badc44728a 100644 (file)
@@ -59,4 +59,5 @@
     <string name="new_transaction_date_hint">Transaction date</string>
     <string name="new_transaction_amount_hint">amount</string>
     <string name="menu_add_account">Add another acount</string>
     <string name="new_transaction_date_hint">Transaction date</string>
     <string name="new_transaction_amount_hint">amount</string>
     <string name="menu_add_account">Add another acount</string>
+    <string name="msg_at_least_two_accounts_are_required">At least two accounts are required</string>
 </resources>
 </resources>