Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings for FilesDisplayActivity #12113

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public class UserAccountManagerImpl implements UserAccountManager {
private static final String TAG = UserAccountManagerImpl.class.getSimpleName();
private static final String PREF_SELECT_OC_ACCOUNT = "select_oc_account";

private Context context;
private AccountManager accountManager;
private final Context context;
private final AccountManager accountManager;

public static UserAccountManagerImpl fromContext(Context context) {
AccountManager am = (AccountManager)context.getSystemService(Context.ACCOUNT_SERVICE);
Expand Down Expand Up @@ -166,7 +166,7 @@ public Account getCurrentAccount() {
}
}

if (defaultAccount == null && ocAccounts.length > 0) {
if (defaultAccount == null) {
// take first which is not pending for removal account as fallback
for (Account account: ocAccounts) {
boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(account.name,
Expand Down Expand Up @@ -262,7 +262,11 @@ public User getAnonymousUser() {
public OwnCloudAccount getCurrentOwnCloudAccount() {
try {
Account currentPlatformAccount = getCurrentAccount();
return new OwnCloudAccount(currentPlatformAccount, context);
if (currentPlatformAccount != null) {
return new OwnCloudAccount(currentPlatformAccount, context);
} else {
return null;
}
} catch (AccountUtils.AccountNotFoundException | IllegalArgumentException ex) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,23 +262,15 @@ public Uri insert(@NonNull Uri uri, ContentValues values) {
private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {
// verify only for those requests that are not internal (files table)
switch (mUriMatcher.match(uri)) {
case ROOT_DIRECTORY:
case SINGLE_FILE:
case DIRECTORY:
VerificationUtils.verifyColumns(values);
break;
case ROOT_DIRECTORY, SINGLE_FILE, DIRECTORY -> VerificationUtils.verifyColumns(values);
}


switch (mUriMatcher.match(uri)) {
case ROOT_DIRECTORY:
case SINGLE_FILE:
case ROOT_DIRECTORY, SINGLE_FILE -> {
String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";

String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
String[] whereArgs = {remotePath, accountName};

Cursor doubleCheck = query(db, uri, PROJECTION_FILE_PATH_AND_OWNER, where, whereArgs, null);
// ugly patch; serious refactoring is needed to reduce work in
// FileDataStorageManager and bring it to FileContentProvider
Expand All @@ -295,13 +287,13 @@ private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {
Uri insertedFileUri = ContentUris.withAppendedId(
ProviderTableMeta.CONTENT_URI_FILE,
doubleCheck.getLong(doubleCheck.getColumnIndexOrThrow(ProviderTableMeta._ID))
);
);
doubleCheck.close();

return insertedFileUri;
}

case SHARES:
}
case SHARES -> {
Uri insertedShareUri;
long idShares = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values);
if (idShares > 0) {
Expand All @@ -311,10 +303,9 @@ private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {

}
updateFilesTableAccordingToShareInsertion(db, values);

return insertedShareUri;

case CAPABILITIES:
}
case CAPABILITIES -> {
Uri insertedCapUri;
long idCapabilities = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values);
if (idCapabilities > 0) {
Expand All @@ -323,8 +314,8 @@ private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {
throw new SQLException(ERROR + uri);
}
return insertedCapUri;

case UPLOADS:
}
case UPLOADS -> {
Uri insertedUploadUri;
long uploadId = db.insert(ProviderTableMeta.UPLOADS_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values);
if (uploadId > 0) {
Expand All @@ -333,8 +324,8 @@ private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {
throw new SQLException(ERROR + uri);
}
return insertedUploadUri;

case SYNCED_FOLDERS:
}
case SYNCED_FOLDERS -> {
Uri insertedSyncedFolderUri;
long syncedFolderId = db.insert(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values);
if (syncedFolderId > 0) {
Expand All @@ -344,8 +335,8 @@ private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {
throw new SQLException("ERROR " + uri);
}
return insertedSyncedFolderUri;

case EXTERNAL_LINKS:
}
case EXTERNAL_LINKS -> {
Uri insertedExternalLinkUri;
long externalLinkId = db.insert(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values);
if (externalLinkId > 0) {
Expand All @@ -355,19 +346,18 @@ private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {
throw new SQLException("ERROR " + uri);
}
return insertedExternalLinkUri;

case VIRTUAL:
}
case VIRTUAL -> {
Uri insertedVirtualUri;
long virtualId = db.insert(ProviderTableMeta.VIRTUAL_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values);

if (virtualId > 0) {
insertedVirtualUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_VIRTUAL, virtualId);
} else {
throw new SQLException("ERROR " + uri);
}

return insertedVirtualUri;
case FILESYSTEM:
}
case FILESYSTEM -> {
Uri insertedFilesystemUri;
long filesystemId = db.insert(ProviderTableMeta.FILESYSTEM_TABLE_NAME, SQLiteDatabase.CONFLICT_REPLACE, values);
if (filesystemId > 0) {
Expand All @@ -377,8 +367,8 @@ private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {
throw new SQLException("ERROR " + uri);
}
return insertedFilesystemUri;
default:
throw new IllegalArgumentException("Unknown uri id: " + uri);
}
default -> throw new IllegalArgumentException("Unknown uri id: " + uri);
}
}

Expand All @@ -387,24 +377,12 @@ private void updateFilesTableAccordingToShareInsertion(SupportSQLiteDatabase db,
ShareType newShareType = ShareType.fromValue(newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE));

switch (newShareType) {
case PUBLIC_LINK:
fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
break;

case USER:
case GROUP:
case EMAIL:
case FEDERATED:
case FEDERATED_GROUP:
case ROOM:
case CIRCLE:
case DECK:
case GUEST:
case PUBLIC_LINK -> fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1);
case USER, GROUP, EMAIL, FEDERATED, FEDERATED_GROUP, ROOM, CIRCLE, DECK, GUEST ->
fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1);
break;

default:
// everything should be handled
default -> {
}
// everything should be handled
}

String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
MainApp.showOnlyFilesOnDevice(false);
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(FileDisplayActivity.LIST_GROUPFOLDERS);
intent.setAction(FileDisplayActivity.LIST_GROUP_FOLDERS);
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
startActivity(intent);
} else {
Expand Down
Loading
Loading