mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Change create group activity as dialog and change style selection
This commit is contained in:
@@ -93,8 +93,6 @@
|
||||
<activity
|
||||
android:name="com.keepassdroid.EntryEditActivityV4"
|
||||
android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="com.keepassdroid.GroupEditActivity" />
|
||||
<activity android:name="com.keepassdroid.IconPickerFragment" />
|
||||
<activity android:name="com.keepassdroid.search.SearchResults" android:launchMode="standard">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
|
||||
@@ -51,9 +51,10 @@ import com.keepassdroid.view.GroupAddEntryView;
|
||||
import com.keepassdroid.view.GroupRootView;
|
||||
import com.keepassdroid.view.GroupViewOnlyView;
|
||||
|
||||
public abstract class GroupActivity extends GroupBaseActivity {
|
||||
public abstract class GroupActivity extends GroupBaseActivity
|
||||
implements GroupEditFragment.CreateGroupListener, IconPickerFragment.IconPickerListener {
|
||||
|
||||
public static final int UNINIT = -1;
|
||||
private static final String TAG_CREATE_GROUP = "TAG_CREATE_GROUP";
|
||||
|
||||
protected boolean addGroupEnabled = false;
|
||||
protected boolean addEntryEnabled = false;
|
||||
@@ -158,7 +159,8 @@ public abstract class GroupActivity extends GroupBaseActivity {
|
||||
addGroup.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
GroupEditActivity.Launch(GroupActivity.this);
|
||||
GroupEditFragment groupEditFragment = new GroupEditFragment();
|
||||
groupEditFragment.show(getSupportFragmentManager(), TAG_CREATE_GROUP);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -195,8 +197,6 @@ public abstract class GroupActivity extends GroupBaseActivity {
|
||||
cv.onCreateMenu(menu, menuInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) item.getMenuInfo();
|
||||
@@ -205,26 +205,30 @@ public abstract class GroupActivity extends GroupBaseActivity {
|
||||
return cv.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
switch (resultCode)
|
||||
{
|
||||
case Activity.RESULT_OK:
|
||||
String GroupName = data.getExtras().getString(GroupEditActivity.KEY_NAME);
|
||||
int GroupIconID = data.getExtras().getInt(GroupEditActivity.KEY_ICON_ID);
|
||||
GroupActivity act = GroupActivity.this;
|
||||
Handler handler = new Handler();
|
||||
AddGroup task = AddGroup.getInstance(this, App.getDB(), GroupName, GroupIconID, mGroup, act.new RefreshTask(handler), false);
|
||||
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
|
||||
pt.run();
|
||||
break;
|
||||
@Override
|
||||
public void approveCreateGroup(Bundle bundle) {
|
||||
String GroupName = bundle.getString(GroupEditFragment.KEY_NAME);
|
||||
int GroupIconID = bundle.getInt(GroupEditFragment.KEY_ICON_ID);
|
||||
GroupActivity act = GroupActivity.this;
|
||||
Handler handler = new Handler();
|
||||
AddGroup task = AddGroup.getInstance(this, App.getDB(), GroupName, GroupIconID, mGroup, act.new RefreshTask(handler), false);
|
||||
ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
|
||||
pt.run();
|
||||
}
|
||||
|
||||
case Activity.RESULT_CANCELED:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void cancelCreateGroup(Bundle bundle) {
|
||||
// Do nothing here
|
||||
}
|
||||
|
||||
@Override
|
||||
// For icon in create group dialog
|
||||
public void iconPicked(Bundle bundle) {
|
||||
GroupEditFragment groupEditFragment = (GroupEditFragment) getSupportFragmentManager().findFragmentByTag(TAG_CREATE_GROUP);
|
||||
if (groupEditFragment != null) {
|
||||
groupEditFragment.iconPicked(bundle);
|
||||
}
|
||||
}
|
||||
|
||||
protected void showWarnings() {
|
||||
if (App.getDB().readOnly) {
|
||||
@@ -236,6 +240,4 @@ public abstract class GroupActivity extends GroupBaseActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.keepassdroid;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.keepass.R;
|
||||
import com.keepassdroid.icons.Icons;
|
||||
|
||||
public class GroupEditActivity extends AppCompatActivity
|
||||
implements IconPickerFragment.IconPickerListener {
|
||||
|
||||
public static final String KEY_NAME = "name";
|
||||
public static final String KEY_ICON_ID = "icon_id";
|
||||
|
||||
private int mSelectedIconID;
|
||||
|
||||
public static void Launch(Activity act) {
|
||||
Intent i = new Intent(act, GroupEditActivity.class);
|
||||
act.startActivityForResult(i, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.group_edit);
|
||||
setTitle(R.string.add_group_title);
|
||||
|
||||
ImageButton iconButton = (ImageButton) findViewById(R.id.icon_button);
|
||||
iconButton.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
IconPickerFragment.Launch(GroupEditActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
Button okButton = (Button) findViewById(R.id.ok);
|
||||
okButton.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
TextView nameField = (TextView) findViewById(R.id.group_name);
|
||||
String name = nameField.getText().toString();
|
||||
|
||||
if ( name.length() > 0 )
|
||||
{
|
||||
final Intent intent = new Intent();
|
||||
|
||||
intent.putExtra(KEY_NAME, name);
|
||||
intent.putExtra(KEY_ICON_ID, mSelectedIconID);
|
||||
setResult(Activity.RESULT_OK, intent);
|
||||
|
||||
finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.makeText(GroupEditActivity.this, R.string.error_no_name, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Button cancel = (Button) findViewById(R.id.cancel);
|
||||
cancel.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
final Intent intent = new Intent();
|
||||
setResult(Activity.RESULT_CANCELED, intent);
|
||||
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
switch (resultCode)
|
||||
{
|
||||
case Activity.RESULT_CANCELED:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iconPicked(Bundle bundle) {
|
||||
mSelectedIconID = bundle.getInt(IconPickerFragment.KEY_ICON_ID);
|
||||
ImageButton currIconButton = (ImageButton) findViewById(R.id.icon_button);
|
||||
currIconButton.setImageResource(Icons.iconToResId(mSelectedIconID));
|
||||
}
|
||||
}
|
||||
122
app/src/main/java/com/keepassdroid/GroupEditFragment.java
Normal file
122
app/src/main/java/com/keepassdroid/GroupEditFragment.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2017 Brian Pellin, Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePass DX.
|
||||
*
|
||||
* KeePass DX is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePass DX is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.keepassdroid;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.keepass.R;
|
||||
import com.keepassdroid.icons.Icons;
|
||||
|
||||
public class GroupEditFragment extends DialogFragment
|
||||
implements IconPickerFragment.IconPickerListener {
|
||||
|
||||
public static final String KEY_NAME = "name";
|
||||
public static final String KEY_ICON_ID = "icon_id";
|
||||
|
||||
private CreateGroupListener createGroupListener;
|
||||
|
||||
private int mSelectedIconID;
|
||||
private View root;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
// Verify that the host activity implements the callback interface
|
||||
try {
|
||||
// Instantiate the NoticeDialogListener so we can send events to the host
|
||||
createGroupListener = (CreateGroupListener) context;
|
||||
createGroupListener = (CreateGroupListener) context;
|
||||
} catch (ClassCastException e) {
|
||||
// The activity doesn't implement the interface, throw exception
|
||||
throw new ClassCastException(context.toString()
|
||||
+ " must implement " + GroupEditFragment.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
|
||||
root = inflater.inflate(R.layout.group_edit, null);
|
||||
builder.setView(root)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
TextView nameField = (TextView) root.findViewById(R.id.group_name);
|
||||
String name = nameField.getText().toString();
|
||||
|
||||
if ( name.length() > 0 ) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(KEY_NAME, name);
|
||||
bundle.putInt(KEY_ICON_ID, mSelectedIconID);
|
||||
createGroupListener.approveCreateGroup(bundle);
|
||||
|
||||
GroupEditFragment.this.getDialog().cancel();
|
||||
}
|
||||
else {
|
||||
Toast.makeText(getContext(), R.string.error_no_name, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
Bundle bundle = new Bundle();
|
||||
createGroupListener.cancelCreateGroup(bundle);
|
||||
|
||||
GroupEditFragment.this.getDialog().cancel();
|
||||
}
|
||||
});
|
||||
|
||||
final ImageButton iconButton = (ImageButton) root.findViewById(R.id.icon_button);
|
||||
iconButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
IconPickerFragment iconPickerFragment = new IconPickerFragment();
|
||||
iconPickerFragment.show(getFragmentManager(), "IconPickerFragment");
|
||||
}
|
||||
});
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void iconPicked(Bundle bundle) {
|
||||
mSelectedIconID = bundle.getInt(IconPickerFragment.KEY_ICON_ID);
|
||||
ImageButton currIconButton = (ImageButton) root.findViewById(R.id.icon_button);
|
||||
currIconButton.setImageResource(Icons.iconToResId(mSelectedIconID));
|
||||
}
|
||||
|
||||
public interface CreateGroupListener {
|
||||
void approveCreateGroup(Bundle bundle);
|
||||
void cancelCreateGroup(Bundle bundle);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,6 @@ public class IconPickerFragment extends DialogFragment {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(KEY_ICON_ID, position);
|
||||
iconPickerListener.iconPicked(bundle);
|
||||
// TODO setResult(EntryEditActivity.RESULT_OK_ICON_PICKER, intent);
|
||||
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_margin="@dimen/default_margin"
|
||||
android:padding="@dimen/default_margin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<android.support.v7.widget.AppCompatImageButton android:id="@+id/icon_button"
|
||||
@@ -37,20 +37,4 @@
|
||||
android:layout_toStartOf="@+id/icon_button"
|
||||
android:maxLines="1"
|
||||
android:hint="@string/hint_group_name"/>
|
||||
<Button android:id="@+id/ok"
|
||||
android:layout_margin="@dimen/button_margin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="100dp"
|
||||
android:layout_below="@id/group_name"
|
||||
android:text="@android:string/ok"/>
|
||||
<Button android:id="@+id/cancel"
|
||||
android:layout_margin="@dimen/button_margin"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="100dp"
|
||||
android:layout_below="@id/group_name"
|
||||
android:layout_toRightOf="@id/ok"
|
||||
android:layout_toEndOf="@id/ok"
|
||||
android:text="@string/cancel"/>
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -37,9 +37,10 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic99_blank"
|
||||
android:visibility="gone"/>
|
||||
android:src="@drawable/ic99_blank" />
|
||||
<TextView android:id="@+id/group_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
style="@style/KeepassDXStyle.TextAppearance.Default"
|
||||
style="@style/KeepassDXStyle.TextAppearance.FolderTitle"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@+id/group_label"
|
||||
android:layout_toStartOf="@+id/group_label"
|
||||
@@ -54,6 +54,7 @@
|
||||
android:text="@string/group"
|
||||
android:layout_margin="@dimen/default_margin"
|
||||
style="@style/KeepassDXStyle.TextAppearance.SecondaryText"
|
||||
android:visibility="gone"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
||||
@@ -86,6 +86,9 @@
|
||||
<style name="KeepassDXStyle.TextAppearance.Default" parent="KeepassDXStyle.TextAppearance">
|
||||
<item name="android:textSize">16sp</item>
|
||||
</style>
|
||||
<style name="KeepassDXStyle.TextAppearance.FolderTitle" parent="KeepassDXStyle.TextAppearance.Default">
|
||||
<item name="android:textColor">@color/colorTextPrimary</item>
|
||||
</style>
|
||||
<style name="KeepassDXStyle.TextAppearance.Title" parent="KeepassDXStyle.TextAppearance">
|
||||
<item name="android:textColor">@color/colorTextPrimary</item>
|
||||
<item name="android:textSize">16sp</item>
|
||||
|
||||
Reference in New Issue
Block a user