From 5da9e67545644925902b04a11306289add29c033 Mon Sep 17 00:00:00 2001 From: Felix Bechstein Date: Tue, 25 Jul 2017 15:23:50 +0200 Subject: 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 --- .../java/com/zeapo/pwdstore/GitActivityClone.java | 6 +- .../java/com/zeapo/pwdstore/GitActivityTest.java | 3 - .../java/com/zeapo/pwdstore/PasswordFragment.java | 24 +- .../java/com/zeapo/pwdstore/PasswordStore.java | 10 +- .../com/zeapo/pwdstore/SelectFolderFragment.java | 109 +------- .../main/java/com/zeapo/pwdstore/ToCloneOrNot.java | 5 - .../java/com/zeapo/pwdstore/UserPreference.java | 3 +- .../zeapo/pwdstore/autofill/AutofillFragment.java | 14 +- .../autofill/AutofillPreferenceActivity.java | 6 +- .../pwdstore/autofill/AutofillRecyclerAdapter.java | 3 +- .../pwdstore/autofill/DividerItemDecoration.java | 105 -------- .../java/com/zeapo/pwdstore/crypto/PgpHandler.java | 99 ++++---- .../com/zeapo/pwdstore/git/CloneOperation.java | 2 - .../java/com/zeapo/pwdstore/git/GitActivity.java | 17 +- .../java/com/zeapo/pwdstore/git/GitOperation.java | 1 - .../git/config/SshConfigSessionFactory.java | 2 - .../com/zeapo/pwdstore/pwgenDialogFragment.java | 6 +- .../zeapo/pwdstore/utils/EntryRecyclerAdapter.java | 25 +- .../com/zeapo/pwdstore/utils/PasswordItem.java | 14 +- .../zeapo/pwdstore/utils/PasswordRepository.java | 25 +- .../main/res/drawable-hdpi/ic_action_accounts.png | Bin 577 -> 0 bytes .../main/res/drawable-hdpi/ic_action_discard.png | Bin 450 -> 0 bytes .../main/res/drawable-mdpi/ic_action_accounts.png | Bin 456 -> 0 bytes .../main/res/drawable-mdpi/ic_action_discard.png | Bin 324 -> 0 bytes .../main/res/drawable-xhdpi/ic_action_accounts.png | Bin 688 -> 0 bytes .../main/res/drawable-xhdpi/ic_action_discard.png | Bin 543 -> 0 bytes .../res/drawable-xxhdpi/ic_action_accounts.png | Bin 973 -> 0 bytes .../main/res/drawable-xxhdpi/ic_action_discard.png | Bin 765 -> 0 bytes app/src/main/res/drawable/actionbar_background.xml | 4 - app/src/main/res/drawable/blue_rectangle.xml | 24 -- app/src/main/res/layout/activity_git_clone.xml | 18 +- app/src/main/res/layout/activity_git_config.xml | 4 +- app/src/main/res/layout/activity_pgp_handler.xml | 52 ---- app/src/main/res/layout/activity_pwdstore.xml | 2 +- app/src/main/res/layout/app_list_item.xml | 23 -- app/src/main/res/layout/child_row_layout.xml | 30 --- app/src/main/res/layout/decrypt_layout.xml | 23 +- app/src/main/res/layout/encrypt_layout.xml | 26 +- app/src/main/res/layout/fragment_autofill.xml | 27 +- app/src/main/res/layout/fragment_pwgen.xml | 7 +- app/src/main/res/layout/key_id.xml | 44 ---- app/src/main/res/layout/openpgp_provider.xml | 158 ------------ app/src/main/res/layout/password_row_layout.xml | 12 +- app/src/main/res/menu/agp_intents.xml | 9 - app/src/main/res/menu/context_pass.xml | 23 +- app/src/main/res/menu/pgp_handler_new_password.xml | 4 +- .../main/res/menu/pgp_handler_select_folder.xml | 2 +- app/src/main/res/values-cs/strings.xml | 29 --- app/src/main/res/values-de/strings.xml | 42 +--- app/src/main/res/values-fr/strings.xml | 29 --- app/src/main/res/values-ja/strings.xml | 29 --- app/src/main/res/values-large/refs.xml | 12 - app/src/main/res/values-ru/strings.xml | 29 --- app/src/main/res/values-sw600dp/refs.xml | 12 - app/src/main/res/values-zh-rCH/strings.xml | 29 --- app/src/main/res/values-zh-rTW/strings.xml | 29 --- app/src/main/res/values/colors.xml | 278 +-------------------- app/src/main/res/values/refs.xml | 11 - app/src/main/res/values/strings.xml | 43 ++-- app/src/main/res/xml/preference.xml | 12 +- 60 files changed, 236 insertions(+), 1319 deletions(-) delete mode 100644 app/src/main/java/com/zeapo/pwdstore/autofill/DividerItemDecoration.java delete mode 100644 app/src/main/res/drawable-hdpi/ic_action_accounts.png delete mode 100644 app/src/main/res/drawable-hdpi/ic_action_discard.png delete mode 100644 app/src/main/res/drawable-mdpi/ic_action_accounts.png delete mode 100644 app/src/main/res/drawable-mdpi/ic_action_discard.png delete mode 100644 app/src/main/res/drawable-xhdpi/ic_action_accounts.png delete mode 100644 app/src/main/res/drawable-xhdpi/ic_action_discard.png delete mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_accounts.png delete mode 100644 app/src/main/res/drawable-xxhdpi/ic_action_discard.png delete mode 100644 app/src/main/res/drawable/actionbar_background.xml delete mode 100644 app/src/main/res/drawable/blue_rectangle.xml delete mode 100644 app/src/main/res/layout/activity_pgp_handler.xml delete mode 100644 app/src/main/res/layout/app_list_item.xml delete mode 100644 app/src/main/res/layout/child_row_layout.xml delete mode 100644 app/src/main/res/layout/key_id.xml delete mode 100644 app/src/main/res/layout/openpgp_provider.xml delete mode 100644 app/src/main/res/menu/agp_intents.xml delete mode 100644 app/src/main/res/values-large/refs.xml delete mode 100644 app/src/main/res/values-sw600dp/refs.xml delete mode 100644 app/src/main/res/values/refs.xml diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/GitActivityClone.java b/app/src/androidTest/java/com/zeapo/pwdstore/GitActivityClone.java index 80a915f8..dccb4eb8 100644 --- a/app/src/androidTest/java/com/zeapo/pwdstore/GitActivityClone.java +++ b/app/src/androidTest/java/com/zeapo/pwdstore/GitActivityClone.java @@ -6,12 +6,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; -import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; -import com.robotium.solo.Solo; import com.zeapo.pwdstore.git.GitActivity; import com.zeapo.pwdstore.utils.PasswordRepository; @@ -20,7 +17,6 @@ import org.apache.commons.io.FileUtils; import java.io.File; public class GitActivityClone extends ActivityInstrumentationTestCase2 { - private static final String TAG = "GitActTest"; private Activity gitActivity; private Instrumentation mInstrumentation; private SharedPreferences settings; @@ -71,7 +67,7 @@ public class GitActivityClone extends ActivityInstrumentationTestCase2 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>(); - scrollPosition = new Stack(); - pathStack = new Stack(); + 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 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>(); - scrollPosition = new Stack(); - pathStack = new Stack(); + 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 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 @@ -13,11 +13,6 @@ public class ToCloneOrNot extends Fragment { // Required empty public constructor } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 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(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 apps; private ArrayList 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(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 keys = new HashSet(); + Set 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 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 { private final Activity activity; - protected final ArrayList values; - protected final Set selectedItems = new TreeSet<>(); + private final ArrayList values; + final Set selectedItems = new TreeSet<>(); - public EntryRecyclerAdapter(Activity activity, ArrayList values) { + EntryRecyclerAdapter(Activity activity, ArrayList values) { this.activity = activity; this.values = values; } @@ -52,7 +52,7 @@ public abstract class EntryRecyclerAdapter extends RecyclerView.Adapter getFilesList(File path){ - if (!path.exists()) return new ArrayList(); + if (!path.exists()) return new ArrayList<>(); Log.d("REPO", "current path: " + path.getPath()); - ArrayList files = new ArrayList(Arrays.asList(path.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()))); - files.addAll( new ArrayList((List)FileUtils.listFiles(path, new String[] {"gpg"}, false))); + ArrayList files = new ArrayList<>(Arrays.asList(path.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()))); + files.addAll(new ArrayList<>((List) FileUtils.listFiles(path, new String[]{"gpg"}, false))); - return new ArrayList(files); + return new ArrayList<>(files); } /** @@ -183,9 +182,9 @@ public class PasswordRepository { //We need to recover the passwords then parse the files ArrayList passList = getFilesList(path); - if (passList.size() == 0) return new ArrayList(); + if (passList.size() == 0) return new ArrayList<>(); - ArrayList passwordList = new ArrayList(); + ArrayList 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()) { diff --git a/app/src/main/res/drawable-hdpi/ic_action_accounts.png b/app/src/main/res/drawable-hdpi/ic_action_accounts.png deleted file mode 100644 index ae02bea6..00000000 Binary files a/app/src/main/res/drawable-hdpi/ic_action_accounts.png and /dev/null differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_discard.png b/app/src/main/res/drawable-hdpi/ic_action_discard.png deleted file mode 100644 index 703b31f8..00000000 Binary files a/app/src/main/res/drawable-hdpi/ic_action_discard.png and /dev/null differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_accounts.png b/app/src/main/res/drawable-mdpi/ic_action_accounts.png deleted file mode 100644 index 2a703c14..00000000 Binary files a/app/src/main/res/drawable-mdpi/ic_action_accounts.png and /dev/null differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_discard.png b/app/src/main/res/drawable-mdpi/ic_action_discard.png deleted file mode 100644 index 248fb09c..00000000 Binary files a/app/src/main/res/drawable-mdpi/ic_action_discard.png and /dev/null differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_accounts.png b/app/src/main/res/drawable-xhdpi/ic_action_accounts.png deleted file mode 100644 index d2cb5819..00000000 Binary files a/app/src/main/res/drawable-xhdpi/ic_action_accounts.png and /dev/null differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_discard.png b/app/src/main/res/drawable-xhdpi/ic_action_discard.png deleted file mode 100644 index 9eeeed12..00000000 Binary files a/app/src/main/res/drawable-xhdpi/ic_action_discard.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_accounts.png b/app/src/main/res/drawable-xxhdpi/ic_action_accounts.png deleted file mode 100644 index 568a47be..00000000 Binary files a/app/src/main/res/drawable-xxhdpi/ic_action_accounts.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_discard.png b/app/src/main/res/drawable-xxhdpi/ic_action_discard.png deleted file mode 100644 index cb1260a4..00000000 Binary files a/app/src/main/res/drawable-xxhdpi/ic_action_discard.png and /dev/null differ diff --git a/app/src/main/res/drawable/actionbar_background.xml b/app/src/main/res/drawable/actionbar_background.xml deleted file mode 100644 index 220eee39..00000000 --- a/app/src/main/res/drawable/actionbar_background.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/blue_rectangle.xml b/app/src/main/res/drawable/blue_rectangle.xml deleted file mode 100644 index 61cb44f5..00000000 --- a/app/src/main/res/drawable/blue_rectangle.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_git_clone.xml b/app/src/main/res/layout/activity_git_clone.xml index d923350a..8001f94d 100644 --- a/app/src/main/res/layout/activity_git_clone.xml +++ b/app/src/main/res/layout/activity_git_clone.xml @@ -106,14 +106,16 @@ android:inputType="textWebEmailAddress" /> + android:layout_toStartOf="@+id/server_port" + android:paddingBottom="8dp" + android:text=":" + tools:ignore="HardcodedText" /> + + android:hint="@string/repository_uri" + android:inputType="textWebEmailAddress" />