Android Open Source - KeepMySecret Edit Entry Activity






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.activities.edit;
// www. java2s.  c o  m
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.ImageView;

import keepmysecretapp.app.com.keepmysecretapp.R;
import keepmysecretapp.app.com.keepmysecretapp.activities.MainActivity;
import keepmysecretapp.app.com.keepmysecretapp.activities.presentation.EntryPresentActivity;
import keepmysecretapp.app.com.keepmysecretapp.dao.Dao;
import keepmysecretapp.app.com.keepmysecretapp.dao.EntryDao;
import keepmysecretapp.app.com.keepmysecretapp.dao.GroupDao;
import keepmysecretapp.app.com.keepmysecretapp.db.DbContext;
import keepmysecretapp.app.com.keepmysecretapp.db.EntryType;
import keepmysecretapp.app.com.keepmysecretapp.fragments.edit.EditDataFragment;
import keepmysecretapp.app.com.keepmysecretapp.fragments.edit.EditGroupFragment;
import keepmysecretapp.app.com.keepmysecretapp.other.Constants;
import keepmysecretapp.app.com.keepmysecretapp.tables.DataTable;
import keepmysecretapp.app.com.keepmysecretapp.types.ListEntry;

public class EditEntryActivity extends FragmentActivity {

    private ImageView mBackButton;
    private ListEntry currentEntry;
    private String actionType;
    private ImageView deleteCurrentEntry;
    private ListEntry parentView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);

        mBackButton = (ImageView) findViewById(R.id.toMainActivityButton);

        deleteCurrentEntry = (ImageView) findViewById(R.id.entries_delete_group_button);

        /* which object we want delete. Group or inner data object */
        actionType = getIntent().getStringExtra(Constants.ENTRY_TYPE);

        parentView = new ListEntry();

        /* If we want to edit the group */
        if (actionType.equals(EntryType.GROUPS.getName())) {
            parentView.setName(getIntent().getStringExtra(Constants.ARG_PARENT_NAME));


            DbContext context = DbContext.getInstance(EditEntryActivity.this);
            Dao dao = new GroupDao(context);

            parentView = (ListEntry) dao.read(parentView);
            currentEntry = parentView;

            getDeleteGroupButtonListener(deleteCurrentEntry);
            getBackButtonListenerGroup(mBackButton);

            FragmentManager fragmentManager = getSupportFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.container_edit_activity,
                    EditGroupFragment.newInstance(currentEntry)).commit();
        }

        if (actionType.equals(EntryType.DATA.getName())) {
            currentEntry = new ListEntry();

            parentView.setName(getIntent().getStringExtra(Constants.ARG_PARENT_NAME));
            parentView.setID(getIntent().getIntExtra(Constants.ARG_PARENT_ID, 0));

            currentEntry.setName(getIntent().getStringExtra(DataTable.KEY_ENTRY_NAME));
            currentEntry.setID(getIntent().getIntExtra(DataTable.KEY_ID, 0));
            currentEntry.setDescribe(getIntent().getStringExtra(DataTable.KEY_ENTRY_DESCRIBE));
            currentEntry.setPassword(getIntent().getStringExtra(DataTable.KEY_ENTRY_PASSWORD));
            currentEntry.setGroupID(getIntent().getIntExtra(DataTable.KEY_ENTRY_GROUP_ID, 0));

            DbContext context = DbContext.getInstance(EditEntryActivity.this);
            Dao dao = new EntryDao(context, currentEntry.getGroupID());

            getDeleteDataButtonListener(deleteCurrentEntry, dao);
            getBackButtonListenerData(mBackButton);

            FragmentManager fragmentManager = getSupportFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.container_edit_activity,
                    EditDataFragment.newInstance(currentEntry)).commit();

        }


    }

    private void getBackButtonListenerGroup(ImageView button) {

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toEntries = new Intent(EditEntryActivity.this,
                        EntryPresentActivity.class);
                toEntries.putExtra(Constants.ENTRY_TITLE, parentView.getName());
                toEntries.putExtra(Constants.ENTRY_TYPE, EntryType.DATA.getName());
                toEntries.putExtra(Constants.ENTRY_ID, parentView.getID());
                startActivity(toEntries);
            }
        });

    }

    private void getBackButtonListenerData(ImageView button) {
        //TODO go to EntryPresentActivity by current entry's group name

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent toEntries = new Intent(EditEntryActivity.this, EntryPresentActivity.class);
                toEntries.putExtra(Constants.ENTRY_TITLE, parentView.getName());
                toEntries.putExtra(Constants.ENTRY_ID, parentView.getID());

                startActivity(toEntries);
            }
        });
    }


    private void getDeleteGroupButtonListener(ImageView button) {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DbContext context = DbContext.getInstance(EditEntryActivity.this);
                Dao dao = new GroupDao(context);

                dao.delete(currentEntry);

                Intent toMain = new Intent(EditEntryActivity.this, MainActivity.class);
                startActivity(toMain);
            }
        });
    }

    private void getDeleteDataButtonListener(ImageView button, final Dao dao) {
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dao.delete(currentEntry);

                Intent toEntries = new Intent(EditEntryActivity.this, EntryPresentActivity.class);
                toEntries.putExtra(Constants.ENTRY_TITLE, parentView.getName());
                toEntries.putExtra(Constants.ENTRY_ID, parentView.getID());

                startActivity(toEntries);
            }
        });
    }
}




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