Skip to content

Commit

Permalink
fix warnings in MyContentProvider.java
Browse files Browse the repository at this point in the history
  • Loading branch information
CampelloManuel committed Apr 28, 2024
1 parent e2bcaab commit 55fb79f
Showing 1 changed file with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.nononsenseapps.notepad.BuildConfig;

import java.util.ArrayList;
import java.util.Objects;

public class MyContentProvider extends ContentProvider {

Expand Down Expand Up @@ -119,28 +120,15 @@ synchronized public Uri insert(@NonNull Uri uri, ContentValues values) {
db.beginTransaction();
// Do not add legacy URIs
try {
final DAO item;
switch (sURIMatcher.match(uri)) {
case TaskList.BASEURICODE:
item = new TaskList(values);
break;
case Task.BASEURICODE:
item = new Task(values);
break;
case Notification.BASEURICODE:
case Notification.WITHTASKQUERYITEMCODE:
item = new Notification(values);
break;
case RemoteTaskList.BASEURICODE:
item = new RemoteTaskList(values);
break;
case RemoteTask.BASEURICODE:
item = new RemoteTask(values);
break;
default:
throw new IllegalArgumentException(
"Faulty insertURI provided: " + uri.toString());
}
final DAO item = switch (sURIMatcher.match(uri)) {
case TaskList.BASEURICODE -> new TaskList(values);
case Task.BASEURICODE -> new Task(values);
case Notification.BASEURICODE, Notification.WITHTASKQUERYITEMCODE ->
new Notification(values);
case RemoteTaskList.BASEURICODE -> new RemoteTaskList(values);
case RemoteTask.BASEURICODE -> new RemoteTask(values);
default -> throw new IllegalArgumentException("Faulty insertURI provided: " + uri);
};

result = item.insert(getContext(), db);
db.setTransactionSuccessful();
Expand All @@ -151,6 +139,7 @@ synchronized public Uri insert(@NonNull Uri uri, ContentValues values) {
}

if (result != null) {
Objects.requireNonNull(getContext());
DAO.notifyProviderOnChange(getContext(), uri);
DAO.notifyProviderOnChange(getContext(), TaskList.URI_WITH_COUNT);
UpdateNotifier.updateWidgets(getContext());
Expand Down Expand Up @@ -259,8 +248,7 @@ synchronized public int update(@NonNull Uri uri, ContentValues values,
);
break;
default:
throw new IllegalArgumentException("Faulty URI provided: "
+ uri.toString());
throw new IllegalArgumentException("Faulty URI provided: " + uri);
}

if (result >= 0) {
Expand All @@ -282,7 +270,9 @@ synchronized public int update(@NonNull Uri uri, ContentValues values,
}

synchronized private int safeDeleteItem(final SQLiteDatabase db,
final String tableName, final Uri uri, final String selection,
final String tableName,
final Uri uri,
final String selection,
final String[] selectionArgs) {
db.beginTransaction();
int result = 0;
Expand Down Expand Up @@ -356,11 +346,11 @@ synchronized public int delete(@NonNull Uri uri, String selection,
selection, selectionArgs);
break;
default:
throw new IllegalArgumentException("Faulty delete-URI provided: "
+ uri.toString());
throw new IllegalArgumentException("Faulty delete-URI provided: " + uri);
}

if (result > 0) {
Objects.requireNonNull(getContext());
DAO.notifyProviderOnChange(getContext(), uri);
DAO.notifyProviderOnChange(getContext(), TaskList.URI_WITH_COUNT);
UpdateNotifier.updateWidgets(getContext());
Expand All @@ -374,6 +364,7 @@ synchronized public Cursor query(@NonNull Uri uri, String[] projection, String s
String[] selectionArgs, String sortOrder) {
Cursor result;
final long id;
Objects.requireNonNull(getContext());
switch (sURIMatcher.match(uri)) {
case TaskList.BASEURICODE:
result = DatabaseHandler
Expand Down Expand Up @@ -639,8 +630,7 @@ synchronized public Cursor query(@NonNull Uri uri, String[] projection, String s
case Task.LEGACYBASEITEMCODE:
case Task.LEGACYVISIBLEITEMCODE:
default:
NnnLogger.debug(MyContentProvider.class,
"Faulty queryURI provided: " + uri.toString());
NnnLogger.debug(MyContentProvider.class, "Faulty queryURI provided: " + uri);
return null;
}

Expand Down

0 comments on commit 55fb79f

Please sign in to comment.