Skip to content

Commit

Permalink
Merge pull request #156 from amardeshbd/feature/151_add_search_result
Browse files Browse the repository at this point in the history
[ADDED] Validation and feed add feature.
  • Loading branch information
hossain-khan authored Nov 21, 2016
2 parents 0a2366f + 346ec95 commit 8de4694
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CoreConfig {
/**
* Search query delay before making network request.
*/
public static final int SEARCH_DELAY_MS = 400;
public static final int SEARCH_DELAY_MS = 500;

/**
* Minimum character required before searching for feeds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.webkit.URLUtil;

import com.feedly.FeedlyApiClient;
import com.feedly.cloud.FeedItem;
Expand Down Expand Up @@ -56,6 +57,11 @@
*/
public class SearchPresenter extends BasePresenter<SearchContract.View> implements SearchContract.Presenter {

/**
* Feed ID prefix from feedly.
* @see FeedItem
*/
private static final String FEED_RESOURCE_ID_PREFIX = "feed/";
private final SearchApi mSearchApi;

/**
Expand Down Expand Up @@ -206,8 +212,13 @@ private String getImageUrl(@NonNull final FeedItem feedItem) {
*/
@Nullable
private String getFeedUrl(@NonNull final String feedId) {
if (feedId.startsWith("feed/")) {
return feedId.replace("feed/", "");
if (feedId.startsWith(FEED_RESOURCE_ID_PREFIX)) {
String feedUrl = feedId.substring(FEED_RESOURCE_ID_PREFIX.length(), feedId.length());
if (URLUtil.isValidUrl(feedUrl)) {
return feedUrl;
} else {
Timber.w("Provided feed ID does not contain valid URL: %s", feedId);
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package info.hossainkhan.dailynewsheadlines.search;

import android.os.Bundle;
import android.support.v17.leanback.app.GuidedStepFragment;
import android.support.v17.leanback.app.SearchFragment;
import android.support.v17.leanback.widget.ArrayObjectAdapter;
import android.support.v17.leanback.widget.ListRowPresenter;
Expand All @@ -33,13 +34,17 @@
import android.support.v17.leanback.widget.Presenter;
import android.support.v17.leanback.widget.Row;
import android.support.v17.leanback.widget.RowPresenter;
import android.widget.Toast;

import java.lang.ref.WeakReference;
import java.util.List;

import info.hossainkhan.android.core.model.CardItem;
import info.hossainkhan.android.core.search.SearchContract;
import info.hossainkhan.android.core.search.SearchPresenter;
import info.hossainkhan.android.core.util.StringUtils;
import info.hossainkhan.dailynewsheadlines.R;
import info.hossainkhan.dailynewsheadlines.addsource.ValidateNewsSourceDialogFragment;
import info.hossainkhan.dailynewsheadlines.browser.RowBuilderFactory;
import rx.Emitter;
import rx.Observable;
Expand Down Expand Up @@ -80,6 +85,20 @@ public void onItemClicked(final Presenter.ViewHolder itemViewHolder, final Objec
final RowPresenter.ViewHolder rowViewHolder, final Row row) {
Timber.d("onItemClicked() called with: itemViewHolder = [" + itemViewHolder + "], item = [" + item +
"], rowViewHolder = [" + rowViewHolder + "], row = [" + row + "]");

if(item instanceof CardItem) {
CardItem cardItem = (CardItem) item;
if(StringUtils.isNotEmpty(cardItem.contentUrl())) {
GuidedStepFragment fragment = ValidateNewsSourceDialogFragment
.newInstance(cardItem.title(), cardItem.contentUrl());
GuidedStepFragment.add(getFragmentManager(), fragment);
} else {
Toast.makeText(getActivity(), R.string.search_result_no_feed_url, Toast.LENGTH_SHORT).show();
}
} else {
Timber.w("Unable to process item. Type unknown: %s", item);
}

}
});
mPresenter = new SearchPresenter(this, searchQueryObserver.getSearchQueryObservable());
Expand Down
1 change: 1 addition & 0 deletions tv/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

<!-- Search screen -->
<string name="search_result_title">News feed search result. Found %d item(s).</string>
<string name="search_result_no_feed_url">Sorry, this feed does not have valid feed URL.</string>

<!-- Contribution Screen -->
<string name="github_project_home_url">https://github.com/amardeshbd/android-daily-headlines</string>
Expand Down

0 comments on commit 8de4694

Please sign in to comment.