aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorzeapo <mohamed@zenadi.com>2014-10-19 12:56:52 +0200
committerzeapo <mohamed@zenadi.com>2014-10-19 12:56:52 +0200
commitb8b5234e5bbef024ca25c63a8882a4d677778e6c (patch)
treee6c618d2af3386a3c68745b9a2c0f60e3477c7bc /app/src/main/java
parent524c9205c08615ce6399361303b411975c08c0f8 (diff)
First shot on Material design (prefrences not working)
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java40
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java53
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java3
4 files changed, 71 insertions, 28 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
index 8278931b..7a327ef2 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
@@ -4,7 +4,9 @@ import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.app.Fragment;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -27,7 +29,9 @@ import com.zeapo.pwdstore.utils.PasswordItem;
import com.zeapo.pwdstore.utils.PasswordRepository;
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Stack;
/**
* A fragment representing a list of Items.
@@ -36,7 +40,10 @@ import java.util.List;
* with a GridView.
* <p />
*/
-public class PasswordFragment extends Fragment implements SwipeListViewListener {
+public class PasswordFragment extends Fragment implements SwipeListViewListener{
+
+ // store the pass files list in a stack
+ private Stack<ArrayList<PasswordItem>> passListStack;
private OnFragmentInteractionListener mListener;
@@ -62,6 +69,9 @@ public class PasswordFragment extends Fragment implements SwipeListViewListener
super.onCreate(savedInstanceState);
String path = getArguments().getString("Path");
+
+ passListStack = new Stack<ArrayList<PasswordItem>>();
+
mAdapter = new PasswordAdapter((PasswordStore) getActivity(), PasswordRepository.getPasswords(new File(path)));
}
@@ -74,8 +84,6 @@ public class PasswordFragment extends Fragment implements SwipeListViewListener
mListView = (SwipeListView) view.findViewById(R.id.pass_list);
((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
mListView.setSwipeListViewListener(this);
- mListView.setSelectionFromTop(getArguments().getInt("Position"), 0);
-
return view;
}
@@ -83,7 +91,23 @@ public class PasswordFragment extends Fragment implements SwipeListViewListener
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
- mListener = (OnFragmentInteractionListener) activity;
+ mListener = new OnFragmentInteractionListener() {
+ @Override
+ public void onFragmentInteraction(PasswordItem item) {
+ if (item.getType() == PasswordItem.TYPE_CATEGORY) {
+ passListStack.push((ArrayList<PasswordItem>) mAdapter.getValues().clone());
+ mAdapter.clear();
+ mAdapter.addAll(PasswordRepository.getPasswords(item.getFile()));
+
+ ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+ }
+
+ @Override
+ public void savePosition(Integer position) {
+
+ }
+ };
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
@@ -195,4 +219,12 @@ public class PasswordFragment extends Fragment implements SwipeListViewListener
mListView.setAdapter((ListAdapter) mAdapter);
}
+ public void popBack() {
+ mAdapter.clear();
+ mAdapter.addAll(passListStack.pop());
+ }
+
+ public boolean isNotEmpty() {
+ return !passListStack.isEmpty();
+ }
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
index 20f58cfb..2ce7120e 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
@@ -10,6 +10,7 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -25,10 +26,11 @@ import org.eclipse.jgit.api.Git;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Stack;
-public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentInteractionListener, PasswordFragment.OnFragmentInteractionListener {
+public class PasswordStore extends ActionBarActivity implements ToCloneOrNot.OnFragmentInteractionListener {
private Stack<Integer> scrollPositions;
/** if we leave the activity to do something, do not add any other fragment */
public boolean leftActivity = false;
@@ -76,6 +78,7 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
Intent intent;
+ Log.d("PASS", "Menu item " + id + " pressed");
AlertDialog.Builder initBefore = new AlertDialog.Builder(this)
.setMessage("Please clone or create a new repository below before trying to add a password or any synchronization operation.")
@@ -137,6 +140,11 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
refreshListAdapter();
return true;
+ case android.R.id.home:
+ Log.d("PASS", "Home pressed");
+ this.onBackPressed();
+ break;
+
default:
break;
}
@@ -266,41 +274,42 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
fragmentTransaction.commit();
break;
default:
- PasswordRepository.setInitialized(true);
- PasswordFragment passFrag = new PasswordFragment();
- Bundle args = new Bundle();
- args.putString("Path", localDir.getAbsolutePath());
- if (!scrollPositions.isEmpty())
- args.putInt("Position", scrollPositions.pop());
- else
- args.putInt("Position", 0);
+ if (fragmentManager.findFragmentByTag("PasswordsList") == null) {
+ PasswordRepository.setInitialized(true);
+ PasswordFragment passFrag = new PasswordFragment();
+ Bundle args = new Bundle();
+ args.putString("Path", localDir.getAbsolutePath());
- passFrag.setArguments(args);
+ passFrag.setArguments(args);
- if (fragmentManager.findFragmentByTag("PasswordsList") != null)
fragmentTransaction.addToBackStack("passlist");
- fragmentTransaction.replace(R.id.main_layout, passFrag, "PasswordsList");
- fragmentTransaction.commit();
+ fragmentTransaction.replace(R.id.main_layout, passFrag, "PasswordsList");
+ fragmentTransaction.commit();
+ }
}
this.leftActivity = false;
}
- /** Stack the positions the different fragments were at */
- @Override
- public void savePosition(Integer position) {
- this.scrollPositions.push(position);
- }
- /* If an item is clicked in the list of passwords, this will be triggered */
+
@Override
- public void onFragmentInteraction(PasswordItem item) {
- if (item.getType() == PasswordItem.TYPE_CATEGORY) {
- checkLocalRepository(item.getFile());
+ public void onBackPressed() {
+ PasswordFragment plist;
+ if ((null != (plist = (PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList"))) &&
+ plist.isNotEmpty()) {
+ plist.popBack();
+ } else {
+ super.onBackPressed();
+ }
+
+ if (!plist.isNotEmpty()) {
+ getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
}
+
public void decryptPassword(PasswordItem item) {
try {
this.leftActivity = true;
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java
index fb9442fb..e3317c01 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java
@@ -41,6 +41,9 @@ public class PasswordAdapter extends ArrayAdapter<PasswordItem>{
this.activity = activity;
}
+ public ArrayList<PasswordItem> getValues() {
+ return values;
+ }
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
index bc36f1cb..b35f9701 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
@@ -32,9 +32,8 @@ public class PasswordRepository {
if (repository == null) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
try {
- repository = builder.setWorkTree(localDir)
+ repository = builder.setGitDir(localDir)
.readEnvironment()
- .findGitDir()
.build();
} catch (Exception e) {
e.printStackTrace();