Skip to content

Commit

Permalink
Fix #318
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Development committed Jun 21, 2015
1 parent bd3c94f commit 17afd9d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
Expand Up @@ -106,10 +106,10 @@ public String toString() {
}
}

int mTextColorLightTheme;
private int mTextColorLightTheme;
private FavIconHandler favIconHandler;

LayoutInflater inflater;
private final String favIconPath;
boolean mIsTwoPane;
public static boolean isTwoPane(Context context) {
return context.getResources().getBoolean(R.bool.two_pane);
Expand All @@ -120,7 +120,8 @@ public SubscriptionExpandableListAdapter(Context mContext, DatabaseConnectionOrm
{
mIsTwoPane = isTwoPane(mContext);

this.favIconPath = FileUtils.getPathFavIcons(mContext);
favIconHandler = new FavIconHandler(mContext);

this.inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mContext = mContext;
this.dbConn = dbConn;
Expand Down Expand Up @@ -186,7 +187,7 @@ public View getChildView(int groupPosition, int childPosition,
else
viewHolder.tV_UnreadCount.setText("");

loadFavIconForFeed(item.favIcon, viewHolder.imgView_FavIcon);
favIconHandler.loadFavIconForFeed(item.favIcon, viewHolder.imgView_FavIcon);
}
else
{
Expand Down Expand Up @@ -316,7 +317,7 @@ public void onClick(View v) {
if(group.idFolder == ITEMS_WITHOUT_FOLDER.getValue())
{
ConcreteFeedItem concreteFeedItem = ((ConcreteFeedItem) group);
loadFavIconForFeed(concreteFeedItem.favIcon, viewHolder.imgView);
favIconHandler.loadFavIconForFeed(concreteFeedItem.favIcon, viewHolder.imgView);
}
} else {
if(group.id_database == ALL_STARRED_ITEMS.getValue()) {
Expand All @@ -343,21 +344,7 @@ public void onClick(View v) {
return convertView;
}

private void loadFavIconForFeed(String favIconUrl, ImageView imgView) {

File cacheFile = ImageHandler.getFullPathOfCacheFileSafe(favIconUrl, favIconPath);
if(cacheFile != null && cacheFile.exists()) {
Picasso.with(mContext)
.load(cacheFile)
.placeholder(FavIconHandler.getResourceIdForRightDefaultFeedIcon(mContext))
.into(imgView, null);
} else {
Picasso.with(mContext)
.load(favIconUrl)
.placeholder(FavIconHandler.getResourceIdForRightDefaultFeedIcon(mContext))
.into(imgView, null);
}
}



Expand Down
Expand Up @@ -50,6 +50,7 @@
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.events.podcast.UpdatePodcastStatusEvent;
import de.luhmer.owncloudnewsreader.helper.FavIconHandler;
import de.luhmer.owncloudnewsreader.helper.FillTextForTextViewHelper;
import de.luhmer.owncloudnewsreader.helper.FontHelper;
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
Expand Down Expand Up @@ -78,7 +79,7 @@ public class NewsListArrayAdapter extends GreenDaoListAdapter<RssItem> {
private int selectedDesign = 0;
private FragmentActivity mActivity;
private IPlayPausePodcastClicked playPausePodcastClicked;

private FavIconHandler favIconHandler;

public NewsListArrayAdapter(FragmentActivity activity, LazyList<RssItem> lazyList, IOnStayUnread onStayUnread, IPlayPausePodcastClicked playPausePodcastClicked) {
super(activity, lazyList);
Expand All @@ -87,6 +88,7 @@ public NewsListArrayAdapter(FragmentActivity activity, LazyList<RssItem> lazyLis
this.onStayUnread = onStayUnread;
this.playPausePodcastClicked = playPausePodcastClicked;

favIconHandler = new FavIconHandler(mActivity);
pDelayHandler = new PostDelayHandler(context);

//simpleDateFormat = new SimpleDateFormat("EEE, d. MMM HH:mm:ss");
Expand Down Expand Up @@ -250,6 +252,9 @@ static class SimpleLayout {
@Optional
@InjectView(R.id.fl_playPausePodcastWrapper)
FrameLayout flPlayPausePodcastWrapper;
@Optional
@InjectView(R.id.imgViewFavIcon)
ImageView imgViewFavIcon;

SimpleLayout(View view) {
ButterKnife.inject(this, view);
Expand Down Expand Up @@ -289,6 +294,8 @@ public void setSimpleLayout(View view, final RssItem rssItem) {
}


favIconHandler.loadFavIconForFeed(rssItem.getFeed().getFaviconUrl(), simpleLayout.imgViewFavIcon);

//Podcast stuff
if (DatabaseConnectionOrm.ALLOWED_PODCASTS_TYPES.contains(rssItem.getEnclosureMime())) {
final boolean isPlaying = idOfCurrentlyPlayedPodcast == rssItem.getId();
Expand Down
Expand Up @@ -33,6 +33,8 @@
import android.util.SparseArray;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.io.File;
import java.lang.ref.WeakReference;

Expand All @@ -44,10 +46,27 @@
public class FavIconHandler {
private static final String TAG = "FavIconHandler";

Context context;
private Context context;
private final String favIconPath;

public FavIconHandler(Context context) {
this.context = context;
favIconPath = FileUtils.getPathFavIcons(context);
}

public void loadFavIconForFeed(String favIconUrl, ImageView imgView) {
File cacheFile = ImageHandler.getFullPathOfCacheFileSafe(favIconUrl, favIconPath);
if(cacheFile != null && cacheFile.exists()) {
Picasso.with(context)
.load(cacheFile)
.placeholder(FavIconHandler.getResourceIdForRightDefaultFeedIcon(context))
.into(imgView, null);
} else {
Picasso.with(context)
.load(favIconUrl)
.placeholder(FavIconHandler.getResourceIdForRightDefaultFeedIcon(context))
.into(imgView, null);
}
}

public static Drawable GetFavIconFromCache(String URL_TO_PAGE, Context context, Long feedID)
Expand Down Expand Up @@ -94,7 +113,7 @@ public void PreCacheFavIcon(Feed feed) {
return;
}

GetImageThreaded giAsync = new GetImageThreaded(feed.getFaviconUrl(), favIconDownloadFinished, feed.getId(), FileUtils.getPathFavIcons(context), context);
GetImageThreaded giAsync = new GetImageThreaded(feed.getFaviconUrl(), favIconDownloadFinished, feed.getId(), favIconPath, context);
giAsync.scaleImage = true;
giAsync.dstHeight = 2*32;
giAsync.dstWidth = 2*32;
Expand Down
Expand Up @@ -31,15 +31,22 @@
android:layout_marginTop="@dimen/listview_row_margin_top"
android:orientation="horizontal" >

<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginTop="3dp"
android:layout_marginRight="5dp"
android:id="@+id/imgViewFavIcon"/>

<TextView
android:id="@+id/tv_subscription"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_vertical"
android:layout_gravity="left"
android:singleLine="true"
android:text="Hdfsa"
android:text="Hdfsffsggfddsa"
android:layout_weight="1"
android:textSize="15sp" />

Expand Down
Expand Up @@ -70,6 +70,13 @@
android:layout_height="match_parent"
android:orientation="horizontal" >

<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_marginTop="2dp"
android:layout_marginRight="5dp"
android:id="@+id/imgViewFavIcon"/>

<TextView
android:id="@+id/tv_subscription"
android:layout_width="0dp"
Expand Down

0 comments on commit 17afd9d

Please sign in to comment.