Skip to content

Commit 4e3ff7d

Browse files
committed
Show description and link
1 parent 1e2342e commit 4e3ff7d

File tree

3 files changed

+124
-25
lines changed

3 files changed

+124
-25
lines changed

app/src/main/java/net/bookbuddy/BookActivity.java

+60-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.bookbuddy.utilities.*;
1717

1818
import org.w3c.dom.Document;
19+
import org.w3c.dom.Text;
1920

2021
import java.io.BufferedInputStream;
2122
import java.io.InputStream;
@@ -88,12 +89,14 @@ private void loadBookImage() {
8889
* @param book Book
8990
*/
9091
private void processResponse(Book book) {
91-
92+
addAuthorsText(book);
93+
addDescriptionText(book);
94+
addGoodReadsAttribution(book);
9295

96+
/*
9397
System.out.println("Url: " + book.getUrl());
9498
System.out.println("ISBN: " + book.getIsbnTen());
9599
System.out.println("ISBN13: " + book.getIsbnThirteen());
96-
System.out.println("Description: " + book.getDescription());
97100
if (book.getPublication() != null) {
98101
int day = book.getPublication().getDayOfMonth();
99102
String suffix = getLastDigitSuffix(day);
@@ -102,17 +105,68 @@ private void processResponse(Book book) {
102105
System.out.println("Publisher: " + book.getPublisher());
103106
System.out.println("Format: " + book.getFormat());
104107
System.out.println("Pages: " + book.getPages());
105-
for (int i = 0; i < book.getAuthors().size(); i++) {
106-
Author a = book.getAuthors().get(i);
107-
System.out.println(a.getId() + ", " + a.getName() + ", " + a.getRole());
108-
}
109108
System.out.println("Widget: " + book.getReviewsWidgetHtml());
109+
*/
110110

111111
// Hide spinner
112112
findViewById(R.id.progressBarSelectedBook).setVisibility(View.GONE);
113113
findViewById(R.id.selectedBookData).setVisibility(View.VISIBLE);
114114
}
115115

116+
/**
117+
* Sets authors.
118+
*
119+
* @param book
120+
*/
121+
private void addAuthorsText(Book book) {
122+
TextView authors = (TextView) findViewById(R.id.textViewBookAuthors);
123+
int size = book.getAuthors().size();
124+
125+
if (size == 1) {
126+
authors.setText("By " + book.getAuthors().get(0).getName());
127+
128+
} else if (size > 1) {
129+
String text = "By ";
130+
for (int i = 0; i < size; i++) {
131+
Author author = book.getAuthors().get(i);
132+
text += author.getName();
133+
if (author.getRole().length() > 0) {
134+
text += " (";
135+
text += author.getRole();
136+
text += ")";
137+
}
138+
if (i < size - 1) {
139+
text += ", ";
140+
}
141+
}
142+
authors.setText(text);
143+
}
144+
}
145+
146+
/**
147+
* Sets description.
148+
*
149+
* @param book
150+
*/
151+
private void addDescriptionText(Book book) {
152+
String descriptionHtml = book.getDescription();
153+
TextView description = (TextView) findViewById(R.id.textViewBookDescription);
154+
description.setText(Html.fromHtml(descriptionHtml));
155+
}
156+
157+
/**
158+
* Creates link to search results on GoodReads.
159+
*
160+
* @param book
161+
*/
162+
private void addGoodReadsAttribution(Book book) {
163+
TextView goodReads = (TextView) findViewById(R.id.textViewGoodReadsBookLink);
164+
String attribution = "Data from <a href='" + book.getUrl() + "'>GoodReads</a>";
165+
goodReads.setClickable(true);
166+
goodReads.setMovementMethod(LinkMovementMethod.getInstance());
167+
goodReads.setText(Html.fromHtml(attribution));
168+
}
169+
116170
/**
117171
* Determines correct suffix for day digit.
118172
*

app/src/main/java/net/bookbuddy/SearchActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private void displayTotalResultsMessage(int totalResults, String query) {
289289

290290
// Add GoodReads attribution and link to data source
291291
String url = createGoodReadsAttribution();
292-
String attribution = "Data from <a href='" + url + "'>GoodReads</a>";
292+
String attribution = "Results from <a href='" + url + "'>GoodReads</a>";
293293
goodReads.setClickable(true);
294294
goodReads.setMovementMethod(LinkMovementMethod.getInstance());
295295
goodReads.setText(Html.fromHtml(attribution));

app/src/main/res/layout/content_book.xml

+63-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
android:id="@+id/layoutContentSearch"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8-
tools:context="net.bookbuddy.SearchActivity">
8+
tools:context="net.bookbuddy.BookActivity">
99

1010
<include layout="@layout/nav_app_bar" />
1111

@@ -23,27 +23,72 @@
2323

2424
<LinearLayout
2525
android:id="@+id/selectedBookData"
26-
android:visibility="gone"
2726
android:layout_width="match_parent"
2827
android:layout_height="wrap_content"
2928
android:orientation="vertical"
30-
android:padding="8dp">
31-
32-
<ImageView
33-
android:id="@+id/imageViewBook"
34-
android:layout_width="112dp"
35-
android:layout_height="148dp"
36-
android:layout_marginTop="20dp"
37-
android:layout_marginBottom="20dp"
38-
android:layout_gravity="center"
39-
android:contentDescription="@string/content_description_book" />
40-
41-
<TextView
42-
android:id="@+id/textViewBookTitle"
43-
style="@style/Base.TextAppearance.AppCompat.Headline"
44-
android:layout_width="wrap_content"
29+
android:visibility="gone">
30+
31+
<!-- Book data -->
32+
<LinearLayout
33+
android:layout_width="match_parent"
4534
android:layout_height="wrap_content"
46-
android:layout_gravity="center"/>
35+
android:orientation="vertical"
36+
android:padding="8dp">
37+
38+
<ImageView
39+
android:id="@+id/imageViewBook"
40+
android:layout_width="112dp"
41+
android:layout_height="148dp"
42+
android:layout_gravity="center"
43+
android:layout_marginBottom="20dp"
44+
android:layout_marginTop="20dp"
45+
android:contentDescription="@string/content_description_book" />
46+
47+
<TextView
48+
android:id="@+id/textViewBookTitle"
49+
style="@style/Base.TextAppearance.AppCompat.Headline"
50+
android:layout_width="wrap_content"
51+
android:layout_height="wrap_content"
52+
android:layout_gravity="center" />
53+
54+
<TextView
55+
android:id="@+id/textViewBookAuthors"
56+
style="@style/TextAppearance.AppCompat.Title"
57+
android:layout_width="wrap_content"
58+
android:layout_height="wrap_content"
59+
android:layout_gravity="center"
60+
android:layout_marginBottom="16dp"
61+
android:layout_marginTop="8dp" />
62+
63+
<TextView
64+
android:id="@+id/textViewBookDescription"
65+
style="@style/TextAppearance.AppCompat.Medium"
66+
android:layout_width="wrap_content"
67+
android:layout_height="wrap_content"
68+
android:textColor="@android:color/primary_text_light" />
69+
</LinearLayout>
70+
71+
<!-- GoodReads attribution -->
72+
<LinearLayout
73+
android:layout_width="match_parent"
74+
android:layout_height="wrap_content"
75+
android:orientation="vertical">
76+
77+
<View
78+
android:layout_width="match_parent"
79+
android:layout_height="1dp"
80+
android:layout_marginTop="12dp"
81+
android:background="?android:attr/dividerVertical" />
82+
83+
<TextView
84+
android:id="@+id/textViewGoodReadsBookLink"
85+
style="@style/TextAppearance.AppCompat.Medium"
86+
android:layout_width="wrap_content"
87+
android:layout_height="wrap_content"
88+
android:layout_gravity="center"
89+
android:layout_marginBottom="12dp"
90+
android:layout_marginTop="12dp" />
91+
</LinearLayout>
4792

4893
</LinearLayout>
4994

0 commit comments

Comments
 (0)