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-07-29 19:44:06 +0300
committerStefan Niedermann <info@niedermann.it>2021-07-29 19:44:06 +0300
commit91055e57f390c40274511566fb347289e906b53f (patch)
treed43a721caf8c550944bc7dfa73e238b1359e309e /app/src/main/java/it/niedermann/owncloud/notes/persistence
parent085bb7a94c2c459f356bc95bb20eca255128b092 (diff)
Revert "Make use of Java 10 var keyword"
This reverts commit 085bb7a94c2c459f356bc95bb20eca255128b092.
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/persistence')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java14
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java16
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java8
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java46
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java30
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java6
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_10_11.java12
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_13_14.java10
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_14_15.java16
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_15_16.java12
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java20
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java4
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_22_23.java8
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java4
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/sync/CapabilitiesDeserializer.java10
15 files changed, 108 insertions, 108 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java
index 0d06def4..6b851ddb 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/ApiProvider.java
@@ -60,7 +60,7 @@ public class ApiProvider {
if (API_CACHE_OCS.containsKey(ssoAccount.name)) {
return API_CACHE_OCS.get(ssoAccount.name);
}
- final var ocsAPI = new NextcloudRetrofitApiBuilder(getNextcloudAPI(context, ssoAccount), API_ENDPOINT_OCS).create(OcsAPI.class);
+ final OcsAPI ocsAPI = new NextcloudRetrofitApiBuilder(getNextcloudAPI(context, ssoAccount), API_ENDPOINT_OCS).create(OcsAPI.class);
API_CACHE_OCS.put(ssoAccount.name, ocsAPI);
return ocsAPI;
}
@@ -72,7 +72,7 @@ public class ApiProvider {
if (API_CACHE_NOTES.containsKey(ssoAccount.name)) {
return API_CACHE_NOTES.get(ssoAccount.name);
}
- final var notesAPI = new NotesAPI(getNextcloudAPI(context, ssoAccount), preferredApiVersion);
+ final NotesAPI notesAPI = new NotesAPI(getNextcloudAPI(context, ssoAccount), preferredApiVersion);
API_CACHE_NOTES.put(ssoAccount.name, notesAPI);
return notesAPI;
}
@@ -82,12 +82,12 @@ public class ApiProvider {
return API_CACHE.get(ssoAccount.name);
} else {
Log.v(TAG, "NextcloudRequest account: " + ssoAccount.name);
- final var nextcloudAPI = new NextcloudAPI(context.getApplicationContext(), ssoAccount,
+ final NextcloudAPI nextcloudAPI = new NextcloudAPI(context.getApplicationContext(), ssoAccount,
new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.registerTypeHierarchyAdapter(Calendar.class, (JsonSerializer<Calendar>) (src, typeOfSrc, ctx) -> new JsonPrimitive(src.getTimeInMillis() / 1_000))
.registerTypeHierarchyAdapter(Calendar.class, (JsonDeserializer<Calendar>) (src, typeOfSrc, ctx) -> {
- final var calendar = Calendar.getInstance();
+ final Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(src.getAsLong() * 1_000);
return calendar;
})
@@ -117,7 +117,7 @@ public class ApiProvider {
public synchronized void invalidateAPICache(@NonNull SingleSignOnAccount ssoAccount) {
Log.v(TAG, "Invalidating API cache for " + ssoAccount.name);
if (API_CACHE.containsKey(ssoAccount.name)) {
- final var nextcloudAPI = API_CACHE.get(ssoAccount.name);
+ final NextcloudAPI nextcloudAPI = API_CACHE.get(ssoAccount.name);
if (nextcloudAPI != null) {
nextcloudAPI.stop();
}
@@ -131,10 +131,10 @@ public class ApiProvider {
* Invalidates the whole API cache for all accounts
*/
public synchronized void invalidateAPICache() {
- for (final String key : API_CACHE.keySet()) {
+ for (String key : API_CACHE.keySet()) {
Log.v(TAG, "Invalidating API cache for " + key);
if (API_CACHE.containsKey(key)) {
- final var nextcloudAPI = API_CACHE.get(key);
+ final NextcloudAPI nextcloudAPI = API_CACHE.get(key);
if (nextcloudAPI != null) {
nextcloudAPI.stop();
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java
index bc53af45..33e42382 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesClient.java
@@ -27,11 +27,11 @@ public class CapabilitiesClient {
@WorkerThread
public static Capabilities getCapabilities(@NonNull Context context, @NonNull SingleSignOnAccount ssoAccount, @Nullable String lastETag, @NonNull ApiProvider apiProvider) throws Throwable {
- final var ocsAPI = apiProvider.getOcsAPI(context, ssoAccount);
+ final OcsAPI ocsAPI = apiProvider.getOcsAPI(context, ssoAccount);
try {
- final var response = ocsAPI.getCapabilities(lastETag).blockingSingle();
- final var capabilities = response.getResponse().ocs.data;
- final var headers = response.getHeaders();
+ final ParsedResponse<OcsResponse<Capabilities>> response = ocsAPI.getCapabilities(lastETag).blockingSingle();
+ final Capabilities capabilities = response.getResponse().ocs.data;
+ final Map<String, String> headers = response.getHeaders();
if (headers != null) {
capabilities.setETag(headers.get(HEADER_KEY_ETAG));
} else {
@@ -39,7 +39,7 @@ public class CapabilitiesClient {
}
return capabilities;
} catch (RuntimeException e) {
- final var cause = e.getCause();
+ final Throwable cause = e.getCause();
if (cause != null) {
throw cause;
} else {
@@ -51,11 +51,11 @@ public class CapabilitiesClient {
@WorkerThread
@Nullable
public static String getDisplayName(@NonNull Context context, @NonNull SingleSignOnAccount ssoAccount, @NonNull ApiProvider apiProvider) {
- final var ocsAPI = apiProvider.getOcsAPI(context, ssoAccount);
+ final OcsAPI ocsAPI = apiProvider.getOcsAPI(context, ssoAccount);
try {
- final var userResponse = ocsAPI.getUser(ssoAccount.userId).execute();
+ final Response<OcsResponse<OcsUser>> userResponse = ocsAPI.getUser(ssoAccount.userId).execute();
if (userResponse.isSuccessful()) {
- final var ocsResponse = userResponse.body();
+ final OcsResponse<OcsUser> ocsResponse = userResponse.body();
if (ocsResponse != null) {
return ocsResponse.ocs.data.displayName;
} else {
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java
index b593f86d..4f8852e7 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/CapabilitiesWorker.java
@@ -42,12 +42,12 @@ public class CapabilitiesWorker extends Worker {
@NonNull
@Override
public Result doWork() {
- final var repo = NotesRepository.getInstance(getApplicationContext());
- for (final var account : repo.getAccounts()) {
+ final NotesRepository repo = NotesRepository.getInstance(getApplicationContext());
+ for (Account account : repo.getAccounts()) {
try {
- final var ssoAccount = AccountImporter.getSingleSignOnAccount(getApplicationContext(), account.getAccountName());
+ final SingleSignOnAccount ssoAccount = AccountImporter.getSingleSignOnAccount(getApplicationContext(), account.getAccountName());
Log.i(TAG, "Refreshing capabilities for " + ssoAccount.name);
- final var capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, account.getCapabilitiesETag(), ApiProvider.getInstance());
+ final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, account.getCapabilitiesETag(), ApiProvider.getInstance());
repo.updateCapabilitiesETag(account.getId(), capabilities.getETag());
repo.updateBrand(account.getId(), capabilities.getColor(), capabilities.getTextColor());
repo.updateApiVersion(account.getId(), capabilities.getApiVersion());
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 59eafa05..51eae0dc 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
@@ -155,7 +155,7 @@ public class NotesRepository {
// Registers BroadcastReceiver to track network connection changes.
this.context.registerReceiver(networkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
- final var prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
prefs.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
syncOnlyOnWifi = prefs.getBoolean(syncOnlyOnWifiKey, false);
@@ -167,7 +167,7 @@ public class NotesRepository {
@AnyThread
public void addAccount(@NonNull String url, @NonNull String username, @NonNull String accountName, @NonNull Capabilities capabilities, @Nullable String displayName, @NonNull IResponseCallback<Account> callback) {
- final var createdAccount = db.getAccountDao().getAccountById(db.getAccountDao().insert(new Account(url, username, accountName, displayName, capabilities)));
+ final Account createdAccount = db.getAccountDao().getAccountById(db.getAccountDao().insert(new Account(url, username, accountName, displayName, capabilities)));
if (createdAccount == null) {
callback.onError(new Exception("Could not read created account."));
} else {
@@ -377,8 +377,8 @@ public class NotesRepository {
@NonNull
@MainThread
public LiveData<Note> addNoteAndSync(Account account, Note note) {
- final var entity = new Note(0, null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), note.getETag(), DBStatus.LOCAL_EDITED, account.getId(), generateNoteExcerpt(note.getContent(), note.getTitle()), 0);
- final var ret = new MutableLiveData<Note>();
+ final Note entity = new Note(0, null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), note.getETag(), DBStatus.LOCAL_EDITED, account.getId(), generateNoteExcerpt(note.getContent(), note.getTitle()), 0);
+ final MutableLiveData<Note> ret = new MutableLiveData<>();
executor.submit(() -> ret.postValue(addNote(account.getId(), entity)));
return map(ret, newNote -> {
notifyWidgets();
@@ -406,7 +406,7 @@ public class NotesRepository {
@MainThread
public LiveData<Note> moveNoteToAnotherAccount(Account account, @NonNull Note note) {
- final var fullNote = new Note(null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null);
+ final Note fullNote = new Note(null, note.getModified(), note.getTitle(), note.getContent(), note.getCategory(), note.getFavorite(), null);
deleteNoteAndSync(account, note.getId());
return map(addNoteAndSync(account, fullNote), (createdNote) -> {
db.getNoteDao().updateStatus(createdNote.getId(), DBStatus.LOCAL_EDITED);
@@ -518,10 +518,10 @@ public class NotesRepository {
scheduleSync(account, true);
if (SDK_INT >= O) {
- final var shortcutManager = context.getSystemService(ShortcutManager.class);
+ ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
shortcutManager.getPinnedShortcuts().forEach((shortcut) -> {
- final String shortcutId = String.valueOf(id);
+ String shortcutId = id + "";
if (shortcut.getId().equals(shortcutId)) {
Log.v(TAG, "Removing shortcut for " + shortcutId);
shortcutManager.disableShortcuts(Collections.singletonList(shortcutId), context.getResources().getString(R.string.note_has_been_deleted));
@@ -549,14 +549,14 @@ public class NotesRepository {
private void updateDynamicShortcuts(long accountId) {
executor.submit(() -> {
if (SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
- final var shortcutManager = this.context.getSystemService(ShortcutManager.class);
+ final ShortcutManager shortcutManager = this.context.getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
if (!shortcutManager.isRateLimitingActive()) {
- var newShortcuts = new ArrayList<ShortcutInfo>();
+ List<ShortcutInfo> newShortcuts = new ArrayList<>();
- for (final var note : db.getNoteDao().getRecentNotes(accountId)) {
+ for (Note note : db.getNoteDao().getRecentNotes(accountId)) {
if (!TextUtils.isEmpty(note.getTitle())) {
- final var intent = new Intent(this.context, EditNoteActivity.class);
+ Intent intent = new Intent(this.context, EditNoteActivity.class);
intent.putExtra(EditNoteActivity.PARAM_NOTE_ID, note.getId());
intent.setAction(ACTION_SHORTCUT);
@@ -583,7 +583,7 @@ public class NotesRepository {
* @param raw has to be a JSON array as a string <code>["0.2", "1.0", ...]</code>
*/
public void updateApiVersion(long accountId, @Nullable String raw) {
- final var apiVersions = ApiVersionUtil.parse(raw);
+ final Collection<ApiVersion> apiVersions = ApiVersionUtil.parse(raw);
if (apiVersions.size() > 0) {
final int updatedRows = db.getAccountDao().updateApiVersion(accountId, ApiVersionUtil.serialize(apiVersions));
if (updatedRows == 0) {
@@ -613,8 +613,8 @@ public class NotesRepository {
@AnyThread
public void modifyCategoryOrder(long accountId, @NonNull NavigationCategory selectedCategory, @NonNull CategorySortingMethod sortingMethod) {
executor.submit(() -> {
- final var ctx = context.getApplicationContext();
- final var sp = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
+ final Context ctx = context.getApplicationContext();
+ final SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
int orderIndex = sortingMethod.getId();
switch (selectedCategory.getType()) {
@@ -636,7 +636,7 @@ public class NotesRepository {
if (category != null) {
if (db.getCategoryOptionsDao().modifyCategoryOrder(accountId, category, sortingMethod) == 0) {
// Nothing updated means we didn't have this yet
- final var categoryOptions = new CategoryOptions();
+ final CategoryOptions categoryOptions = new CategoryOptions();
categoryOptions.setAccountId(accountId);
categoryOptions.setCategory(category);
categoryOptions.setSortingMethod(sortingMethod);
@@ -667,7 +667,7 @@ public class NotesRepository {
@NonNull
@MainThread
public LiveData<CategorySortingMethod> getCategoryOrder(@NonNull NavigationCategory selectedCategory) {
- final var sp = PreferenceManager.getDefaultSharedPreferences(context);
+ final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String prefKey;
switch (selectedCategory.getType()) {
@@ -838,9 +838,9 @@ public class NotesRepository {
Log.d(TAG, "... scheduled");
syncScheduled.put(account.getId(), true);
if (callbacksPush.containsKey(account.getId()) && callbacksPush.get(account.getId()) != null) {
- final var callbacks = callbacksPush.get(account.getId());
+ final List<ISyncCallback> callbacks = callbacksPush.get(account.getId());
if (callbacks != null) {
- for (final var callback : callbacks) {
+ for (ISyncCallback callback : callbacks) {
callback.onScheduled();
}
} else {
@@ -850,9 +850,9 @@ public class NotesRepository {
} else {
Log.d(TAG, "... do nothing");
if (callbacksPush.containsKey(account.getId()) && callbacksPush.get(account.getId()) != null) {
- final var callbacks = callbacksPush.get(account.getId());
+ final List<ISyncCallback> callbacks = callbacksPush.get(account.getId());
if (callbacks != null) {
- for (final var callback : callbacks) {
+ for (ISyncCallback callback : callbacks) {
callback.onScheduled();
}
} else {
@@ -865,12 +865,12 @@ public class NotesRepository {
public void updateNetworkStatus() {
try {
- final var connMgr = (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ final ConnectivityManager connMgr = (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connMgr == null) {
throw new NetworkErrorException("ConnectivityManager is null");
}
- final var activeInfo = connMgr.getActiveNetworkInfo();
+ final NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
if (activeInfo == null) {
throw new NetworkErrorException("NetworkInfo is null");
}
@@ -878,7 +878,7 @@ public class NotesRepository {
if (activeInfo.isConnected()) {
networkConnected = true;
- final var networkInfo = connMgr.getNetworkInfo((ConnectivityManager.TYPE_WIFI));
+ final NetworkInfo networkInfo = connMgr.getNetworkInfo((ConnectivityManager.TYPE_WIFI));
if (networkInfo == null) {
throw new NetworkErrorException("connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI) is null");
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java
index f50dd21e..a7df68bd 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesServerSyncTask.java
@@ -90,7 +90,7 @@ abstract class NotesServerSyncTask extends Thread {
Log.i(TAG, "STARTING SYNCHRONIZATION");
- final var status = new SyncResultStatus();
+ final SyncResultStatus status = new SyncResultStatus();
status.pushSuccessful = pushLocalChanges();
if (!onlyLocalChanges) {
status.pullSuccessful = pullRemoteChanges();
@@ -112,7 +112,7 @@ abstract class NotesServerSyncTask extends Thread {
Log.d(TAG, "pushLocalChanges()");
boolean success = true;
- final var notes = repo.getLocalModifiedNotes(localAccount.getId());
+ final List<Note> notes = repo.getLocalModifiedNotes(localAccount.getId());
for (Note note : notes) {
Log.d(TAG, " Process Local Note: " + (BuildConfig.DEBUG ? note : note.getTitle()));
try {
@@ -122,7 +122,7 @@ abstract class NotesServerSyncTask extends Thread {
Log.v(TAG, " ...create/edit");
if (note.getRemoteId() != null) {
Log.v(TAG, " ...Note has remoteId → try to edit");
- final var editResponse = notesAPI.editNote(note).execute();
+ final Response<Note> editResponse = notesAPI.editNote(note).execute();
if (editResponse.isSuccessful()) {
remoteNote = editResponse.body();
if (remoteNote == null) {
@@ -131,7 +131,7 @@ abstract class NotesServerSyncTask extends Thread {
}
} else if (editResponse.code() == HTTP_NOT_FOUND) {
Log.v(TAG, " ...Note does no longer exist on server → recreate");
- final var createResponse = notesAPI.createNote(note).execute();
+ final Response<Note> createResponse = notesAPI.createNote(note).execute();
if (createResponse.isSuccessful()) {
remoteNote = createResponse.body();
if (remoteNote == null) {
@@ -146,7 +146,7 @@ abstract class NotesServerSyncTask extends Thread {
}
} else {
Log.v(TAG, " ...Note does not have a remoteId yet → create");
- final var createResponse = notesAPI.createNote(note).execute();
+ final Response<Note> createResponse = notesAPI.createNote(note).execute();
if (createResponse.isSuccessful()) {
remoteNote = createResponse.body();
if (remoteNote == null) {
@@ -166,7 +166,7 @@ abstract class NotesServerSyncTask extends Thread {
Log.v(TAG, " ...delete (only local, since it has never been synchronized)");
} else {
Log.v(TAG, " ...delete (from server and local)");
- final var deleteResponse = notesAPI.deleteNote(note.getRemoteId()).execute();
+ final Response<Void> deleteResponse = notesAPI.deleteNote(note.getRemoteId()).execute();
if (!deleteResponse.isSuccessful()) {
if (deleteResponse.code() == HTTP_NOT_FOUND) {
Log.v(TAG, " ...delete (note has already been deleted remotely)");
@@ -205,10 +205,10 @@ abstract class NotesServerSyncTask extends Thread {
private boolean pullRemoteChanges() {
Log.d(TAG, "pullRemoteChanges() for account " + localAccount.getAccountName());
try {
- final var idMap = repo.getIdMap(localAccount.getId());
+ final Map<Long, Long> idMap = repo.getIdMap(localAccount.getId());
// FIXME re-reading the localAccount is only a workaround for a not-up-to-date eTag in localAccount.
- final var accountFromDatabase = repo.getAccountById(localAccount.getId());
+ final Account accountFromDatabase = repo.getAccountById(localAccount.getId());
if (accountFromDatabase == null) {
callbacks.remove(localAccount.getId());
return true;
@@ -216,18 +216,18 @@ abstract class NotesServerSyncTask extends Thread {
localAccount.setModified(accountFromDatabase.getModified());
localAccount.setETag(accountFromDatabase.getETag());
- final var fetchResponse = notesAPI.getNotes(localAccount.getModified(), localAccount.getETag()).blockingSingle();
- final var remoteNotes = fetchResponse.getResponse();
- final var remoteIDs = new HashSet<Long>();
+ final ParsedResponse<List<Note>> fetchResponse = notesAPI.getNotes(localAccount.getModified(), localAccount.getETag()).blockingSingle();
+ final List<Note> remoteNotes = fetchResponse.getResponse();
+ final Set<Long> remoteIDs = new HashSet<>();
// pull remote changes: update or create each remote note
- for (final var remoteNote : remoteNotes) {
+ for (Note remoteNote : remoteNotes) {
Log.v(TAG, " Process Remote Note: " + (BuildConfig.DEBUG ? remoteNote : remoteNote.getTitle()));
remoteIDs.add(remoteNote.getRemoteId());
if (remoteNote.getModified() == null) {
Log.v(TAG, " ... unchanged");
} else if (idMap.containsKey(remoteNote.getRemoteId())) {
Log.v(TAG, " ... found → Update");
- final Long localId = idMap.get(remoteNote.getRemoteId());
+ Long localId = idMap.get(remoteNote.getRemoteId());
if (localId != null) {
repo.updateIfNotModifiedLocallyAndAnyRemoteColumnHasChanged(
localId, remoteNote.getModified().getTimeInMillis(), remoteNote.getTitle(), remoteNote.getFavorite(), remoteNote.getCategory(), remoteNote.getETag(), remoteNote.getContent(), generateNoteExcerpt(remoteNote.getContent(), remoteNote.getTitle()));
@@ -241,7 +241,7 @@ abstract class NotesServerSyncTask extends Thread {
}
Log.d(TAG, " Remove remotely deleted Notes (only those without local changes)");
// remove remotely deleted notes (only those without local changes)
- for (final var entry : idMap.entrySet()) {
+ for (Map.Entry<Long, Long> entry : idMap.entrySet()) {
if (!remoteIDs.contains(entry.getKey())) {
Log.v(TAG, " ... remove " + entry.getValue());
repo.deleteByNoteId(entry.getValue(), DBStatus.VOID);
@@ -251,7 +251,7 @@ abstract class NotesServerSyncTask extends Thread {
// update ETag and Last-Modified in order to reduce size of next response
localAccount.setETag(fetchResponse.getHeaders().get(HEADER_KEY_ETAG));
- final var lastModified = Calendar.getInstance();
+ final Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(0);
final String lastModifiedHeader = fetchResponse.getHeaders().get(HEADER_KEY_LAST_MODIFIED);
if (lastModifiedHeader != null)
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java
index ab2a90f6..adb7eff0 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/SyncWorker.java
@@ -33,8 +33,8 @@ public class SyncWorker extends Worker {
@NonNull
@Override
public Result doWork() {
- final var repo = NotesRepository.getInstance(getApplicationContext());
- for (final var account : repo.getAccounts()) {
+ NotesRepository repo = NotesRepository.getInstance(getApplicationContext());
+ for (Account account : repo.getAccounts()) {
Log.v(TAG, "Starting background synchronization for " + account.getAccountName());
repo.addCallbackPull(account, () -> Log.v(TAG, "Finished background synchronization for " + account.getAccountName()));
repo.scheduleSync(account, false);
@@ -53,7 +53,7 @@ public class SyncWorker extends Worker {
public static void update(@NonNull Context context, boolean backgroundSync) {
deregister(context);
if (backgroundSync) {
- final var work = new PeriodicWorkRequest.Builder(SyncWorker.class, 15, TimeUnit.MINUTES)
+ PeriodicWorkRequest work = new PeriodicWorkRequest.Builder(SyncWorker.class, 15, TimeUnit.MINUTES)
.setConstraints(constraints).build();
WorkManager.getInstance(context.getApplicationContext()).enqueueUniquePeriodicWork(WORKER_TAG, ExistingPeriodicWorkPolicy.REPLACE, work);
Log.i(TAG, "Registering worker running each " + 15 + " " + TimeUnit.MINUTES);
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_10_11.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_10_11.java
index 84ef2105..5a739b7d 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_10_11.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_10_11.java
@@ -26,14 +26,14 @@ public class Migration_10_11 extends Migration {
*/
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
- final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
- final var editor = sharedPreferences.edit();
- final var prefs = sharedPreferences.getAll();
- for (final var pref : prefs.entrySet()) {
- final String key = pref.getKey();
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ Map<String, ?> prefs = sharedPreferences.getAll();
+ for (Map.Entry<String, ?> pref : prefs.entrySet()) {
+ String key = pref.getKey();
final String DARK_THEME_KEY = "NLW_darkTheme";
if ("darkTheme".equals(key) || key.startsWith(DARK_THEME_KEY) || key.startsWith("SNW_darkTheme")) {
- final Boolean darkTheme = (Boolean) pref.getValue();
+ Boolean darkTheme = (Boolean) pref.getValue();
editor.putString(pref.getKey(), darkTheme ? DarkModeSetting.DARK.name() : DarkModeSetting.LIGHT.name());
}
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_13_14.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_13_14.java
index 805204f6..3d0147fb 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_13_14.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_13_14.java
@@ -47,10 +47,10 @@ public class Migration_13_14 extends Migration {
final String SP_WIDGET_KEY = "single_note_widget";
final String SP_ACCOUNT_ID_KEY = "SNW_accountId";
final String SP_DARK_THEME_KEY = "SNW_darkTheme";
- final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
- final var editor = sharedPreferences.edit();
- final var prefs = sharedPreferences.getAll();
- for (final var pref : prefs.entrySet()) {
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ Map<String, ?> prefs = sharedPreferences.getAll();
+ for (Map.Entry<String, ?> pref : prefs.entrySet()) {
final String key = pref.getKey();
Integer widgetId = null;
Long noteId = null;
@@ -69,7 +69,7 @@ public class Migration_13_14 extends Migration {
themeMode = sharedPreferences.getBoolean(SP_DARK_THEME_KEY + widgetId, false) ? DarkModeSetting.DARK.getModeId() : DarkModeSetting.LIGHT.getModeId();
}
- final var migratedWidgetValues = new ContentValues();
+ ContentValues migratedWidgetValues = new ContentValues();
migratedWidgetValues.put("ID", widgetId);
migratedWidgetValues.put("ACCOUNT_ID", accountId);
migratedWidgetValues.put("NOTE_ID", noteId);
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_14_15.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_14_15.java
index bda4d046..a66fc0e9 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_14_15.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_14_15.java
@@ -27,7 +27,7 @@ public class Migration_14_15 extends Migration {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
// Rename a tmp_NOTES table.
- final String tmpTableNotes = String.format("tmp_%s", "NOTES");
+ String tmpTableNotes = String.format("tmp_%s", "NOTES");
db.execSQL("ALTER TABLE NOTES RENAME TO " + tmpTableNotes);
db.execSQL("CREATE TABLE NOTES ( " +
"ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
@@ -53,14 +53,14 @@ public class Migration_14_15 extends Migration {
createIndex(db, "CATEGORIES", "CATEGORY_ID", "CATEGORY_ACCOUNT_ID", "CATEGORY_TITLE");
// A hashtable storing categoryTitle - categoryId Mapping
// This is used to prevent too many searches in database
- final var categoryTitleIdMap = new Hashtable<String, Integer>();
+ Hashtable<String, Integer> categoryTitleIdMap = new Hashtable<>();
int id = 1;
- final var tmpNotesCursor = db.query("SELECT * FROM " + tmpTableNotes, null);
+ Cursor tmpNotesCursor = db.query("SELECT * FROM " + tmpTableNotes, null);
while (tmpNotesCursor.moveToNext()) {
- final String categoryTitle = tmpNotesCursor.getString(8);
- final int accountId = tmpNotesCursor.getInt(2);
+ String categoryTitle = tmpNotesCursor.getString(8);
+ int accountId = tmpNotesCursor.getInt(2);
Log.e("###", accountId + "");
- final Integer categoryId;
+ Integer categoryId;
if (categoryTitleIdMap.containsKey(categoryTitle) && categoryTitleIdMap.get(categoryTitle) != null) {
categoryId = categoryTitleIdMap.get(categoryTitle);
} else {
@@ -74,7 +74,7 @@ public class Migration_14_15 extends Migration {
categoryTitleIdMap.put(categoryTitle, categoryId);
}
// Move the data in tmp_NOTES to NOTES
- final ContentValues values = new ContentValues();
+ ContentValues values = new ContentValues();
values.put("ID", tmpNotesCursor.getInt(0));
values.put("REMOTEID", tmpNotesCursor.getInt(1));
values.put("ACCOUNT_ID", tmpNotesCursor.getInt(2));
@@ -99,7 +99,7 @@ public class Migration_14_15 extends Migration {
}
private static void createIndex(@NonNull SupportSQLiteDatabase db, @NonNull String table, @NonNull String column) {
- final String indexName = table + "_" + column + "_idx";
+ String indexName = table + "_" + column + "_idx";
Log.v(TAG, "Creating database index: CREATE INDEX IF NOT EXISTS " + indexName + " ON " + table + "(" + column + ")");
db.execSQL("CREATE INDEX " + indexName + " ON " + table + "(" + column + ")");
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_15_16.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_15_16.java
index 7be78511..48b7195b 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_15_16.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_15_16.java
@@ -51,10 +51,10 @@ public class Migration_15_16 extends Migration {
final String SP_DARK_THEME_KEY = "NLW_darkTheme";
final String SP_CATEGORY_KEY = "NLW_cat";
- final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
- final var editor = sharedPreferences.edit();
- final var prefs = sharedPreferences.getAll();
- for (final var pref : prefs.entrySet()) {
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ Map<String, ?> prefs = sharedPreferences.getAll();
+ for (Map.Entry<String, ?> pref : prefs.entrySet()) {
final String key = pref.getKey();
Integer widgetId = null;
Integer mode = null;
@@ -76,7 +76,7 @@ public class Migration_15_16 extends Migration {
if (mode == 2) {
final String categoryTitle = sharedPreferences.getString(SP_CATEGORY_KEY + widgetId, null);
- final var cursor = db.query("SELECT CATEGORY_ID FROM CATEGORIES WHERE CATEGORY_TITLE = ? AND CATEGORY_ACCOUNT_ID = ?", new String[]{categoryTitle, String.valueOf(accountId)});
+ Cursor cursor = db.query("SELECT CATEGORY_ID FROM CATEGORIES WHERE CATEGORY_TITLE = ? AND CATEGORY_ACCOUNT_ID = ?", new String[]{categoryTitle, String.valueOf(accountId)});
if (cursor.moveToNext()) {
categoryId = cursor.getInt(0);
} else {
@@ -85,7 +85,7 @@ public class Migration_15_16 extends Migration {
cursor.close();
}
- final var migratedWidgetValues = new ContentValues();
+ ContentValues migratedWidgetValues = new ContentValues();
migratedWidgetValues.put("ID", widgetId);
migratedWidgetValues.put("ACCOUNT_ID", accountId);
migratedWidgetValues.put("CATEGORY_ID", categoryId);
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java
index 32ede8b1..d9ed2041 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_20_21.java
@@ -90,8 +90,8 @@ public final class Migration_20_21 extends Migration {
}
private static void migrateAccounts(@NonNull SupportSQLiteDatabase db) {
- final var cursor = db.query("SELECT * FROM ACCOUNTS", null);
- final var values = new ContentValues(10);
+ final Cursor cursor = db.query("SELECT * FROM ACCOUNTS", null);
+ final ContentValues values = new ContentValues(10);
final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
final int COLUMN_POSITION_URL = cursor.getColumnIndex("URL");
@@ -131,8 +131,8 @@ public final class Migration_20_21 extends Migration {
}
private static void migrateCategories(@NonNull SupportSQLiteDatabase db) {
- final var cursor = db.query("SELECT * FROM CATEGORIES", null);
- final var values = new ContentValues(3);
+ final Cursor cursor = db.query("SELECT * FROM CATEGORIES", null);
+ final ContentValues values = new ContentValues(3);
final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("CATEGORY_ACCOUNT_ID");
final int COLUMN_POSITION_TITLE = cursor.getColumnIndex("CATEGORY_TITLE");
@@ -148,8 +148,8 @@ public final class Migration_20_21 extends Migration {
}
private static void migrateNotes(@NonNull SupportSQLiteDatabase db) {
- final var cursor = db.query("SELECT NOTES.*, CATEGORIES.category_title as `CAT_TITLE` FROM NOTES LEFT JOIN CATEGORIES ON NOTES.category = CATEGORIES.category_id", null);
- final var values = new ContentValues(12);
+ final Cursor cursor = db.query("SELECT NOTES.*, CATEGORIES.category_title as `CAT_TITLE` FROM NOTES LEFT JOIN CATEGORIES ON NOTES.category = CATEGORIES.category_id", null);
+ final ContentValues values = new ContentValues(12);
final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
final int COLUMN_POSITION_REMOTEID = cursor.getColumnIndex("REMOTEID");
@@ -183,8 +183,8 @@ public final class Migration_20_21 extends Migration {
}
private static void migrateNotesListWidgets(@NonNull SupportSQLiteDatabase db) {
- final var cursor = db.query("SELECT WIDGET_NOTE_LISTS.*, CATEGORIES.category_title as `CATEGORY` FROM WIDGET_NOTE_LISTS LEFT JOIN CATEGORIES ON WIDGET_NOTE_LISTS.CATEGORY_ID = CATEGORIES.category_id", null);
- final var values = new ContentValues(5);
+ final Cursor cursor = db.query("SELECT WIDGET_NOTE_LISTS.*, CATEGORIES.category_title as `CATEGORY` FROM WIDGET_NOTE_LISTS LEFT JOIN CATEGORIES ON WIDGET_NOTE_LISTS.CATEGORY_ID = CATEGORIES.category_id", null);
+ final ContentValues values = new ContentValues(5);
final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("ACCOUNT_ID");
@@ -204,8 +204,8 @@ public final class Migration_20_21 extends Migration {
}
private static void migrateSingleNotesWidgets(@NonNull SupportSQLiteDatabase db) {
- final var cursor = db.query("SELECT * FROM WIDGET_SINGLE_NOTES", null);
- final var values = new ContentValues(4);
+ final Cursor cursor = db.query("SELECT * FROM WIDGET_SINGLE_NOTES", null);
+ final ContentValues values = new ContentValues(4);
final int COLUMN_POSITION_ID = cursor.getColumnIndex("ID");
final int COLUMN_POSITION_ACCOUNT_ID = cursor.getColumnIndex("ACCOUNT_ID");
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java
index c076d38e..f4413bba 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java
@@ -25,8 +25,8 @@ public class Migration_21_22 extends Migration {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
- final var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
- final var editor = sharedPreferences.edit();
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
if (sharedPreferences.contains("backgroundSync")) {
editor.remove("backgroundSync");
if (sharedPreferences.getString("backgroundSync", "").equals("off")) {
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_22_23.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_22_23.java
index 1ba08a3c..b6a7494b 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_22_23.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_22_23.java
@@ -46,8 +46,8 @@ public class Migration_22_23 extends Migration {
}
private static void sanitizeAccounts(@NonNull SupportSQLiteDatabase db) {
- final var cursor = db.query("SELECT id, apiVersion FROM ACCOUNT", null);
- final var values = new ContentValues(1);
+ final Cursor cursor = db.query("SELECT id, apiVersion FROM ACCOUNT", null);
+ final ContentValues values = new ContentValues(1);
final int COLUMN_POSITION_ID = cursor.getColumnIndex("id");
final int COLUMN_POSITION_API_VERSION = cursor.getColumnIndex("apiVersion");
@@ -77,10 +77,10 @@ public class Migration_22_23 extends Migration {
}
}
- final var result = new ArrayList<ApiVersion>();
+ final Collection<ApiVersion> result = new ArrayList<>();
for (int i = 0; i < a.length(); i++) {
try {
- final var version = ApiVersion.of(a.getString(i));
+ final ApiVersion version = ApiVersion.of(a.getString(i));
if (version.getMajor() != 0 || version.getMinor() != 0) {
result.add(version);
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java
index 9b4b328f..7cdab8c0 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_9_10.java
@@ -24,9 +24,9 @@ public class Migration_9_10 extends Migration {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
db.execSQL("ALTER TABLE NOTES ADD COLUMN EXCERPT INTEGER NOT NULL DEFAULT ''");
- final var cursor = db.query("NOTES", new String[]{"ID", "CONTENT", "TITLE"});
+ Cursor cursor = db.query("NOTES", new String[]{"ID", "CONTENT", "TITLE"});
while (cursor.moveToNext()) {
- final var values = new ContentValues();
+ ContentValues values = new ContentValues();
values.put("EXCERPT", NoteUtil.generateNoteExcerpt(cursor.getString(1), cursor.getString(2)));
db.update("NOTES", OnConflictStrategy.REPLACE, values, "ID" + " = ? ", new String[]{cursor.getString(0)});
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/sync/CapabilitiesDeserializer.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/sync/CapabilitiesDeserializer.java
index d5ae7b49..141443e3 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/sync/CapabilitiesDeserializer.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/sync/CapabilitiesDeserializer.java
@@ -34,18 +34,18 @@ public class CapabilitiesDeserializer implements JsonDeserializer<Capabilities>
@Override
public Capabilities deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
- final var response = new Capabilities();
- final var data = json.getAsJsonObject();
+ final Capabilities response = new Capabilities();
+ final JsonObject data = json.getAsJsonObject();
if (data.has(CAPABILITIES)) {
- final var capabilities = data.getAsJsonObject(CAPABILITIES);
+ final JsonObject capabilities = data.getAsJsonObject(CAPABILITIES);
if (capabilities.has(CAPABILITIES_NOTES)) {
- final var notes = capabilities.getAsJsonObject(CAPABILITIES_NOTES);
+ final JsonObject notes = capabilities.getAsJsonObject(CAPABILITIES_NOTES);
if (notes.has(CAPABILITIES_NOTES_API_VERSION)) {
response.setApiVersion(notes.get(CAPABILITIES_NOTES_API_VERSION).toString());
}
}
if (capabilities.has(CAPABILITIES_THEMING)) {
- final var theming = capabilities.getAsJsonObject(CAPABILITIES_THEMING);
+ final JsonObject theming = capabilities.getAsJsonObject(CAPABILITIES_THEMING);
if (theming.has(CAPABILITIES_THEMING_COLOR)) {
try {
response.setColor(Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(theming.get(CAPABILITIES_THEMING_COLOR).getAsString())));