now possible to clone/create repository in a given external directory.
*issues*: - not possible to switch between external/local directory without closing the app. (PasswordRepository is a singleton, has to be cleaned when a change is made)
This commit is contained in:
parent
994cb0272b
commit
62b4d78e93
4 changed files with 34 additions and 28 deletions
|
@ -1,7 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.zeapo.pwdstore">
|
package="com.zeapo.pwdstore">
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
<application android:allowBackup="true" android:icon="@drawable/ic_launcher"
|
<application android:allowBackup="true" android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/app_name" android:theme="@style/AppTheme">
|
android:label="@string/app_name" android:theme="@style/AppTheme">
|
||||||
<activity android:name=".PasswordStore" android:label="@string/app_name">
|
<activity android:name=".PasswordStore" android:label="@string/app_name">
|
||||||
|
@ -34,8 +36,4 @@
|
||||||
<activity android:name="net.rdrei.android.dirchooser.DirectoryChooserActivity" />
|
<activity android:name="net.rdrei.android.dirchooser.DirectoryChooserActivity" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -47,9 +47,31 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onResume(){
|
public void onResume(){
|
||||||
super.onResume();
|
super.onResume();
|
||||||
// create the repository static variable in PasswordRepository
|
File dir = null;
|
||||||
PasswordRepository.getRepository(new File(getFilesDir() + this.getResources().getString(R.string.store_git)));
|
|
||||||
|
|
||||||
|
if (settings.getBoolean("git_external", false)) {
|
||||||
|
if (settings.getString("git_external_repo", null) == null)
|
||||||
|
{
|
||||||
|
// todo: show the main screen
|
||||||
|
} else {
|
||||||
|
dir = new File(settings.getString("git_external_repo", null));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dir = new File(getFilesDir() + "/store");
|
||||||
|
}
|
||||||
|
assert dir != null;
|
||||||
|
|
||||||
|
// uninitialize the repo if the dir does not exist or is absolutely empty
|
||||||
|
if (!dir.exists() || !dir.isDirectory()) {
|
||||||
|
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();
|
checkLocalRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +214,8 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
private void createRepository() {
|
private void createRepository() {
|
||||||
// final String keyId = settings.getString("openpgp_key_ids", "");
|
// final String keyId = settings.getString("openpgp_key_ids", "");
|
||||||
|
|
||||||
File localDir = new File(getFilesDir() + "/store/");
|
File localDir = PasswordRepository.getWorkTree();
|
||||||
|
|
||||||
localDir.mkdir();
|
localDir.mkdir();
|
||||||
try {
|
try {
|
||||||
PasswordRepository.createRepository(localDir);
|
PasswordRepository.createRepository(localDir);
|
||||||
|
@ -239,8 +262,7 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getFragmentManager();
|
||||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||||
|
|
||||||
// TODO: Remove the getpaswords() as it is a temporary fix until every user has the repository_initialized set
|
if (settings.getBoolean("repository_initialized", false)) {
|
||||||
if (settings.getBoolean("repository_initialized", false) || PasswordRepository.getPasswords(localDir).size() > 0) {
|
|
||||||
// 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) {
|
if (fragmentManager.findFragmentByTag("PasswordsList") == null) {
|
||||||
|
|
||||||
|
@ -249,7 +271,6 @@ public class PasswordStore extends ActionBarActivity {
|
||||||
fragmentManager.popBackStack();
|
fragmentManager.popBackStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
PasswordRepository.setInitialized(true);
|
|
||||||
plist = new PasswordFragment();
|
plist = new PasswordFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("Path", PasswordRepository.getWorkTree().getAbsolutePath());
|
args.putString("Path", PasswordRepository.getWorkTree().getAbsolutePath());
|
||||||
|
|
|
@ -432,8 +432,7 @@ public class GitActivity extends ActionBarActivity {
|
||||||
* @param view
|
* @param view
|
||||||
*/
|
*/
|
||||||
public void cloneRepository(View view) {
|
public void cloneRepository(View view) {
|
||||||
localDir = new File(getApplicationContext().getFilesDir().getAbsoluteFile() + "/store");
|
localDir = PasswordRepository.getWorkTree();
|
||||||
|
|
||||||
hostname = ((EditText) findViewById(R.id.clone_uri)).getText().toString();
|
hostname = ((EditText) findViewById(R.id.clone_uri)).getText().toString();
|
||||||
port = ((EditText) findViewById(R.id.server_port)).getText().toString();
|
port = ((EditText) findViewById(R.id.server_port)).getText().toString();
|
||||||
// don't ask the user, take off the protocol that he puts in
|
// don't ask the user, take off the protocol that he puts in
|
||||||
|
|
|
@ -5,8 +5,8 @@ import android.util.Log;
|
||||||
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;
|
||||||
import org.eclipse.jgit.lib.StoredConfig;
|
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
import org.eclipse.jgit.lib.StoredConfig;
|
||||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||||
import org.eclipse.jgit.transport.RefSpec;
|
import org.eclipse.jgit.transport.RefSpec;
|
||||||
import org.eclipse.jgit.transport.RemoteConfig;
|
import org.eclipse.jgit.transport.RemoteConfig;
|
||||||
|
@ -49,11 +49,7 @@ public class PasswordRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInitialized() {
|
public static boolean isInitialized() {
|
||||||
return initialized;
|
return repository != null;
|
||||||
}
|
|
||||||
|
|
||||||
public static void setInitialized(boolean v) {
|
|
||||||
initialized = v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createRepository(File localDir) throws Exception{
|
public static void createRepository(File localDir) throws Exception{
|
||||||
|
@ -112,6 +108,7 @@ public class PasswordRepository {
|
||||||
|
|
||||||
public static void closeRepository() {
|
public static void closeRepository() {
|
||||||
repository.close();
|
repository.close();
|
||||||
|
repository = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<File> getFilesList(){
|
public static ArrayList<File> getFilesList(){
|
||||||
|
@ -130,15 +127,6 @@ public class PasswordRepository {
|
||||||
return repository.getWorkTree();
|
return repository.getWorkTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a file from the working tree
|
|
||||||
* @param name the relative path of the file
|
|
||||||
* @return the file in the repository
|
|
||||||
*/
|
|
||||||
public static File getFile(String name) {
|
|
||||||
return new File(repository.getWorkTree() + "/" + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the .gpg files in a directory
|
* Gets the .gpg files in a directory
|
||||||
* @param path the directory path
|
* @param path the directory path
|
||||||
|
|
Loading…
Reference in a new issue