Android Open Source - KeepMySecret Entry Dao






From Project

Back to project page KeepMySecret.

License

The source code is released under:

GNU General Public License

If you think the Android project KeepMySecret listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package keepmysecretapp.app.com.keepmysecretapp.dao;
/*www  . ja va2 s  . com*/
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;

import keepmysecretapp.app.com.keepmysecretapp.db.DbContext;
import keepmysecretapp.app.com.keepmysecretapp.db.EntryType;
import keepmysecretapp.app.com.keepmysecretapp.other.Tools;
import keepmysecretapp.app.com.keepmysecretapp.tables.DataTable;
import keepmysecretapp.app.com.keepmysecretapp.tables.GroupTable;
import keepmysecretapp.app.com.keepmysecretapp.types.ListEntry;

public class EntryDao extends Dao {

    private int groupID;

    public EntryDao(DbContext inContext, int groupID) {
        super(inContext);
        this.groupID = groupID;
    }

    @Override
    public void create(Object obj) {

        ListEntry entry = (ListEntry) obj;

        SQLiteDatabase db = this.dbContext.getWritableDatabase();

        ContentValues values = new ContentValues();

        values.put(DataTable.KEY_ENTRY_NAME, entry.getName());
        values.put(DataTable.KEY_ENTRY_DESCRIBE, entry.getDescribe());
        values.put(DataTable.KEY_ENTRY_PASSWORD, entry.getPassword());
        values.put(DataTable.KEY_ENTRY_GROUP_ID, entry.getGroupID());

        db.insert(EntryType.DATA.getName(), null, values);
        db.close();

    }

    @Override
    public void delete(Object obj) {

        ListEntry entry = (ListEntry) obj;

        SQLiteDatabase db = this.dbContext.getWritableDatabase();
        db.delete(EntryType.DATA.getName(),
                DataTable.KEY_ID + " = ?", new String[]{entry.getID() + ""});

        db.close();

    }

    @Override
    public int update(Object obj) {


        ListEntry entry = (ListEntry) obj;

        SQLiteDatabase db = this.dbContext.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(DataTable.KEY_ENTRY_NAME, entry.getName());
        values.put(DataTable.KEY_ENTRY_GROUP_ID, entry.getGroupID());
        values.put(DataTable.KEY_ENTRY_PASSWORD, entry.getPassword());
        values.put(DataTable.KEY_ENTRY_DESCRIBE, entry.getDescribe());

        return db.update(EntryType.DATA.getName(), values,
                DataTable.KEY_ID + " = ?", new String[]{String.valueOf(entry.getID())});

    }

    @Override
    public Object read(Object obj) {
        SQLiteDatabase db = this.dbContext.getReadableDatabase();

        ListEntry entry = (ListEntry) obj;

        if (Tools.isStringEmpty(entry.getName()))
            return null;

        Cursor cursor = db.query(EntryType.DATA.getName(),
                new String[]{DataTable.KEY_ID, DataTable.KEY_ENTRY_NAME,
                        DataTable.KEY_ENTRY_DESCRIBE, DataTable.KEY_ENTRY_PASSWORD,
                        DataTable.KEY_ENTRY_GROUP_ID},
                DataTable.KEY_ENTRY_NAME + "=?",
                new String[]{entry.getName()}, null, null, null, null);

        entry = null;

        if (cursor != null) {
            if (cursor.moveToFirst()) {
                entry = new ListEntry();
                entry.setName(cursor.getString(1));
                entry.setDescribe(cursor.getString(2));
                entry.setPassword(cursor.getString(3));
                entry.setGroupID(Integer.parseInt(cursor.getString(4)));
            }

        }

        return entry;
    }

    @Override
    public ArrayList<Object> getAllEntries() {

        ArrayList<Object> entries = new ArrayList<>();

        SQLiteDatabase db = this.dbContext.getReadableDatabase();

        Cursor cursor = db.query(EntryType.DATA.getName(),
                new String[]{DataTable.KEY_ID, DataTable.KEY_ENTRY_NAME,
                        DataTable.KEY_ENTRY_PASSWORD, DataTable.KEY_ENTRY_DESCRIBE,
                        DataTable.KEY_ENTRY_GROUP_ID},
                DataTable.KEY_ENTRY_GROUP_ID + "=?",
                new String[]{this.groupID + ""}, null, null, null, null);

        if (cursor.moveToFirst()) {

            do {

                ListEntry entry = new ListEntry();
                entry.setID(Integer.parseInt(cursor.getString(0)));
                entry.setName(cursor.getString(1));
                entry.setPassword(cursor.getString(2));
                entry.setDescribe(cursor.getString(3));
                entry.setGroupID(Integer.parseInt(cursor.getString(4)));
                entries.add(entry);

            } while (cursor.moveToNext());
        }

        return entries;


    }
}




Java Source Code List

keepmysecretapp.app.com.keepmysecretapp.ApplicationTest.java
keepmysecretapp.app.com.keepmysecretapp.activities.MainActivity.java
keepmysecretapp.app.com.keepmysecretapp.activities.creation.CreateNewEntryActivity.java
keepmysecretapp.app.com.keepmysecretapp.activities.edit.EditEntryActivity.java
keepmysecretapp.app.com.keepmysecretapp.activities.presentation.EntryPresentActivity.java
keepmysecretapp.app.com.keepmysecretapp.adapters.DataEntryAdapter.java
keepmysecretapp.app.com.keepmysecretapp.adapters.GroupEntryAdapter.java
keepmysecretapp.app.com.keepmysecretapp.dao.Dao.java
keepmysecretapp.app.com.keepmysecretapp.dao.EntryDao.java
keepmysecretapp.app.com.keepmysecretapp.dao.GroupDao.java
keepmysecretapp.app.com.keepmysecretapp.db.DbContext.java
keepmysecretapp.app.com.keepmysecretapp.db.EntryType.java
keepmysecretapp.app.com.keepmysecretapp.fragments.creation.CreateDataEntryFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.creation.CreateGroupFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.dialogs.GeneratePasswordDialog.java
keepmysecretapp.app.com.keepmysecretapp.fragments.edit.EditDataFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.edit.EditGroupFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.other.NavigationDrawerFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.other.SideLogic.java
keepmysecretapp.app.com.keepmysecretapp.fragments.presentation.EntryPresentFragment.java
keepmysecretapp.app.com.keepmysecretapp.fragments.presentation.TextKeeperFragment.java
keepmysecretapp.app.com.keepmysecretapp.other.Constants.java
keepmysecretapp.app.com.keepmysecretapp.other.Tools.java
keepmysecretapp.app.com.keepmysecretapp.tables.AuthTable.java
keepmysecretapp.app.com.keepmysecretapp.tables.DataTable.java
keepmysecretapp.app.com.keepmysecretapp.tables.GroupTable.java
keepmysecretapp.app.com.keepmysecretapp.tables.QueryTable.java
keepmysecretapp.app.com.keepmysecretapp.types.CopyTextButtonListener.java
keepmysecretapp.app.com.keepmysecretapp.types.GenerateButtonListener.java
keepmysecretapp.app.com.keepmysecretapp.types.ListEntry.java