Search in sources :

Example 1 with SearchIndex

use of org.sorz.lab.tinykeepass.search.SearchIndex in project TinyKeePass by sorz.

the class AuthActivity method onDatabaseOpened.

@Override
protected void onDatabaseOpened() {
    StructureParser.Result result = parseStructure();
    KeePassFile keePass = KeePassStorage.get(this);
    SearchIndex index = new SearchIndex(keePass);
    StringBuilder queryBuilder = new StringBuilder();
    result.title.forEach(title -> queryBuilder.append(title).append(' '));
    Stream<Entry> entryStream = index.search(queryBuilder.toString()).map(keePass::getEntryByUUID);
    FillResponse.Builder responseBuilder = new FillResponse.Builder();
    // add matched entities
    entryStream.map(entry -> AutofillUtils.buildDataset(this, entry, result)).filter(Objects::nonNull).limit(MAX_NUM_CANDIDATE_ENTRIES).forEach(responseBuilder::addDataset);
    // add "show all" item
    RemoteViews presentation = AutofillUtils.getRemoteViews(this, getString(R.string.autofill_item_show_all), R.drawable.ic_more_horiz_gray_24dp);
    presentation.setTextColor(R.id.textView, getColor(R.color.hint));
    Dataset.Builder datasetBuilder = new Dataset.Builder(presentation).setAuthentication(EntrySelectActivity.getAuthIntentSenderForResponse(this));
    result.allAutofillIds().forEach(id -> datasetBuilder.setValue(id, null));
    responseBuilder.addDataset(datasetBuilder.build());
    setFillResponse(responseBuilder.build());
    finish();
}
Also used : RemoteViews(android.widget.RemoteViews) Context(android.content.Context) Dataset(android.service.autofill.Dataset) KeyException(java.security.KeyException) KeePassFile(de.slackspace.openkeepass.domain.KeePassFile) R(org.sorz.lab.tinykeepass.R) SearchIndex(org.sorz.lab.tinykeepass.search.SearchIndex) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi) PendingIntent(android.app.PendingIntent) Objects(java.util.Objects) IntentSender(android.content.IntentSender) Stream(java.util.stream.Stream) FillResponse(android.service.autofill.FillResponse) KeePassStorage(org.sorz.lab.tinykeepass.keepass.KeePassStorage) Build(android.os.Build) Entry(de.slackspace.openkeepass.domain.Entry) SearchIndex(org.sorz.lab.tinykeepass.search.SearchIndex) Dataset(android.service.autofill.Dataset) FillResponse(android.service.autofill.FillResponse) Entry(de.slackspace.openkeepass.domain.Entry) RemoteViews(android.widget.RemoteViews) Objects(java.util.Objects) KeePassFile(de.slackspace.openkeepass.domain.KeePassFile)

Aggregations

PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentSender (android.content.IntentSender)1 Build (android.os.Build)1 Dataset (android.service.autofill.Dataset)1 FillResponse (android.service.autofill.FillResponse)1 RequiresApi (android.support.annotation.RequiresApi)1 RemoteViews (android.widget.RemoteViews)1 Entry (de.slackspace.openkeepass.domain.Entry)1 KeePassFile (de.slackspace.openkeepass.domain.KeePassFile)1 KeyException (java.security.KeyException)1 Objects (java.util.Objects)1 Stream (java.util.stream.Stream)1 R (org.sorz.lab.tinykeepass.R)1 KeePassStorage (org.sorz.lab.tinykeepass.keepass.KeePassStorage)1 SearchIndex (org.sorz.lab.tinykeepass.search.SearchIndex)1