]> git.ktnx.net Git - mobile-ledger.git/commitdiff
hookAutocompletion: leave the "focus the next view" logic for the callback
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Sep 2019 17:53:53 +0000 (20:53 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Sep 2019 17:57:30 +0000 (20:57 +0300)
getting to the "next" view from the auto completion adapter is rather
difficult, and the callback already has all the needed information

app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java
app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java

index ac01c93e014be58d7958caf439ef9c3b3736a938..c87550f58d562e129fb8c92cde9efb6777afd67f 100644 (file)
@@ -103,7 +103,7 @@ public class NewTransactionActivity extends ProfileThemedActivity
         });
         tvDescription = findViewById(R.id.new_transaction_description);
         MLDB.hookAutocompletionAdapter(this, tvDescription, MLDB.DESCRIPTION_HISTORY_TABLE,
-                "description", false, findViewById(R.id.new_transaction_acc_1), this, mProfile);
+                "description", false, this, mProfile);
         hookTextChangeListener(tvDescription);
 
         progress = findViewById(R.id.save_transaction_progress);
@@ -365,8 +365,8 @@ public class NewTransactionActivity extends ProfileThemedActivity
         if (focus) acc.requestFocus();
 
         hookSwipeListener(row);
-        MLDB.hookAutocompletionAdapter(this, acc, MLDB.ACCOUNTS_TABLE, "name", true, amt, null,
-                mProfile);
+        MLDB.hookAutocompletionAdapter(this, acc, MLDB.ACCOUNTS_TABLE, "name", true,
+                description -> amt.requestFocus(), mProfile);
         hookTextChangeListener(acc);
         hookTextChangeListener(amt);
 
index 5741a2e6fb45bf8357b7a8b07d66df3685ba1b62..ab792ae47d1e7b7c54cb97cc77f5031e40a12713 100644 (file)
@@ -25,7 +25,6 @@ import android.database.sqlite.SQLiteDatabase;
 import android.os.AsyncTask;
 import android.os.Build;
 import android.provider.FontsContract;
-import android.view.View;
 import android.widget.AutoCompleteTextView;
 import android.widget.FilterQueryProvider;
 import android.widget.SimpleCursorAdapter;
@@ -137,13 +136,13 @@ public final class MLDB {
     public static void hookAutocompletionAdapter(final Context context,
                                                  final AutoCompleteTextView view,
                                                  final String table, final String field) {
-        hookAutocompletionAdapter(context, view, table, field, true, null, null, null);
+        hookAutocompletionAdapter(context, view, table, field, true, null, null);
     }
     @TargetApi(Build.VERSION_CODES.N)
     public static void hookAutocompletionAdapter(final Context context,
                                                  final AutoCompleteTextView view,
                                                  final String table, final String field,
-                                                 final boolean profileSpecific, final View nextView,
+                                                 final boolean profileSpecific,
                                                  final DescriptionSelectedCallback callback,
                                                  final MobileLedgerProfile profile) {
         String[] from = {field};
@@ -204,14 +203,9 @@ public final class MLDB {
 
         view.setAdapter(adapter);
 
-        if (nextView != null) {
-            view.setOnItemClickListener((parent, itemView, position, id) -> {
-                nextView.requestFocus(View.FOCUS_FORWARD);
-                if (callback != null) {
-                    callback.descriptionSelected(String.valueOf(view.getText()));
-                }
-            });
-        }
+        if (callback != null) view.setOnItemClickListener((parent, itemView, position, id) -> {
+            callback.descriptionSelected(String.valueOf(view.getText()));
+        });
     }
 }