Search in sources :

Example 6 with Book

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

the class BookChooserActivity method onBookClicked.

@Override
public void onBookClicked(long bookId) {
    if (BuildConfig.LOG_DEBUG)
        LogUtils.d(TAG, bookId, action);
    if (action != null && action.equals(Intent.ACTION_CREATE_SHORTCUT)) {
        // Get Book by its ID
        Book book = dataRepository.getBook(bookId);
        if (book == null) {
            Toast.makeText(this, R.string.book_does_not_exist_anymore, Toast.LENGTH_SHORT).show();
            setResult(RESULT_CANCELED);
            finish();
            return;
        }
        String id = "notebook-" + bookId;
        String name = book.getName();
        String title = BookUtils.getFragmentTitleForBook(book);
        Intent launchIntent = createLaunchIntent(book);
        IconCompat icon = createIcon();
        ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(this, id).setShortLabel(name).setLongLabel(title).setIcon(icon).setIntent(launchIntent).build();
        setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
        finish();
    }
}
Also used : Book(com.orgzly.android.db.entity.Book) IconCompat(androidx.core.graphics.drawable.IconCompat) Intent(android.content.Intent) AppIntent(com.orgzly.android.AppIntent) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 7 with Book

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

the class LocalDbRepoTest method testStoringBook.

@Test
public void testStoringBook() throws IOException {
    SyncRepo repo;
    long now = System.currentTimeMillis();
    /* Write local book's content to a temporary file. */
    Book book = dataRepository.getBook("local-book-1");
    File tmpFile = dataRepository.getTempBookFile();
    try {
        new NotesOrgExporter(dataRepository).exportBook(book, tmpFile);
        repo = testUtils.repoInstance(RepoType.MOCK, "mock://repo-a");
        repo.storeBook(tmpFile, BookName.fileName(book.getName(), BookFormat.ORG));
    } finally {
        tmpFile.delete();
    }
    List<VersionedRook> books = repo.getBooks();
    assertEquals(1, books.size());
    VersionedRook vrook = books.get(0);
    assertEquals("local-book-1", BookName.getInstance(context, vrook).getName());
    assertEquals("mock://repo-a", vrook.getRepoUri().toString());
    assertTrue(vrook.getMtime() >= now);
}
Also used : NotesOrgExporter(com.orgzly.android.NotesOrgExporter) Book(com.orgzly.android.db.entity.Book) File(java.io.File) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

Book (com.orgzly.android.db.entity.Book)7 Intent (android.content.Intent)3 Uri (android.net.Uri)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 SearchView (androidx.appcompat.widget.SearchView)2 ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)2 IconCompat (androidx.core.graphics.drawable.IconCompat)2 NavigationView (com.google.android.material.navigation.NavigationView)2 AppIntent (com.orgzly.android.AppIntent)2 OrgzlyTest (com.orgzly.android.OrgzlyTest)2 Repo (com.orgzly.android.db.entity.Repo)2 Query (com.orgzly.android.query.Query)2 File (java.io.File)2 AlertDialog (android.app.AlertDialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 Configuration (android.content.res.Configuration)1 Bundle (android.os.Bundle)1