prompt for an external dir if none is selected

This commit is contained in:
Mohamed Zenadi
2015-07-26 14:53:31 +02:00
parent e45afa3392
commit 294f068991
3 changed files with 20 additions and 15 deletions

View File

@@ -28,6 +28,7 @@ import com.zeapo.pwdstore.utils.PasswordRepository;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import java.io.File;
import java.util.HashSet;
@@ -43,6 +44,7 @@ public class PasswordStore extends AppCompatActivity {
private final static int CLONE_REPO_BUTTON = 401;
private final static int NEW_REPO_BUTTON = 402;
private final static int HOME = 403;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -253,15 +255,21 @@ public class PasswordStore extends AppCompatActivity {
}
private void checkLocalRepository() {
PasswordRepository.initialize(this);
checkLocalRepository(PasswordRepository.getWorkTree());
Repository repo = PasswordRepository.initialize(this);
if (repo == null) {
Intent intent = new Intent(activity, UserPreference.class);
intent.putExtra("operation", "git_external");
startActivityForResult(intent, HOME);
} else {
checkLocalRepository(PasswordRepository.getWorkTree());
}
}
private void checkLocalRepository(File localDir) {
Log.d("PASS", "Check, dir: " + localDir.getAbsolutePath());
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if (settings.getBoolean("repository_initialized", false)) {
if (localDir != null && settings.getBoolean("repository_initialized", false)) {
Log.d("PASS", "Check, dir: " + localDir.getAbsolutePath());
// do not push the fragment if we already have it
if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) {
settings.edit().putBoolean("repo_changed", false).apply();
@@ -432,6 +440,9 @@ public class PasswordStore extends AppCompatActivity {
case GitActivity.REQUEST_PULL:
updateListAdapter();
break;
case HOME:
checkLocalRepository();
break;
case NEW_REPO_BUTTON:
initializeRepositoryInfo();
break;

View File

@@ -318,7 +318,7 @@ public class UserPreference extends AppCompatActivity {
PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
.edit()
.putString("git_external_repo", data.getStringExtra(DirectoryChooserActivity.RESULT_SELECTED_DIR))
.commit();
.apply();
}
}
}

View File

@@ -1,13 +1,10 @@
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 com.zeapo.pwdstore.UserPreference;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.eclipse.jgit.api.Git;
@@ -117,7 +114,7 @@ public class PasswordRepository {
repository = null;
}
public static void initialize(Activity callingActivity) {
public static Repository initialize(Activity callingActivity) {
File dir = null;
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(callingActivity.getApplicationContext());
@@ -128,12 +125,9 @@ public class PasswordRepository {
} 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;
return null;
}
// uninitialize the repo if the dir does not exist or is absolutely empty
@@ -146,7 +140,7 @@ public class PasswordRepository {
}
// create the repository static variable in PasswordRepository
PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git"));
return PasswordRepository.getRepository(new File(dir.getAbsolutePath() + "/.git"));
}
public static ArrayList<File> getFilesList(){