mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Set messages in threads
This commit is contained in:
@@ -387,7 +387,11 @@ public class GroupActivity extends ListNodesActivity
|
||||
}
|
||||
|
||||
private void moveGroup(PwGroup groupToMove, PwGroup newParent) {
|
||||
MoveGroupRunnable task = new MoveGroupRunnable(this, App.getDB(), groupToMove, newParent,
|
||||
MoveGroupRunnable task = new MoveGroupRunnable(
|
||||
this,
|
||||
App.getDB(),
|
||||
groupToMove,
|
||||
newParent,
|
||||
new AfterAddNode());
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
@@ -398,7 +402,11 @@ public class GroupActivity extends ListNodesActivity
|
||||
}
|
||||
|
||||
private void moveEntry(PwEntry entryToMove, PwGroup newParent) {
|
||||
MoveEntryRunnable task = new MoveEntryRunnable(this, App.getDB(), entryToMove, newParent,
|
||||
MoveEntryRunnable task = new MoveEntryRunnable(
|
||||
this,
|
||||
App.getDB(),
|
||||
entryToMove,
|
||||
newParent,
|
||||
new AfterAddNode());
|
||||
task.setUpdateProgressTaskStatus(
|
||||
new UpdateProgressTaskStatus(this,
|
||||
|
||||
@@ -26,7 +26,7 @@ public abstract class ActionDatabaseRunnable extends RunnableOnFinish {
|
||||
save.run();
|
||||
}
|
||||
|
||||
abstract protected void onFinish(boolean success);
|
||||
abstract protected void onFinish(boolean success, String message);
|
||||
|
||||
private class AfterActionRunnable extends OnFinishRunnable {
|
||||
|
||||
@@ -36,7 +36,7 @@ public abstract class ActionDatabaseRunnable extends RunnableOnFinish {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
onFinish(mSuccess);
|
||||
onFinish(mSuccess, mMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class AssignPasswordInDBRunnable extends ActionDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if (!success) {
|
||||
// Erase the current master key
|
||||
erase(mDb.getPwDatabase().getMasterKey());
|
||||
|
||||
@@ -76,7 +76,10 @@ public class OnFinishRunnable implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Move
|
||||
/**
|
||||
* ONLY to use in UIThread, typically in an Activity, Fragment or a Service
|
||||
* @param ctx Context to show the message
|
||||
*/
|
||||
protected void displayMessage(Context ctx) {
|
||||
if ( mMessage != null && mMessage.length() > 0 ) {
|
||||
Toast.makeText(ctx, mMessage, Toast.LENGTH_LONG).show();
|
||||
|
||||
@@ -23,9 +23,10 @@ abstract class ActionNodeDatabaseRunnable extends ActionDatabaseRunnable {
|
||||
* - Move : @param oldNode NULL, @param NodeToMove
|
||||
* - Update : @param oldNode NodeToUpdate, @param NodeUpdated
|
||||
*/
|
||||
protected void callbackNodeAction(boolean success, PwNode oldNode, PwNode newNode) {
|
||||
protected void callbackNodeAction(boolean success, String message, PwNode oldNode, PwNode newNode) {
|
||||
if (callbackRunnable != null) {
|
||||
callbackRunnable.setSuccess(success);
|
||||
callbackRunnable.setMessage(message);
|
||||
callbackRunnable.run(oldNode, newNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ public class AddEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
mDb.removeEntryFrom(mNewEntry, mNewEntry.getParent());
|
||||
}
|
||||
callbackNodeAction(success, null, mNewEntry);
|
||||
callbackNodeAction(success, message, null, mNewEntry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ public class AddGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
mDb.removeGroupFrom(mNewGroup, mNewGroup.getParent());
|
||||
}
|
||||
callbackNodeAction(success, null, mNewGroup);
|
||||
callbackNodeAction(success, message, null, mNewGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class CopyEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to delete the copy
|
||||
try {
|
||||
@@ -70,6 +70,6 @@ public class CopyEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
Log.i(TAG, "Unable to delete the copied entry");
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, mEntryToCopy, mEntryCopied);
|
||||
callbackNodeAction(success, message, mEntryToCopy, mEntryCopied);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DeleteEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
if (mRecycle) {
|
||||
mDb.undoRecycle(mEntryToDelete, mParent);
|
||||
@@ -68,6 +68,6 @@ public class DeleteEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
mDb.undoDeleteEntry(mEntryToDelete, mParent);
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, mEntryToDelete, null);
|
||||
callbackNodeAction(success, message, mEntryToDelete, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class DeleteGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
if (mRecycle) {
|
||||
mDb.undoRecycle(mGroupToDelete, mParent);
|
||||
@@ -91,6 +91,6 @@ public class DeleteGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
// TODO TEST pm.undoDeleteGroup(mGroup, mParent);
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, mGroupToDelete, null);
|
||||
callbackNodeAction(success, message, mGroupToDelete, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MoveEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to remove in the first place
|
||||
try {
|
||||
@@ -72,6 +72,6 @@ public class MoveEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
Log.i(TAG, "Unable to replace the entry");
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, null, mEntryToMove);
|
||||
callbackNodeAction(success, message, null, mEntryToMove);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.kunzisoft.keepass.database.action.node;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.kunzisoft.keepass.database.Database;
|
||||
import com.kunzisoft.keepass.database.PwGroup;
|
||||
|
||||
@@ -63,13 +64,15 @@ public class MoveGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
} else {
|
||||
// Only finish thread
|
||||
mFinish.setResult(false);
|
||||
String message = mContext.getString(R.string.error_move_folder_in_itself);
|
||||
Log.e(TAG, message);
|
||||
mFinish.setMessage(message);
|
||||
mFinish.run();
|
||||
Log.e(TAG, "Unable to move a group in itself");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, try to move in the first place
|
||||
try {
|
||||
@@ -78,6 +81,6 @@ public class MoveGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
Log.i(TAG, "Unable to replace the group");
|
||||
}
|
||||
}
|
||||
callbackNodeAction(success, null, mGroupToMove);
|
||||
callbackNodeAction(success, message, null, mGroupToMove);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,11 +53,11 @@ public class UpdateEntryRunnable extends ActionNodeDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, back out changes to global structure
|
||||
mDb.updateEntry(mOldEntry, mBackupEntry);
|
||||
}
|
||||
callbackNodeAction(success, mOldEntry, mNewEntry);
|
||||
callbackNodeAction(success, message, mOldEntry, mNewEntry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,11 +54,11 @@ public class UpdateGroupRunnable extends ActionNodeDatabaseRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinish(boolean success) {
|
||||
protected void onFinish(boolean success, String message) {
|
||||
if ( !success ) {
|
||||
// If we fail to save, back out changes to global structure
|
||||
mDb.updateGroup(mOldGroup, mBackupGroup);
|
||||
}
|
||||
callbackNodeAction(success, mOldGroup, mNewGroup);
|
||||
callbackNodeAction(success, message, mOldGroup, mNewGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@
|
||||
<string name="error_title_required">A title is required.</string>
|
||||
<string name="error_wrong_length">Enter a positive integer on length field</string>
|
||||
<string name="error_autofill_enable_service">Autofill service can\'t be enabled.</string>
|
||||
<string name="error_move_folder_in_itself">Unable to move a group in itself.</string>
|
||||
<string name="field_name">Field Name</string>
|
||||
<string name="field_value">Field value</string>
|
||||
<string name="file_not_found">File not found.</string>
|
||||
|
||||
Reference in New Issue
Block a user