Search in sources :

Example 1 with Book

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

the class BooksClient method fromCursor.

public static Book fromCursor(Cursor cursor) {
    Book book = new Book(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.NAME)), cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.PREFACE)), cursor.getLong(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.MTIME)), cursor.getInt(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.IS_DUMMY)) == 1);
    book.getOrgFileSettings().setTitle(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.TITLE)));
    book.getOrgFileSettings().setIndented(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.IS_INDENTED)) == 1);
    book.setId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param._ID)));
    book.setSyncStatus(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNC_STATUS)));
    book.setDetectedEncoding(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.DETECTED_ENCODING)));
    book.setSelectedEncoding(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SELECTED_ENCODING)));
    book.setUsedEncoding(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.USED_ENCODING)));
    /* Set link. */
    int linkRepoUriColumn = cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.LINK_REPO_URL);
    if (!cursor.isNull(linkRepoUriColumn)) {
        Uri uri = Uri.parse(cursor.getString(linkRepoUriColumn));
        book.setLinkRepo(uri);
    }
    /* Set versioned rook. */
    if (!cursor.isNull(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_ROOK_URL))) {
        Uri syncRookUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_ROOK_URL)));
        Uri syncRepoUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_REPO_URL)));
        String rev = cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_ROOK_REVISION));
        long mtime = cursor.getLong(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_ROOK_MTIME));
        VersionedRook vrook = new VersionedRook(syncRepoUri, syncRookUri, rev, mtime);
        book.setLastSyncedToRook(vrook);
    }
    /* Set last action. */
    String lastActionMessage = cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.LAST_ACTION));
    if (!TextUtils.isEmpty(lastActionMessage)) {
        BookAction.Type lastActionType = BookAction.Type.valueOf(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.LAST_ACTION_TYPE)));
        long lastActionTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.LAST_ACTION_TIMESTAMP));
        BookAction lastAction = new BookAction(lastActionType, lastActionMessage, lastActionTimestamp);
        book.setLastAction(lastAction);
    }
    return book;
}
Also used : VersionedRook(com.orgzly.android.repos.VersionedRook) BookAction(com.orgzly.android.BookAction) Book(com.orgzly.android.Book) Uri(android.net.Uri)

Example 2 with Book

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

the class BookNamesake method getAll.

/**
 * Create links between each local book and each remote book with the same name.
 */
public static Map<String, BookNamesake> getAll(Context context, List<Book> books, List<VersionedRook> versionedRooks) {
    Map<String, BookNamesake> namesakes = new HashMap<>();
    /* Create links from all local books first. */
    for (Book book : books) {
        BookNamesake pair = new BookNamesake(book.getName());
        namesakes.put(book.getName(), pair);
        pair.setBook(book);
    }
    /* Set repo books. */
    for (VersionedRook book : versionedRooks) {
        String fileName = BookName.getFileName(context, book.getUri());
        String name = BookName.fromFileName(fileName).getName();
        BookNamesake pair = namesakes.get(name);
        if (pair == null) {
            /* Local file doesn't exists, create new pair. */
            pair = new BookNamesake(name);
            namesakes.put(name, pair);
        }
        /* Add remote book. */
        pair.addRook(book);
    }
    return namesakes;
}
Also used : VersionedRook(com.orgzly.android.repos.VersionedRook) HashMap(java.util.HashMap) Book(com.orgzly.android.Book)

Example 3 with Book

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

the class MainActivity method onBookRenameRequest.

@Override
public void onBookRenameRequest(final long bookId) {
    final Book book = BooksClient.get(this, bookId);
    if (book == null) {
        return;
    }
    final View dialogView = View.inflate(this, R.layout.dialog_book_rename, null);
    final TextInputLayout nameInputLayout = dialogView.findViewById(R.id.name_input_layout);
    final EditText name = dialogView.findViewById(R.id.name);
    DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
        switch(which) {
            case DialogInterface.BUTTON_POSITIVE:
                doRenameBook(book, name.getText().toString(), nameInputLayout);
                break;
            case DialogInterface.BUTTON_NEGATIVE:
                break;
        }
    };
    AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.rename_book, MiscUtils.quotedString(book.getName()))).setPositiveButton(R.string.rename, dialogClickListener).setNegativeButton(R.string.cancel, dialogClickListener).setView(dialogView);
    name.setText(book.getName());
    final AlertDialog dialog = builder.create();
    /* Finish on keyboard action press. */
    name.setOnEditorActionListener((v, actionId, event) -> {
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
        return true;
    });
    final Activity activity = this;
    dialog.setOnShowListener(d -> ActivityUtils.INSTANCE.openSoftKeyboard(activity, name));
    dialog.setOnDismissListener(d -> ActivityUtils.INSTANCE.closeSoftKeyboard(activity));
    name.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable str) {
            /* Disable the button is nothing is entered. */
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!TextUtils.isEmpty(str));
        }
    });
    dialog.show();
}
Also used : EditText(android.widget.EditText) NavigationView(android.support.design.widget.NavigationView) Shelf(com.orgzly.android.Shelf) Bundle(android.os.Bundle) Notifications(com.orgzly.android.Notifications) FilterFragment(com.orgzly.android.ui.fragments.FilterFragment) SearchView(android.support.v7.widget.SearchView) Uri(android.net.Uri) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Note(com.orgzly.android.Note) TextInputLayout(android.support.design.widget.TextInputLayout) BooksClient(com.orgzly.android.provider.clients.BooksClient) ActivityUtils(com.orgzly.android.ui.util.ActivityUtils) CheckBox(android.widget.CheckBox) Query(com.orgzly.android.query.Query) BookPrefaceFragment(com.orgzly.android.ui.fragments.BookPrefaceFragment) Handler(android.os.Handler) Map(java.util.Map) View(android.view.View) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) Repo(com.orgzly.android.repos.Repo) ActionMode(android.support.v7.view.ActionMode) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) NotesBatch(com.orgzly.android.NotesBatch) Set(java.util.Set) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) TextView(android.widget.TextView) BookFragment(com.orgzly.android.ui.fragments.BookFragment) SyncFragment(com.orgzly.android.ui.fragments.SyncFragment) Book(com.orgzly.android.Book) BuildConfig(com.orgzly.BuildConfig) SimpleOneLinerDialog(com.orgzly.android.ui.dialogs.SimpleOneLinerDialog) NoteListFragment(com.orgzly.android.ui.fragments.NoteListFragment) BooksFragment(com.orgzly.android.ui.fragments.BooksFragment) Snackbar(android.support.design.widget.Snackbar) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) TextWatcher(android.text.TextWatcher) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) MiscUtils(com.orgzly.android.util.MiscUtils) Context(android.content.Context) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) AppPermissions(com.orgzly.android.util.AppPermissions) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) SettingsActivity(com.orgzly.android.ui.settings.SettingsActivity) ArrayList(java.util.ArrayList) GravityCompat(android.support.v4.view.GravityCompat) LinkedHashMap(java.util.LinkedHashMap) AppPreferences(com.orgzly.android.prefs.AppPreferences) NoteFragment(com.orgzly.android.ui.fragments.NoteFragment) R(com.orgzly.R) Menu(android.view.Menu) AppIntent(com.orgzly.android.AppIntent) DrawerLayout(android.support.v4.widget.DrawerLayout) FiltersFragment(com.orgzly.android.ui.fragments.FiltersFragment) DialogInterface(android.content.DialogInterface) CompoundButton(android.widget.CompoundButton) TextUtils(android.text.TextUtils) IOException(java.io.IOException) File(java.io.File) Spinner(android.widget.Spinner) Filter(com.orgzly.android.filter.Filter) ArrayAdapter(android.widget.ArrayAdapter) ReposClient(com.orgzly.android.provider.clients.ReposClient) Toolbar(android.support.v7.widget.Toolbar) Configuration(android.content.res.Configuration) Condition(com.orgzly.android.query.Condition) ActionService(com.orgzly.android.ActionService) BookName(com.orgzly.android.BookName) Activity(android.app.Activity) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) EditText(android.widget.EditText) LogUtils(com.orgzly.android.util.LogUtils) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) SettingsActivity(com.orgzly.android.ui.settings.SettingsActivity) Activity(android.app.Activity) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) TextView(android.widget.TextView) Book(com.orgzly.android.Book) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout)

Example 4 with Book

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

the class ShareActivity method getBooksList.

/**
 * Collects list of books from database.
 * If there are no books available, create one.
 */
private List<Book> getBooksList() {
    Shelf shelf = new Shelf(this);
    List<Book> books = shelf.getBooks();
    if (books.size() == 0) {
        try {
            Book book = shelf.createBook(AppPreferences.shareNotebook(getApplicationContext()));
            books.add(book);
        } catch (IOException e) {
            // TODO: Test and handle better.
            e.printStackTrace();
            finish();
        }
    }
    return books;
}
Also used : Book(com.orgzly.android.Book) Shelf(com.orgzly.android.Shelf) IOException(java.io.IOException)

Example 5 with Book

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

the class ProviderTest method testCreatingFirstEmptyBook.

@Test
public void testCreatingFirstEmptyBook() throws IOException {
    shelfTestUtils.setupBook("notebook", "");
    Book book = shelf.getBook(1);
    assertEquals("There should be one book", 1, shelf.getBooks().size());
    assertEquals("Book should have id 1", 1, book.getId());
    assertEquals("Book should not contain any notes", 0, NotesClient.getCount(context, book.getId()));
}
Also used : Book(com.orgzly.android.Book) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

Book (com.orgzly.android.Book)60 OrgzlyTest (com.orgzly.android.OrgzlyTest)47 Test (org.junit.Test)47 Note (com.orgzly.android.Note)21 NotePosition (com.orgzly.android.NotePosition)11 IOException (java.io.IOException)8 Shelf (com.orgzly.android.Shelf)6 Uri (android.net.Uri)5 Context (android.content.Context)4 Intent (android.content.Intent)4 TypedArray (android.content.res.TypedArray)4 NavigationView (android.support.design.widget.NavigationView)4 SearchView (android.support.v7.widget.SearchView)4 MenuItem (android.view.MenuItem)4 View (android.view.View)4 TextView (android.widget.TextView)4 Query (com.orgzly.android.query.Query)4 File (java.io.File)4 Activity (android.app.Activity)3 AlertDialog (android.app.AlertDialog)3