This commit is contained in:
Adam Smith
2014-10-31 14:04:34 +00:00
3 changed files with 27 additions and 38 deletions

View File

@@ -186,6 +186,17 @@ public class PasswordFragment extends Fragment{
pathStack.pop(); pathStack.pop();
} }
/**
* gets the current directory
* @return the current directory
*/
public File getCurrentDir() {
if (pathStack.isEmpty())
return PasswordRepository.getWorkTree();
else
return pathStack.peek();
}
public boolean isNotEmpty() { public boolean isNotEmpty() {
return !passListStack.isEmpty(); return !passListStack.isEmpty();
} }

View File

@@ -38,6 +38,7 @@ public class PasswordStore extends ActionBarActivity {
private File currentDir; private File currentDir;
private SharedPreferences settings; private SharedPreferences settings;
private Activity activity; private Activity activity;
private PasswordFragment plist;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -302,15 +303,15 @@ public class PasswordStore extends ActionBarActivity {
if (fragmentManager.findFragmentByTag("PasswordsList") == null) { if (fragmentManager.findFragmentByTag("PasswordsList") == null) {
PasswordRepository.setInitialized(true); PasswordRepository.setInitialized(true);
PasswordFragment passFrag = new PasswordFragment(); plist = new PasswordFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("Path", localDir.getAbsolutePath()); args.putString("Path", localDir.getAbsolutePath());
passFrag.setArguments(args); plist.setArguments(args);
fragmentTransaction.addToBackStack("passlist"); fragmentTransaction.addToBackStack("passlist");
fragmentTransaction.replace(R.id.main_layout, passFrag, "PasswordsList"); fragmentTransaction.replace(R.id.main_layout, plist, "PasswordsList");
fragmentTransaction.commit(); fragmentTransaction.commit();
} }
} }
@@ -322,9 +323,7 @@ public class PasswordStore extends ActionBarActivity {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
PasswordFragment plist; if ((null != plist) && plist.isNotEmpty()) {
if ((null != (plist = (PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList"))) &&
plist.isNotEmpty()) {
plist.popBack(); plist.popBack();
} else { } else {
super.onBackPressed(); super.onBackPressed();
@@ -359,7 +358,7 @@ public class PasswordStore extends ActionBarActivity {
try { try {
Intent intent = new Intent(this, PgpHandler.class); Intent intent = new Intent(this, PgpHandler.class);
intent.putExtra("PGP-ID", FileUtils.readFileToString(PasswordRepository.getFile("/.gpg-id"))); intent.putExtra("PGP-ID", FileUtils.readFileToString(PasswordRepository.getFile("/.gpg-id")));
intent.putExtra("FILE_PATH", this.currentDir.getAbsolutePath()); intent.putExtra("FILE_PATH", getCurrentDir().getAbsolutePath());
intent.putExtra("Operation", "ENCRYPT"); intent.putExtra("Operation", "ENCRYPT");
startActivityForResult(intent, PgpHandler.REQUEST_CODE_ENCRYPT); startActivityForResult(intent, PgpHandler.REQUEST_CODE_ENCRYPT);
} catch (Exception e) { } catch (Exception e) {
@@ -402,9 +401,7 @@ public class PasswordStore extends ActionBarActivity {
* clears adapter's content and updates it with a fresh list of passwords from the root * clears adapter's content and updates it with a fresh list of passwords from the root
*/ */
public void updateListAdapter() { public void updateListAdapter() {
PasswordFragment plist; if ((null != plist)) {
if (null !=
(plist = (PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList"))) {
plist.updateAdapter(); plist.updateAdapter();
} }
} }
@@ -413,23 +410,22 @@ public class PasswordStore extends ActionBarActivity {
* Updates the adapter with the current view of passwords * Updates the adapter with the current view of passwords
*/ */
public void refreshListAdapter() { public void refreshListAdapter() {
PasswordFragment plist; if ((null != plist)) {
if (null !=
(plist = (PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList"))) {
plist.refreshAdapter(); plist.refreshAdapter();
} }
} }
public void filterListAdapter(String filter) { public void filterListAdapter(String filter) {
PasswordFragment plist; if ((null != plist)) {
if (null !=
(plist = (PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList"))) {
plist.filterAdapter(filter); plist.filterAdapter(filter);
} }
} }
private File getCurrentDir() { private File getCurrentDir() {
return new File(((PasswordFragment) getFragmentManager().findFragmentByTag("PasswordsList")).getArguments().getString("Path")); if ((null != plist)) {
return plist.getCurrentDir();
}
return null;
} }
protected void onActivityResult(int requestCode, int resultCode, protected void onActivityResult(int requestCode, int resultCode,
@@ -446,7 +442,7 @@ public class PasswordStore extends ActionBarActivity {
git.add().addFilepattern("."), git.add().addFilepattern("."),
git.commit().setMessage(this.getResources().getString(R.string.add_commit_text) + data.getExtras().getString("NAME") + this.getResources().getString(R.string.from_store)) git.commit().setMessage(this.getResources().getString(R.string.add_commit_text) + data.getExtras().getString("NAME") + this.getResources().getString(R.string.from_store))
); );
updateListAdapter(); refreshListAdapter();
break; break;
case GitHandler.REQUEST_INIT: case GitHandler.REQUEST_INIT:
initRepository(getCurrentFocus()); initRepository(getCurrentFocus());

View File

@@ -58,8 +58,6 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
private Activity activity; private Activity activity;
ClipboardManager clipboard; ClipboardManager clipboard;
private ProgressDialog bindingDialog;
private boolean registered; private boolean registered;
public static final int REQUEST_CODE_SIGN = 9910; public static final int REQUEST_CODE_SIGN = 9910;
@@ -104,12 +102,6 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
mServiceConnection = new OpenPgpServiceConnection( mServiceConnection = new OpenPgpServiceConnection(
PgpHandler.this, providerPackageName, this); PgpHandler.this, providerPackageName, this);
mServiceConnection.bindToService(); mServiceConnection.bindToService();
bindingDialog = new ProgressDialog(this);
bindingDialog.setMessage(this.getResources().getString(R.string.okc_progress_text));
bindingDialog.setCancelable(false);
bindingDialog.show();
registered = true; registered = true;
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
@@ -141,7 +133,7 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
int id = item.getItemId(); int id = item.getItemId();
switch (id) { switch (id) {
case android.R.id.home: case android.R.id.home:
setResult(RESULT_OK); setResult(RESULT_CANCELED);
finish(); finish();
return true; return true;
case R.id.copy_password: case R.id.copy_password:
@@ -295,7 +287,6 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
break; break;
} }
} else if (resultCode == RESULT_CANCELED) { } else if (resultCode == RESULT_CANCELED) {
bindingDialog.dismiss();
setResult(RESULT_CANCELED, data); setResult(RESULT_CANCELED, data);
finish(); finish();
} }
@@ -323,8 +314,6 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
Log.d(OpenPgpApi.TAG, "result: " + os.toByteArray().length Log.d(OpenPgpApi.TAG, "result: " + os.toByteArray().length
+ " str=" + os.toString("UTF-8")); + " str=" + os.toString("UTF-8"));
bindingDialog.dismiss();
if (returnToCiphertextField) { if (returnToCiphertextField) {
findViewById(R.id.crypto_container).setVisibility(View.VISIBLE); findViewById(R.id.crypto_container).setVisibility(View.VISIBLE);
@@ -342,7 +331,7 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
copyToClipBoard(); copyToClipBoard();
} }
} else { } else {
showToast(os.toString()); Log.d("PGPHANDLER", "Error message after decrypt : " + os.toString());
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
Log.e(Constants.TAG, "UnsupportedEncodingException", e); Log.e(Constants.TAG, "UnsupportedEncodingException", e);
@@ -406,13 +395,9 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
* *
* Check in open-pgp-lib how their definitions and error code * Check in open-pgp-lib how their definitions and error code
*/ */
showToast("ERROR");
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR); OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
handleError(error); handleError(error);
// close the dialog
bindingDialog.dismiss();
break; break;
} }
@@ -526,15 +511,12 @@ public class PgpHandler extends ActionBarActivity implements OpenPgpServiceConne
((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/"); ((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/");
decryptAndVerify(new Intent()); decryptAndVerify(new Intent());
} else if (extra.getString("Operation").equals("ENCRYPT")) { } else if (extra.getString("Operation").equals("ENCRYPT")) {
bindingDialog.dismiss();
setContentView(R.layout.encrypt_layout); setContentView(R.layout.encrypt_layout);
String cat = extra.getString("FILE_PATH"); String cat = extra.getString("FILE_PATH");
cat = cat.replace(PasswordRepository.getWorkTree().getAbsolutePath(), ""); cat = cat.replace(PasswordRepository.getWorkTree().getAbsolutePath(), "");
cat = cat + "/"; cat = cat + "/";
((TextView) findViewById(R.id.crypto_password_category)).setText(cat); ((TextView) findViewById(R.id.crypto_password_category)).setText(cat);
} else if (extra.getString("Operation").equals("GET_KEY_ID")) { } else if (extra.getString("Operation").equals("GET_KEY_ID")) {
bindingDialog.dismiss();
getKeyIds(new Intent()); getKeyIds(new Intent());
// setContentView(R.layout.key_id); // setContentView(R.layout.key_id);