Skip to content

Commit

Permalink
[ADDED] [#127] Better logging for news source loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
hossain-khan committed Nov 11, 2016
1 parent 825ce49 commit 0827fa2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public void onError(final Throwable e) {

@Override
public void onNext(final List<NavigationRow> navigationRows) {
int navRowSize = 0;
String sourceId = "UNKNOWN";
if (navigationRows != null && !navigationRows.isEmpty()) {
navRowSize = navigationRows.size();
sourceId = navigationRows.get(0).sourceId();
}

Timber.i("onNext() returned - Loaded %d items from %s.", navRowSize, sourceId);
navigationRowList.addAll(navigationRows);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ protected void log(final int priority, final String tag, final String message, f
if (t != null) {
FirebaseCrash.report(t);
}
FirebaseCrash.log(message);
if (message != null) {
FirebaseCrash.log(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public abstract class NavigationRow {
@SerializedName("title")
public abstract String title();

@Nullable
@SerializedName("news_source_id")
public abstract String sourceId();

@Nullable
@SerializedName("category")
public abstract ArticleCategory category();
Expand All @@ -77,15 +81,37 @@ public static Builder builder() {

@AutoValue.Builder
public abstract static class Builder {
/**
* Type of navigation item.
*
* @param type Allowed values are {@link NavigationRow#TYPE_DEFAULT},
* {@link NavigationRow#TYPE_DIVIDER}, {@link NavigationRow#TYPE_DIVIDER}
* @return The builder instance.
*/
public abstract Builder type(int type);

@Nullable
public abstract Builder title(String title);

/**
* {@link NewsSource#id()} for current navigation row, when {@link #type()} is
* {@link NavigationRow#TYPE_SECTION_HEADER} or {@link NavigationRow#TYPE_DEFAULT}.
*
* @param newsSourceId News source ID from {@link NewsSource#id()}
* @return The builder instance.
*/
@Nullable
public abstract Builder sourceId(String newsSourceId);

@Nullable
public abstract Builder category(ArticleCategory category);

@Nullable
public abstract Builder cards(List<CardItem> cards);

/**
* Used to determine whether the row shall use shadows when displaying its cards or not.
*
* @param useShadow flag for card shadow
* @return Builder
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public List<NavigationRow> call(final List<InlineResponse200> inlineResponse200s
navigationHeadlines.add(NavigationRow.builder()
.title(mNewsSource.name())
.type(NavigationRow.TYPE_SECTION_HEADER)
.sourceId(mNewsSource.id())
.build());

for (int i = 0; i < totalResponseItemSize; i++) {
Expand All @@ -175,6 +176,7 @@ public List<NavigationRow> call(final List<InlineResponse200> inlineResponse200s
.title(mContext.getString(CategoryNameResolver
.resolveCategoryResId(articleCategory)))
.category(articleCategory)
.sourceId(mNewsSource.id())
.cards(convertArticleToCardItems(inlineResponse200s.get(i).getResults()))
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void call(final Subscriber<? super List<NavigationRow>> subscriber) {
navigationHeadlines.add(NavigationRow.builder()
.title(getNewsSource().name())
.type(NavigationRow.TYPE_SECTION_HEADER)
.sourceId(getNewsSource().id())
.build());


Expand All @@ -95,6 +96,7 @@ public void call(final Subscriber<? super List<NavigationRow>> subscriber) {
.title("Headlines")
.category(ArticleCategory.technology)
.cards(convertArticleToCardItems(articleList))
.sourceId(getNewsSource().id())
.build()
);
subscriber.onNext(navigationHeadlines);
Expand Down

0 comments on commit 0827fa2

Please sign in to comment.