mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
Add permission to write database and read one without content provider
This commit is contained in:
1 parent
60e2209281
commit
f13c595bf9
4 files changed
+64
-39
No files matched your search
@@ -29,6 +29,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@@ -57,7 +58,6 @@ import com.keepassdroid.utils.EmptyUtils;
|
||||
import com.keepassdroid.utils.Interaction;
|
||||
import com.keepassdroid.utils.MenuUtil;
|
||||
import com.keepassdroid.utils.UriUtil;
|
||||
import com.keepassdroid.utils.Util;
|
||||
import com.keepassdroid.view.AssignPasswordHelper;
|
||||
import com.keepassdroid.view.FileNameView;
|
||||
import com.kunzisoft.keepass.R;
|
||||
@@ -117,6 +117,15 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
toolbar.setTitle(getString(R.string.app_name));
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
openFileNameView = (EditText) findViewById(R.id.file_filename);
|
||||
|
||||
// Set the initial value of the filename
|
||||
String defaultPath = Environment.getExternalStorageDirectory().getAbsolutePath()
|
||||
+ getString(R.string.database_file_path_default)
|
||||
+ getString(R.string.database_file_name_default)
|
||||
+ getString(R.string.database_file_extension_default);
|
||||
openFileNameView.setText(defaultPath);
|
||||
|
||||
mListFiles = (RecyclerView) findViewById(R.id.file_list);
|
||||
mListFiles.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
@@ -125,8 +134,7 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
openButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
String fileName = Util.getEditText(FileSelectActivity.this,
|
||||
R.id.file_filename);
|
||||
String fileName = openFileNameView.getText().toString();
|
||||
try {
|
||||
PasswordActivity.Launch(FileSelectActivity.this, fileName);
|
||||
}
|
||||
@@ -145,8 +153,8 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
View createButton = findViewById(R.id.create_database);
|
||||
createButton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
CreateFileDialogFragment createFileDialogFragment = new CreateFileDialogFragment();
|
||||
createFileDialogFragment.show(getSupportFragmentManager(), "createFileDialogFragment");
|
||||
FileSelectActivityPermissionsDispatcher
|
||||
.openCreateFileDialogFragmentWithPermissionCheck(FileSelectActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -182,7 +190,7 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
private void lookForOpenIntentsFilePicker() {
|
||||
if (Interaction.isIntentAvailable(FileSelectActivity.this, Intents.OPEN_INTENTS_FILE_BROWSE)) {
|
||||
Intent i = new Intent(Intents.OPEN_INTENTS_FILE_BROWSE);
|
||||
i.setData(Uri.parse("file://" + Util.getEditText(FileSelectActivity.this, R.id.file_filename)));
|
||||
i.setData(Uri.parse("file://" + openFileNameView.getText().toString()));
|
||||
try {
|
||||
startActivityForResult(i, FILE_BROWSE);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
@@ -199,14 +207,6 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
}
|
||||
});
|
||||
|
||||
// Set the initial value of the filename
|
||||
openFileNameView = (EditText) findViewById(R.id.file_filename);
|
||||
String defaultPath = Environment.getExternalStorageDirectory().getAbsolutePath()
|
||||
+ getString(R.string.database_file_path_default)
|
||||
+ getString(R.string.database_file_name_default)
|
||||
+ getString(R.string.database_file_extension_default);
|
||||
openFileNameView.setText(defaultPath);
|
||||
|
||||
// Construct adapter with listeners
|
||||
mAdapter = new FileSelectAdapter(FileSelectActivity.this, fileHistory.getDbList());
|
||||
mAdapter.setOnItemClickListener(this);
|
||||
@@ -246,6 +246,19 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
// NOTE: delegate the permission handling to generated method
|
||||
FileSelectActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
|
||||
}
|
||||
|
||||
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
public void openCreateFileDialogFragment() {
|
||||
CreateFileDialogFragment createFileDialogFragment = new CreateFileDialogFragment();
|
||||
createFileDialogFragment.show(getSupportFragmentManager(), "createFileDialogFragment");
|
||||
}
|
||||
|
||||
private void updateTitleFileListView() {
|
||||
if(mAdapter.getItemCount() == 0)
|
||||
fileListTitle.setVisibility(View.INVISIBLE);
|
||||
@@ -487,9 +500,6 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// check for storage permission
|
||||
checkStoragePermission();
|
||||
|
||||
// Check to see if we need to change modes
|
||||
if ( fileHistory.hasRecentFiles() != recentMode ) {
|
||||
@@ -507,14 +517,11 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NeedsPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
void checkStoragePermission() {}
|
||||
|
||||
@OnShowRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
void showRationaleForExternalStorage(final PermissionRequest request) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.permission_external_storage_rationale)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
.setMessage(R.string.permission_external_storage_rationale_write_database)
|
||||
.setPositiveButton(R.string.allow, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
request.proceed();
|
||||
@@ -536,7 +543,7 @@ public class FileSelectActivity extends StylishActivity implements
|
||||
|
||||
@OnNeverAskAgain(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
void showNeverAskForExternalStorage() {
|
||||
Toast.makeText(this, R.string.permission_external_storage_neverask, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(this, R.string.permission_external_storage_never_ask, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user