From 20a53eb828b3e821c31dffbcbad12601c5eaa232 Mon Sep 17 00:00:00 2001 From: Christoph Loy Date: Fri, 6 Mar 2020 21:43:38 +0100 Subject: [PATCH] Fix some lint issues --- .../owncloud/notes/android/activity/EditNoteActivity.java | 4 ++-- .../owncloud/notes/android/activity/ExceptionActivity.java | 6 ++++-- .../notes/android/activity/NotesListViewActivity.java | 4 +++- .../android/appwidget/NoteListWidgetConfiguration.java | 2 ++ .../owncloud/notes/android/fragment/CategoryAdapter.java | 2 +- .../notes/android/fragment/CategoryDialogFragment.java | 4 ++-- .../notes/android/fragment/NotePreviewFragment.java | 2 +- .../notes/android/fragment/NoteReadonlyFragment.java | 2 +- .../notes/android/fragment/PreferencesFragment.java | 6 +++--- .../java/it/niedermann/owncloud/notes/model/CloudNote.java | 5 ++--- .../niedermann/owncloud/notes/model/NavigationAdapter.java | 5 +---- .../owncloud/notes/persistence/AbstractNotesDatabase.java | 4 +++- .../owncloud/notes/persistence/NotesDatabase.java | 4 ++-- .../niedermann/owncloud/notes/persistence/SyncWorker.java | 3 ++- .../it/niedermann/owncloud/notes/util/ClipboardUtil.java | 2 +- 15 files changed, 30 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java index 8c7c1b7f..8658a56d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java @@ -160,7 +160,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm String category = null; boolean favorite = false; if (intent.hasExtra(PARAM_CATEGORY)) { - Category categoryPreselection = (Category) intent.getSerializableExtra(PARAM_CATEGORY); + Category categoryPreselection = (Category) Objects.requireNonNull(intent.getSerializableExtra(PARAM_CATEGORY)); category = categoryPreselection.category; favorite = categoryPreselection.favorite != null ? categoryPreselection.favorite : false; } @@ -168,7 +168,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm String content = ""; if ( intent.hasExtra(Intent.EXTRA_TEXT) && - MIMETYPE_TEXT_PLAIN.equals(intent.getType()) && + MIMETYPE_TEXT_PLAIN.equals(intent.getType()) && (Intent.ACTION_SEND.equals(intent.getAction()) || INTENT_GOOGLE_ASSISTANT.equals(intent.getAction())) ) { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java index 06a681b5..c6cd8af1 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/ExceptionActivity.java @@ -11,6 +11,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import java.util.Objects; + import it.niedermann.nextcloud.exception.ExceptionUtil; import it.niedermann.owncloud.notes.R; @@ -36,7 +38,7 @@ public class ExceptionActivity extends AppCompatActivity { findViewById(R.id.close).setOnClickListener((v) -> close()); setSupportActionBar(toolbar); - throwable = ((Throwable) getIntent().getSerializableExtra(KEY_THROWABLE)); + throwable = (Throwable) Objects.requireNonNull(getIntent().getSerializableExtra(KEY_THROWABLE)); throwable.printStackTrace(); toolbar.setTitle(getString(R.string.simple_error)); message.setText(throwable.getMessage()); @@ -45,7 +47,7 @@ public class ExceptionActivity extends AppCompatActivity { void copyStacktraceToClipboard() { - final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + final ClipboardManager clipboardManager = (ClipboardManager) Objects.requireNonNull(getSystemService(CLIPBOARD_SERVICE)); ClipData clipData = ClipData.newPlainText(getString(R.string.simple_exception), "```\n" + this.stacktrace.getText() + "\n```"); clipboardManager.setPrimaryClip(clipData); Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java index 10a8e474..a63cd515 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java @@ -63,8 +63,8 @@ import it.niedermann.owncloud.notes.model.NavigationAdapter; import it.niedermann.owncloud.notes.model.NavigationAdapter.NavigationItem; import it.niedermann.owncloud.notes.persistence.LoadNotesListTask; import it.niedermann.owncloud.notes.persistence.LoadNotesListTask.NotesLoadedListener; -import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper; +import it.niedermann.owncloud.notes.persistence.NotesDatabase; import it.niedermann.owncloud.notes.util.NoteUtil; import static it.niedermann.owncloud.notes.util.SSOUtil.askForNewAccount; @@ -415,7 +415,9 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap } Map favorites = db.getFavoritesCount(localAccount.getId()); + //noinspection ConstantConditions int numFavorites = favorites.containsKey("1") ? favorites.get("1") : 0; + //noinspection ConstantConditions int numNonFavorites = favorites.containsKey("0") ? favorites.get("0") : 0; itemFavorites.count = numFavorites; itemRecent.count = numFavorites + numNonFavorites; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/appwidget/NoteListWidgetConfiguration.java b/app/src/main/java/it/niedermann/owncloud/notes/android/appwidget/NoteListWidgetConfiguration.java index 28e28ebd..318aad73 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/appwidget/NoteListWidgetConfiguration.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/appwidget/NoteListWidgetConfiguration.java @@ -145,7 +145,9 @@ public class NoteListWidgetConfiguration extends AppCompatActivity { } Map favorites = db.getFavoritesCount(localAccount.getId()); + //noinspection ConstantConditions int numFavorites = favorites.containsKey("1") ? favorites.get("1") : 0; + //noinspection ConstantConditions int numNonFavorites = favorites.containsKey("0") ? favorites.get("0") : 0; itemFavorites.count = numFavorites; itemRecent.count = numFavorites + numNonFavorites; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryAdapter.java index e6c3077c..792e2b9b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryAdapter.java @@ -66,7 +66,7 @@ public class CategoryAdapter extends RecyclerView.Adapter 0) { + if (category.count != null && category.count > 0) { categoryViewHolder.getCount().setText(String.valueOf(category.count)); } else { categoryViewHolder.getCount().setVisibility(View.GONE); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryDialogFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryDialogFragment.java index 01a23e70..65626269 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryDialogFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryDialogFragment.java @@ -61,7 +61,7 @@ public class CategoryDialogFragment extends AppCompatDialogFragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - if (requireArguments() != null && requireArguments().containsKey(PARAM_ACCOUNT_ID)) { + if (getArguments() != null && requireArguments().containsKey(PARAM_ACCOUNT_ID)) { accountId = requireArguments().getLong(PARAM_ACCOUNT_ID); } else { throw new IllegalArgumentException("Provide at least \"" + PARAM_ACCOUNT_ID + "\""); @@ -151,7 +151,7 @@ public class CategoryDialogFragment extends AppCompatDialogFragment { super.onActivityCreated(savedInstanceState); if (editCategory.getText() == null || editCategory.getText().length() == 0) { editCategory.requestFocus(); - if (getDialog().getWindow() != null) { + if (getDialog() != null && getDialog().getWindow() != null) { getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } else { Log.w(TAG, "can not set SOFT_INPUT_STATE_ALWAYAS_VISIBLE because getWindow() == null"); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NotePreviewFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NotePreviewFragment.java index 8bf2614b..91aca788 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NotePreviewFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NotePreviewFragment.java @@ -94,7 +94,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = FragmentNotePreviewBinding.inflate(inflater, container, false); return binding.getRoot(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NoteReadonlyFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NoteReadonlyFragment.java index ea0482c2..5a2bf35d 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NoteReadonlyFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/NoteReadonlyFragment.java @@ -87,7 +87,7 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment { @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = FragmentNotePreviewBinding.inflate(inflater, container, false); return binding.getRoot(); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java index 84b8820b..5f9f5b59 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/fragment/PreferencesFragment.java @@ -31,8 +31,8 @@ public class PreferencesFragment extends PreferenceFragmentCompat { assert themePref != null; themePref.setOnPreferenceChangeListener((preference, newValue) -> { Notes.setAppTheme(DarkModeSetting.valueOf((String) newValue)); - getActivity().setResult(Activity.RESULT_OK); - getActivity().recreate(); + requireActivity().setResult(Activity.RESULT_OK); + requireActivity().recreate(); return true; }); @@ -47,7 +47,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat { assert syncPref != null; syncPref.setOnPreferenceChangeListener((preference, newValue) -> { Log.v(TAG, "syncPref: " + preference + " - newValue: " + newValue); - SyncWorker.update(getContext(), newValue.toString()); + SyncWorker.update(requireContext(), newValue.toString()); return true; }); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/CloudNote.java b/app/src/main/java/it/niedermann/owncloud/notes/model/CloudNote.java index 559367da..18d9a208 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/CloudNote.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/CloudNote.java @@ -14,9 +14,9 @@ import it.niedermann.owncloud.notes.util.NoteUtil; * It can be directly generated from the JSON answer from the server. */ public class CloudNote implements Serializable { - private long remoteId = 0; + private long remoteId; private String title = ""; - private Calendar modified = null; + private Calendar modified; private String content = ""; private boolean favorite = false; private String category = ""; @@ -51,7 +51,6 @@ public class CloudNote implements Serializable { this.title = NoteUtil.removeMarkDown(title); } - @SuppressWarnings("WeakerAccess") public Calendar getModified() { return modified; } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/NavigationAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/model/NavigationAdapter.java index 0e7957dc..57f7ac67 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/NavigationAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/NavigationAdapter.java @@ -57,9 +57,6 @@ public class NavigationAdapter extends RecyclerView.Adapter