Clean up switch statements with only a single option.
This commit is contained in:
parent
fd50a2c730
commit
005d109818
@ -785,22 +785,12 @@ public class AppProvider extends FDroidProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri uri, String where, String[] whereArgs) {
|
public int delete(Uri uri, String where, String[] whereArgs) {
|
||||||
|
if (MATCHER.match(uri) != NO_APKS) {
|
||||||
QuerySelection query = new QuerySelection(where, whereArgs);
|
throw new UnsupportedOperationException("Delete not supported for " + uri + ".");
|
||||||
switch (MATCHER.match(uri)) {
|
|
||||||
|
|
||||||
case NO_APKS:
|
|
||||||
query = query.add(queryNoApks());
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new UnsupportedOperationException("Delete not supported for " + uri + ".");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = db().delete(getTableName(), query.getSelection(), query.getArgs());
|
AppQuerySelection selection = new AppQuerySelection(where, whereArgs).add(queryNoApks());
|
||||||
getContext().getContentResolver().notifyChange(uri, null);
|
return db().delete(getTableName(), selection.getSelection(), selection.getArgs());
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,6 @@ import android.content.Context;
|
|||||||
import android.content.UriMatcher;
|
import android.content.UriMatcher;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.fdroid.fdroid.data.Schema.ApkTable;
|
import org.fdroid.fdroid.data.Schema.ApkTable;
|
||||||
|
|
||||||
@ -16,8 +15,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class TempApkProvider extends ApkProvider {
|
public class TempApkProvider extends ApkProvider {
|
||||||
|
|
||||||
private static final String TAG = "TempApkProvider";
|
|
||||||
|
|
||||||
private static final String PROVIDER_NAME = "TempApkProvider";
|
private static final String PROVIDER_NAME = "TempApkProvider";
|
||||||
|
|
||||||
static final String TABLE_TEMP_APK = "temp_" + ApkTable.NAME;
|
static final String TABLE_TEMP_APK = "temp_" + ApkTable.NAME;
|
||||||
@ -89,18 +86,16 @@ public class TempApkProvider extends ApkProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri insert(Uri uri, ContentValues values) {
|
public Uri insert(Uri uri, ContentValues values) {
|
||||||
switch (MATCHER.match(uri)) {
|
if (MATCHER.match(uri) == CODE_INIT) {
|
||||||
case CODE_INIT:
|
initTable();
|
||||||
initTable();
|
return null;
|
||||||
return null;
|
|
||||||
default:
|
|
||||||
return super.insert(uri, values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return super.insert(uri, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
|
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
|
||||||
|
|
||||||
if (MATCHER.match(uri) != CODE_SINGLE) {
|
if (MATCHER.match(uri) != CODE_SINGLE) {
|
||||||
throw new UnsupportedOperationException("Cannot update anything other than a single apk.");
|
throw new UnsupportedOperationException("Cannot update anything other than a single apk.");
|
||||||
}
|
}
|
||||||
@ -110,20 +105,15 @@ public class TempApkProvider extends ApkProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri uri, String where, String[] whereArgs) {
|
public int delete(Uri uri, String where, String[] whereArgs) {
|
||||||
|
if (MATCHER.match(uri) != CODE_REPO_APK) {
|
||||||
QuerySelection query = new QuerySelection(where, whereArgs);
|
throw new UnsupportedOperationException("Invalid URI for apk content provider: " + uri);
|
||||||
|
|
||||||
switch (MATCHER.match(uri)) {
|
|
||||||
case CODE_REPO_APK:
|
|
||||||
List<String> pathSegments = uri.getPathSegments();
|
|
||||||
query = query.add(queryRepo(Long.parseLong(pathSegments.get(1)), false)).add(queryApks(pathSegments.get(2), false));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Log.e(TAG, "Invalid URI for apk content provider: " + uri);
|
|
||||||
throw new UnsupportedOperationException("Invalid URI for apk content provider: " + uri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> pathSegments = uri.getPathSegments();
|
||||||
|
QuerySelection query = new QuerySelection(where, whereArgs)
|
||||||
|
.add(queryRepo(Long.parseLong(pathSegments.get(1)), false))
|
||||||
|
.add(queryApks(pathSegments.get(2), false));
|
||||||
|
|
||||||
int rowsAffected = db().delete(getTableName(), query.getSelection(), query.getArgs());
|
int rowsAffected = db().delete(getTableName(), query.getSelection(), query.getArgs());
|
||||||
if (!isApplyingBatch()) {
|
if (!isApplyingBatch()) {
|
||||||
getContext().getContentResolver().notifyChange(uri, null);
|
getContext().getContentResolver().notifyChange(uri, null);
|
||||||
|
@ -122,16 +122,12 @@ public class TempAppProvider extends AppProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
|
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
|
||||||
QuerySelection query = new QuerySelection(where, whereArgs);
|
if (MATCHER.match(uri) != CODE_SINGLE) {
|
||||||
switch (MATCHER.match(uri)) {
|
throw new UnsupportedOperationException("Update not supported for " + uri + ".");
|
||||||
case CODE_SINGLE:
|
|
||||||
query = query.add(querySingle(uri.getLastPathSegment()));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new UnsupportedOperationException("Update not supported for " + uri + ".");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QuerySelection query = new QuerySelection(where, whereArgs).add(querySingle(uri.getLastPathSegment()));
|
||||||
|
|
||||||
int count = db().update(getTableName(), values, query.getSelection(), query.getArgs());
|
int count = db().update(getTableName(), values, query.getSelection(), query.getArgs());
|
||||||
if (!isApplyingBatch()) {
|
if (!isApplyingBatch()) {
|
||||||
getContext().getContentResolver().notifyChange(uri, null);
|
getContext().getContentResolver().notifyChange(uri, null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user