]> git.ktnx.net Git - mobile-ledger.git/commitdiff
abandon the new transaction FAB and use a menu item
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 6 Dec 2018 18:24:23 +0000 (18:24 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 6 Dec 2018 18:24:23 +0000 (18:24 +0000)
apart of the problems with the check-mark not appearing in submits after
the first, the button stays on the screen and obstructs the access to
the bottom account amounts

app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java
app/src/main/res/layout/activity_new_transaction.xml
app/src/main/res/layout/content_new_transaction.xml
app/src/main/res/menu/new_transaction.xml
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index d7ce8b5560cf2354a02b5672a7ada6cee432e17b..dca8d463263623469af193670079199f072b44c6 100644 (file)
@@ -6,10 +6,8 @@ import android.database.MatrixCursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Handler;
 import android.preference.PreferenceManager;
 import android.provider.FontsContract;
-import android.support.design.widget.FloatingActionButton;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.DialogFragment;
 import android.support.v7.app.AppCompatActivity;
@@ -53,51 +51,11 @@ import java.util.Objects;
 
 public class NewTransactionActivity extends AppCompatActivity implements TaskCallback {
     private TableLayout table;
-    private FloatingActionButton fab;
-    boolean fab_should_be_visible;
     private ProgressBar progress;
     private TextView text_date;
     private TextView text_descr;
     private static SaveTransactionTask saver;
-    FloatingActionButton.OnVisibilityChangedListener fab_visibility_changed_listener = new FloatingActionButton.OnVisibilityChangedListener() {
-        @Override
-        public void onShown(FloatingActionButton fab) {
-            Log.d("visuals", "FAB shown");
-            super.onShown(fab);
-            if (!fab_should_be_visible) fab.hide();
-        }
-
-        @Override
-        public void onHidden(FloatingActionButton fab) {
-            Log.d("visuals", "FAB hidden");
-            fab.setImageResource(R.drawable.ic_save_white_24dp);
-            fab.setEnabled(true);
-//            super.onHidden(fab);
-            if (fab_should_be_visible) fab.show();
-        }
-    };
-
-    private void hide_fab() {
-        hide_fab(false);
-    }
-
-    private void hide_fab(boolean force) {
-        if (!fab_should_be_visible && !force) return;
-
-        fab_should_be_visible = false;
-        fab.hide(fab_visibility_changed_listener);
-    }
-
-    private void show_fab() {
-        show_fab(false);
-    }
-
-    private void show_fab(boolean force) {
-        if (fab_should_be_visible && !force) return;
-
-        fab_should_be_visible = true;
-        fab.show(fab_visibility_changed_listener);
-    }
+    private MenuItem mSave;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -113,13 +71,6 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
             text_descr.setAutofillHints("");
         }
 
-        fab = findViewById(R.id.fab);
-        fab.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-                new_transaction_save_clicked(view);
-            }
-        });
         progress = findViewById(R.id.save_transaction_progress);
 
         Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
@@ -136,8 +87,8 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         }
     }
 
-    public void new_transaction_save_clicked(View view) {
-        fab.setEnabled(false);
+    public void save_transaction() {
+        mSave.setVisible(false);
         toggle_all_editing(false);
         progress.setVisibility(View.VISIBLE);
 
@@ -262,6 +213,8 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
     public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
         getMenuInflater().inflate(R.menu.new_transaction, menu);
+        mSave = menu.findItem(R.id.action_submit_transaction);
+        assert mSave != null;
 
         return true;
     }
@@ -307,6 +260,10 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         do_add_account_row(true);
     }
 
+    public void saveTransactionFromMenu(MenuItem item) {
+        save_transaction();
+    }
+
     private void check_transaction_submittable() {
         TableLayout table = findViewById(R.id.new_transaction_accounts_table);
         int accounts = 0;
@@ -334,26 +291,17 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal
         }
 
         if ((accounts >= 2) && (accounts_with_values >= (accounts - 1))) {
-            show_fab();
-        } else hide_fab();
+            mSave.setVisible(true);
+        } else {
+            mSave.setVisible(false);
+        }
     }
 
     @Override
     public void done() {
-        fab.setImageResource(R.drawable.ic_check_white_24dp);
         progress.setVisibility(View.INVISIBLE);
         Log.d("visuals", "hiding progress");
 
-        fab_should_be_visible = false;
-        final Handler fade_out = new Handler();
-        fade_out.postDelayed(new Runnable() {
-            @Override
-            public void run() {
-                Log.d("visuals", "hiding FAB");
-
-                hide_fab(true);
-            }
-        }, 1000);
         reset_form();
         toggle_all_editing(true);
     }
index 0db12f2f70959b87bd9ec511efa69e8d721f72c3..d5f2087730f7f24c9bfed27c060be99f2add1334 100644 (file)
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintEnd_toEndOf="parent" />
 
