it is no longer necessary to go through settings to initialize an external repo
This commit is contained in:
parent
a21dd84c2b
commit
7fe81e9c27
1 changed files with 52 additions and 28 deletions
|
@ -51,34 +51,6 @@ public class PasswordStore extends AppCompatActivity {
|
|||
@Override
|
||||
public void onResume(){
|
||||
super.onResume();
|
||||
File dir = null;
|
||||
|
||||
if (settings.getBoolean("git_external", false)) {
|
||||
if (settings.getString("git_external_repo", null) != null) {
|
||||
dir = new File(settings.getString("git_external_repo", null));
|
||||
}
|
||||
} else {
|
||||
dir = new File(getFilesDir() + "/store");
|
||||
}
|
||||
// temp for debug
|
||||
if (dir == null) {
|
||||
Intent intent = new Intent(this, UserPreference.class);
|
||||
intent.putExtra("operation", "git_external");
|
||||
startActivity(intent);
|
||||
return;
|
||||
}
|
||||
|
||||
// uninitialize the repo if the dir does not exist or is absolutely empty
|
||||
if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) {
|
||||
settings.edit().putBoolean("repository_initialized", false).apply();
|
||||
}
|
||||
|
||||
if (!PasswordRepository.getPasswords(dir).isEmpty()) {
|
||||
settings.edit().putBoolean("repository_initialized", true).apply();
|
||||
}
|
||||
|
||||
// create the repository static variable in PasswordRepository
|
||||
PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git"));
|
||||
checkLocalRepository();
|
||||
}
|
||||
|
||||
|
@ -239,6 +211,17 @@ public class PasswordStore extends AppCompatActivity {
|
|||
}
|
||||
|
||||
public void initializeRepositoryInfo() {
|
||||
if (settings.getBoolean("git_external", false) && settings.getString("git_external_repo", null) != null) {
|
||||
File dir = new File(settings.getString("git_external_repo", null));
|
||||
|
||||
if (dir.exists() && dir.isDirectory() && !FileUtils.listFiles(dir, null, true).isEmpty() &&
|
||||
!PasswordRepository.getPasswords(dir).isEmpty()) {
|
||||
PasswordRepository.closeRepository();
|
||||
checkLocalRepository();
|
||||
return; // if not empty, just show me the passwords!
|
||||
}
|
||||
}
|
||||
|
||||
final String keyId = settings.getString("openpgp_key_ids", "");
|
||||
|
||||
if (keyId != null && keyId.isEmpty())
|
||||
|
@ -263,6 +246,35 @@ public class PasswordStore extends AppCompatActivity {
|
|||
}
|
||||
|
||||
private void checkLocalRepository() {
|
||||
File dir = null;
|
||||
|
||||
if (settings.getBoolean("git_external", false)) {
|
||||
if (settings.getString("git_external_repo", null) != null) {
|
||||
dir = new File(settings.getString("git_external_repo", null));
|
||||
}
|
||||
} else {
|
||||
dir = new File(getFilesDir() + "/store");
|
||||
}
|
||||
// temp for debug
|
||||
if (dir == null) {
|
||||
Intent intent = new Intent(this, UserPreference.class);
|
||||
intent.putExtra("operation", "git_external");
|
||||
startActivity(intent);
|
||||
return;
|
||||
}
|
||||
|
||||
// uninitialize the repo if the dir does not exist or is absolutely empty
|
||||
if (!dir.exists() || !dir.isDirectory() || FileUtils.listFiles(dir, null, false).isEmpty()) {
|
||||
settings.edit().putBoolean("repository_initialized", false).apply();
|
||||
}
|
||||
|
||||
if (!PasswordRepository.getPasswords(dir).isEmpty()) {
|
||||
settings.edit().putBoolean("repository_initialized", true).apply();
|
||||
}
|
||||
|
||||
// create the repository static variable in PasswordRepository
|
||||
PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git"));
|
||||
|
||||
checkLocalRepository(PasswordRepository.getWorkTree());
|
||||
}
|
||||
|
||||
|
@ -446,6 +458,17 @@ public class PasswordStore extends AppCompatActivity {
|
|||
initializeRepositoryInfo();
|
||||
break;
|
||||
case CLONE_REPO_BUTTON:
|
||||
// duplicate code
|
||||
if (settings.getBoolean("git_external", false) && settings.getString("git_external_repo", null) != null) {
|
||||
File dir = new File(settings.getString("git_external_repo", null));
|
||||
|
||||
if (dir.exists() && dir.isDirectory() && !FileUtils.listFiles(dir, null, true).isEmpty() &&
|
||||
!PasswordRepository.getPasswords(dir).isEmpty()) {
|
||||
PasswordRepository.closeRepository();
|
||||
checkLocalRepository();
|
||||
return; // if not empty, just show me the passwords!
|
||||
}
|
||||
}
|
||||
Intent intent = new Intent(activity, GitActivity.class);
|
||||
intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
|
||||
startActivityForResult(intent, GitActivity.REQUEST_CLONE);
|
||||
|
@ -467,6 +490,7 @@ public class PasswordStore extends AppCompatActivity {
|
|||
intent.putExtra("operation", "git_external");
|
||||
startActivityForResult(intent, operation);
|
||||
} else {
|
||||
PasswordRepository.closeRepository();
|
||||
checkLocalRepository();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue