Search in sources :

Example 1 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class EntryActivity method fillData.

protected void fillData() {
    Database db = App.getDB();
    PwDatabase pm = db.pm;
    mEntry.startToDecodeReference(pm);
    // Assign title
    populateTitle(db.drawFactory.getIconDrawable(getResources(), mEntry.getIcon()), mEntry.getTitle());
    // Assign basic fields
    entryContentsView.assignUserName(mEntry.getUsername());
    entryContentsView.assignUserNameCopyListener(view -> clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(), getString(R.string.copy_field, getString(R.string.entry_user_name))));
    entryContentsView.assignPassword(mEntry.getPassword());
    if (PreferencesUtil.allowCopyPassword(this)) {
        entryContentsView.assignPasswordCopyListener(view -> clipboardHelper.timeoutCopyToClipboard(mEntry.getPassword(), getString(R.string.copy_field, getString(R.string.entry_password))));
    }
    entryContentsView.assignURL(mEntry.getUrl());
    entryContentsView.setHiddenPasswordStyle(!mShowPassword);
    entryContentsView.assignComment(mEntry.getNotes());
    // Assign custom fields
    if (mEntry.allowExtraFields()) {
        entryContentsView.clearExtraFields();
        for (Map.Entry<String, String> field : mEntry.getExtraFields().entrySet()) {
            final String label = field.getKey();
            final String value = field.getValue();
            entryContentsView.addExtraField(label, value, view -> clipboardHelper.timeoutCopyToClipboard(value, getString(R.string.copy_field, label)));
        }
    }
    // Assign dates
    entryContentsView.assignCreationDate(mEntry.getCreationTime().getDate());
    entryContentsView.assignModificationDate(mEntry.getLastModificationTime().getDate());
    entryContentsView.assignLastAccessDate(mEntry.getLastAccessTime().getDate());
    Date expires = mEntry.getExpiryTime().getDate();
    if (mEntry.expires()) {
        entryContentsView.assignExpiresDate(expires);
    } else {
        entryContentsView.assignExpiresDate(getString(R.string.never));
    }
    mEntry.endToDecodeReference(pm);
}
Also used : PwDatabase(com.keepassdroid.database.PwDatabase) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database) Map(java.util.Map) Date(java.util.Date)

Example 2 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class EntryActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.entry_view);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    assert getSupportActionBar() != null;
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    Database db = App.getDB();
    // Likely the app has been killed exit the activity
    if (!db.Loaded()) {
        finish();
        return;
    }
    readOnly = db.readOnly;
    mShowPassword = !PreferencesUtil.isPasswordMask(this);
    // Get Entry from UUID
    Intent i = getIntent();
    UUID uuid = Types.bytestoUUID(i.getByteArrayExtra(KEY_ENTRY));
    mEntry = db.pm.entries.get(uuid);
    if (mEntry == null) {
        Toast.makeText(this, R.string.entry_not_found, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    // Refresh Menu contents in case onCreateMenuOptions was called before mEntry was set
    invalidateOptionsMenu();
    // Update last access time.
    mEntry.touch(false, false);
    // Get views
    titleIconView = findViewById(R.id.entry_icon);
    titleView = findViewById(R.id.entry_title);
    entryContentsView = findViewById(R.id.entry_contents);
    entryContentsView.applyFontVisibilityToFields(PreferencesUtil.fieldFontIsInVisibility(this));
    // Setup Edit Buttons
    View edit = findViewById(R.id.entry_edit);
    edit.setOnClickListener(v -> EntryEditActivity.Launch(EntryActivity.this, mEntry));
    if (readOnly) {
        edit.setVisibility(View.GONE);
    }
    // Init the clipboard helper
    clipboardHelper = new ClipboardHelper(this);
    firstLaunchOfActivity = true;
}
Also used : PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database) Intent(android.content.Intent) UUID(java.util.UUID) ImageView(android.widget.ImageView) EntryContentsView(com.keepassdroid.view.EntryContentsView) View(android.view.View) TextView(android.widget.TextView) ClipboardHelper(com.keepassdroid.timeout.ClipboardHelper) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class DeleteEntry method testDelete.

