mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add dialog to create database file
This commit is contained in:
@@ -78,6 +78,7 @@ public class AssignPasswordDialog extends DialogFragment {
|
||||
|
||||
rootView = inflater.inflate(R.layout.set_password, null);
|
||||
builder.setView(rootView)
|
||||
.setTitle(R.string.assign_master_key)
|
||||
// Add action buttons
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
||||
100
app/src/main/java/com/keepassdroid/CreateFileDialog.java
Normal file
100
app/src/main/java/com/keepassdroid/CreateFileDialog.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.keepassdroid;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.Uri;
|
||||
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.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
public class CreateFileDialog extends DialogFragment implements AdapterView.OnItemSelectedListener{
|
||||
|
||||
private View rootView;
|
||||
private DefinePathDialogListener mListener;
|
||||
|
||||
public interface DefinePathDialogListener {
|
||||
void onDefinePathDialogPositiveClick(Uri pathFile);
|
||||
void onDefinePathDialogNegativeClick(Uri pathFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
mListener = (DefinePathDialogListener) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(activity.toString()
|
||||
+ " must implement " + DefinePathDialogListener.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
|
||||
rootView = inflater.inflate(R.layout.file_creation, null);
|
||||
builder.setView(rootView)
|
||||
.setTitle(R.string.create_keepass_file)
|
||||
// Add action buttons
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
mListener.onDefinePathDialogPositiveClick(buildPath());
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
mListener.onDefinePathDialogNegativeClick(buildPath());
|
||||
}
|
||||
});
|
||||
|
||||
// TODO Add default path
|
||||
// TODO Add intent for path selection
|
||||
|
||||
// Extension
|
||||
Spinner spinner = (Spinner) rootView.findViewById(R.id.file_types);
|
||||
spinner.setOnItemSelectedListener(this);
|
||||
|
||||
// Spinner Drop down elements
|
||||
String[] fileTypes = getResources().getStringArray(R.array.file_types);
|
||||
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, fileTypes);
|
||||
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinner.setAdapter(dataAdapter);
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
|
||||
String item = adapterView.getItemAtPosition(position).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapterView) {
|
||||
|
||||
}
|
||||
|
||||
private Uri buildPath() {
|
||||
// TODO Correct path
|
||||
TextView folderPath = (TextView) rootView.findViewById(R.id.folder_path);
|
||||
TextView filename = (TextView) rootView.findViewById(R.id.filename);
|
||||
|
||||
|
||||
Uri path = new Uri.Builder().path(folderPath.getText().toString())
|
||||
.appendPath(filename.getText().toString()).build();
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,6 +51,7 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.keepassdroid.AssignPasswordDialog;
|
||||
import com.keepassdroid.CreateFileDialog;
|
||||
import com.keepassdroid.GroupActivity;
|
||||
import com.keepassdroid.PasswordActivity;
|
||||
import com.keepassdroid.ProgressTask;
|
||||
@@ -77,6 +78,7 @@ import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public class FileSelectActivity extends StylishActivity implements
|
||||
CreateFileDialog.DefinePathDialogListener ,
|
||||
AssignPasswordDialog.AssignPasswordDialogListener {
|
||||
|
||||
private static final int MY_PERMISSIONS_REQUEST_EXTERNAL_STORAGE = 111;
|
||||
@@ -152,8 +154,8 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
createButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
AssignPasswordDialog assignPasswordDialog = new AssignPasswordDialog();
|
||||
assignPasswordDialog.show(getSupportFragmentManager(), "passwordDialog");
|
||||
CreateFileDialog createFileDialog = new CreateFileDialog();
|
||||
createFileDialog.show(getSupportFragmentManager(), "createFileDialog");
|
||||
}
|
||||
|
||||
});
|
||||
@@ -298,6 +300,18 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefinePathDialogPositiveClick(Uri pathFile) {
|
||||
// TODO stock path
|
||||
AssignPasswordDialog assignPasswordDialog = new AssignPasswordDialog();
|
||||
assignPasswordDialog.show(getSupportFragmentManager(), "passwordDialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDefinePathDialogNegativeClick(Uri pathFile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAssignKeyDialogPositiveClick(String masterPassword, Uri keyFile) {
|
||||
|
||||
@@ -332,7 +346,7 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
|
||||
}
|
||||
|
||||
private class AssignPasswordOnFinish extends FileOnFinish {
|
||||
private class AssignPasswordOnFinish extends FileOnFinish {
|
||||
|
||||
public AssignPasswordOnFinish(FileOnFinish fileOnFinish) {
|
||||
super(fileOnFinish);
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* Copyright 2017 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.view;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -17,9 +36,6 @@ import java.io.File;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
/**
|
||||
* Created by joker on 01/12/17.
|
||||
*/
|
||||
|
||||
public class KeyFileHelper {
|
||||
|
||||
|
||||
78
app/src/main/res/layout/file_creation.xml
Normal file
78
app/src/main/res/layout/file_creation.xml
Normal file
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/default_margin">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:id="@+id/browse_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="6dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignBottom="@+id/folder_path_input_layout"
|
||||
android:src="@drawable/ic_folder_white_24dp"
|
||||
android:tint="?attr/colorAccentCompat" />
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/folder_path_input_layout"
|
||||
android:layout_toLeftOf="@id/browse_button"
|
||||
android:layout_toStartOf="@id/browse_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/folder_path"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/path"
|
||||
android:inputType="textUri"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/filename_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toLeftOf="@+id/file_types"
|
||||
android:layout_toStartOf="@+id/file_types">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/filename"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/file_name"
|
||||
android:text="@string/database_file_name_default"
|
||||
android:inputType="textUri"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.v7.widget.AppCompatSpinner
|
||||
android:id="@+id/file_types"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/filename_input_layout"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -20,8 +20,7 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:paddingBottom="12dp">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/filename_container"
|
||||
|
||||
@@ -209,6 +209,10 @@
|
||||
<string name="list_password_generator_options_summary">Définir les caractères par défaut du générateur de mot de passe</string>
|
||||
<string name="clipboard_notifications_title">Notifications du presse-papiers</string>
|
||||
<string name="clipboard_notifications_summary">Activer les notifications du presse-papiers pour copier le nom d\'utilisateur et le mot de passe</string>
|
||||
<string name="file_name">Nom de fichier</string>
|
||||
<string name="path">Chemin</string>
|
||||
<string name="assign_master_key">Assigner une clé maître</string>
|
||||
<string name="create_keepass_file">Créer un fichier keepass</string>
|
||||
|
||||
<string-array name="clipboard_timeout_options">
|
||||
<item>30 secondes</item>
|
||||
|
||||
@@ -126,4 +126,9 @@
|
||||
<item translatable="false">@string/special</item>
|
||||
<item translatable="false">@string/brackets</item>
|
||||
</string-array>
|
||||
|
||||
<string name="database_file_name_default" translatable="false">New database</string>
|
||||
<string-array name="file_types">
|
||||
<item translatable="false">.kdbx</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
@@ -209,6 +209,10 @@
|
||||
<string name="list_password_generator_options_summary">Set the default password generator characters</string>
|
||||
<string name="clipboard_notifications_title">Clipboard Notifications</string>
|
||||
<string name="clipboard_notifications_summary">Enable clipboard notifications to copy username and password</string>
|
||||
<string name="file_name">File name</string>
|
||||
<string name="path">Path</string>
|
||||
<string name="assign_master_key">Assign a master key</string>
|
||||
<string name="create_keepass_file">Create a keepass file</string>
|
||||
|
||||
<string-array name="clipboard_timeout_options">
|
||||
<item>30 seconds</item>
|
||||
@@ -228,4 +232,5 @@
|
||||
<item>Light Theme</item>
|
||||
<item>Night Theme</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user