Search in sources :

Example 6 with PwGroup

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

the class DeleteEntry method run.

@Override
public void run() {
    PwDatabase pm = mDb.pm;
    PwGroup parent = mEntry.getParent();
    // Remove Entry from parent
    boolean recycle = pm.canRecycle(mEntry);
    if (recycle) {
        pm.recycle(mEntry);
    } else {
        pm.deleteEntry(mEntry);
    }
    // Save
    mFinish = new AfterDelete(mFinish, parent, mEntry, recycle);
    // Commit database
    SaveDB save = new SaveDB(ctx, mDb, mFinish, mDontSave);
    save.run();
}
Also used : PwDatabase(com.keepassdroid.database.PwDatabase) PwGroup(com.keepassdroid.database.PwGroup)

Example 7 with PwGroup

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

the class DeleteGroup method run.

@Override
public void run() {
    PwDatabase pm = mDb.pm;
    PwGroup parent = mGroup.getParent();
    // Remove Group from parent
    boolean recycle = pm.canRecycle(mGroup);
    if (recycle) {
        pm.recycle(mGroup);
    } else {
        // TODO tests
        // Remove child entries
        List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries());
        for (int i = 0; i < childEnt.size(); i++) {
            DeleteEntry task = new DeleteEntry(mContext, mDb, childEnt.get(i), null, true);
            task.run();
        }
        // Remove child groups
        List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups());
        for (int i = 0; i < childGrp.size(); i++) {
            DeleteGroup task = new DeleteGroup(mContext, mDb, childGrp.get(i), null, true);
            task.run();
        }
        pm.deleteGroup(mGroup);
        // Remove from PwDatabaseV3
        // TODO ENcapsulate
        mDb.pm.getGroups().remove(mGroup);
    }
    // Save
    mFinish = new AfterDelete(mFinish, parent, mGroup, recycle);
    // Commit Database
    SaveDB save = new SaveDB(mContext, mDb, mFinish, mDontSave);
    save.run();
}
Also used : PwDatabase(com.keepassdroid.database.PwDatabase) PwEntry(com.keepassdroid.database.PwEntry) ArrayList(java.util.ArrayList) PwGroup(com.keepassdroid.database.PwGroup)

Example 8 with PwGroup

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

the class EntryEditActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.entry_edit);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    setSupportActionBar(toolbar);
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    scrollView = findViewById(R.id.entry_scroll);
    scrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
    entryTitleView = findViewById(R.id.entry_title);
    entryUserNameView = findViewById(R.id.entry_user_name);
    entryUrlView = findViewById(R.id.entry_url);
    entryPasswordView = findViewById(R.id.entry_password);
    entryConfirmationPasswordView = findViewById(R.id.entry_confpassword);
    entryCommentView = findViewById(R.id.entry_comment);
    entryExtraFieldsContainer = findViewById(R.id.advanced_container);
    // Likely the app has been killed exit the activity
    Database db = App.getDB();
    if (!db.Loaded()) {
        finish();
        return;
    }
    Intent intent = getIntent();
    byte[] uuidBytes = intent.getByteArrayExtra(KEY_ENTRY);
    PwDatabase pm = db.pm;
    if (uuidBytes == null) {
        PwGroupId parentId = (PwGroupId) intent.getSerializableExtra(KEY_PARENT);
        PwGroup parent = pm.groups.get(parentId);
        mEntry = PwEntry.getInstance(parent);
        mIsNew = true;
    } else {
        UUID uuid = Types.bytestoUUID(uuidBytes);
        mEntry = pm.entries.get(uuid);
        mIsNew = false;
        fillData();
    }
    View iconButton = findViewById(R.id.icon_button);
    iconButton.setOnClickListener(v -> IconPickerDialogFragment.launch(EntryEditActivity.this));
    // Generate password button
    View generatePassword = findViewById(R.id.generate_button);
    generatePassword.setOnClickListener(v -> {
        GeneratePasswordDialogFragment generatePasswordDialogFragment = new GeneratePasswordDialogFragment();
        generatePasswordDialogFragment.show(getSupportFragmentManager(), "PasswordGeneratorFragment");
    });
    // Save button
    View save = findViewById(R.id.entry_save);
    save.setOnClickListener(v -> {
        if (!validateBeforeSaving()) {
            return;
        }
        mCallbackNewEntry = populateNewEntry();
        OnFinish onFinish = new AfterSave();
        EntryEditActivity act = EntryEditActivity.this;
        RunnableOnFinish task;
        if (mIsNew) {
            task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish);
        } else {
            task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
        }
        ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
        pt.run();
    });
    if (mEntry.allowExtraFields()) {
        View add = findViewById(R.id.add_new_field);
        add.setVisibility(View.VISIBLE);
        add.setOnClickListener(v -> {
            EntryEditNewField ees = new EntryEditNewField(EntryEditActivity.this);
            ees.setData("", new ProtectedString(false, ""));
            entryExtraFieldsContainer.addView(ees);
            // Scroll bottom
            scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN));
        });
    }
}
Also used : ProgressTask(com.keepassdroid.tasks.ProgressTask) UpdateEntry(com.keepassdroid.database.edit.UpdateEntry) PwDatabase(com.keepassdroid.database.PwDatabase) RunnableOnFinish(com.keepassdroid.database.edit.RunnableOnFinish) Intent(android.content.Intent) OnFinish(com.keepassdroid.database.edit.OnFinish) RunnableOnFinish(com.keepassdroid.database.edit.RunnableOnFinish) EntryEditNewField(com.keepassdroid.view.EntryEditNewField) View(android.view.View) ScrollView(android.widget.ScrollView) AddEntry(com.keepassdroid.database.edit.AddEntry) GeneratePasswordDialogFragment(com.keepassdroid.dialogs.GeneratePasswordDialogFragment) PwGroupId(com.keepassdroid.database.PwGroupId) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database) ProtectedString(com.keepassdroid.database.security.ProtectedString) PwGroup(com.keepassdroid.database.PwGroup) UUID(java.util.UUID) Toolbar(android.support.v7.widget.Toolbar)

