aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeapo <mohamed@zenadi.com>2014-07-27 18:58:42 +0100
committerZeapo <mohamed@zenadi.com>2014-07-27 18:58:42 +0100
commita0b8301a4976aaa2ed170542bbfcedca84cd57fc (patch)
treeaabf35451085ec5ec5b0570aa26b5e8d72b5ab74
parentc75fd77fdf39328e41a2e23c26583ab745df44a3 (diff)
Some refactoring and organisation for listview.. sooooon
-rw-r--r--app/src/main/AndroidManifest.xml2
-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
-rw-r--r--app/src/main/res/layout/fragment_password_list.xml7
-rw-r--r--app/src/main/res/layout/fragment_to_clone_or_not.xml11
-rw-r--r--app/src/main/res/values/strings.xml7
9 files changed, 143 insertions, 74 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index b26aba3f..16210fdc 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -12,7 +12,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
- android:name=".pwdstore"
+ android:name=".PasswordStore"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
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");
+ }
+
}
diff --git a/app/src/main/res/layout/fragment_password_list.xml b/app/src/main/res/layout/fragment_password_list.xml
index 9ee68056..e3f04ece 100644
--- a/app/src/main/res/layout/fragment_password_list.xml
+++ b/app/src/main/res/layout/fragment_password_list.xml
@@ -6,10 +6,15 @@
tools:context="com.zeapo.pwdstore.PasswordFragment">
<ListView
- android:id="@android:id/list"
+ android:id="@+id/pass_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="8dp"
android:divider="@android:color/transparent"/>
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="Add!"
+ android:onClick="addItem"/>
</FrameLayout>
diff --git a/app/src/main/res/layout/fragment_to_clone_or_not.xml b/app/src/main/res/layout/fragment_to_clone_or_not.xml
index c11f3567..90a1ac32 100644
--- a/app/src/main/res/layout/fragment_to_clone_or_not.xml
+++ b/app/src/main/res/layout/fragment_to_clone_or_not.xml
@@ -7,8 +7,10 @@
<LinearLayout
android:id="@+id/myRectangleView"
- android:layout_width="200dp"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_marginLeft="18dp"
+ android:layout_marginRight="18dp"
android:background="@drawable/rectangle"
android:layout_gravity="center"
android:orientation="vertical">
@@ -16,7 +18,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
- android:text="You have no git repository for the password store."/>
+ android:gravity="center"
+ android:text="@string/clone_fragment_text"/>
<Button
android:id="@+id/main_clone_button"
android:layout_width="match_parent"
@@ -25,13 +28,13 @@
android:layout_marginBottom="8dp"
android:background="@android:color/holo_green_light"
android:onClick="getClone"
- android:text="Clone!"/>
+ android:text="@string/clone"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@android:color/holo_red_light"
- android:text="Initialize!"/>
+ android:text="@string/initialize"/>
</LinearLayout>
</FrameLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c348f3aa..d3e70a68 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -2,7 +2,7 @@
<resources>
<string name="app_name">PwdStore</string>
- <string name="clone">Clone!</string>
+
<string name="clone_settings">Clone</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
@@ -21,6 +21,11 @@
<item>http://</item>
</string-array>
+ <!-- Clone fragment -->
+ <string name="clone_fragment_text">Password store empty</string>
+ <string name="clone">Clone a git repository</string>
+ <string name="initialize">Initialize a git repository</string>
+
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>