diff --git a/app/src/main/java/com/zeapo/pwdstore/GitClone.java b/app/src/main/java/com/zeapo/pwdstore/GitClone.java index a7c817c50..cab56e96f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/GitClone.java +++ b/app/src/main/java/com/zeapo/pwdstore/GitClone.java @@ -325,33 +325,43 @@ public class GitClone extends Activity { if (connectionMode.equalsIgnoreCase("ssh-key")) { } else { - final EditText password = new EditText(activity); - password.setHint("Password"); - password.setWidth(LinearLayout.LayoutParams.MATCH_PARENT); - password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + if (protocol.equals("ssh://")) { - new AlertDialog.Builder(activity) - .setTitle("Authenticate") - .setMessage("Please provide the password for this repository") - .setView(password) - .setPositiveButton("OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { + final EditText password = new EditText(activity); + password.setHint("Password"); + password.setWidth(LinearLayout.LayoutParams.MATCH_PARENT); + password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); - SshSessionFactory.setInstance(new GitConfigSessionFactory()); + new AlertDialog.Builder(activity) + .setTitle("Authenticate") + .setMessage("Please provide the password for this repository") + .setView(password) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { - CloneCommand cmd = Git.cloneRepository(). - setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password.getText().toString())). - setCloneAllBranches(true). - setDirectory(localDir). - setURI(hostname); + SshSessionFactory.setInstance(new GitConfigSessionFactory()); - new CloneTask(activity).execute(cmd); - } - }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - // Do nothing. - } - }).show(); + CloneCommand cmd = Git.cloneRepository(). + setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password.getText().toString())). + setCloneAllBranches(true). + setDirectory(localDir). + setURI(hostname); + + new CloneTask(activity).execute(cmd); + } + }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + // Do nothing. + } + }).show(); + } else { + CloneCommand cmd = Git.cloneRepository(). + setCloneAllBranches(true). + setDirectory(localDir). + setURI(hostname); + + new CloneTask(activity).execute(cmd); + } } } diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java new file mode 100644 index 000000000..462324dbc --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -0,0 +1,155 @@ +package com.zeapo.pwdstore; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +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; + +/** + * A fragment representing a list of Items. + *
+ * Large screen devices (such as tablets) are supported by replacing the ListView + * with a GridView. + * + * Activities containing this fragment MUST implement the {@link Callbacks} + * interface. + */ +public class PasswordFragment extends Fragment implements AbsListView.OnItemClickListener { + + private OnFragmentInteractionListener mListener; + + /** + * The fragment's ListView/GridView. + */ + private AbsListView mListView; + + /** + * The Adapter which will be used to populate the ListView/GridView with + * Views. + */ + 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() { + } + + @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); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_password, container, false); + + // Set the adapter + mListView = (AbsListView) view.findViewById(android.R.id.list); + ((AdapterView
+ * See the Android Training lesson Communicating with Other Fragments for more information.
+ */
+ public interface OnFragmentInteractionListener {
+ // TODO: Update argument type and name
+ public void onFragmentInteraction(Uri uri);
+ }
+
+}
diff --git a/app/src/main/java/com/zeapo/pwdstore/pwdstore.java b/app/src/main/java/com/zeapo/pwdstore/pwdstore.java
index 54e1605b2..52071957c 100644
--- a/app/src/main/java/com/zeapo/pwdstore/pwdstore.java
+++ b/app/src/main/java/com/zeapo/pwdstore/pwdstore.java
@@ -1,26 +1,48 @@
package com.zeapo.pwdstore;
import android.app.Activity;
+import android.app.FragmentManager;
+import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.hardware.display.DisplayManager;
+import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.DirectoryFileFilter;
+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.lib.Repository;
+import org.eclipse.jgit.lib.RepositoryBuilder;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+
+import java.io.File;
+import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.util.Collection;
-public class pwdstore extends Activity {
+public class pwdstore extends Activity implements ToCloneOrNot.OnFragmentInteractionListener, PasswordFragment.OnFragmentInteractionListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pwdstore);
- System.out.println("HEE");
+ }
+
+ @Override
+ public void onResume(){
+ super.onResume();
+ // re-check that there was no change with the repository state
+ checkLocalRepository();
}
@@ -36,16 +58,57 @@ public class pwdstore extends Activity {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.clone_setting) {
- getClone();
- return true;
- }
+// int id = item.getItemId();
+// if (id == R.id.clone_setting) {
+// getClone();
+// return true;
+// }
return super.onOptionsItemSelected(item);
}
- public void getClone(){
+ public void getClone(View view){
Intent intent = new Intent(this, GitClone.class);
startActivity(intent);
}
+
+ @Override
+ public void onFragmentInteraction(Uri uri) {
+
+ }
+
+ @Override
+ public void onFragmentInteraction(String id) {
+
+ }
+
+ private void checkLocalRepository() {
+ int status = 0;
+ final File localDir = new File(getCacheDir() + "/store");
+
+ FragmentManager fragmentManager = getFragmentManager();
+ FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
+
+
+ if (localDir.exists()) {
+ File[] folders = localDir.listFiles((FileFilter) FileFilterUtils.directoryFileFilter());
+ status = folders.length;
+ }
+
+ // either the repo is empty or it was not correctly cloned
+ switch (status) {
+ case 0:
+ ToCloneOrNot cloneFrag = new ToCloneOrNot();
+ fragmentTransaction.replace(R.id.main_layout, cloneFrag);
+ fragmentTransaction.commit();
+ break;
+ case 1:
+ // empty
+ break;
+ default:
+ PasswordFragment passFrag = new PasswordFragment();
+ fragmentTransaction.replace(R.id.main_layout, passFrag);
+ fragmentTransaction.commit();
+ }
+ }
+
}
diff --git a/app/src/main/res/drawable-xxhdpi/rectangle.xml b/app/src/main/res/drawable-xxhdpi/rectangle.xml
new file mode 100644
index 000000000..67e169df3
--- /dev/null
+++ b/app/src/main/res/drawable-xxhdpi/rectangle.xml
@@ -0,0 +1,23 @@
+
+
+