Example 9 with PwGroup

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

the class GroupActivity method initCurrentGroup.

protected PwGroup initCurrentGroup() {
    PwGroup currentGroup;
    Database db = App.getDB();
    readOnly = db.readOnly;
    PwGroup root = db.pm.rootGroup;
    Log.w(TAG, "Creating tree view");
    PwGroupId pwGroupId = (PwGroupId) getIntent().getSerializableExtra(GROUP_ID_KEY);
    if (pwGroupId == null) {
        currentGroup = root;
    } else {
        currentGroup = db.pm.groups.get(pwGroupId);
    }
    if (currentGroup != null) {
        addGroupEnabled = !readOnly;
        // TODO ReadOnly
        addEntryEnabled = !readOnly;
        isRoot = (currentGroup == root);
        if (!currentGroup.allowAddEntryIfIsRoot())
            addEntryEnabled = !isRoot && addEntryEnabled;
    }
    return currentGroup;
}
Also used : PwGroupId(com.keepassdroid.database.PwGroupId) Database(com.keepassdroid.database.Database) PwGroup(com.keepassdroid.database.PwGroup)

Example 10 with PwGroup

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

the class SearchTest method testSearch.

public void testSearch() {
    PwGroup results = mDb.Search("Amazon");
    assertTrue("Search result not found.", results.numbersOfChildEntries() > 0);
}
Also used : PwGroup(com.keepassdroid.database.PwGroup)

Aggregations

PwGroup (com.keepassdroid.database.PwGroup)10 PwDatabase (com.keepassdroid.database.PwDatabase)5 Database (com.keepassdroid.database.Database)3 PwEntry (com.keepassdroid.database.PwEntry)3 PwDatabaseV3 (com.keepassdroid.database.PwDatabaseV3)2 PwGroupId (com.keepassdroid.database.PwGroupId)2 PwGroupV3 (com.keepassdroid.database.PwGroupV3)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ScrollView (android.widget.ScrollView)1 PwDatabaseV4 (com.keepassdroid.database.PwDatabaseV4)1 PwEntryV3 (com.keepassdroid.database.PwEntryV3)1 PwGroupV4 (com.keepassdroid.database.PwGroupV4)1 AddEntry (com.keepassdroid.database.edit.AddEntry)1 DeleteGroup (com.keepassdroid.database.edit.DeleteGroup)1 OnFinish (com.keepassdroid.database.edit.OnFinish)1 RunnableOnFinish (com.keepassdroid.database.edit.RunnableOnFinish)1 UpdateEntry (com.keepassdroid.database.edit.UpdateEntry)1