aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/GitClone.java20
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/GitRepo.java41
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordAdapter.java48
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java63
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java (renamed from app/src/main/java/com/zeapo/pwdstore/pwdstore.java)18
5 files changed, 123 insertions, 67 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/GitClone.java b/app/src/main/java/com/zeapo/pwdstore/GitClone.java
index cab56e96..6166ba2c 100644
--- a/app/src/main/java/com/zeapo/pwdstore/GitClone.java
+++ b/app/src/main/java/com/zeapo/pwdstore/GitClone.java
@@ -31,9 +31,17 @@ import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.errors.NotSupportedException;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.JschConfigSessionFactory;
import org.eclipse.jgit.transport.OpenSshConfig;
+import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.SshSessionFactory;
+import org.eclipse.jgit.transport.Transport;
+import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.eclipse.jgit.util.FS;
@@ -246,7 +254,7 @@ public class GitClone extends Activity {
public void cloneRepository(View view) {
- localDir = new File(getApplicationContext().getCacheDir().getAbsoluteFile() + "/store");
+ localDir = new File(getApplicationContext().getFilesDir().getAbsoluteFile() + "/store");
hostname = ((TextView) findViewById(R.id.clone_uri)).getText().toString();
// don't ask the user, take off the protocol that he puts in
@@ -355,10 +363,12 @@ public class GitClone extends Activity {
}
}).show();
} else {
- CloneCommand cmd = Git.cloneRepository().
- setCloneAllBranches(true).
- setDirectory(localDir).
- setURI(hostname);
+ CloneCommand cmd = Git.cloneRepository()
+ .setDirectory(localDir)
+ .setURI(hostname)
+ .setBare(false)
+ .setNoCheckout(false)
+ .setCloneAllBranches(true);
new CloneTask(activity).execute(cmd);
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/GitRepo.java b/app/src/main/java/com/zeapo/pwdstore/GitRepo.java
new file mode 100644
index 00000000..34757b88
--- /dev/null
+++ b/app/src/main/java/com/zeapo/pwdstore/GitRepo.java
@@ -0,0 +1,41 @@
+package com.zeapo.pwdstore;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryBuilder;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Created by zeapo on 7/27/14.
+ */
+public class GitRepo {
+
+ private static Repository repository;
+
+ protected GitRepo(){ }
+
+ public static Repository getRepository(File localDir) {
+ if (repository == null) {
+ FileRepositoryBuilder builder = new FileRepositoryBuilder();
+ try {
+ repository = builder.setGitDir(localDir)
+ .readEnvironment()
+ .findGitDir()
+ .build();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ return repository;
+ }
+
+ public static void closeRepository() {
+ repository.close();
+ }
+}
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordAdapter.java b/app/src/main/java/com/zeapo/pwdstore/PasswordAdapter.java
new file mode 100644
index 00000000..023c8c8a
--- /dev/null
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordAdapter.java
@@ -0,0 +1,48 @@
+package com.zeapo.pwdstore;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import com.zeapo.pwdstore.R;
+
+import java.util.ArrayList;
+
+public class PasswordAdapter extends ArrayAdapter<String> {
+ private final Context context;
+ private final ArrayList<String> values;
+
+ static class ViewHolder {
+ public TextView text;
+ }
+
+ public PasswordAdapter(Context context, ArrayList<String> values) {
+ super(context, R.layout.password_row_layout, values);
+ this.context = context;
+ this.values = values;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View rowView = convertView;
+
+ // reuse for performance, holder pattern!
+ if (rowView == null) {
+ LayoutInflater inflater = (LayoutInflater) context
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ rowView = inflater.inflate(R.layout.password_row_layout, null);
+
+ ViewHolder viewHolder = new ViewHolder();
+ viewHolder.text = (TextView) rowView.findViewById(R.id.label);
+ rowView.setTag(viewHolder);
+ }
+
+ ViewHolder holder = (ViewHolder) rowView.getTag();
+ holder.text.setText( values.get(position) );
+
+ return rowView;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
index 462324db..f6a2d822 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
@@ -11,13 +11,9 @@ import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
-import android.widget.RelativeLayout;
import android.widget.TextView;
-
-import com.zeapo.pwdstore.dummy.DummyContent;
-
-import java.util.List;
+import java.util.ArrayList;
/**
* A fragment representing a list of Items.
@@ -25,8 +21,6 @@ import java.util.List;
* Large screen devices (such as tablets) are supported by replacing the ListView
* with a GridView.
* <p />
- * Activities containing this fragment MUST implement the {@link Callbacks}
- * interface.
*/
public class PasswordFragment extends Fragment implements AbsListView.OnItemClickListener {
@@ -43,31 +37,17 @@ public class PasswordFragment extends Fragment implements AbsListView.OnItemClic
*/
private ListAdapter mAdapter;
- // TODO: Rename and change types of parameters
- public static PasswordFragment newInstance(String param1, String param2) {
- PasswordFragment fragment = new PasswordFragment();
- Bundle args = new Bundle();
- fragment.setArguments(args);
- return fragment;
- }
-
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
- public PasswordFragment() {
- }
+ public PasswordFragment() { }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (getArguments() != null) {
- }
- String[] values = new String[] { "NOT", "YET", "IMPLEMENTED" };
-
- // TODO: Change Adapter to display your content
- mAdapter = new MySimpleArrayAdapter(getActivity(), values);
+ mAdapter = new PasswordAdapter(getActivity(), new ArrayList<String>());
}
@Override
@@ -76,7 +56,7 @@ public class PasswordFragment extends Fragment implements AbsListView.OnItemClic
View view = inflater.inflate(R.layout.fragment_password, container, false);
// Set the adapter
- mListView = (AbsListView) view.findViewById(android.R.id.list);
+ mListView = (AbsListView) view.findViewById(R.id.pass_list);
((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
// Set OnItemClickListener so we can be notified on item clicks
@@ -112,44 +92,9 @@ public class PasswordFragment extends Fragment implements AbsListView.OnItemClic
}
}
- /**
- * The default content for this Fragment has a TextView that is shown when
- * the list is empty. If you would like to change the text, call this method
- * to supply the text it should use.
- */
- public void setEmptyText(CharSequence emptyText) {
- View emptyView = mListView.getEmptyView();
-
- if (emptyText instanceof TextView) {
- ((TextView) emptyView).setText(emptyText);
- }
- }
-
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(String id);
}
-
- public class MySimpleArrayAdapter extends ArrayAdapter<String> {
- private final Context context;
- private final String[] values;
-
- public MySimpleArrayAdapter(Context context, String[] values) {
- super(context, R.layout.password_row_layout, values);
- this.context = context;
- this.values = values;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View rowView = inflater.inflate(R.layout.password_row_layout, parent, false);
- TextView textView = (TextView) rowView.findViewById(R.id.label);
- textView.setText(values[position]);
-
- return rowView;
- }
- }
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/pwdstore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
index 52071957..8b047626 100644
--- a/app/src/main/java/com/zeapo/pwdstore/pwdstore.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
@@ -11,6 +11,8 @@ import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
import android.widget.TextView;
import org.apache.commons.io.FileUtils;
@@ -19,6 +21,8 @@ import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.NotFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.ListBranchCommand;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
@@ -28,9 +32,10 @@ import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Collection;
+import java.util.List;
-public class pwdstore extends Activity implements ToCloneOrNot.OnFragmentInteractionListener, PasswordFragment.OnFragmentInteractionListener {
+public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentInteractionListener, PasswordFragment.OnFragmentInteractionListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -83,12 +88,11 @@ public class pwdstore extends Activity implements ToCloneOrNot.OnFragmentIntera
private void checkLocalRepository() {
int status = 0;
- final File localDir = new File(getCacheDir() + "/store");
+ final File localDir = new File(getFilesDir() + "/store/.git");
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
-
if (localDir.exists()) {
File[] folders = localDir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
status = folders.length;
@@ -111,4 +115,12 @@ public class pwdstore extends Activity implements ToCloneOrNot.OnFragmentIntera
}
}
+ public void addItem(View view) {
+ ListView l = (ListView) findViewById(R.id.pass_list);
+
+ PasswordAdapter pad = (PasswordAdapter) l.getAdapter();
+
+ pad.add("Something");
+ }
+
}