Search in sources :

Example 11 with BookView

use of com.orgzly.android.db.entity.BookView in project orgzly-android by orgzly.

the class SyncStatusBroadcastReceiver method createSyncFailedNotification.

private void createSyncFailedNotification(Context context, SyncStatus status) {
    PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannels.SYNC_FAILED).setAutoCancel(true).setSmallIcon(R.drawable.ic_logo_for_notification).setContentTitle(context.getString(R.string.syncing_failed_title)).setColor(ContextCompat.getColor(context, R.color.notification)).setContentIntent(openAppPendingIntent);
    if (status.type == SyncStatus.Type.FAILED) {
        builder.setContentText(status.message);
    } else {
        // FIXME: ANR reported
        List<BookView> books = dataRepository.getBooks();
        StringBuilder sb = new StringBuilder();
        for (BookView book : books) {
            BookAction action = book.getBook().getLastAction();
            if (action != null && action.getType() == BookAction.Type.ERROR) {
                sb.append(book.getBook().getName()).append(": ").append(action.getMessage()).append("\n");
            }
        }
        String message = sb.toString().trim();
        if (message.length() == 0) {
            /* no error, don't show the notification */
            return;
        }
        builder.setContentText(message);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
    }
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Notifications.SYNC_FAILED_ID, builder.build());
}
Also used : BookAction(com.orgzly.android.db.entity.BookAction) NotificationManager(android.app.NotificationManager) NotificationCompat(androidx.core.app.NotificationCompat) BookView(com.orgzly.android.db.entity.BookView) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) MainActivity(com.orgzly.android.ui.main.MainActivity)

Example 12 with BookView

use of com.orgzly.android.db.entity.BookView in project orgzly-android by orgzly.

the class SyncTest method testRenameUsedRepo.

@Test
public void testRenameUsedRepo() {
    Repo repo = testUtils.setupRepo(RepoType.MOCK, "mock://repo-a");
    testUtils.setupRook(repo, "mock://repo-a/book.org", "Content A", "1abcde", 1400067156000L);
    BookView book;
    testUtils.sync();
    testUtils.renameRepo("mock://repo-a", "mock://repo-b");
    book = dataRepository.getBookView("book");
    assertNull(book.getLinkRepo());
    assertNull(book.getSyncedTo());
    testUtils.sync();
    book = dataRepository.getBookView("book");
    assertEquals(BookSyncStatus.ONLY_BOOK_WITHOUT_LINK_AND_ONE_REPO.toString(), book.getBook().getSyncStatus());
    assertEquals("mock://repo-b", book.getLinkRepo().getUrl());
    assertEquals("mock://repo-b", book.getSyncedTo().getRepoUri().toString());
    assertEquals("mock://repo-b/book.org", book.getSyncedTo().getUri().toString());
    testUtils.renameRepo("mock://repo-b", "mock://repo-a");
    testUtils.sync();
    book = dataRepository.getBookView("book");
    assertEquals(BookSyncStatus.BOOK_WITHOUT_LINK_AND_ONE_OR_MORE_ROOKS_EXIST.toString(), book.getBook().getSyncStatus());
    assertNull(book.getLinkRepo());
    assertNull("mock://repo-b/book.org", book.getSyncedTo());
}
Also used : Repo(com.orgzly.android.db.entity.Repo) BookView(com.orgzly.android.db.entity.BookView) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 13 with BookView

use of com.orgzly.android.db.entity.BookView in project orgzly-android by orgzly.

the class SyncTest method testMultipleRooks.

@Test
public void testMultipleRooks() {
    Repo repoA = testUtils.setupRepo(RepoType.MOCK, "mock://repo-a");
    testUtils.setupRook(repoA, "mock://repo-a/book.org", "Content A", "revA", 1234567890000L);
    Repo repoB = testUtils.setupRepo(RepoType.MOCK, "mock://repo-b");
    testUtils.setupRook(repoB, "mock://repo-b/book.org", "Content B", "revB", 1234567890000L);
    testUtils.sync();
    BookView book = dataRepository.getBooks().get(0);
    assertEquals(BookSyncStatus.DUMMY_WITHOUT_LINK_AND_MULTIPLE_ROOKS.toString(), book.getBook().getSyncStatus());
    assertTrue(book.getBook().isDummy());
    dataRepository.setLink(book.getBook().getId(), repoA);
    testUtils.sync();
    book = dataRepository.getBooks().get(0);
    assertEquals(BookSyncStatus.DUMMY_WITH_LINK.toString(), book.getBook().getSyncStatus());
    assertTrue(!book.getBook().isDummy());
    assertEquals("mock://repo-a/book.org", book.getSyncedTo().getUri().toString());
}
Also used : Repo(com.orgzly.android.db.entity.Repo) BookView(com.orgzly.android.db.entity.BookView) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 14 with BookView