public void testDelete() {
    Database db;
    Context ctx = getContext();
    try {
        db = TestData.GetDb(ctx, ASSET, PASSWORD, KEYFILE, FILENAME);
    } catch (Exception e) {
        assertTrue("Failed to open database: " + e.getMessage(), false);
        return;
    }
    PwDatabaseV3 pm = (PwDatabaseV3) db.pm;
    PwGroup group1 = getGroup(pm, GROUP1_NAME);
    assertNotNull("Could not find group1", group1);
    // Delete the group
    DeleteGroup task = new DeleteGroup(db, group1, null, true);
    task.run();
    // Verify the entries were deleted
    PwEntry entry1 = getEntry(pm, ENTRY1_NAME);
    assertNull("Entry 1 was not removed", entry1);
    PwEntry entry2 = getEntry(pm, ENTRY2_NAME);
    assertNull("Entry 2 was not removed", entry2);
    // Verify the entries were removed from the search index
    SearchDbHelper dbHelp = new SearchDbHelper(ctx);
    PwGroup results1 = dbHelp.search(db, ENTRY1_NAME);
    PwGroup results2 = dbHelp.search(db, ENTRY2_NAME);
    assertEquals("Entry1 was not removed from the search results", 0, results1.numbersOfChildEntries());
    assertEquals("Entry2 was not removed from the search results", 0, results2.numbersOfChildEntries());
    // Verify the group was deleted
    group1 = getGroup(pm, GROUP1_NAME);
    assertNull("Group 1 was not removed.", group1);
}
Also used : Context(android.content.Context) PwDatabaseV3(com.keepassdroid.database.PwDatabaseV3) SearchDbHelper(com.keepassdroid.search.SearchDbHelper) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database) PwEntry(com.keepassdroid.database.PwEntry) PwGroup(com.keepassdroid.database.PwGroup) DeleteGroup(com.keepassdroid.database.edit.DeleteGroup)

Example 4 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class MainPreferenceFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);
    // add listeners for non-default actions
    Preference preference = findPreference(getString(R.string.app_key));
    preference.setOnPreferenceClickListener(this);
    preference = findPreference(getString(R.string.settings_form_filling_key));
    preference.setOnPreferenceClickListener(this);
    preference = findPreference(getString(R.string.db_key));
    preference.setOnPreferenceClickListener(this);
    Database db = App.getDB();
    if (!(db.Loaded())) {
        preference.setEnabled(false);
    }
}
Also used : Preference(android.support.v7.preference.Preference) Database(com.keepassdroid.database.Database)

Example 5 with Database

use of com.keepassdroid.database.Database in project KeePassDX by Kunzisoft.

the class RoundsPreferenceDialogFragmentCompat method onBindDialogView.

@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);
    mRoundsView = (TextView) view.findViewById(R.id.rounds);
    // Get the time from the related Preference
    Database db = App.getDB();
    mPM = db.pm;
    long numRounds = mPM.getNumRounds();
    DialogPreference preference = getPreference();
    if (preference instanceof RoundsPreference) {
        numRounds = ((RoundsPreference) preference).getRounds();
    }
    mRoundsView.setText(String.valueOf(numRounds));
}
Also used : DialogPreference(android.support.v7.preference.DialogPreference) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database)

Aggregations

Database (com.keepassdroid.database.Database)11 PwDatabase (com.keepassdroid.database.PwDatabase)6 Intent (android.content.Intent)3 PwGroup (com.keepassdroid.database.PwGroup)3 Uri (android.net.Uri)2 Preference (android.support.v7.preference.Preference)2 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 PwGroupId (com.keepassdroid.database.PwGroupId)2 ProgressTask (com.keepassdroid.tasks.ProgressTask)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 AssetManager (android.content.res.AssetManager)1 Resources (android.content.res.Resources)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Settings (android.provider.Settings)1 RequiresApi (android.support.annotation.RequiresApi)1