Skip to content

Commit

Permalink
Fix issue with Crash on BookInfoActivity when trying to share a book …
Browse files Browse the repository at this point in the history
…but the book information hasn't loaded yet.

Refactor BookViewHolder
Change gradle build tools to alpha9
  • Loading branch information
riggaroo committed Feb 7, 2016
1 parent 919a1d0 commit 5dd1afb
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
applicationId "org.bookdash.android"
minSdkVersion 16
targetSdkVersion 23
versionCode 12
versionName "1.0.12"
versionCode 13
versionName "1.0.13"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField "String", "PARSE_APPLICATION_ID", "\"${BOOKDASH_PARSE_APP_ID}\""
buildConfigField "String", "PARSE_CLIENT_KEY", "\"${BOOKDASH_PARSE_CLIENT_ID}\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class BookInfoPresenter implements BookInfoContract.UserActionsListener {
private final BookDetailRepository bookDetailRepository;

private final Context context;

public BookInfoPresenter(Context context, @NonNull BookInfoContract.View booksView, @NonNull BookDetailRepository bookDetailRepository) {

this.booksView = booksView;
Expand Down Expand Up @@ -60,7 +61,7 @@ private void showBookDetail(BookDetail bookDetail) {
booksView.setBookInfoBinding(bookDetail);

booksView.setToolbarTitle(bookDetail.getBookTitle());
if (bookDetail.isDownloadedAlready()){
if (bookDetail.isDownloadedAlready()) {
booksView.showDownloadFinished();
}
booksView.showBookDetailView();
Expand All @@ -81,7 +82,7 @@ public void onContributorsLoadError(Exception e) {

@Override
public void downloadBook(@NonNull final BookDetail bookInfo) {
if (bookInfo.isDownloading()){
if (bookInfo.isDownloading()) {
booksView.showSnackBarMessage(R.string.book_is_downloading);
return;
}
Expand Down Expand Up @@ -132,7 +133,10 @@ public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glid

@Override
public void shareBookClicked(BookDetail bookInfo) {

if (bookInfo == null) {
booksView.showError(context.getString(R.string.book_info_still_loading));
return;
}
booksView.sendShareEvent(bookInfo.getBookTitle());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public BookViewHolder onCreateViewHolder(ViewGroup parent,
@Override
public void onBindViewHolder(BookViewHolder holder, int position) {
BookDetail bookDetail = bookDetails.get(position);
holder.mTextView.setText(bookDetail.getBookTitle());
Glide.with(context).load(bookDetail.getBookCoverUrl()).into(holder.mImageView);
holder.bookTitle.setText(bookDetail.getBookTitle());
Glide.with(context).load(bookDetail.getBookCoverUrl()).into(holder.bookCover);
holder.bookDetail = bookDetail;
holder.mImageViewDownloaded.setVisibility(bookDetail.isDownloadedAlready() ? View.VISIBLE : View.INVISIBLE);
holder.mCardView.setTag(holder);
holder.mCardView.setOnClickListener(onClickListener);
holder.downloadedIcon.setVisibility(bookDetail.isDownloadedAlready() ? View.VISIBLE : View.INVISIBLE);
holder.cardContainer.setTag(holder);
holder.cardContainer.setOnClickListener(onClickListener);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.bookdash.android.presentation.listbooks;

import android.media.Image;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
Expand All @@ -15,18 +14,20 @@
* @since 15/11/11.
*/
public class BookViewHolder extends RecyclerView.ViewHolder {
public TextView mTextViewBookAuthor;
public TextView mTextView;
public ImageView mImageView;
public CardView mCardView;

public TextView author;
public TextView bookTitle;
public ImageView bookCover;
public CardView cardContainer;
public BookDetail bookDetail;
public ImageView mImageViewDownloaded;
public ImageView downloadedIcon;

public BookViewHolder(View v) {
super(v);
mCardView = (CardView) v.findViewById(R.id.card_view);
mTextView = (TextView) v.findViewById(R.id.textViewBookName);
mImageView = (ImageView) v.findViewById(R.id.imageViewBookCover);
mTextViewBookAuthor = (TextView) v.findViewById(R.id.textViewAuthor);
mImageViewDownloaded = (ImageView) v.findViewById(R.id.imageViewBookDownloaded);
cardContainer = (CardView) v.findViewById(R.id.card_view);
bookTitle = (TextView) v.findViewById(R.id.textViewBookName);
bookCover = (ImageView) v.findViewById(R.id.imageViewBookCover);
author = (TextView) v.findViewById(R.id.textViewAuthor);
downloadedIcon = (ImageView) v.findViewById(R.id.imageViewBookDownloaded);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void showAboutPage() {
public void openBookDetails(View v) {
/* if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
ImageView imageView =
((BookViewHolder) v.getTag()).mImageView;
((BookViewHolder) v.getTag()).bookCover;
imageView.setTransitionName(getString(R.string.transition_book));
v.setBackgroundColor(
ContextCompat.getColor(ListBooksActivity.this, android.R.color.transparent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
public interface SplashContract {
interface View {
void loadTutorial();

void loadMainScreen();
}

interface UserActionsListener {
void loadSplash();

ArrayList<TutorialItem> getTutorialItems(Context context);

void finishedTutorial();
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@
<string name="action_downloads">Downloaded Books</string>
<string name="no_books_downloaded">No books are downloaded. Head to the \"All Books\" section to download some!</string>
<string name="no_books_available">No books available at the moment. Check back soon!</string>
<string name="book_info_still_loading">Book information is still loading...</string>

</resources>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:2.0.0-alpha3"
classpath "com.android.databinding:dataBinder:1.+"
classpath 'com.android.tools.build:gradle:2.0.0-alpha9'
classpath "com.android.databinding:dataBinder:1.0-rc4"
classpath 'com.google.gms:google-services:1.5.0-beta2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

0 comments on commit 5dd1afb

Please sign in to comment.