First shot on Material design (prefrences not working)
This commit is contained in:
parent
524c9205c0
commit
b8b5234e5b
6 changed files with 79 additions and 43 deletions
|
@ -3,14 +3,14 @@ apply from: 'copyLibs.gradle' // enable 'copyLibs.gradle' script plugin
|
||||||
apply plugin: 'eclipse'
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 19
|
compileSdkVersion 21
|
||||||
buildToolsVersion "19.1.0"
|
buildToolsVersion "21.0.1"
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.zeapo.pwdstore"
|
applicationId "com.zeapo.pwdstore"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 19
|
targetSdkVersion 21
|
||||||
versionCode 15
|
versionCode 16
|
||||||
versionName "1.1-b8"
|
versionName "1.2-b1"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -29,6 +29,8 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile "com.android.support:appcompat-v7:21.+"
|
||||||
|
|
||||||
//compile fileTree(dir: 'libs', include: ['*.jar'])
|
//compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
compile project(':libraries:openpgp-api-lib')
|
compile project(':libraries:openpgp-api-lib')
|
||||||
compile 'org.eclipse.jgit:org.eclipse.jgit:3.5.+'
|
compile 'org.eclipse.jgit:org.eclipse.jgit:3.5.+'
|
||||||
|
|
|
@ -4,7 +4,9 @@ import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -27,7 +29,9 @@ import com.zeapo.pwdstore.utils.PasswordItem;
|
||||||
import com.zeapo.pwdstore.utils.PasswordRepository;
|
import com.zeapo.pwdstore.utils.PasswordRepository;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment representing a list of Items.
|
* A fragment representing a list of Items.
|
||||||
|
@ -36,7 +40,10 @@ import java.util.List;
|
||||||
* with a GridView.
|
* with a GridView.
|
||||||
* <p />
|
* <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;
|
private OnFragmentInteractionListener mListener;
|
||||||
|
|
||||||
|
@ -62,6 +69,9 @@ public class PasswordFragment extends Fragment implements SwipeListViewListener
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
String path = getArguments().getString("Path");
|
String path = getArguments().getString("Path");
|
||||||
|
|
||||||
|
passListStack = new Stack<ArrayList<PasswordItem>>();
|
||||||
|
|
||||||
mAdapter = new PasswordAdapter((PasswordStore) getActivity(), PasswordRepository.getPasswords(new File(path)));
|
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);
|
mListView = (SwipeListView) view.findViewById(R.id.pass_list);
|
||||||
((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
|
((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
|
||||||
mListView.setSwipeListViewListener(this);
|
mListView.setSwipeListViewListener(this);
|
||||||
mListView.setSelectionFromTop(getArguments().getInt("Position"), 0);
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +91,23 @@ public class PasswordFragment extends Fragment implements SwipeListViewListener
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
try {
|
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) {
|
} catch (ClassCastException e) {
|
||||||
throw new ClassCastException(activity.toString()
|
throw new ClassCastException(activity.toString()
|
||||||
+ " must implement OnFragmentInteractionListener");
|
+ " must implement OnFragmentInteractionListener");
|
||||||
|
@ -195,4 +219,12 @@ public class PasswordFragment extends Fragment implements SwipeListViewListener
|
||||||
mListView.setAdapter((ListAdapter) mAdapter);
|
mListView.setAdapter((ListAdapter) mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void popBack() {
|
||||||
|
mAdapter.clear();
|
||||||
|
mAdapter.addAll(passListStack.pop());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNotEmpty() {
|
||||||
|
return !passListStack.isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -25,10 +26,11 @@ import org.eclipse.jgit.api.Git;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Stack;
|
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;
|
private Stack<Integer> scrollPositions;
|
||||||
/** if we leave the activity to do something, do not add any other fragment */
|
/** if we leave the activity to do something, do not add any other fragment */
|
||||||
public boolean leftActivity = false;
|
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.
|
// as you specify a parent activity in AndroidManifest.xml.
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
Intent intent;
|
Intent intent;
|
||||||
|
Log.d("PASS", "Menu item " + id + " pressed");
|
||||||
|
|
||||||
AlertDialog.Builder initBefore = new AlertDialog.Builder(this)
|
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.")
|
.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();
|
refreshListAdapter();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case android.R.id.home:
|
||||||
|
Log.d("PASS", "Home pressed");
|
||||||
|
this.onBackPressed();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -266,41 +274,42 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
if (fragmentManager.findFragmentByTag("PasswordsList") == null) {
|
||||||
PasswordRepository.setInitialized(true);
|
PasswordRepository.setInitialized(true);
|
||||||
PasswordFragment passFrag = new PasswordFragment();
|
PasswordFragment passFrag = new PasswordFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("Path", localDir.getAbsolutePath());
|
args.putString("Path", localDir.getAbsolutePath());
|
||||||
|
|
||||||
if (!scrollPositions.isEmpty())
|
|
||||||
args.putInt("Position", scrollPositions.pop());
|
|
||||||
else
|
|
||||||
args.putInt("Position", 0);
|
|
||||||
|
|
||||||
passFrag.setArguments(args);
|
passFrag.setArguments(args);
|
||||||
|
|
||||||
if (fragmentManager.findFragmentByTag("PasswordsList") != null)
|
|
||||||
fragmentTransaction.addToBackStack("passlist");
|
fragmentTransaction.addToBackStack("passlist");
|
||||||
|
|
||||||
fragmentTransaction.replace(R.id.main_layout, passFrag, "PasswordsList");
|
fragmentTransaction.replace(R.id.main_layout, passFrag, "PasswordsList");
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.leftActivity = false;
|
this.leftActivity = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Stack the positions the different fragments were at */
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void savePosition(Integer position) {
|
public void onBackPressed() {
|
||||||
this.scrollPositions.push(position);
|
PasswordFragment plist;
|
||||||
|
if ((null != (plist = (PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList"))) &&
|
||||||
|
plist.isNotEmpty()) {
|
||||||
|
plist.popBack();
|
||||||
|
} else {
|
||||||
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If an item is clicked in the list of passwords, this will be triggered */
|
if (!plist.isNotEmpty()) {
|
||||||
@Override
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
public void onFragmentInteraction(PasswordItem item) {
|
|
||||||
if (item.getType() == PasswordItem.TYPE_CATEGORY) {
|
|
||||||
checkLocalRepository(item.getFile());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decryptPassword(PasswordItem item) {
|
public void decryptPassword(PasswordItem item) {
|
||||||
try {
|
try {
|
||||||
this.leftActivity = true;
|
this.leftActivity = true;
|
||||||
|
|
|
@ -41,6 +41,9 @@ public class PasswordAdapter extends ArrayAdapter<PasswordItem>{
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<PasswordItem> getValues() {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int i, View convertView, ViewGroup viewGroup) {
|
public View getView(int i, View convertView, ViewGroup viewGroup) {
|
||||||
|
|
|
@ -32,9 +32,8 @@ public class PasswordRepository {
|
||||||
if (repository == null) {
|
if (repository == null) {
|
||||||
FileRepositoryBuilder builder = new FileRepositoryBuilder();
|
FileRepositoryBuilder builder = new FileRepositoryBuilder();
|
||||||
try {
|
try {
|
||||||
repository = builder.setWorkTree(localDir)
|
repository = builder.setGitDir(localDir)
|
||||||
.readEnvironment()
|
.readEnvironment()
|
||||||
.findGitDir()
|
|
||||||
.build();
|
.build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -1,15 +1,6 @@
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<!-- Base application theme. -->
|
<!-- Base application theme. -->
|
||||||
<style name="AppTheme" parent="android:Theme.Holo.Light">
|
<style name="AppTheme" parent="Theme.AppCompat.Light">
|
||||||
<item name="android:actionBarStyle">@style/MyActionBar</item>
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
<!-- ActionBar styles -->
|
|
||||||
<style name="MyActionBar"
|
|
||||||
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
|
|
||||||
<item name="android:background">@drawable/actionbar_background</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue