Android Open Source - Book-MetaSearch Book






From Project

Back to project page Book-MetaSearch.

License

The source code is released under:

Apache License

If you think the Android project Book-MetaSearch listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.grosinger.bookmetasearch.book;
//from w  ww  .j av  a 2s  .c  o m
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import android.widget.ImageView;

import net.grosinger.bookmetasearch.loader.AsyncImageLoader;
import net.grosinger.bookmetasearch.loader.ProductQuery;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * Container object for a book and all required information.
 *
 * @author Tony
 * @since 11/2/2013
 */
public class Book implements Parcelable {

    private String id;
    private ProductQuery provider;

    private String title;
    private Author author;
    private String isbn;
    private String isbn13;
    private String publisher;
    private double avg_rating;
    private String description;
    private int num_pages;

    private Bitmap large_img;
    private Bitmap small_img;
    private String large_img_url;
    private String small_img_url;

    // TODO: Adapt to support multiple authors

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Parcelable.Creator<Book> CREATOR = new Parcelable.Creator<Book>() {
        public Book createFromParcel(Parcel in) {
            return new Book(in);
        }

        public Book[] newArray(int size) {
            return new Book[size];
        }
    };

    private Book(Parcel parcel) {
        Log.d(getClass().getSimpleName(), "Un-parceling book");

        id = parcel.readString();
        title = parcel.readString();
        author = parcel.readParcelable(Author.class.getClassLoader());
        isbn = parcel.readString();
        isbn13 = parcel.readString();
        large_img = parcel.readParcelable(Bitmap.class.getClassLoader());
        small_img = parcel.readParcelable(Bitmap.class.getClassLoader());
        large_img_url = parcel.readString();
        small_img_url = parcel.readString();
        publisher = parcel.readString();
        avg_rating = parcel.readDouble();
        description = parcel.readString();
        num_pages = parcel.readInt();
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        Log.d(getClass().getSimpleName(), "Parceling book");

        // TODO: Add provider to parcel

        parcel.writeString(id);
        parcel.writeString(title);
        parcel.writeParcelable(author, i);
        parcel.writeString(isbn);
        parcel.writeString(isbn13);
        parcel.writeParcelable(large_img, i);
        parcel.writeParcelable(small_img, i);
        parcel.writeString(large_img_url);
        parcel.writeString(small_img_url);
        parcel.writeString(publisher);
        parcel.writeDouble(avg_rating);
        parcel.writeString(description);
        parcel.writeInt(num_pages);
    }

    private Book(String id, ProductQuery provider) {
        this.id = id;
        this.provider = provider;
    }

    public String getId() {
        return id;
    }

    public ProductQuery getProvider() {
        return provider;
    }

    public String getTitle() {
        return title;
    }

    public Author getAuthor() {
        return author;
    }

    public String getIsbn() {
        return isbn;
    }

    public String getIsbn13() {
        return isbn13;
    }

    public Bitmap getLargeImg() {
        return large_img;
    }

    public Bitmap getSmallImg() {
        return small_img;
    }

    public void getLargeImgAsync(ImageView view) {
        if(large_img != null) {
            view.setImageBitmap(large_img);
        } else {
            AsyncImageLoader loader = new AsyncImageLoader(view, title);
            loader.execute(large_img_url);
        }
    }

    public void getSmallImgAsync(ImageView view) {
        if (small_img != null) {
            view.setImageBitmap(small_img);
        } else {
            AsyncImageLoader loader = new AsyncImageLoader(view, title);
            loader.execute(small_img_url);
        }
    }

    public void getImageAsync(ImageView view) {
        if(large_img_url != null && !large_img_url.equals("")) {
            getLargeImgAsync(view);
        } else if (small_img_url != null && !small_img_url.equals("")) {
            getSmallImgAsync(view);
        } else {
            Log.d(getClass().getSimpleName(), "No image URL available to load: " + title);
        }
    }

    public String getLargeImgUrl() {
        return large_img_url;
    }

    public String getSmallImgUrl() {
        return small_img_url;
    }

    public String getPublisher() {
        return publisher;
    }

    public double getAvg_rating() {
        return avg_rating;
    }

    public String getDescription() {
        return description;
    }

    public int getNum_pages() {
        return num_pages;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 31)
                .append(id).append(title).append(author).append(isbn).append(isbn13).append(publisher)
                .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (obj == this) {
            return true;
        }

        if (!(obj instanceof Book)) {
            return false;
        }

        Book rhs = (Book) obj;
        return new EqualsBuilder()
                .append(id, rhs.id).append(title, rhs.title).append(author, rhs.author).append(isbn, rhs.isbn)
                .append(isbn13, rhs.isbn13).append(publisher, rhs.publisher)
                .isEquals();
    }

    @Override
    public String toString() {
        return title + " - " + author;
    }

    public static class BookBuilder {
        private Book instance;

        public BookBuilder(String id, ProductQuery provider) {
            instance = new Book(id, provider);
        }

        public BookBuilder setTitle(String title) {
            instance.title = title;
            return this;
        }

        public BookBuilder setAuthor(Author author) {
            instance.author = author;
            return this;
        }

        public BookBuilder setIsbn(String isbn) {
            instance.isbn = isbn;
            return this;
        }

        public BookBuilder setIsbn13(String isbn13) {
            instance.isbn13 = isbn13;
            return this;
        }

        public BookBuilder setLargeImg(String largeImg) {
            instance.large_img_url = largeImg;
            return this;
        }

        public BookBuilder setSmallImg(String smallImg) {
            instance.small_img_url = smallImg;
            return this;
        }

        public BookBuilder setPublisher(String publisher) {
            instance.publisher = publisher;
            return this;
        }

        public BookBuilder setAvgRating(double avgRating) {
            instance.avg_rating = avgRating;
            return this;
        }

        public BookBuilder setNumPages(int numPages) {
            instance.num_pages = numPages;
            return this;
        }

        public BookBuilder setDescription(String description) {
            instance.description = description;
            return this;
        }

        public Book build() {
            return instance;
        }
    }
}




Java Source Code List

com.ECS.client.jax.Accessories.java
com.ECS.client.jax.Arguments.java
com.ECS.client.jax.BrowseNode.java
com.ECS.client.jax.BrowseNodes.java
com.ECS.client.jax.Collections.java
com.ECS.client.jax.CustomerReviews.java
com.ECS.client.jax.DecimalWithUnits.java
com.ECS.client.jax.EditorialReview.java
com.ECS.client.jax.EditorialReviews.java
com.ECS.client.jax.Errors.java
com.ECS.client.jax.ImageSet.java
com.ECS.client.jax.Image.java
com.ECS.client.jax.ItemAttributes.java
com.ECS.client.jax.ItemLink.java
com.ECS.client.jax.ItemLinks.java
com.ECS.client.jax.Item.java
com.ECS.client.jax.LoyaltyPoints.java
com.ECS.client.jax.Merchant.java
com.ECS.client.jax.NewReleases.java
com.ECS.client.jax.NonNegativeIntegerWithUnits.java
com.ECS.client.jax.OfferAttributes.java
com.ECS.client.jax.OfferListing.java
com.ECS.client.jax.OfferSummary.java
com.ECS.client.jax.Offer.java
com.ECS.client.jax.Offers.java
com.ECS.client.jax.Price.java
com.ECS.client.jax.Promotion.java
com.ECS.client.jax.Promotions.java
com.ECS.client.jax.Property.java
com.ECS.client.jax.RelatedItem.java
com.ECS.client.jax.RelatedItems.java
com.ECS.client.jax.SimilarProducts.java
com.ECS.client.jax.TopItemSet.java
com.ECS.client.jax.TopSellers.java
com.ECS.client.jax.Tracks.java
com.ECS.client.jax.VariationAttribute.java
com.ECS.client.jax.VariationDimensions.java
com.ECS.client.jax.VariationSummary.java
com.ECS.client.jax.Variations.java
net.grosinger.bookmetasearch.BookDetail.java
net.grosinger.bookmetasearch.BookInventoryAdapter.java
net.grosinger.bookmetasearch.Home.java
net.grosinger.bookmetasearch.SearchActivity.java
net.grosinger.bookmetasearch.book.Author.java
net.grosinger.bookmetasearch.book.Book.java
net.grosinger.bookmetasearch.book.provider.BookProvider.java
net.grosinger.bookmetasearch.book.provider.LibraryBookProvider.java
net.grosinger.bookmetasearch.book.provider.RetailBookProvider.java
net.grosinger.bookmetasearch.fragment.DetailFragment.java
net.grosinger.bookmetasearch.fragment.HomeFragment.java
net.grosinger.bookmetasearch.fragment.SearchResultsFragment.java
net.grosinger.bookmetasearch.inventory.AvailableBook.java
net.grosinger.bookmetasearch.inventory.InventoryHeader.java
net.grosinger.bookmetasearch.inventory.InventoryListItem.java
net.grosinger.bookmetasearch.loader.AmazonQuery.java
net.grosinger.bookmetasearch.loader.AsyncImageLoader.java
net.grosinger.bookmetasearch.loader.GoodreadsQuery.java
net.grosinger.bookmetasearch.loader.GoogleQuery.java
net.grosinger.bookmetasearch.loader.InventoryLoader.java
net.grosinger.bookmetasearch.loader.InventoryQuery.java
net.grosinger.bookmetasearch.loader.ProductLoader.java
net.grosinger.bookmetasearch.loader.ProductQuery.java
net.grosinger.bookmetasearch.search.RecentBookSearchSuggestionsProvider.java
net.grosinger.bookmetasearch.search.SearchResultAdapter.java