From 651ecfd2f12e10f9cf2c43fcca8d8df69a30a134 Mon Sep 17 00:00:00 2001 From: Campello Manuel <9112949+CampelloManuel@users.noreply.github.com> Date: Sun, 28 Apr 2024 19:19:21 +0200 Subject: [PATCH] fix some problems found by code analysis --- .../notepad/activities/main/ActivityMain.java | 2 +- .../notepad/android/provider/TextFileProvider.java | 10 ++++++---- .../notepad/database/MyContentProvider.java | 12 +++++++----- .../nononsenseapps/notepad/prefs/PasswordPrefs.java | 4 ++-- .../notepad/sync/orgsync/OrgProvider.java | 8 ++++---- .../notepad/sync/orgsync/OrgSyncService.java | 3 ++- .../main/java/com/nononsenseapps/ui/DateView.java | 6 +++--- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/nononsenseapps/notepad/activities/main/ActivityMain.java b/app/src/main/java/com/nononsenseapps/notepad/activities/main/ActivityMain.java index 5fabc976..fd579756 100644 --- a/app/src/main/java/com/nononsenseapps/notepad/activities/main/ActivityMain.java +++ b/app/src/main/java/com/nononsenseapps/notepad/activities/main/ActivityMain.java @@ -198,7 +198,7 @@ public boolean onPrepareOptionsMenu(Menu menu) { } @Override - public boolean onOptionsItemSelected(MenuItem item) { + public boolean onOptionsItemSelected(@NonNull MenuItem item) { // Pass the event to ActionBarDrawerToggle. If it returns true, then it has handled the // drawer icon touch event if (mDrawerToggle.onOptionsItemSelected(item)) { diff --git a/app/src/main/java/com/nononsenseapps/notepad/android/provider/TextFileProvider.java b/app/src/main/java/com/nononsenseapps/notepad/android/provider/TextFileProvider.java index 69a4cbbf..ebcb484f 100644 --- a/app/src/main/java/com/nononsenseapps/notepad/android/provider/TextFileProvider.java +++ b/app/src/main/java/com/nononsenseapps/notepad/android/provider/TextFileProvider.java @@ -26,6 +26,8 @@ import android.os.Environment; import android.util.Log; +import androidx.annotation.NonNull; + import com.nononsenseapps.notepad.BuildConfig; import com.nononsenseapps.notepad.providercontract.ProviderContract; @@ -73,20 +75,20 @@ public TextFileProvider() { } @Override - public int delete(Uri uri, String selection, String[] selectionArgs) { + public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) { // Implement this to handle requests to delete one or more rows. throw new UnsupportedOperationException("Not yet implemented"); } @Override - public String getType(Uri uri) { + public String getType(@NonNull Uri uri) { // TODO: Implement this to handle requests for the MIME type of the data // at the given URI. throw new UnsupportedOperationException("Not yet implemented"); } @Override - public Uri insert(Uri uri, ContentValues values) { + public Uri insert(@NonNull Uri uri, ContentValues values) { // TODO: Implement this to handle requests to insert a new row. throw new UnsupportedOperationException("Not yet implemented"); } @@ -154,7 +156,7 @@ public Cursor query(Uri uri, String[] projection, String selection, } @Override - public int update(Uri uri, ContentValues values, String selection, + public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) { // TODO: Implement this to handle requests to update one or more rows. throw new UnsupportedOperationException("Not yet implemented"); diff --git a/app/src/main/java/com/nononsenseapps/notepad/database/MyContentProvider.java b/app/src/main/java/com/nononsenseapps/notepad/database/MyContentProvider.java index d12274a7..b68029b5 100644 --- a/app/src/main/java/com/nononsenseapps/notepad/database/MyContentProvider.java +++ b/app/src/main/java/com/nononsenseapps/notepad/database/MyContentProvider.java @@ -28,6 +28,8 @@ import android.database.sqlite.SQLiteStatement; import android.net.Uri; +import androidx.annotation.NonNull; + import com.nononsenseapps.helpers.NnnLogger; import com.nononsenseapps.helpers.UpdateNotifier; import com.nononsenseapps.notepad.BuildConfig; @@ -59,7 +61,7 @@ public MyContentProvider() { } @Override - public String getType(Uri uri) { + public String getType(@NonNull Uri uri) { switch (sURIMatcher.match(uri)) { case Notification.BASEITEMCODE: case Notification.BASEURICODE: @@ -108,7 +110,7 @@ public boolean onCreate() { } @Override - synchronized public Uri insert(Uri uri, ContentValues values) { + synchronized public Uri insert(@NonNull Uri uri, ContentValues values) { final SQLiteDatabase db = DatabaseHandler.getInstance(getContext()) .getWritableDatabase(); @@ -159,7 +161,7 @@ synchronized public Uri insert(Uri uri, ContentValues values) { } @Override - synchronized public int update(Uri uri, ContentValues values, + synchronized public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) { final SQLiteDatabase db = DatabaseHandler.getInstance(getContext()) .getWritableDatabase(); @@ -299,7 +301,7 @@ synchronized private int safeDeleteItem(final SQLiteDatabase db, } @Override - synchronized public int delete(Uri uri, String selection, + synchronized public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) { final SQLiteDatabase db = DatabaseHandler.getInstance(getContext()) .getWritableDatabase(); @@ -368,7 +370,7 @@ synchronized public int delete(Uri uri, String selection, } @Override - synchronized public Cursor query(Uri uri, String[] projection, String selection, + synchronized public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { Cursor result; final long id; diff --git a/app/src/main/java/com/nononsenseapps/notepad/prefs/PasswordPrefs.java b/app/src/main/java/com/nononsenseapps/notepad/prefs/PasswordPrefs.java index bcde0ca0..57dcfcf9 100644 --- a/app/src/main/java/com/nononsenseapps/notepad/prefs/PasswordPrefs.java +++ b/app/src/main/java/com/nononsenseapps/notepad/prefs/PasswordPrefs.java @@ -72,7 +72,7 @@ private void applyPassword() { .getDefaultSharedPreferences(this.getContext()); String currentPassword = settings.getString(KEY_PASSWORD, ""); - if ("".equals(currentPassword)) { + if (currentPassword.isEmpty()) { // it's new => Save the password directly settings.edit() .putString(KEY_PASSWORD, passw1) @@ -100,7 +100,7 @@ private void clearPassword() { .getDefaultSharedPreferences(this.getContext()); String currentPassword = settings.getString(KEY_PASSWORD, ""); - if ("".equals(currentPassword)) { + if (currentPassword.isEmpty()) { // Save the (empty) password directly settings.edit() .putString(KEY_PASSWORD, "") diff --git a/app/src/main/java/com/nononsenseapps/notepad/sync/orgsync/OrgProvider.java b/app/src/main/java/com/nononsenseapps/notepad/sync/orgsync/OrgProvider.java index e4b46464..5fa5b1e5 100644 --- a/app/src/main/java/com/nononsenseapps/notepad/sync/orgsync/OrgProvider.java +++ b/app/src/main/java/com/nononsenseapps/notepad/sync/orgsync/OrgProvider.java @@ -143,7 +143,7 @@ public boolean onCreate() { } @Override - public Cursor query(Uri uri, String[] projection, String selection, + public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { if (!PreferencesHelper.isSdSyncEnabled(getContext())) { return null; @@ -168,12 +168,12 @@ public Cursor query(Uri uri, String[] projection, String selection, } @Override - public String getType(Uri uri) { + public String getType(@NonNull Uri uri) { throw new UnsupportedOperationException("Not yet implemented"); } @Override - public Uri insert(Uri uri, ContentValues values) { + public Uri insert(@NonNull Uri uri, ContentValues values) { if (!PreferencesHelper.isSdSyncEnabled(getContext())) { return null; } @@ -207,7 +207,7 @@ public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) { } @Override - public int update(Uri uri, ContentValues values, String selection, + public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) { if (!PreferencesHelper.isSdSyncEnabled(getContext())) { return -1; diff --git a/app/src/main/java/com/nononsenseapps/notepad/sync/orgsync/OrgSyncService.java b/app/src/main/java/com/nononsenseapps/notepad/sync/orgsync/OrgSyncService.java index 936285f1..0461db5a 100644 --- a/app/src/main/java/com/nononsenseapps/notepad/sync/orgsync/OrgSyncService.java +++ b/app/src/main/java/com/nononsenseapps/notepad/sync/orgsync/OrgSyncService.java @@ -29,6 +29,7 @@ import android.os.Message; import android.os.Process; +import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; import com.nononsenseapps.helpers.NnnLogger; @@ -192,7 +193,7 @@ public void onMonitorChange() { } @Override - public void handleMessage(Message msg) { + public void handleMessage(@NonNull Message msg) { if (synchronizers.isEmpty()) { synchronizers.addAll(getSynchronizers()); diff --git a/app/src/main/java/com/nononsenseapps/ui/DateView.java b/app/src/main/java/com/nononsenseapps/ui/DateView.java index 05214b78..fb2db030 100644 --- a/app/src/main/java/com/nononsenseapps/ui/DateView.java +++ b/app/src/main/java/com/nononsenseapps/ui/DateView.java @@ -28,6 +28,7 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; /** @@ -48,7 +49,6 @@ public DateView(Context context) { // TODO if you want to also show a "due time" on the note, use this instead: // mDateFormatter = TimeFormatter.getLocalFormatterShort(context); // as of now we only show the date, which for me is good enough. - // (note that this line is called many times in this file) mDateFormatter = TimeFormatter.getLocalFormatterShortDateOnly(context); } @@ -58,8 +58,8 @@ public DateView(Context context, AttributeSet attrs) { try { mDateFormatter = TimeFormatter.getLocalFormatterShortDateOnly(context); } catch (Exception e) { - // Just to function in view - mDateFormatter = new SimpleDateFormat(); + // return a simple fallback formatter, just to show something in the view + mDateFormatter = new SimpleDateFormat("E d MMM yyyy, HH:ss", Locale.US); } }