From 2d1a9f7a44154035b5a47b0a9843c365dadcb62c Mon Sep 17 00:00:00 2001 From: shanavas Date: Thu, 27 Apr 2017 19:12:50 +0300 Subject: Make git username and email configurable (#289) * Gather git config data and save in preferences * Align text box properly * Apply git configs from settings * Validate email address --- .../zeapo/pwdstore/utils/PasswordRepository.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'app/src/main/java/com/zeapo/pwdstore/utils') diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java index 90cd5ed0..b1c99232 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java @@ -200,4 +200,39 @@ public class PasswordRepository { sort(passwordList); return passwordList; } + + /** + * Sets the git user name + * @param String username username + */ + public static void setUserName(String username) { + setStringConfig("user", null, "name", username); + } + + /** + * Sets the git user email + * @param String email email + */ + public static void setUserEmail(String email) { + setStringConfig("user", null, "email", email); + } + + /** + * Sets a git config value + * @param String section config section name + * @param String subsection config subsection name + * @param String name config name + * @param String value the value to be set + */ + private static void setStringConfig(String section, String subsection, String name, String value) { + if (isInitialized()) { + StoredConfig config = repository.getConfig(); + config.setString(section, subsection, name, value); + try { + config.save(); + } catch(Exception e) { + e.printStackTrace(); + } + } + } } -- cgit v1.2.3