Fix back button behaviour
This commit is contained in:
parent
4589c0f833
commit
017650bf37
2 changed files with 12 additions and 25 deletions
|
@ -1,7 +1,7 @@
|
||||||
package com.zeapo.pwdstore;
|
package com.zeapo.pwdstore;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
@ -94,24 +94,23 @@ public class PasswordFragment extends Fragment{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(final Activity activity) {
|
public void onAttach(final Context context) {
|
||||||
super.onAttach(activity);
|
super.onAttach(context);
|
||||||
try {
|
try {
|
||||||
mListener = new OnFragmentInteractionListener() {
|
mListener = new OnFragmentInteractionListener() {
|
||||||
public void onFragmentInteraction(PasswordItem item) {
|
public void onFragmentInteraction(PasswordItem item) {
|
||||||
if (item.getType() == PasswordItem.TYPE_CATEGORY) {
|
if (item.getType() == PasswordItem.TYPE_CATEGORY) {
|
||||||
// push the current password list (non filtered plz!)
|
// push the current password list (non filtered plz!)
|
||||||
passListStack.push(pathStack.isEmpty() ?
|
passListStack.push(pathStack.isEmpty() ?
|
||||||
PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(activity)) :
|
PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(context)) :
|
||||||
PasswordRepository.getPasswords(pathStack.peek(), PasswordRepository.getRepositoryDirectory(activity)));
|
PasswordRepository.getPasswords(pathStack.peek(), PasswordRepository.getRepositoryDirectory(context)));
|
||||||
|
|
||||||
//push the category were we're going
|
//push the category were we're going
|
||||||
pathStack.push(item.getFile());
|
pathStack.push(item.getFile());
|
||||||
scrollPosition.push(recyclerView.getVerticalScrollbarPosition());
|
scrollPosition.push(recyclerView.getVerticalScrollbarPosition());
|
||||||
|
|
||||||
recyclerView.scrollToPosition(0);
|
recyclerView.scrollToPosition(0);
|
||||||
recyclerAdapter.clear();
|
recyclerAdapter.clear();
|
||||||
recyclerAdapter.addAll(PasswordRepository.getPasswords(item.getFile(), PasswordRepository.getRepositoryDirectory(activity)));
|
recyclerAdapter.addAll(PasswordRepository.getPasswords(item.getFile(), PasswordRepository.getRepositoryDirectory(context)));
|
||||||
|
|
||||||
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -128,7 +127,7 @@ public class PasswordFragment extends Fragment{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
throw new ClassCastException(activity.toString()
|
throw new ClassCastException(context.toString()
|
||||||
+ " must implement OnFragmentInteractionListener");
|
+ " must implement OnFragmentInteractionListener");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,16 +339,6 @@ public class PasswordStore extends AppCompatActivity {
|
||||||
if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) {
|
if (fragmentManager.findFragmentByTag("PasswordsList") == null || settings.getBoolean("repo_changed", false)) {
|
||||||
settings.edit().putBoolean("repo_changed", false).apply();
|
settings.edit().putBoolean("repo_changed", false).apply();
|
||||||
|
|
||||||
// todo move this as it is duplicated upthere!
|
|
||||||
if (fragmentManager.findFragmentByTag("PasswordsList") != null) {
|
|
||||||
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// clean things up
|
|
||||||
if (fragmentManager.findFragmentByTag("ToCloneOrNot") != null) {
|
|
||||||
fragmentManager.popBackStack();
|
|
||||||
}
|
|
||||||
|
|
||||||
plist = new PasswordFragment();
|
plist = new PasswordFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString("Path", PasswordRepository.getWorkTree().getAbsolutePath());
|
args.putString("Path", PasswordRepository.getWorkTree().getAbsolutePath());
|
||||||
|
@ -361,21 +351,19 @@ public class PasswordStore extends AppCompatActivity {
|
||||||
|
|
||||||
plist.setArguments(args);
|
plist.setArguments(args);
|
||||||
|
|
||||||
fragmentTransaction.addToBackStack("passlist");
|
|
||||||
|
|
||||||
getSupportActionBar().show();
|
getSupportActionBar().show();
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
|
|
||||||
|
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
|
|
||||||
fragmentTransaction.replace(R.id.main_layout, plist, "PasswordsList");
|
fragmentTransaction.replace(R.id.main_layout, plist, "PasswordsList");
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if we still have the pass list (after deleting the repository for instance) remove it
|
|
||||||
if (fragmentManager.findFragmentByTag("PasswordsList") != null) {
|
|
||||||
fragmentManager.popBackStack();
|
|
||||||
}
|
|
||||||
|
|
||||||
getSupportActionBar().hide();
|
getSupportActionBar().hide();
|
||||||
|
|
||||||
|
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
|
|
||||||
ToCloneOrNot cloneFrag = new ToCloneOrNot();
|
ToCloneOrNot cloneFrag = new ToCloneOrNot();
|
||||||
fragmentTransaction.replace(R.id.main_layout, cloneFrag, "ToCloneOrNot");
|
fragmentTransaction.replace(R.id.main_layout, cloneFrag, "ToCloneOrNot");
|
||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
|
|
Loading…
Reference in a new issue