First shot on Material design (prefrences not working)

This commit is contained in:
zeapo 2014-10-19 12:56:52 +02:00
parent 524c9205c0
commit b8b5234e5b
6 changed files with 79 additions and 43 deletions

View file

@ -3,14 +3,14 @@ apply from: 'copyLibs.gradle' // enable 'copyLibs.gradle' script plugin
apply plugin: 'eclipse'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
compileSdkVersion 21
buildToolsVersion "21.0.1"
defaultConfig {
applicationId "com.zeapo.pwdstore"
minSdkVersion 15
targetSdkVersion 19
versionCode 15
versionName "1.1-b8"
targetSdkVersion 21
versionCode 16
versionName "1.2-b1"
}
buildTypes {
release {
@ -29,6 +29,8 @@ repositories {
}
dependencies {
compile "com.android.support:appcompat-v7:21.+"
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':libraries:openpgp-api-lib')
compile 'org.eclipse.jgit:org.eclipse.jgit:3.5.+'

View file

@ -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();
}
}

View file

@ -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:
if (fragmentManager.findFragmentByTag("PasswordsList") == null) {
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);
passFrag.setArguments(args);
if (fragmentManager.findFragmentByTag("PasswordsList") != null)
fragmentTransaction.addToBackStack("passlist");
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);
public void onBackPressed() {
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 */
@Override
public void onFragmentInteraction(PasswordItem item) {
if (item.getType() == PasswordItem.TYPE_CATEGORY) {
checkLocalRepository(item.getFile());
if (!plist.isNotEmpty()) {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
}
public void decryptPassword(PasswordItem item) {
try {
this.leftActivity = true;

View file

@ -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) {

View file

@ -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();

View file

@ -1,15 +1,6 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<style name="AppTheme" parent="Theme.AppCompat.Light">
</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>