From 81aff5d870af5da4b16cc5ed455106dd58aefd54 Mon Sep 17 00:00:00 2001 From: حسين Date: Tue, 25 Dec 2018 14:39:32 +0000 Subject: 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 --- .../java/com/zeapo/pwdstore/PasswordStore.java | 43 ++++++++++++++++------ .../java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 29 ++++++++++++--- .../com/zeapo/pwdstore/utils/PasswordItem.java | 24 ++++++++---- app/src/main/res/values-ar/strings.xml | 2 +- app/src/main/res/values-cs/strings.xml | 3 -- app/src/main/res/values-de/strings.xml | 3 -- app/src/main/res/values-fr/strings.xml | 5 +-- app/src/main/res/values-ja/strings.xml | 5 +-- app/src/main/res/values-ru/strings.xml | 5 +-- app/src/main/res/values-zh-rCN/strings.xml | 5 +-- app/src/main/res/values-zh-rTW/strings.xml | 3 -- app/src/main/res/values/strings.xml | 9 +++-- 12 files changed, 86 insertions(+), 50 deletions(-) (limited to 'app/src/main') 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", ""); diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 5b863e6d..95c95f7f 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -15,7 +15,7 @@ تعديل حذف -   مِن المخزن. + لم يتم إختيار مزود الأوبن بي جي بي بعد ! diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index a8bb0a50..407b6367 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -18,9 +18,6 @@ Opravdu chcete smazat heslo /" - [ANDROID PwdStore] Add   - [ANDROID PwdStore] Edit   -   from store. Nebyl vybrán poskytovatel OpenPGP! diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 8c63a37b..bfa35daf 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -21,8 +21,6 @@ Löschen - [ANDROID PwdStore] Add   -   from store. Kein OpenPGP-Provider ausgewählt! @@ -170,7 +168,6 @@ Soll weiterer Inhalt sichtbar sein? Generieren Kein externes Repository ausgewählt - [ANDROID PwdStore] Edit   Passwort senden als Nur-Text mit behilfe von… Password wiedergeben Repository URI diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 0f4b427d..a3905ced 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -18,9 +18,8 @@ Êtes-vous sûr de vouloir supprimer le mot de passe /" - [ANDROID PwdStore] Ajouter   - [ANDROID PwdStore] Editer   -   depuis le dépôt. + Ajouter %1$s depuis le dépôt. + Editer %1$s depuis le dépôt. Aucun prestataire OpenPGP sélectionné ! diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 051d7edf..ca1c08da 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -18,9 +18,8 @@ パスワードを削除してもよろしいですか /" - [ANDROID PwdStore] 追加   - [ANDROID PwdStore] 編集   -   ストアから。 + 追加 %1$s ストアから。 + 編集 %1$s ストアから。 OpenPGP プロバイダが選択されていません! diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index d8177901..6863d800 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -21,9 +21,8 @@ Удалить - [ANDROID PwdStore] Добавлен пароль   - [ANDROID PwdStore] Отредактирован пароль   -   из хранилища. + Добавлен пароль %1$s из хранилища. + Отредактирован %1$s из хранилища. Не выбран провайдер OpenPGP! diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 6854271d..e0b2a54d 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -3,7 +3,6 @@ Password Store 搜索 设置 - [ANDROID PwdStore] 添加   使用默认设置 删除 自动匹配 @@ -30,11 +29,11 @@ 确定 糟糕… 确定 - [ANDROID PwdStore] 修改   无法使用空白密码或者空白的额外内容 请提供一个文件名 你忘了提供用户名了吗? -   从商店 + 修改 %1$s 从商店 + 添加 %1$s 从商店 Git Pull Git Push 同步 Repo diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index d0970f00..3a9fca05 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -3,7 +3,6 @@ Password Store 搜尋 設定 - [ANDROID PwdStore] Add   使用預設值 刪除 自動選取 @@ -30,11 +29,9 @@ 確定 糟糕… 確定 - [ANDROID PwdStore] Modify   不能使用空白密碼或者空白的備註 請填寫文件名稱 你忘記輸入使用者名稱了嗎? -   從商店 Git Pull Git Push 同步 Repo diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 247275a1..a5506aa7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -22,10 +22,11 @@ Delete - [ANDROID PwdStore] Add   - "[ANDROID PwdStore] Edit " - "[ANDROID PwdStore] Increment HOTP counter for " -   from store. + Add password for %1$s using android password store. + "Edit %1$s using android password store." + "Remove %1$s from store." + "Rename %1$s to %2$s." + "Increment HOTP counter for %1$s." No OpenPGP Provider selected! -- cgit v1.2.3