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);
}
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;
}
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);
}
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);
}
}
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));
}
Aggregations