mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Patch to allow autofill in search #62
This commit is contained in:
1 parent
747135afae
commit
5c1e9bd94f
2 files changed
+71
-52
No files matched your search
@@ -75,8 +75,6 @@ public class GroupActivity extends ListNodesActivity
|
||||
protected boolean readOnly = false;
|
||||
protected EditGroupDialogAction editGroupDialogAction = EditGroupDialogAction.NONE;
|
||||
|
||||
private AutofillHelper autofillHelper;
|
||||
|
||||
private enum EditGroupDialogAction {
|
||||
CREATION, UPDATE, NONE
|
||||
}
|
||||
@@ -163,11 +161,6 @@ public class GroupActivity extends ListNodesActivity
|
||||
setGroupTitle();
|
||||
setGroupIcon();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
autofillHelper = new AutofillHelper();
|
||||
autofillHelper.retrieveAssistStructure(getIntent());
|
||||
}
|
||||
|
||||
Log.w(TAG, "Finished creating tree");
|
||||
|
||||
if (isRoot) {
|
||||
@@ -205,31 +198,6 @@ public class GroupActivity extends ListNodesActivity
|
||||
return (RecyclerView) findViewById(R.id.nodes_list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNodeClick(PwNode node) {
|
||||
// Add event when we have Autofill
|
||||
AssistStructure assistStructure = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
assistStructure = autofillHelper.getAssistStructure();
|
||||
if (assistStructure != null) {
|
||||
mAdapter.registerANodeToUpdate(node);
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
GroupActivity.launch(this, (PwGroup) node, assistStructure);
|
||||
break;
|
||||
case ENTRY:
|
||||
// Build response with the entry selected
|
||||
autofillHelper.buildResponseWhenEntrySelected(this, (PwEntry) node);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( assistStructure == null ){
|
||||
super.onNodeClick(node);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addOptionsToAdapter(NodeAdapter nodeAdapter) {
|
||||
super.addOptionsToAdapter(nodeAdapter);
|
||||
@@ -297,15 +265,6 @@ public class GroupActivity extends ListNodesActivity
|
||||
addNodeButtonView.hideButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSortSelected(SortNodeEnum sortNodeEnum, boolean ascending, boolean groupsBefore, boolean recycleBinBottom) {
|
||||
super.onSortSelected(sortNodeEnum, ascending, groupsBefore, recycleBinBottom);
|
||||
@@ -364,6 +323,30 @@ public class GroupActivity extends ListNodesActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent) {
|
||||
boolean customSearchQueryExecuted = false;
|
||||
|
||||
// Get the intent, verify the action and get the query
|
||||
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
||||
// manually launch the real search activity
|
||||
final Intent searchIntent = new Intent(getApplicationContext(), SearchResultsActivity.class);
|
||||
// add query to the Intent Extras
|
||||
searchIntent.putExtra(SearchManager.QUERY, query);
|
||||
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||
&& autofillHelper.getAssistStructure() != null ) {
|
||||
AutofillHelper.addAssistStructureExtraInIntent(searchIntent, autofillHelper.getAssistStructure());
|
||||
startActivityForResult(searchIntent, AutofillHelper.AUTOFILL_RESPONSE_REQUEST_CODE);
|
||||
customSearchQueryExecuted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!customSearchQueryExecuted) {
|
||||
super.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
*/
|
||||
package com.keepassdroid.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.assist.AssistStructure;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
@@ -38,6 +40,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.keepassdroid.adapters.NodeAdapter;
|
||||
import com.keepassdroid.app.App;
|
||||
import com.keepassdroid.autofill.AutofillHelper;
|
||||
import com.keepassdroid.compat.EditorCompat;
|
||||
import com.keepassdroid.database.Database;
|
||||
import com.keepassdroid.database.PwDatabase;
|
||||
@@ -65,6 +68,8 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
private SharedPreferences prefs;
|
||||
|
||||
protected AutofillHelper autofillHelper;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -90,6 +95,11 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
mAdapter = new NodeAdapter(this);
|
||||
addOptionsToAdapter(mAdapter);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
autofillHelper = new AutofillHelper();
|
||||
autofillHelper.retrieveAssistStructure(getIntent());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PwGroup initCurrentGroup();
|
||||
@@ -111,7 +121,7 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
protected void setGroupTitle() {
|
||||
if ( mCurrentGroup != null ) {
|
||||
String name = mCurrentGroup.getName();
|
||||
TextView tv = (TextView) findViewById(R.id.group_name);
|
||||
TextView tv = findViewById(R.id.group_name);
|
||||
if ( name != null && name.length() > 0 ) {
|
||||
if ( tv != null ) {
|
||||
tv.setText(name);
|
||||
@@ -133,14 +143,35 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
|
||||
@Override
|
||||
public void onNodeClick(PwNode node) {
|
||||
mAdapter.registerANodeToUpdate(node);
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
GroupActivity.launch(this, (PwGroup) node);
|
||||
break;
|
||||
case ENTRY:
|
||||
EntryActivity.launch(this, (PwEntry) node);
|
||||
break;
|
||||
|
||||
mAdapter.registerANodeToUpdate(node);
|
||||
|
||||
// Add event when we have Autofill
|
||||
AssistStructure assistStructure = null;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
assistStructure = autofillHelper.getAssistStructure();
|
||||
if (assistStructure != null) {
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
GroupActivity.launch(this, (PwGroup) node, assistStructure);
|
||||
break;
|
||||
case ENTRY:
|
||||
// Build response with the entry selected
|
||||
autofillHelper.buildResponseWhenEntrySelected(this, (PwEntry) node);
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( assistStructure == null ){
|
||||
switch (node.getType()) {
|
||||
case GROUP:
|
||||
GroupActivity.launch(this, (PwGroup) node);
|
||||
break;
|
||||
case ENTRY:
|
||||
EntryActivity.launch(this, (PwEntry) node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +259,7 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
switch (requestCode) {
|
||||
case EntryEditActivity.ADD_OR_UPDATE_ENTRY_REQUEST_CODE:
|
||||
if (resultCode == EntryEditActivity.ADD_ENTRY_RESULT_CODE ||
|
||||
@@ -246,9 +278,14 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Override
|
||||
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
|
||||
/*
|
||||
* ACTION_SEARCH automatically forces a new task. This occurs when you open a kdb file in
|
||||
@@ -262,7 +299,6 @@ public abstract class ListNodesActivity extends LockingActivity
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
// TODO BUG HERE
|
||||
super.startActivityForResult(intent, requestCode, options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user