aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java96
1 files changed, 46 insertions, 50 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
index f6179703..63211af0 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
@@ -4,16 +4,16 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
-import androidx.fragment.app.Fragment;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.zeapo.pwdstore.utils.PasswordItem;
import com.zeapo.pwdstore.utils.PasswordRecyclerAdapter;
import com.zeapo.pwdstore.utils.PasswordRepository;
@@ -24,16 +24,12 @@ import java.util.Stack;
/**
* A fragment representing a list of Items.
- * <p />
+ * <p/>
* Large screen devices (such as tablets) are supported by replacing the ListView
* with a GridView.
- * <p />
+ * <p/>
*/
-public class PasswordFragment extends Fragment{
-
- public interface OnFragmentInteractionListener {
- void onFragmentInteraction(PasswordItem item);
- }
+public class PasswordFragment extends Fragment {
// store the pass files list in a stack
private Stack<ArrayList<PasswordItem>> passListStack;
@@ -43,12 +39,12 @@ public class PasswordFragment extends Fragment{
private RecyclerView recyclerView;
private OnFragmentInteractionListener mListener;
private SharedPreferences settings;
-
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
- public PasswordFragment() { }
+ public PasswordFragment() {
+ }
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -60,18 +56,18 @@ public class PasswordFragment extends Fragment{
scrollPosition = new Stack<>();
pathStack = new Stack<>();
recyclerAdapter = new PasswordRecyclerAdapter((PasswordStore) getActivity(), mListener,
- PasswordRepository.getPasswords(new File(path), PasswordRepository.getRepositoryDirectory(getActivity()), getSortOrder()));
+ PasswordRepository.getPasswords(new File(path), PasswordRepository.getRepositoryDirectory(getActivity()), getSortOrder()));
}
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.password_recycler_view, container, false);
// use a linear layout manager
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
- recyclerView = (RecyclerView) view.findViewById(R.id.pass_recycler);
+ recyclerView = view.findViewById(R.id.pass_recycler);
recyclerView.setLayoutManager(mLayoutManager);
// use divider
@@ -80,13 +76,8 @@ public class PasswordFragment extends Fragment{
// Set the adapter
recyclerView.setAdapter(recyclerAdapter);
- final FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- ((PasswordStore) getActivity()).createPassword();
- }
- });
+ final FloatingActionButton fab = view.findViewById(R.id.fab);
+ fab.setOnClickListener(v -> ((PasswordStore) getActivity()).createPassword());
registerForContextMenu(recyclerView);
return view;
@@ -96,34 +87,32 @@ public class PasswordFragment extends Fragment{
public void onAttach(final Context context) {
super.onAttach(context);
try {
- mListener = new OnFragmentInteractionListener() {
- public void onFragmentInteraction(PasswordItem item) {
- if (item.getType() == PasswordItem.TYPE_CATEGORY) {
- // push the current password list (non filtered plz!)
- passListStack.push(pathStack.isEmpty() ?
- PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(context), getSortOrder()) :
- PasswordRepository.getPasswords(pathStack.peek(), PasswordRepository.getRepositoryDirectory(context), getSortOrder()));
- //push the category were we're going
- pathStack.push(item.getFile());
- scrollPosition.push(recyclerView.getVerticalScrollbarPosition());
-
- recyclerView.scrollToPosition(0);
- recyclerAdapter.clear();
- recyclerAdapter.addAll(PasswordRepository.getPasswords(item.getFile(), PasswordRepository.getRepositoryDirectory(context), getSortOrder()));
-
- ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ mListener = item -> {
+ if (item.getType() == PasswordItem.TYPE_CATEGORY) {
+ // push the current password list (non filtered plz!)
+ passListStack.push(pathStack.isEmpty() ?
+ PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(context), getSortOrder()) :
+ PasswordRepository.getPasswords(pathStack.peek(), PasswordRepository.getRepositoryDirectory(context), getSortOrder()));
+ //push the category were we're going
+ pathStack.push(item.getFile());
+ scrollPosition.push(recyclerView.getVerticalScrollbarPosition());
+
+ recyclerView.scrollToPosition(0);
+ recyclerAdapter.clear();
+ recyclerAdapter.addAll(PasswordRepository.getPasswords(item.getFile(), PasswordRepository.getRepositoryDirectory(context), getSortOrder()));
+
+ ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ } else {
+ if (getArguments().getBoolean("matchWith", false)) {
+ ((PasswordStore) getActivity()).matchPasswordWithApp(item);
} else {
- if (getArguments().getBoolean("matchWith", false)) {
- ((PasswordStore) getActivity()).matchPasswordWithApp(item);
- } else {
- ((PasswordStore) getActivity()).decryptPassword(item);
- }
+ ((PasswordStore) getActivity()).decryptPassword(item);
}
}
};
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
- + " must implement OnFragmentInteractionListener");
+ + " must implement OnFragmentInteractionListener");
}
}
@@ -146,12 +135,13 @@ public class PasswordFragment extends Fragment{
public void refreshAdapter() {
recyclerAdapter.clear();
recyclerAdapter.addAll(pathStack.isEmpty() ?
- PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(getActivity()), getSortOrder()) :
- PasswordRepository.getPasswords(pathStack.peek(), PasswordRepository.getRepositoryDirectory(getActivity()), getSortOrder()));
+ PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(getActivity()), getSortOrder()) :
+ PasswordRepository.getPasswords(pathStack.peek(), PasswordRepository.getRepositoryDirectory(getActivity()), getSortOrder()));
}
/**
* filters the list adapter
+ *
* @param filter the filter to apply
*/
public void filterAdapter(String filter) {
@@ -166,8 +156,9 @@ public class PasswordFragment extends Fragment{
/**
* recursively filters a directory and extract all the matching items
+ *
* @param filter the filter to apply
- * @param dir the directory to filter
+ * @param dir the directory to filter
*/
private void recursiveFilter(String filter, File dir) {
// on the root the pathStack is empty
@@ -205,6 +196,7 @@ public class PasswordFragment extends Fragment{
/**
* gets the current directory
+ *
* @return the current directory
*/
public File getCurrentDir() {
@@ -227,4 +219,8 @@ public class PasswordFragment extends Fragment{
private PasswordRepository.PasswordSortOrder getSortOrder() {
return PasswordRepository.PasswordSortOrder.getSortOrder(settings);
}
+
+ public interface OnFragmentInteractionListener {
+ void onFragmentInteraction(PasswordItem item);
+ }
}