-        <android.support.design.widget.FloatingActionButton
-            android:id="@+id/fab"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center"
-            android:padding="@dimen/fab_margin"
-            android:tint="@android:color/white"
-            android:visibility="visible"
-            app:backgroundTint="@color/colorPrimary"
-            app:layout_constraintBottom_toBottomOf="@id/save_transaction_progress"
-            app:layout_constraintEnd_toEndOf="@id/save_transaction_progress"
-            app:layout_constraintStart_toStartOf="@id/save_transaction_progress"
-            app:layout_constraintTop_toTopOf="@id/save_transaction_progress"
-            app:srcCompat="@drawable/ic_save_white_24dp" />
-
     </android.support.constraint.ConstraintLayout>
 
 </android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
index 2589d33ec131eba13efbac809e4e39aa1c3ffab9..b4b6babedf9bc1a90e3310dba53742171682d1a0 100644 (file)
@@ -12,8 +12,6 @@
         android:id="@+id/transaction_details"
         android:layout_width="match_parent"
         android:layout_height="0dp"
-        android:layout_marginBottom="8dp"
-        app:layout_constraintBottom_toTopOf="@+id/constraintLayout"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent">
                     android:layout_width="0dp"
                     android:layout_height="wrap_content"
                     android:layout_marginStart="8dp"
+                    android:autofillHints=""
                     android:ems="10"
                     android:hint="@string/new_transaction_description_hint"
                     android:inputType="textPersonName"
                     app:layout_constraintEnd_toEndOf="parent"
                     app:layout_constraintHorizontal_weight="30"
                     app:layout_constraintStart_toEndOf="@+id/new_transaction_date"
-                    app:layout_constraintTop_toTopOf="parent"
-                    android:autofillHints="" />
+                    app:layout_constraintTop_toTopOf="parent" />
             </android.support.constraint.ConstraintLayout>
 
             <TableLayout
         </LinearLayout>
     </ScrollView>
 
-    <android.support.constraint.ConstraintLayout
-        android:id="@+id/constraintLayout"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginBottom="8dp"
-        android:visibility="gone"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent">
-
-        <ProgressBar
-            android:id="@+id/progressBar3"
-            style="?android:attr/progressBarStyle"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content" />
-
-        <TextView
-            android:id="@+id/textView3"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_marginStart="8dp"
-            android:layout_marginTop="8dp"
-            android:layout_marginEnd="8dp"
-            android:layout_marginBottom="8dp"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintHorizontal_bias="0.0"
-            app:layout_constraintStart_toEndOf="@+id/progressBar3"
-            app:layout_constraintTop_toTopOf="parent"
-            app:layout_constraintVertical_bias="0.615" />
-    </android.support.constraint.ConstraintLayout>
-
 </android.support.constraint.ConstraintLayout>
\ No newline at end of file
index 056bfb2c761fe54c2cd9f95d16dadc131136e795..7785b0aa0a6ea9a85f7aee2fd311c69d671ceca3 100644 (file)
@@ -1,11 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
     <menu xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto">
+        <item
+            android:id="@+id/action_submit_transaction"
+            android:icon="@drawable/ic_save_white_24dp"
+            android:onClick="saveTransactionFromMenu"
+            android:title="@string/action_submit_transaction_title"
+            android:visible="false"
+            app:showAsAction="always" />
         <item
             android:id="@+id/action_add_account"
             android:icon="@drawable/svg_thick_plus_white"
             android:onClick="addTransactionAccountFromMenu"
             android:orderInCategory="100"
             android:title="@string/menu_add_account"
+            android:visible="false"
             app:showAsAction="never|ifRoom" />
-</menu>
\ No newline at end of file
+    </menu>
\ No newline at end of file
index ba40a0edaab4a560fbcdd0cd5a3783e9c40dc93b..b6d39b1dc0891975ff240e762982166a3dea8276 100644 (file)
@@ -23,4 +23,5 @@
     <string name="progress_connecting">Свързване…</string>
     <string name="new_transaction_description_hint">Описание</string>
     <string name="progress_N_accounts_loaded">Заредени са %d сметки</string>
+    <string name="action_submit_transaction_title">Запазване</string>
 </resources>
\ No newline at end of file
index 633aa840179ca310c66ad86a8578bf1b8c392527..24bd8ecd2fce9cbfd29fbd134c1d22b5bf1c5abf 100644 (file)
@@ -67,4 +67,5 @@
     <string name="progress_connecting">Connecting…</string>
     <string name="progress_N_accounts_loaded">%d accounts loaded</string>
     <string name="new_transaction_description_hint">Description</string>
+    <string name="action_submit_transaction_title">Save</string>
 </resources>