Merge branch 'master' into support-multiple-api-levels

# Conflicts:
#	app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java
#	app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
This commit is contained in:
Stefan Niedermann 2020-04-16 08:10:25 +02:00
commit 4df11459d5
3 changed files with 20 additions and 9 deletions

View file

@ -261,7 +261,7 @@ public class NotesListViewActivity extends LockedActivity implements ItemAdapter
selectAccount(localAccount.getAccountName());
});
v.findViewById(R.id.delete).setOnClickListener(clickedView -> {
db.deleteAccount(localAccount.getId());
db.deleteAccount(localAccount);
if (localAccount.getId() == this.localAccount.getId()) {
List<LocalAccount> remainingAccounts = db.getAccounts();
if (remainingAccounts.size() > 0) {

View file

@ -6,6 +6,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;
import com.nextcloud.android.sso.aidl.NextcloudRequest;

View file

@ -20,6 +20,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.nextcloud.android.sso.AccountImporter;
import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException;
import com.nextcloud.android.sso.model.SingleSignOnAccount;
import org.json.JSONArray;
@ -793,21 +795,29 @@ public class NotesDatabase extends AbstractNotesDatabase {
}
/**
* @param accountId the id of the account that should be deleted
* @param localAccount the account that should be deleted
* @throws IllegalArgumentException if no account has been deleted by the given accountId
*/
public void deleteAccount(long accountId) throws IllegalArgumentException {
validateAccountId(accountId);
public void deleteAccount(@NonNull LocalAccount localAccount) throws IllegalArgumentException {
validateAccountId(localAccount.getId());
SQLiteDatabase db = this.getWritableDatabase();
int deletedAccounts = db.delete(table_accounts, key_id + " = ?", new String[]{String.valueOf(accountId)});
int deletedAccounts = db.delete(table_accounts, key_id + " = ?", new String[]{String.valueOf(localAccount.getId())});
if (deletedAccounts < 1) {
Log.e(TAG, "AccountId '" + accountId + "' did not delete any account");
Log.e(TAG, "AccountId '" + localAccount.getId() + "' did not delete any account");
throw new IllegalArgumentException("The given accountId does not delete any row");
} else if (deletedAccounts > 1) {
Log.e(TAG, "AccountId '" + accountId + "' deleted unexpectedly '" + deletedAccounts + "' accounts");
Log.e(TAG, "AccountId '" + localAccount.getId() + "' deleted unexpectedly '" + deletedAccounts + "' accounts");
}
final int deletedNotes = db.delete(table_notes, key_account_id + " = ?", new String[]{String.valueOf(accountId)});
Log.v(TAG, "Deleted " + deletedNotes + " notes from account " + accountId);
try {
NotesClient.invalidateAPICache(AccountImporter.getSingleSignOnAccount(getContext(), localAccount.getAccountName()));
} catch (NextcloudFilesAppAccountNotFoundException e) {
e.printStackTrace();
NotesClient.invalidateAPICache();
}
final int deletedNotes = db.delete(table_notes, key_account_id + " = ?", new String[]{String.valueOf(localAccount.getId())});
Log.v(TAG, "Deleted " + deletedNotes + " notes from account " + localAccount.getId());
}
void updateETag(long accountId, String etag) {