Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2021-04-24 15:03:07 +0300
committerStefan Niedermann <info@niedermann.it>2021-04-24 15:03:07 +0300
commit78555dcfab452ff12529a8fda2b5e9a65c56485d (patch)
tree78c7fc8a7145c9d0d1d6caa39e8314ada7afb939
parentd42638e8efd4552dd3f09d4f4fb6b125f87fd5a4 (diff)
#1170 Remove unnecessary code
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java75
1 files changed, 17 insertions, 58 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
index e0491b07..21c6ab5c 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
@@ -158,12 +158,26 @@ public class NotesRepository {
// Accounts
+ @AnyThread
+ public LiveData<Account> addAccount(@NonNull String url, @NonNull String username, @NonNull String accountName, @NonNull Capabilities capabilities) {
+ return db.getAccountDao().getAccountById$(db.getAccountDao().insert(new Account(url, username, accountName, capabilities)));
+ }
+
+ @WorkerThread
public List<Account> getAccounts() {
return db.getAccountDao().getAccounts();
}
- public int deleteAccount(Account localAccount) {
- return db.getAccountDao().deleteAccount(localAccount);
+ @WorkerThread
+ public void deleteAccount(@NonNull Account account) {
+ try {
+ SSOClient.invalidateAPICache(AccountImporter.getSingleSignOnAccount(context, account.getAccountName()));
+ } catch (NextcloudFilesAppAccountNotFoundException e) {
+ e.printStackTrace();
+ SSOClient.invalidateAPICache();
+ }
+
+ db.getAccountDao().deleteAccount(account);
}
public Account getAccountByName(String accountName) {
@@ -391,7 +405,6 @@ public class NotesRepository {
@NonNull
@WorkerThread
public Map<Long, Long> getIdMap(long accountId) {
- validateAccountId(accountId);
return db.getNoteDao()
.getRemoteIdAndId(accountId)
.stream()
@@ -513,7 +526,7 @@ public class NotesRepository {
}
@AnyThread
- void updateDynamicShortcuts(long accountId) {
+ private void updateDynamicShortcuts(long accountId) {
new Thread(() -> {
if (SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = context.getApplicationContext().getSystemService(ShortcutManager.class);
@@ -546,18 +559,12 @@ public class NotesRepository {
}).start();
}
- @AnyThread
- public LiveData<Account> addAccount(@NonNull String url, @NonNull String username, @NonNull String accountName, @NonNull Capabilities capabilities) {
- return db.getAccountDao().getAccountById$(db.getAccountDao().insert(new Account(url, username, accountName, capabilities)));
- }
-
/**
* @param apiVersion has to be a JSON array as a string <code>["0.2", "1.0", ...]</code>
* @return whether or not the given {@link ApiVersion} has been written to the database
* @throws IllegalArgumentException if the apiVersion does not match the expected format
*/
public boolean updateApiVersion(long accountId, @Nullable String apiVersion) throws IllegalArgumentException {
- validateAccountId(accountId);
if (apiVersion != null) {
try {
JSONArray apiVersions = new JSONArray(apiVersion);
@@ -587,44 +594,6 @@ public class NotesRepository {
}
/**
- * @param localAccount the {@link Account} that should be deleted
- * @throws IllegalArgumentException if no account has been deleted by the given accountId
- */
- @AnyThread
- public LiveData<Void> deleteAccount$(@NonNull Account localAccount) throws IllegalArgumentException {
- validateAccountId(localAccount.getId());
- MutableLiveData<Void> ret = new MutableLiveData<>();
- new Thread(() -> {
- int deletedAccounts = db.getAccountDao().deleteAccount(localAccount);
- if (deletedAccounts < 1) {
- 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 '" + localAccount.getId() + "' deleted unexpectedly '" + deletedAccounts + "' accounts");
- }
-
- try {
- SSOClient.invalidateAPICache(AccountImporter.getSingleSignOnAccount(context, localAccount.getAccountName()));
- } catch (NextcloudFilesAppAccountNotFoundException e) {
- e.printStackTrace();
- SSOClient.invalidateAPICache();
- }
-
- // TODO this should already be handled by foreign key cascade, no?
- final int deletedNotes = db.getNoteDao().deleteByAccountId(localAccount.getId());
- Log.v(TAG, "Deleted " + deletedNotes + " notes from account " + localAccount.getId());
- ret.postValue(null);
- }).start();
- return ret;
- }
-
- private static void validateAccountId(long accountId) {
- if (accountId < 1) {
- throw new IllegalArgumentException("accountId must be greater than 0");
- }
- }
-
- /**
* Modifies the sorting method for one category, the category can be normal category or
* one of "All notes", "Favorite", and "Uncategorized".
* If category is one of these three, sorting method will be modified in android.content.SharedPreference.
@@ -637,8 +606,6 @@ public class NotesRepository {
*/
@AnyThread
public void modifyCategoryOrder(long accountId, @NonNull NavigationCategory selectedCategory, @NonNull CategorySortingMethod sortingMethod) {
- validateAccountId(accountId);
-
new Thread(() -> {
final Context ctx = context.getApplicationContext();
final SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
@@ -726,11 +693,6 @@ public class NotesRepository {
return map(new SharedPreferenceIntLiveData(sp, prefKey, CategorySortingMethod.SORT_MODIFIED_DESC.getId()), CategorySortingMethod::findById);
}
- public Context getContext() {
- return context;
- }
-
-
@Override
protected void finalize() throws Throwable {
context.getApplicationContext().unregisterReceiver(networkReceiver);
@@ -900,13 +862,11 @@ public class NotesRepository {
public void updateNetworkStatus() {
try {
final ConnectivityManager connMgr = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
-
if (connMgr == null) {
throw new NetworkErrorException("ConnectivityManager is null");
}
final NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
-
if (activeInfo == null) {
throw new NetworkErrorException("NetworkInfo is null");
}
@@ -915,7 +875,6 @@ public class NotesRepository {
networkConnected = true;
final NetworkInfo networkInfo = connMgr.getNetworkInfo((ConnectivityManager.TYPE_WIFI));
-
if (networkInfo == null) {
throw new NetworkErrorException("connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI) is null");
}