-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from amardeshbd/feature/150_search_card_ui
Feature/150 search card ui
- Loading branch information
Showing
13 changed files
with
380 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
tv/src/main/java/info/hossainkhan/dailynewsheadlines/cards/TextFeedCardView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2016 Hossain Khan | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package info.hossainkhan.dailynewsheadlines.cards; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.support.v17.leanback.widget.BaseCardView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.squareup.picasso.Picasso; | ||
|
||
import java.text.NumberFormat; | ||
|
||
import info.hossainkhan.android.core.model.CardItem; | ||
import info.hossainkhan.android.core.picasso.BlurTransformation; | ||
import info.hossainkhan.android.core.picasso.GrayscaleTransformation; | ||
import info.hossainkhan.android.core.usersource.UserSourceManager; | ||
import info.hossainkhan.android.core.util.StringUtils; | ||
import info.hossainkhan.dailynewsheadlines.R; | ||
import timber.log.Timber; | ||
|
||
|
||
/** | ||
* Text based card view for feed. | ||
*/ | ||
public class TextFeedCardView extends BaseCardView { | ||
|
||
/** | ||
* User source manager used to check if source is already added. | ||
*/ | ||
private final UserSourceManager mUserSourceManager; | ||
|
||
public TextFeedCardView(final Context context) { | ||
super(context, null, R.style.TextCardStyle); | ||
LayoutInflater.from(getContext()).inflate(R.layout.text_icon_card_feed, this); | ||
setFocusable(true); | ||
|
||
mUserSourceManager = new UserSourceManager(context); | ||
} | ||
|
||
public void updateUi(CardItem cardItem) { | ||
final TextView primaryHeadline = (TextView) findViewById(R.id.primary_headline_text); | ||
final TextView summaryText1 = (TextView) findViewById(R.id.summary_text_1); | ||
final TextView summaryText2 = (TextView) findViewById(R.id.summary_text_2); | ||
final ImageView mainContentBackground = (ImageView) findViewById(R.id.main_content_background); | ||
final ImageView iconImage = (ImageView) findViewById(R.id.feed_provider_icon); | ||
final ImageView bookmarkedBadge = (ImageView) findViewById(R.id.feed_subscribed_marker_badge); | ||
|
||
if (mUserSourceManager.isAdded(cardItem.contentUrl())) { | ||
bookmarkedBadge.setVisibility(View.VISIBLE); | ||
} else { | ||
bookmarkedBadge.setVisibility(View.INVISIBLE); | ||
} | ||
|
||
|
||
primaryHeadline.setText(cardItem.title()); | ||
summaryText1.setText(cardItem.description()); | ||
|
||
// Reusing the "CardItem.width" to get total subscriber stats | ||
summaryText2.setText(String.format(getContext().getString(R.string.feed_stats_overview), | ||
NumberFormat.getInstance().format(cardItem.width()))); | ||
|
||
Context context = getContext(); | ||
Picasso picasso = Picasso.with(context); | ||
Resources resources = context.getResources(); | ||
if (StringUtils.isNotEmpty(cardItem.imageUrl())) { | ||
picasso | ||
.load(cardItem.imageUrl()) | ||
.resize((int) resources.getDimension(R.dimen.card_text_container_width), | ||
(int) resources.getDimension(R.dimen.card_text_container_height)) | ||
.transform(new GrayscaleTransformation(picasso)) | ||
.transform(new BlurTransformation(context)) | ||
.centerInside() | ||
.into(mainContentBackground); | ||
} else { | ||
Timber.w("Unable to load thumb image."); | ||
} | ||
|
||
// Reusing the "CardItem.extraText" to get the icon image URL | ||
if (StringUtils.isNotEmpty(cardItem.extraText())) { | ||
picasso | ||
.load(cardItem.extraText()) | ||
.into(iconImage); | ||
} else { | ||
Timber.w("Unable to load icon image."); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...main/java/info/hossainkhan/dailynewsheadlines/cards/presenters/TextFeedCardPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2016 Hossain Khan | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package info.hossainkhan.dailynewsheadlines.cards.presenters; | ||
|
||
import android.content.Context; | ||
|
||
import info.hossainkhan.android.core.model.CardItem; | ||
import info.hossainkhan.dailynewsheadlines.cards.TextFeedCardView; | ||
|
||
/** | ||
* The Presenter displays feed item. | ||
*/ | ||
public class TextFeedCardPresenter extends AbstractCardPresenter<TextFeedCardView> { | ||
|
||
public TextFeedCardPresenter(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
protected TextFeedCardView onCreateView() { | ||
return new TextFeedCardView(getContext()); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(CardItem cardItem, TextFeedCardView cardView) { | ||
cardView.updateUi(cardItem); | ||
} | ||
|
||
} |
Oops, something went wrong.