Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
amberin committed Aug 31, 2024
1 parent b85be02 commit 97e2fb5
Show file tree
Hide file tree
Showing 21 changed files with 686 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testRepoAndShelfSetup() throws IOException {
testUtils.setupBook("local-book-1", "");

assertEquals("Local books", 1, dataRepository.getBooks().size());
assertEquals("Remote books", 3, SyncUtils.getBooksFromAllRepos(dataRepository, null).size());
assertEquals("Remote books", 3, SyncUtils.getBooksFromNonIntegrallySyncedRepos(dataRepository, null).size());
}

@Test
Expand All @@ -61,7 +61,7 @@ public void testLoadRook() throws IOException {
testUtils.setupRook(repo, "mock://repo-a/remote-book-2.org", "", "1abcdef", 1300067156000L);
testUtils.setupRook(repo, "mock://repo-a/remote-book-3.org", "", "2abcdef", 1200067156000L);

VersionedRook vrook = SyncUtils.getBooksFromAllRepos(dataRepository, null).get(0);
VersionedRook vrook = SyncUtils.getBooksFromNonIntegrallySyncedRepos(dataRepository, null).get(0);

dataRepository.loadBookFromRepo(vrook);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void testGetBooksFromAllRepos() throws IOException {
Repo repo = testUtils.setupRepo(RepoType.MOCK, "mock://repo-a");
testUtils.setupRook(repo, "mock://repo-a/mock-book.org", "book content\n\n* First note\n** Second note", "rev1", 1234567890000L);

List<VersionedRook> books = SyncUtils.getBooksFromAllRepos(dataRepository, null);
List<VersionedRook> books = SyncUtils.getBooksFromNonIntegrallySyncedRepos(dataRepository, null);

assertEquals(1, books.size());

Expand Down Expand Up @@ -78,7 +78,7 @@ public void testRetrievingBook() throws IOException {
testUtils.setupRook(repo, "mock://repo-a/mock-book.org", "book content\n\n* First note\n** Second note", "rev1", 1234567890000L);

SyncRepo syncRepo = testUtils.repoInstance(RepoType.MOCK, "mock://repo-a");
VersionedRook vrook = SyncUtils.getBooksFromAllRepos(dataRepository, null).get(0);
VersionedRook vrook = SyncUtils.getBooksFromNonIntegrallySyncedRepos(dataRepository, null).get(0);

File tmpFile = dataRepository.getTempBookFile();
try {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/orgzly/android/BookName.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public static String lastPathSegment(String name, BookFormat format) {
}
}

public static String getNameFromUris(Uri repoUri, Uri fileUri) {
return fromRepoRelativePath(getRepoRelativePath(repoUri, fileUri)).getName();
}

public static BookName fromRepoRelativePath(String repoRelativePath) {
if (repoRelativePath != null) {
Matcher m = PATTERN.matcher(repoRelativePath);
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/orgzly/android/NotesOrgExporter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.orgzly.android

import android.util.Log
import com.orgzly.R
import com.orgzly.android.data.DataRepository
import com.orgzly.android.data.mappers.OrgMapper
Expand Down
49 changes: 48 additions & 1 deletion app/src/main/java/com/orgzly/android/data/DataRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,26 @@ class DataRepository @Inject constructor(
}
}

fun getBookViewsWithoutLink(): List<BookView> {
return db.bookView().getWithoutLink()
}
fun getBooksWithError(): List<Book> {
return db.book().getWithActionType(BookAction.Type.ERROR)
}

fun getModifiedBooksLinkedToRepo(repoId: Long): List<Book> {
val allModifiedBooks = db.book().getAllModified()
return allModifiedBooks.filter { book ->
getBookView(book.id)?.linkRepo?.id == repoId
}
}

fun getBooksLinkedToRepo(repoId: Long): List<Book> {
return db.book().getAll().filter {book ->
getBookView(book.id)?.linkRepo?.id == repoId
}
}

fun getBookView(name: String): BookView? {
return db.bookView().get(name)
}
Expand Down Expand Up @@ -448,6 +464,10 @@ class DataRepository @Inject constructor(
db.bookSync().delete(bookId)
}

fun setBookIsNotModified(bookId: Long) {
db.book().setIsNotModified(setOf(bookId))
}

private fun updateBookIsModified(bookId: Long, isModified: Boolean, time: Long = System.currentTimeMillis()) {
updateBookIsModified(setOf(bookId), isModified, time)
}
Expand Down Expand Up @@ -2337,15 +2357,42 @@ class DataRepository @Inject constructor(
}
}

fun getSyncRepos(): List<SyncRepo> {
fun getNonIntegrallySyncedRepos(): List<SyncRepo> {
val list = ArrayList<SyncRepo>()
for ((id, type, url) in getRepos()) {
if (type.isIntegrallySynced())
continue
try {
list.add(getRepoInstance(id, type, url))
} catch (e: Exception) {
e.printStackTrace()
}
}
return list
}

fun getIntegrallySyncedRepos(): List<SyncRepo> {
val list = ArrayList<SyncRepo>()
for ((id, type, url) in getRepos()) {
if (!type.isIntegrallySynced())
continue
try {
list.add(getRepoInstance(id, type, url))
} catch (e: Exception) {
e.printStackTrace()
}
}
return list
}

fun getAllSyncRepos(): List<SyncRepo> {
val list = ArrayList<SyncRepo>()
for ((id, type, url) in getRepos()) {
try {
list.add(getRepoInstance(id, type, url))
} catch (e: Exception) {
e.printStackTrace()
}
}
return list
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/orgzly/android/db/dao/BookDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ abstract class BookDao : BaseDao<Book> {
@Query("SELECT * FROM books WHERE last_action_type = :type")
abstract fun getWithActionType(type: BookAction.Type): List<Book>

@Query("SELECT * FROM books WHERE is_modified = 1")
abstract fun getAllModified(): List<Book>

@Query("SELECT * FROM books")
abstract fun getAll(): List<Book>

@Insert
abstract fun insertBooks(vararg books: Book): LongArray

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/orgzly/android/db/dao/BookViewDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ abstract class BookViewDao {
@Query("$QUERY WHERE books.name = :name GROUP BY books.id")
abstract fun get(name: String): BookView?

@Query("$QUERY WHERE link_repo_id IS NULL GROUP BY books.id")
abstract fun getWithoutLink(): List<BookView>

@Query("$QUERY GROUP BY books.id ORDER BY $ORDER_BY_NAME")
abstract fun getAllFOrderByNameLiveData(): LiveData<List<BookView>>

Expand Down
Loading

0 comments on commit 97e2fb5

Please sign in to comment.