summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorحسين <zidhussein@gmail.com>2018-12-25 14:39:32 +0000
committerGitHub <noreply@github.com>2018-12-25 14:39:32 +0000
commit81aff5d870af5da4b16cc5ed455106dd58aefd54 (patch)
tree69923380f3522b603d5041e72f65335e5ff0a0dd /app/src/main/java
parent62954ee78f007545d7630d74c9e11ede90627309 (diff)
Commit messages (#455)
* use full password path in add/edit git commit message * commit strings are format strings * use format strings in other languages * use move/rename commit message
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java43
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt29
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java24
3 files changed, 72 insertions, 24 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
index 04a7f9de..d79e7c19 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
@@ -40,6 +40,7 @@ import com.zeapo.pwdstore.utils.PasswordItem;
import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter;
import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
@@ -557,7 +558,8 @@ public class PasswordStore extends AppCompatActivity {
it.remove();
adapter.updateSelectedItems(position, selectedItems);
- commitChange("[ANDROID PwdStore] Remove " + item + " from store.");
+ commitChange(getResources().getString(R.string.git_commit_remove_text,
+ item.getLongName()));
deletePasswords(adapter, selectedItems);
}
})
@@ -641,19 +643,23 @@ public class PasswordStore extends AppCompatActivity {
// if went from decrypt->edit and user saved changes or HOTP counter was incremented, we need to commitChange
if (data != null && data.getBooleanExtra("needCommit", false)) {
if (data.getStringExtra("OPERATION").equals("EDIT")) {
- commitChange(this.getResources().getString(R.string.edit_commit_text) + data.getExtras().getString("NAME"));
+ commitChange(this.getResources().getString(R.string.git_commit_edit_text,
+ data.getExtras().getString("LONG_NAME")));
} else {
- commitChange(this.getResources().getString(R.string.increment_commit_text) + data.getExtras().getString("NAME"));
+ commitChange(this.getResources().getString(R.string.git_commit_increment_text,
+ data.getExtras().getString("LONG_NAME")));
}
}
refreshListAdapter();
break;
case REQUEST_CODE_ENCRYPT:
- commitChange(this.getResources().getString(R.string.add_commit_text) + data.getExtras().getString("NAME") + this.getResources().getString(R.string.from_store));
+ commitChange(this.getResources().getString(R.string.git_commit_add_text,
+ data.getExtras().getString("LONG_NAME")));
refreshListAdapter();
break;
case REQUEST_CODE_EDIT:
- commitChange(this.getResources().getString(R.string.edit_commit_text) + data.getExtras().getString("NAME"));
+ commitChange(this.getResources().getString(R.string.git_commit_edit_text,
+ data.getExtras().getString("LONG_NAME")));
refreshListAdapter();
break;
case GitActivity.REQUEST_INIT:
@@ -698,22 +704,35 @@ public class PasswordStore extends AppCompatActivity {
break;
}
+ String repositoryPath = PasswordRepository
+ .getRepositoryDirectory(getApplicationContext())
+ .getAbsolutePath();
+
// TODO move this to an async task
- for (String string : data.getStringArrayListExtra("Files")) {
- File source = new File(string);
+ for (String fileString : data.getStringArrayListExtra("Files")) {
+ File source = new File(fileString);
if (!source.exists()) {
Log.e("Moving", "Tried moving something that appears non-existent.");
continue;
}
+
+
if (!source.renameTo(new File(target.getAbsolutePath() + "/" + source.getName()))) {
// TODO this should show a warning to the user
Log.e("Moving", "Something went wrong while moving.");
} else {
- commitChange("[ANDROID PwdStore] Moved "
- + string.replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()) + "/", "")
- + " to "
- + target.getAbsolutePath().replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()) + "/", "")
- + target.getAbsolutePath() + "/" + source.getName() + ".");
+ String basename = FilenameUtils.getBaseName(source.getAbsolutePath());
+
+ String sourceLongName = PgpActivity.getLongName(source.getParent(),
+ repositoryPath, basename);
+
+ String destinationLongName = PgpActivity.getLongName(target.getAbsolutePath(),
+ repositoryPath, basename);
+
+ commitChange(this.getResources()
+ .getString(R.string.git_commit_move_text,
+ sourceLongName,
+ destinationLongName));
}
}
updateListAdapter();
diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt
index 74295e6a..53582973 100644
--- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt
@@ -41,6 +41,7 @@ import com.zeapo.pwdstore.utils.Otp
import kotlinx.android.synthetic.main.decrypt_layout.*
import kotlinx.android.synthetic.main.encrypt_layout.*
import org.apache.commons.io.FileUtils
+import org.apache.commons.io.FilenameUtils
import org.openintents.openpgp.IOpenPgpService2
import org.openintents.openpgp.OpenPgpError
import org.openintents.openpgp.util.OpenPgpApi
@@ -73,7 +74,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
private val repoPath: String by lazy { intent.getStringExtra("REPO_PATH") }
private val fullPath: String by lazy { intent.getStringExtra("FILE_PATH") }
- private val name: String by lazy { getName(fullPath, repoPath) }
+ private val name: String by lazy { getName(fullPath) }
private val lastChangedString: CharSequence by lazy { getLastChangedString(intent.getIntExtra("LAST_CHANGED_TIMESTAMP", -1)) }
private val relativeParentPath: String by lazy { getParentPath(fullPath, repoPath) }
@@ -412,6 +413,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
val returnIntent = Intent()
returnIntent.putExtra("CREATED_FILE", path)
returnIntent.putExtra("NAME", editName)
+ returnIntent.putExtra("LONG_NAME", getLongName(fullPath, repoPath, this.editName!!))
// if coming from decrypt screen->edit button
if (intent.getBooleanExtra("fromDecrypt", false)) {
@@ -785,10 +787,27 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
/**
* Gets the name of the password (excluding .gpg)
*/
- fun getName(fullPath: String, repositoryPath: String): String {
- val relativePath = getRelativePath(fullPath, repositoryPath)
- val index = relativePath.lastIndexOf("/")
- return relativePath.substring(index + 1).replace("\\.gpg$".toRegex(), "")
+ fun getName(fullPath: String): String {
+ return FilenameUtils.getBaseName(fullPath);
+ }
+
+ /**
+ * /path/to/store/social/facebook.gpg -> social/facebook
+ */
+ @JvmStatic
+ fun getLongName(fullPath: String, repositoryPath: String, basename: String): String {
+ var relativePath = getRelativePath(fullPath, repositoryPath)
+ if (relativePath.isNotEmpty() && relativePath != "/") {
+ // remove preceding '/'
+ relativePath = relativePath.substring(1);
+ if (relativePath.endsWith('/')) {
+ return relativePath + basename
+ } else {
+ return "$relativePath/$basename"
+ }
+ } else {
+ return basename
+ }
}
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java
index d02adeda..5c2231a5 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java
@@ -1,19 +1,22 @@
package com.zeapo.pwdstore.utils;
+import com.zeapo.pwdstore.crypto.PgpActivity;
+
import androidx.annotation.NonNull;
import java.io.File;
-public class PasswordItem implements Comparable{
+public class PasswordItem implements Comparable {
public final static char TYPE_CATEGORY = 'c';
public final static char TYPE_PASSWORD = 'p';
- private char type;
- private String name;
- private PasswordItem parent;
- private File file;
- private String fullPathToParent;
+ private final char type;
+ private final String name;
+ private final PasswordItem parent;
+ private final File file;
+ private final String fullPathToParent;
+ private final String longName;
/** Create a password item
*
@@ -24,7 +27,10 @@ public class PasswordItem implements Comparable{
this.parent = parent;
this.type = type;
this.file = file;
- this.fullPathToParent = file.getAbsolutePath().replace(rootDir.getAbsolutePath(), "").replace(file.getName(), "");
+ fullPathToParent = file.getAbsolutePath()
+ .replace(rootDir.getAbsolutePath(), "")
+ .replace(file.getName(), "");
+ longName = PgpActivity.getLongName(fullPathToParent, rootDir.getAbsolutePath(), toString());
}
/** Create a new Category item
@@ -71,6 +77,10 @@ public class PasswordItem implements Comparable{
return this.fullPathToParent;
}
+ public String getLongName() {
+ return longName;
+ }
+
@Override
public String toString(){
return this.getName().replace(".gpg", "");