summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorFelix Bechstein <f@ub0r.de>2017-07-25 15:23:50 +0200
committerMohamed Zenadi <zeapo@users.noreply.github.com>2017-07-25 14:23:50 +0100
commit5da9e67545644925902b04a11306289add29c033 (patch)
treede8ec31c4fe216157b7680a4defdee86429a4122 /app/src/main/java
parent5cba6c62d7b4628dfaf482dd883e333f93d323d4 (diff)
Fix lint warnings (#319)
* Fix lint errors/warnings Fix a lot of lint errors and warnings. Most things are automatically applied fixes done with android studio: * externalize strings * remove unused code / classes / layouts / imports * migrate some fields to local variables * Remove dead code from comments Removed code that is commented out long ago. * remove unused resources * colors * strings * drawables * layouts * menus
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java24
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java10
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.java109
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.java5
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java14
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java6
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java3
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/DividerItemDecoration.java105
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java99
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java17
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java1
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java2
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java6
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/EntryRecyclerAdapter.java25
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java14
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java25
18 files changed, 115 insertions, 355 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
index 49d57e30..646e44c7 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
@@ -1,11 +1,11 @@
package com.zeapo.pwdstore;
-import android.support.v4.app.Fragment;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
+import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@@ -32,7 +32,7 @@ import java.util.Stack;
public class PasswordFragment extends Fragment{
public interface OnFragmentInteractionListener {
- public void onFragmentInteraction(PasswordItem item);
+ void onFragmentInteraction(PasswordItem item);
}
// store the pass files list in a stack
@@ -41,7 +41,6 @@ public class PasswordFragment extends Fragment{
private Stack<Integer> scrollPosition;
private PasswordRecyclerAdapter recyclerAdapter;
private RecyclerView recyclerView;
- private RecyclerView.LayoutManager mLayoutManager;
private OnFragmentInteractionListener mListener;
private SharedPreferences settings;
@@ -57,9 +56,9 @@ public class PasswordFragment extends Fragment{
String path = getArguments().getString("Path");
settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
- passListStack = new Stack<ArrayList<PasswordItem>>();
- scrollPosition = new Stack<Integer>();
- pathStack = new Stack<File>();
+ passListStack = new Stack<>();
+ scrollPosition = new Stack<>();
+ pathStack = new Stack<>();
recyclerAdapter = new PasswordRecyclerAdapter((PasswordStore) getActivity(), mListener,
PasswordRepository.getPasswords(new File(path), PasswordRepository.getRepositoryDirectory(getActivity())));
}
@@ -70,7 +69,7 @@ public class PasswordFragment extends Fragment{
View view = inflater.inflate(R.layout.password_recycler_view, container, false);
// use a linear layout manager
- mLayoutManager = new LinearLayoutManager(getActivity());
+ RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView = (RecyclerView) view.findViewById(R.id.pass_recycler);
recyclerView.setLayoutManager(mLayoutManager);
@@ -121,10 +120,6 @@ public class PasswordFragment extends Fragment{
}
}
}
-
- public void savePosition(Integer position) {
-
- }
};
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
@@ -132,13 +127,6 @@ public class PasswordFragment extends Fragment{
}
}
- @Override
- public void onPause() {
- super.onPause();
-// mListener.savePosition(mListView.getFirstVisiblePosition());
-// mListView.closeOpenedItems();
- }
-
/**
* clears the adapter content and sets it back to the root view
*/
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
index 5b2a7624..f4ea9ec6 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
@@ -13,6 +13,7 @@ import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
@@ -52,11 +53,9 @@ import java.util.Set;
public class PasswordStore extends AppCompatActivity {
private static final String TAG = "PwdStrAct";
- private File currentDir;
private SharedPreferences settings;
private Activity activity;
private PasswordFragment plist;
- private AlertDialog selectDestinationDialog;
private ShortcutManager shortcutManager;
private final static int CLONE_REPO_BUTTON = 401;
@@ -125,8 +124,7 @@ public class PasswordStore extends AppCompatActivity {
}
@Override
- public void onRequestPermissionsResult(int requestCode,
- String permissions[], int[] grantResults) {
+ public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_EXTERNAL_STORAGE: {
// If request is cancelled, the result arrays are empty.
@@ -458,8 +456,8 @@ public class PasswordStore extends AppCompatActivity {
return;
}
- this.currentDir = getCurrentDir();
- Log.i("PWDSTR", "Adding file to : " + this.currentDir.getAbsolutePath());
+ File currentDir = getCurrentDir();
+ Log.i("PWDSTR", "Adding file to : " + currentDir.getAbsolutePath());
Intent intent = new Intent(this, PgpHandler.class);
intent.putExtra("FILE_PATH", getCurrentDir().getAbsolutePath());
diff --git a/app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.java b/app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.java
index bf378153..e9c9bbab 100644
--- a/app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/SelectFolderFragment.java
@@ -1,15 +1,12 @@
package com.zeapo.pwdstore;
import android.content.Context;
-import android.content.SharedPreferences;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -33,7 +30,7 @@ import java.util.Stack;
public class SelectFolderFragment extends Fragment{
public interface OnFragmentInteractionListener {
- public void onFragmentInteraction(PasswordItem item);
+ void onFragmentInteraction(PasswordItem item);
}
// store the pass files list in a stack
@@ -42,9 +39,7 @@ public class SelectFolderFragment extends Fragment{
private Stack<Integer> scrollPosition;
private FolderRecyclerAdapter recyclerAdapter;
private RecyclerView recyclerView;
- private RecyclerView.LayoutManager mLayoutManager;
private OnFragmentInteractionListener mListener;
- private SharedPreferences settings;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
@@ -57,10 +52,9 @@ public class SelectFolderFragment extends Fragment{
super.onCreate(savedInstanceState);
String path = getArguments().getString("Path");
- settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
- passListStack = new Stack<ArrayList<PasswordItem>>();
- scrollPosition = new Stack<Integer>();
- pathStack = new Stack<File>();
+ passListStack = new Stack<>();
+ scrollPosition = new Stack<>();
+ pathStack = new Stack<>();
recyclerAdapter = new FolderRecyclerAdapter((PgpHandler) getActivity(), mListener,
PasswordRepository.getPasswords(new File(path), PasswordRepository.getRepositoryDirectory(getActivity())));
}
@@ -71,10 +65,8 @@ public class SelectFolderFragment extends Fragment{
View view = inflater.inflate(R.layout.password_recycler_view, container, false);
// use a linear layout manager
- mLayoutManager = new LinearLayoutManager(getActivity());
-
recyclerView = (RecyclerView) view.findViewById(R.id.pass_recycler);
- recyclerView.setLayoutManager(mLayoutManager);
+ recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
// use divider
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), R.drawable.divider));
@@ -116,10 +108,6 @@ public class SelectFolderFragment extends Fragment{
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
-
- public void savePosition(Integer position) {
-
- }
};
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
@@ -127,89 +115,6 @@ public class SelectFolderFragment extends Fragment{
}
}
- @Override
- public void onPause() {
- super.onPause();
-// mListener.savePosition(mListView.getFirstVisiblePosition());
-// mListView.closeOpenedItems();
- }
-
- /**
- * clears the adapter content and sets it back to the root view
- */
- public void updateAdapter() {
- passListStack.clear();
- pathStack.clear();
- scrollPosition.clear();
- recyclerAdapter.clear();
- recyclerAdapter.addAll(PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(getActivity())));
-
- ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- }
-
- /**
- * refreshes the adapter with the latest opened category
- */
- public void refreshAdapter() {
- recyclerAdapter.clear();
- recyclerAdapter.addAll(pathStack.isEmpty() ?
- PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(getActivity())) :
- PasswordRepository.getPasswords(pathStack.peek(), PasswordRepository.getRepositoryDirectory(getActivity())));
- }
-
- /**
- * filters the list adapter
- * @param filter the filter to apply
- */
- public void filterAdapter(String filter) {
- Log.d("FRAG", "filter: " + filter);
-
- if (filter.isEmpty()) {
- refreshAdapter();
- } else {
- recursiveFilter(filter, pathStack.isEmpty() ? null : pathStack.peek());
- }
- }
-
- /**
- * recursively filters a directory and extract all the matching items
- * @param filter the filter to apply
- * @param dir the directory to filter
- */
- private void recursiveFilter(String filter, File dir) {
- // on the root the pathStack is empty
- ArrayList<PasswordItem> passwordItems = dir == null ?
- PasswordRepository.getPasswords(PasswordRepository.getRepositoryDirectory(getActivity())) :
- PasswordRepository.getPasswords(dir, PasswordRepository.getRepositoryDirectory(getActivity()));
-
- boolean rec = settings.getBoolean("filter_recursively", true);
- for (PasswordItem item : passwordItems) {
- if (item.getType() == PasswordItem.TYPE_CATEGORY && rec) {
- recursiveFilter(filter, item.getFile());
- }
- boolean matches = item.toString().toLowerCase().contains(filter.toLowerCase());
- boolean inAdapter = recyclerAdapter.getValues().contains(item);
- if (matches && !inAdapter) {
- recyclerAdapter.add(item);
- } else if (!matches && inAdapter) {
- recyclerAdapter.remove(recyclerAdapter.getValues().indexOf(item));
- }
- }
- }
-
- /**
- * Goes back one level back in the path
- */
- public void popBack() {
- if (passListStack.isEmpty())
- return;
-
- recyclerView.scrollToPosition(scrollPosition.pop());
- recyclerAdapter.clear();
- recyclerAdapter.addAll(passListStack.pop());
- pathStack.pop();
- }
-
/**
* gets the current directory
* @return the current directory
@@ -220,8 +125,4 @@ public class SelectFolderFragment extends Fragment{
else
return pathStack.peek();
}
-
- public boolean isNotEmpty() {
- return !passListStack.isEmpty();
- }
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.java b/app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.java
index ab245746..fb3f4008 100644
--- a/app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.java
+++ b/app/src/main/java/com/zeapo/pwdstore/ToCloneOrNot.java
@@ -14,11 +14,6 @@ public class ToCloneOrNot extends Fragment {
}
@Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-
- @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index 54e04b70..ad2a1ffe 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -18,6 +18,7 @@ import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.provider.Settings;
+import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
@@ -547,7 +548,7 @@ public class UserPreference extends AppCompatActivity {
}
@Override
- public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
+ public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
switch (requestCode) {
case REQUEST_EXTERNAL_STORAGE: {
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
index 583b5064..4edfc3e3 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
@@ -1,16 +1,17 @@
package com.zeapo.pwdstore.autofill;
import android.app.Activity;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.support.v4.content.ContextCompat;
-import android.support.v7.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -71,8 +72,9 @@ public class AutofillFragment extends DialogFragment {
adapter = new ArrayAdapter<String>(getActivity().getApplicationContext()
, android.R.layout.simple_list_item_1, android.R.id.text1) {
// set text color to black because default is white...
+ @NonNull
@Override
- public View getView(int position, View convertView, ViewGroup parent) {
+ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
textView.setTextColor(ContextCompat.getColor(getContext(), R.color.grey_black_1000));
return textView;
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java
index b3991238..7696d82e 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java
@@ -13,6 +13,7 @@ import android.support.v4.app.NavUtils;
import android.support.v4.app.TaskStackBuilder;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
@@ -30,7 +31,6 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
private RecyclerView recyclerView;
AutofillRecyclerAdapter recyclerAdapter; // let fragment have access
- private RecyclerView.LayoutManager layoutManager;
private PackageManager pm;
@@ -43,9 +43,9 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
setContentView(R.layout.autofill_recycler_view);
recyclerView = (RecyclerView) findViewById(R.id.autofill_recycler);
- layoutManager = new LinearLayoutManager(this);
+ RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
- recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
+ recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
pm = getPackageManager();
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
index 901ff903..80942c58 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
@@ -22,7 +22,6 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
private SortedList<AppInfo> apps;
private ArrayList<AppInfo> allApps; // for filtering, maintain a list of all
- private PackageManager pm;
private AutofillPreferenceActivity activity;
Drawable browserIcon = null;
@@ -93,7 +92,7 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
this.apps = new SortedList<>(AppInfo.class, callback);
this.apps.addAll(allApps);
this.allApps = new ArrayList<>(allApps);
- this.pm = pm;
+ PackageManager pm1 = pm;
this.activity = activity;
try {
browserIcon = activity.getPackageManager().getApplicationIcon("com.android.browser");
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/DividerItemDecoration.java b/app/src/main/java/com/zeapo/pwdstore/autofill/DividerItemDecoration.java
deleted file mode 100644
index bd5ec9de..00000000
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/DividerItemDecoration.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package com.zeapo.pwdstore.autofill;
-
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.Canvas;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.view.View;
-
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-public class DividerItemDecoration extends RecyclerView.ItemDecoration {
-
- private static final int[] ATTRS = new int[]{
- android.R.attr.listDivider
- };
-
- public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
-
- public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
-
- private Drawable mDivider;
-
- private int mOrientation;
-
- public DividerItemDecoration(Context context, int orientation) {
- final TypedArray a = context.obtainStyledAttributes(ATTRS);
- mDivider = a.getDrawable(0);
- a.recycle();
- setOrientation(orientation);
- }
-
- public void setOrientation(int orientation) {
- if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
- throw new IllegalArgumentException("invalid orientation");
- }
- mOrientation = orientation;
- }
-
- @Override
- public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
- if (mOrientation == VERTICAL_LIST) {
- drawVertical(c, parent);
- } else {
- drawHorizontal(c, parent);
- }
- }
-
- public void drawVertical(Canvas c, RecyclerView parent) {
- final int left = parent.getPaddingLeft();
- final int right = parent.getWidth() - parent.getPaddingRight();
-
- final int childCount = parent.getChildCount();
- for (int i = 0; i < childCount; i++) {
- final View child = parent.getChildAt(i);
- final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
- .getLayoutParams();
- final int top = child.getBottom() + params.bottomMargin;
- final int bottom = top + mDivider.getIntrinsicHeight();
- mDivider.setBounds(left, top, right, bottom);
- mDivider.draw(c);
- }
- }
-
- public void drawHorizontal(Canvas c, RecyclerView parent) {
- final int top = parent.getPaddingTop();
- final int bottom = parent.getHeight() - parent.getPaddingBottom();
-
- final int childCount = parent.getChildCount();
- for (int i = 0; i < childCount; i++) {
- final View child = parent.getChildAt(i);
- final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
- .getLayoutParams();
- final int left = child.getRight() + params.rightMargin;
- final int right = left + mDivider.getIntrinsicHeight();
- mDivider.setBounds(left, top, right, bottom);
- mDivider.draw(c);
- }
- }
-
- @Override
- public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
- if (mOrientation == VERTICAL_LIST) {
- outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
- } else {
- outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
- }
- }
-}
-
diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
index e938fdd4..12f2bcad 100644
--- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
+++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpHandler.java
@@ -132,7 +132,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
try {
this.mServiceConnection.unbindFromService();
} catch (Exception e) {
-
+ // ignore any errors, we'll stop anyway.
}
}
@@ -273,22 +273,12 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
public void handleClick(View view) {
switch (view.getId()) {
- case R.id.crypto_show_button:
- decryptAndVerify(new Intent());
- break;
- case R.id.crypto_delete_button:
-// deletePassword();
- break;
- case R.id.crypto_get_key_ids:
- getKeyIds(new Intent());
- break;
case R.id.generate_password:
DialogFragment df = new pwgenDialogFragment();
df.show(getFragmentManager(), "generator");
default:
Log.wtf(Constants.TAG,"This should not happen.... PgpHandler.java#handleClick(View) default reached.");
// should not happen
-
}
}
@@ -571,7 +561,7 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
// get key ids
if (result.hasExtra(OpenPgpApi.RESULT_KEY_IDS)) {
long[] ids = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS);
- Set<String> keys = new HashSet<String>();
+ Set<String> keys = new HashSet<>();
for (long id : ids) keys.add(String.valueOf(id)); // use Long
settings.edit().putStringSet("openpgp_key_ids_set", keys).apply();
@@ -734,44 +724,53 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
if (operation == null){
return;
}
- if (operation.equals("DECRYPT")) {
- setContentView(R.layout.decrypt_layout);
- ((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME"));
- String path = extra
- .getString("FILE_PATH")
- .replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath(), "");
- String cat = new File(path).getParentFile().getName();
-
- ((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/");
- decryptAndVerify(new Intent());
- } else if (operation.equals("ENCRYPT")) {
- setContentView(R.layout.encrypt_layout);
- Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
- ((EditText) findViewById(R.id.crypto_password_edit)).setTypeface(monoTypeface);
- ((EditText) findViewById(R.id.crypto_extra_edit)).setTypeface(monoTypeface);
- String cat = extra.getString("FILE_PATH");
- cat = cat.replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath(), "");
- cat = cat + "/";
- ((TextView) findViewById(R.id.crypto_password_category)).setText(cat);
- } else if (operation.equals("GET_KEY_ID")) {
- getKeyIds(new Intent());
-
-// setContentView(R.layout.key_id);
-// if (!keyIDs.isEmpty()) {
-// String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0];
-// ((TextView) findViewById(R.id.crypto_key_ids)).setText(keys);
-// }
- } else if (operation.equals("EDIT")) {
- setContentView(R.layout.decrypt_layout);
- ((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME"));
- String cat = new File(extra.getString("FILE_PATH").replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath(), ""))
- .getParentFile().getName();
-
- ((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/");
- edit(new Intent());
- } else if (operation.equals("SELECTFOLDER")){
- setContentView(R.layout.select_folder_layout);
- selectFolder(getIntent());
+ switch (operation) {
+ case "DECRYPT": {
+ setContentView(R.layout.decrypt_layout);
+ ((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME"));
+ String path = extra
+ .getString("FILE_PATH")
+ .replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath(), "");
+ String cat = new File(path).getParentFile().getName();
+
+ ((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/");
+ decryptAndVerify(new Intent());
+ break;
+ }
+ case "ENCRYPT": {
+ setContentView(R.layout.encrypt_layout);
+ Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
+ ((EditText) findViewById(R.id.crypto_password_edit)).setTypeface(monoTypeface);
+ ((EditText) findViewById(R.id.crypto_extra_edit)).setTypeface(monoTypeface);
+ String cat = extra.getString("FILE_PATH");
+ cat = cat.replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath(), "");
+ cat = cat + "/";
+ ((TextView) findViewById(R.id.crypto_password_category)).setText(cat);
+ break;
+ }
+ case "GET_KEY_ID":
+ getKeyIds(new Intent());
+
+// setContentView(R.layout.key_id);
+// if (!keyIDs.isEmpty()) {
+// String keys = keyIDs.split(",").length > 1 ? keyIDs : keyIDs.split(",")[0];
+// ((TextView) findViewById(R.id.crypto_key_ids)).setText(keys);
+// }
+ break;
+ case "EDIT": {
+ setContentView(R.layout.decrypt_layout);
+ ((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME"));
+ String cat = new File(extra.getString("FILE_PATH").replace(PasswordRepository.getRepositoryDirectory(getApplicationContext()).getAbsolutePath(), ""))
+ .getParentFile().getName();
+
+ ((TextView) findViewById(R.id.crypto_password_category)).setText(cat + "/");
+ edit(new Intent());
+ break;
+ }
+ case "SELECTFOLDER":
+ setContentView(R.layout.select_folder_layout);
+ selectFolder(getIntent());
+ break;
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java
index 25dba1fc..61e08dc2 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.java
@@ -12,8 +12,6 @@ import org.eclipse.jgit.api.Git;
import java.io.File;
public class CloneOperation extends GitOperation {
- private static final String TAG = "CLONEOPT";
-
/**
* Creates a new clone operation
*
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java
index 66e308b9..6314a4b3 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitActivity.java
@@ -32,8 +32,6 @@ import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-// TODO move the messages to strings.xml
-
public class GitActivity extends AppCompatActivity {
private static final String TAG = "GitAct";
private static final String emailPattern = "^[^@]+@[^@]+$";
@@ -46,7 +44,6 @@ public class GitActivity extends AppCompatActivity {
private File localDir;
private String hostname;
- private String port;
private SharedPreferences settings;
@@ -158,13 +155,6 @@ public class GitActivity extends AppCompatActivity {
final EditText server_user = ((EditText) findViewById(R.id.server_user));
final EditText server_uri = ((EditText) findViewById(R.id.clone_uri));
- View.OnFocusChangeListener updateListener = new View.OnFocusChangeListener() {
- @Override
- public void onFocusChange(View view, boolean b) {
- updateURI();
- }
- };
-
server_url.setText(settings.getString("git_remote_server", ""));
server_port.setText(settings.getString("git_remote_port", ""));
server_user.setText(settings.getString("git_remote_username", ""));
@@ -307,7 +297,7 @@ public class GitActivity extends AppCompatActivity {
if (server_port.getText().toString().equals("22")) {
hostname += server_path.getText().toString();
- ((TextView) findViewById(R.id.warn_url)).setVisibility(View.GONE);
+ findViewById(R.id.warn_url).setVisibility(View.GONE);
} else {
TextView warn_url = (TextView) findViewById(R.id.warn_url);
if (!server_path.getText().toString().matches("/.*") && !server_port.getText().toString().isEmpty()) {
@@ -329,7 +319,7 @@ public class GitActivity extends AppCompatActivity {
if (server_port.getText().toString().equals("443")) {
hostname.append(server_path.getText().toString());
- ((TextView) findViewById(R.id.warn_url)).setVisibility(View.GONE);
+ findViewById(R.id.warn_url).setVisibility(View.GONE);
} else {
hostname.append("/");
hostname.append(server_port.getText().toString())
@@ -417,6 +407,7 @@ public class GitActivity extends AppCompatActivity {
/**
* Saves the configuration found in the form
*/
+ @SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean saveConfiguration() {
// remember the settings
SharedPreferences.Editor editor = settings.edit();
@@ -432,7 +423,7 @@ public class GitActivity extends AppCompatActivity {
// 'save' hostname variable for use by addRemote() either here or later
// in syncRepository()
hostname = ((EditText) findViewById(R.id.clone_uri)).getText().toString();
- port = ((EditText) findViewById(R.id.server_port)).getText().toString();
+ String port = ((EditText) findViewById(R.id.server_port)).getText().toString();
// don't ask the user, take off the protocol that he puts in
hostname = hostname.replaceFirst("^.+://", "");
((TextView) findViewById(R.id.clone_uri)).setText(hostname);
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
index f6b05f4c..4002d24e 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java
@@ -27,7 +27,6 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import java.io.File;
public abstract class GitOperation {
- private static final String TAG = "GitOpt";
public static final int GET_SSH_KEY_FROM_CLONE = 201;
protected final Repository repository;
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java b/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java
index e156ca4d..b958546e 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java
+++ b/app/src/main/java/com/zeapo/pwdstore/git/config/SshConfigSessionFactory.java
@@ -1,7 +1,5 @@
package com.zeapo.pwdstore.git.config;
-import android.content.SharedPreferences;
-
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
diff --git a/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java b/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
index 7d798a81..7b55dccf 100644
--- a/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/pwgenDialogFragment.java
@@ -103,7 +103,7 @@ public class pwgenDialogFragment extends DialogFragment {
return ad;
}
- private boolean setPreferences () {
+ private void setPreferences () {
ArrayList<String> preferences = new ArrayList<>();
if (!((CheckBox) getDialog().findViewById(R.id.numerals)).isChecked()) {
preferences.add("0");
@@ -123,9 +123,9 @@ public class pwgenDialogFragment extends DialogFragment {
EditText editText = (EditText) getDialog().findViewById(R.id.lengthNumber);
try {
int length = Integer.valueOf(editText.getText().toString());
- return pwgen.setPrefs(getActivity().getApplicationContext(), preferences, length);
+ pwgen.setPrefs(getActivity().getApplicationContext(), preferences, length);
} catch(NumberFormatException e) {
- return pwgen.setPrefs(getActivity().getApplicationContext(), preferences);
+ pwgen.setPrefs(getActivity().getApplicationContext(), preferences);
}
}
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/EntryRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/EntryRecyclerAdapter.java
index 5247c6a3..a36b1124 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/EntryRecyclerAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/EntryRecyclerAdapter.java
@@ -19,10 +19,10 @@ import java.util.TreeSet;
public abstract class EntryRecyclerAdapter extends RecyclerView.Adapter<EntryRecyclerAdapter.ViewHolder> {
private final Activity activity;
- protected final ArrayList<PasswordItem> values;
- protected final Set<Integer> selectedItems = new TreeSet<>();
+ private final ArrayList<PasswordItem> values;
+ final Set<Integer> selectedItems = new TreeSet<>();
- public EntryRecyclerAdapter(Activity activity, ArrayList<PasswordItem> values) {
+ EntryRecyclerAdapter(Activity activity, ArrayList<PasswordItem> values) {
this.activity = activity;
this.values = values;
}
@@ -52,7 +52,7 @@ public abstract class EntryRecyclerAdapter extends RecyclerView.Adapter<EntryRec
this.notifyItemInserted(getItemCount());
}
- public void toggleSelection(int position) {
+ void toggleSelection(int position) {
if (!selectedItems.remove(position)) {
selectedItems.add(position);
}
@@ -106,11 +106,6 @@ public abstract class EntryRecyclerAdapter extends RecyclerView.Adapter<EntryRec
}
holder.type.setText(pass.getFullPathToParent());
- if (pass.getType() == PasswordItem.TYPE_CATEGORY) {
-// holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_200));
- } else {
-// holder.card.setCardBackgroundColor(activity.getResources().getColor(R.color.blue_grey_50));
- }
holder.view.setOnClickListener(getOnClickListener(holder, pass));
@@ -134,14 +129,14 @@ public abstract class EntryRecyclerAdapter extends RecyclerView.Adapter<EntryRec
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
- public static class ViewHolder extends RecyclerView.ViewHolder {
+ static class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
- public View view;
- public TextView name;
- public TextView type;
- public ImageView typeImage;
+ public final View view;
+ public final TextView name;
+ final TextView type;
+ final ImageView typeImage;
- public ViewHolder(View v) {
+ ViewHolder(View v) {
super(v);
view = v;
name = (TextView) view.findViewById(R.id.label);
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java
index 404091b2..cfdb829d 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordItem.java
@@ -1,5 +1,7 @@
package com.zeapo.pwdstore.utils;
+import android.support.annotation.NonNull;
+
import java.io.File;
public class PasswordItem implements Comparable{
@@ -12,7 +14,6 @@ public class PasswordItem implements Comparable{
private PasswordItem parent;
private File file;
private String fullPathToParent;
- public boolean selected = false;
/** Create a password item
*
@@ -93,14 +94,15 @@ public class PasswordItem implements Comparable{
}
@Override
- public boolean equals(Object o){
- PasswordItem other = (PasswordItem) o;
+ public boolean equals(Object o) {
// Makes it possible to have a category and a password with the same name
- return (other.getFile().equals(this.getFile()));
-}
+ return o != null
+ && o.getClass() == PasswordItem.class
+ && ((PasswordItem) o).getFile().equals(this.getFile());
+ }
@Override
- public int compareTo(Object o) {
+ public int compareTo(@NonNull Object o) {
PasswordItem other = (PasswordItem) o;
// Appending the type will make the sort type dependent
return (this.getType() + this.getName())
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
index ab86d2e1..d97e3294 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRepository.java
@@ -27,7 +27,6 @@ import static java.util.Collections.sort;
public class PasswordRepository {
private static Repository repository;
- private static boolean initialized = false;
protected PasswordRepository(){ }
@@ -165,13 +164,13 @@ public class PasswordRepository {
* @return the list of gpg files in that directory
*/
public static ArrayList<File> getFilesList(File path){
- if (!path.exists()) return new ArrayList<File>();
+ if (!path.exists()) return new ArrayList<>();
Log.d("REPO", "current path: " + path.getPath());
- ArrayList<File> files = new ArrayList<File>(Arrays.asList(path.listFiles((FileFilter) FileFilterUtils.directoryFileFilter())));
- files.addAll( new ArrayList<File>((List<File>)FileUtils.listFiles(path, new String[] {"gpg"}, false)));
+ ArrayList<File> files = new ArrayList<>(Arrays.asList(path.listFiles((FileFilter) FileFilterUtils.directoryFileFilter())));
+ files.addAll(new ArrayList<>((List<File>) FileUtils.listFiles(path, new String[]{"gpg"}, false)));
- return new ArrayList<File>(files);
+ return new ArrayList<>(files);
}
/**
@@ -183,9 +182,9 @@ public class PasswordRepository {
//We need to recover the passwords then parse the files
ArrayList<File> passList = getFilesList(path);
- if (passList.size() == 0) return new ArrayList<PasswordItem>();
+ if (passList.size() == 0) return new ArrayList<>();
- ArrayList<PasswordItem> passwordList = new ArrayList<PasswordItem>();
+ ArrayList<PasswordItem> passwordList = new ArrayList<>();
for (File file : passList) {
if (file.isFile()) {
@@ -203,7 +202,7 @@ public class PasswordRepository {
/**
* Sets the git user name
- * @param String username username
+ * @param username username
*/
public static void setUserName(String username) {
setStringConfig("user", null, "name", username);
@@ -211,7 +210,7 @@ public class PasswordRepository {
/**
* Sets the git user email
- * @param String email email
+ * @param email email
*/
public static void setUserEmail(String email) {
setStringConfig("user", null, "email", email);
@@ -219,10 +218,10 @@ public class PasswordRepository {
/**
* Sets a git config value
- * @param String section config section name
- * @param String subsection config subsection name
- * @param String name config name
- * @param String value the value to be set
+ * @param section config section name
+ * @param subsection config subsection name
+ * @param name config name
+ * @param value the value to be set
*/
private static void setStringConfig(String section, String subsection, String name, String value) {
if (isInitialized()) {