use of com.orgzly.android.db.entity.BookView in project orgzly-android by orgzly.

the class SyncTest method testDeletedRepoShouldStayAsBookLink.

@Test
public void testDeletedRepoShouldStayAsBookLink() {
    Repo repoA = testUtils.setupRepo(RepoType.MOCK, "mock://repo-a");
    testUtils.setupRepo(RepoType.MOCK, "mock://repo-b");
    testUtils.setupRook(repoA, "mock://repo-a/booky.org", "", "1abcdef", 1400067155);
    BookView book;
    Map<String, BookNamesake> namesakes;
    namesakes = testUtils.sync();
    book = dataRepository.getBookView("booky");
    assertEquals(BookSyncStatus.DUMMY_WITHOUT_LINK_AND_ONE_ROOK, namesakes.get("booky").getStatus());
    assertFalse(book.getBook().isDummy());
    assertEquals("mock://repo-a", book.getLinkRepo().getUrl());
    assertEquals("mock://repo-a", book.getSyncedTo().getRepoUri().toString());
    testUtils.deleteRepo("mock://repo-a");
    testUtils.deleteRepo("mock://repo-b");
    testUtils.setupRepo(RepoType.MOCK, "mock://repo-c");
    // TODO: Don't use namesakes, be consistent and use book.status like in some methods
    namesakes = testUtils.sync();
    book = dataRepository.getBookView("booky");
    assertEquals(BookSyncStatus.ONLY_BOOK_WITHOUT_LINK_AND_ONE_REPO, namesakes.get("booky").getStatus());
    assertFalse(book.getBook().isDummy());
    assertEquals("mock://repo-c", book.getLinkRepo().getUrl());
    assertEquals("mock://repo-c", book.getSyncedTo().getRepoUri().toString());
}
Also used : Repo(com.orgzly.android.db.entity.Repo) BookView(com.orgzly.android.db.entity.BookView) BookNamesake(com.orgzly.android.sync.BookNamesake) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 15 with BookView

use of com.orgzly.android.db.entity.BookView in project orgzly-android by orgzly.

the class SyncTest method testEncodingStaysTheSameAfterSecondSync.

@Test
public void testEncodingStaysTheSameAfterSecondSync() {
    BookView book;
    Repo repo = testUtils.setupRepo(RepoType.MOCK, "mock://repo-a");
    testUtils.setupRook(repo, "mock://repo-a/book.org", "Content A", "1abcde", 1400067156000L);
    testUtils.sync();
    book = dataRepository.getBooks().get(0);
    assertEquals(BookSyncStatus.DUMMY_WITHOUT_LINK_AND_ONE_ROOK.toString(), book.getBook().getSyncStatus());
    switch(EncodingDetect.USED_METHOD) {
        // assertEquals("ASCII", versionedRook.getUsedEncoding());
        case JUNIVERSALCHARDET:
            assertNull(book.getBook().getDetectedEncoding());
            assertEquals("UTF-8", book.getBook().getUsedEncoding());
            break;
    }
    assertNull(book.getBook().getSelectedEncoding());
    testUtils.sync();
    book = dataRepository.getBooks().get(0);
    assertEquals(BookSyncStatus.NO_CHANGE.toString(), book.getBook().getSyncStatus());
    switch(EncodingDetect.USED_METHOD) {
        // break;
        case JUNIVERSALCHARDET:
            assertNull(book.getBook().getDetectedEncoding());
            assertEquals("UTF-8", book.getBook().getUsedEncoding());
            break;
    }
    assertNull(book.getBook().getSelectedEncoding());
}
Also used : Repo(com.orgzly.android.db.entity.Repo) BookView(com.orgzly.android.db.entity.BookView) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

BookView (com.orgzly.android.db.entity.BookView)19 OrgzlyTest (com.orgzly.android.OrgzlyTest)16 Test (org.junit.Test)16 Repo (com.orgzly.android.db.entity.Repo)11 BookNamesake (com.orgzly.android.sync.BookNamesake)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NotificationCompat (androidx.core.app.NotificationCompat)1 BookAction (com.orgzly.android.db.entity.BookAction)1 Note (com.orgzly.android.db.entity.Note)1 VersionedRook (com.orgzly.android.repos.VersionedRook)1 MainActivity (com.orgzly.android.ui.main.MainActivity)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1