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>2020-10-05 17:18:30 +0300
committerStefan Niedermann <info@niedermann.it>2020-10-05 17:18:30 +0300
commitf0b57a2ad8f16cb0e18765b4dea03605f1c7ad13 (patch)
tree1ef297cffaf17b80b5e431c433916b5662f61ad9 /app/src/main/java/it/niedermann/owncloud
parente58623a078a632d8d18d2b903ef5d325330415eb (diff)
#831 Migrate from SQLiteOpenHelper to Room
Fix some build bugs
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java2
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java47
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java14
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java2
4 files changed, 43 insertions, 22 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
index 5e207a9b..da60e366 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java
@@ -436,7 +436,7 @@ public class NoteServerSyncHelper {
private boolean pullRemoteChanges() {
Log.d(TAG, "pullRemoteChanges() for account " + localAccount.getAccountName());
try {
- final Map<Long, Long> idMap = sqliteOpenHelperDatabase.getIdMap(localAccount.getId());
+ final Map<Long, Long> idMap = roomDatabase.getIdMap(localAccount.getId());
final ServerResponse.NotesResponse response = notesClient.getNotes(ssoAccount, localAccount.getModified(), localAccount.getEtag());
List<CloudNote> remoteNotes = response.getNotes();
Set<Long> remoteIDs = new HashSet<>();
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
index 34c50c62..9c9c7563 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesDatabase.java
@@ -160,20 +160,6 @@ public class NotesDatabase extends AbstractNotesDatabase {
);
}
- @NonNull
- @WorkerThread
- public Map<Long, Long> getIdMap(long accountId) {
- validateAccountId(accountId);
- Map<Long, Long> result = new HashMap<>();
- SQLiteDatabase db = getReadableDatabase();
- Cursor cursor = db.query(table_notes, new String[]{key_remote_id, key_id}, key_status + " != ? AND " + key_account_id + " = ? ", new String[]{DBStatus.LOCAL_DELETED.getTitle(), "" + accountId}, null, null, null);
- while (cursor.moveToNext()) {
- result.put(cursor.getLong(0), cursor.getLong(1));
- }
- cursor.close();
- return result;
- }
-
/**
* Returns a list of all Notes in the Database
*
@@ -186,13 +172,6 @@ public class NotesDatabase extends AbstractNotesDatabase {
return getNotesCustom(accountId, key_status + " != ? AND " + key_account_id + " = ?", new String[]{DBStatus.LOCAL_DELETED.getTitle(), "" + accountId}, default_order, false);
}
- @NonNull
- @WorkerThread
- public List<DBNote> getRecentNotes(long accountId) {
- validateAccountId(accountId);
- return getNotesCustom(accountId, key_status + " != ? AND " + key_account_id + " = ?", new String[]{DBStatus.LOCAL_DELETED.getTitle(), "" + accountId}, key_modified + " DESC", "4", true);
- }
-
/**
* This method is overloading searchNotes method.
* In order to keep the original code (called this method) still work.
@@ -511,6 +490,32 @@ public class NotesDatabase extends AbstractNotesDatabase {
return false;
}
+
+ /**
+ * Set the category for a given note.
+ * This method will search in the database to find out the category id in the db.
+ * If there is no such category existing, this method will create it and search again.
+ *
+ * @param ssoAccount The single sign on account
+ * @param note The note which will be updated
+ * @param category The category title which should be used to find the category id.
+ * @param callback When the synchronization is finished, this callback will be invoked (optional).
+ */
+ public void setCategory(SingleSignOnAccount ssoAccount, @NonNull DBNote note, @NonNull String category, @Nullable ISyncCallback callback) {
+ note.setCategory(category);
+ note.setStatus(DBStatus.LOCAL_EDITED);
+ SQLiteDatabase db = this.getWritableDatabase();
+ ContentValues values = new ContentValues(2);
+ values.put(key_status, note.getStatus().getTitle());
+ int id = getCategoryIdByTitle(note.getAccountId(), note.getCategory());
+ values.put(key_category, id);
+ db.update(table_notes, values, key_id + " = ?", new String[]{String.valueOf(note.getId())});
+ removeEmptyCategory(note.getAccountId());
+ if (callback != null) {
+ serverSyncHelper.addCallbackPush(ssoAccount, callback);
+ }
+ serverSyncHelper.scheduleSync(ssoAccount, true);
+ }
/**
* @param localAccount the {@link LocalAccount} that should be deleted
* @throws IllegalArgumentException if no account has been deleted by the given accountId
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java
index d82d8f0b..57f0a56a 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRoomDatabase.java
@@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
+import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Icon;
import android.os.Build;
@@ -25,7 +26,9 @@ import com.nextcloud.android.sso.model.SingleSignOnAccount;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.edit.EditNoteActivity;
@@ -319,4 +322,15 @@ public abstract class NotesRoomDatabase extends RoomDatabase {
}
syncHelper.scheduleSync(ssoAccount, true);
}
+
+ @NonNull
+ @WorkerThread
+ public Map<Long, Long> getIdMap(long accountId) {
+ validateAccountId(accountId);
+ Map<Long, Long> result = new HashMap<>();
+ for(NoteEntity note : getNoteDao().getRemoteIdAndId(accountId)) {
+ result.put(note.getRemoteId(), note.getId());
+ }
+ return result;
+ }
}
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java
index fdd95714..ff387668 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/dao/NoteDao.java
@@ -44,6 +44,8 @@ public interface NoteDao {
@Query("SELECT DISTINCT remoteId FROM NoteEntity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\"")
List<Long> getRemoteIds(long accountId);
+ @Query("SELECT * FROM NoteEntity WHERE accountId = :accountId AND status != \"LOCAL_DELETED\"")
+ List<NoteEntity> getRemoteIdAndId(long accountId);
/**
* Get a single Note by remote Id (aka. nextcloud file id)