mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-09-01 14:55:19 +00:00
fix some issues where the password repository was not initialized
This commit is contained in:
@@ -54,7 +54,6 @@ public class PasswordFragment extends Fragment{
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
String path = getArguments().getString("Path");
|
String path = getArguments().getString("Path");
|
||||||
|
|
||||||
settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
|
@@ -198,7 +198,9 @@ public class PasswordStore extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createRepository() {
|
private void createRepository() {
|
||||||
// final String keyId = settings.getString("openpgp_key_ids", "");
|
if (!PasswordRepository.isInitialized()) {
|
||||||
|
PasswordRepository.initialize(this);
|
||||||
|
}
|
||||||
|
|
||||||
File localDir = PasswordRepository.getWorkTree();
|
File localDir = PasswordRepository.getWorkTree();
|
||||||
|
|
||||||
@@ -251,35 +253,7 @@ public class PasswordStore extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkLocalRepository() {
|
private void checkLocalRepository() {
|
||||||
File dir = null;
|
PasswordRepository.initialize(this);
|
||||||
|
|
||||||
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());
|
checkLocalRepository(PasswordRepository.getWorkTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +261,6 @@ public class PasswordStore extends AppCompatActivity {
|
|||||||
Log.d("PASS", "Check, dir: " + localDir.getAbsolutePath());
|
Log.d("PASS", "Check, dir: " + localDir.getAbsolutePath());
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
|
|
||||||
if (settings.getBoolean("repository_initialized", false)) {
|
if (settings.getBoolean("repository_initialized", false)) {
|
||||||
// do not push the fragment if we already have it
|
// do not push the fragment if we already have it
|
||||||
if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) {
|
if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) {
|
||||||
@@ -483,6 +456,8 @@ public class PasswordStore extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void initRepository(final int operation) {
|
protected void initRepository(final int operation) {
|
||||||
|
PasswordRepository.closeRepository();
|
||||||
|
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.setTitle("Repositiory location")
|
.setTitle("Repositiory location")
|
||||||
.setMessage("Select where to create or clone your password repository.")
|
.setMessage("Select where to create or clone your password repository.")
|
||||||
@@ -495,19 +470,32 @@ public class PasswordStore extends AppCompatActivity {
|
|||||||
intent.putExtra("operation", "git_external");
|
intent.putExtra("operation", "git_external");
|
||||||
startActivityForResult(intent, operation);
|
startActivityForResult(intent, operation);
|
||||||
} else {
|
} else {
|
||||||
PasswordRepository.closeRepository();
|
switch (operation) {
|
||||||
checkLocalRepository();
|
case NEW_REPO_BUTTON:
|
||||||
|
initializeRepositoryInfo();
|
||||||
|
break;
|
||||||
|
case CLONE_REPO_BUTTON:
|
||||||
|
PasswordRepository.initialize(PasswordStore.this);
|
||||||
|
|
||||||
|
Intent intent = new Intent(activity, GitActivity.class);
|
||||||
|
intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
|
||||||
|
startActivityForResult(intent, GitActivity.REQUEST_CLONE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton("Internal", new DialogInterface.OnClickListener() {
|
.setNegativeButton("Internal", new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
settings.edit().putBoolean("git_external", false).apply();
|
settings.edit().putBoolean("git_external", false).apply();
|
||||||
|
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case NEW_REPO_BUTTON:
|
case NEW_REPO_BUTTON:
|
||||||
initializeRepositoryInfo();
|
initializeRepositoryInfo();
|
||||||
break;
|
break;
|
||||||
case CLONE_REPO_BUTTON:
|
case CLONE_REPO_BUTTON:
|
||||||
|
PasswordRepository.initialize(PasswordStore.this);
|
||||||
|
|
||||||
Intent intent = new Intent(activity, GitActivity.class);
|
Intent intent = new Intent(activity, GitActivity.class);
|
||||||
intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
|
intent.putExtra("Operation", GitActivity.REQUEST_CLONE);
|
||||||
startActivityForResult(intent, GitActivity.REQUEST_CLONE);
|
startActivityForResult(intent, GitActivity.REQUEST_CLONE);
|
||||||
|
@@ -104,6 +104,7 @@ public class UserPreference extends AppCompatActivity {
|
|||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
try {
|
try {
|
||||||
FileUtils.cleanDirectory(PasswordRepository.getWorkTree());
|
FileUtils.cleanDirectory(PasswordRepository.getWorkTree());
|
||||||
|
PasswordRepository.closeRepository();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//TODO Handle the diffent cases of exceptions
|
//TODO Handle the diffent cases of exceptions
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,13 @@
|
|||||||
package com.zeapo.pwdstore.utils;
|
package com.zeapo.pwdstore.utils;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.zeapo.pwdstore.UserPreference;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.filefilter.FileFilterUtils;
|
import org.apache.commons.io.filefilter.FileFilterUtils;
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
@@ -111,6 +117,38 @@ public class PasswordRepository {
|
|||||||
repository = null;
|
repository = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void initialize(Activity callingActivity) {
|
||||||
|
File dir = null;
|
||||||
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(callingActivity.getApplicationContext());
|
||||||
|
|
||||||
|
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(callingActivity.getFilesDir() + "/store");
|
||||||
|
}
|
||||||
|
// temp for debug
|
||||||
|
if (dir == null) {
|
||||||
|
Intent intent = new Intent(callingActivity, UserPreference.class);
|
||||||
|
intent.putExtra("operation", "git_external");
|
||||||
|
callingActivity.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"));
|
||||||
|
}
|
||||||
|
|
||||||
public static ArrayList<File> getFilesList(){
|
public static ArrayList<File> getFilesList(){
|
||||||
return getFilesList(repository.getWorkTree());
|
return getFilesList(repository.getWorkTree());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user