package com.aesthetikx.hubski;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import com.aesthetikx.hubski.model.Feed;
import com.aesthetikx.hubski.model.Post;

public class FeedListAdapter extends BaseAdapter implements ListAdapter {

    private Feed feed;
    private Context context;

    public FeedListAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return (feed == null) ? 0 : feed.getPosts().size();
    }

    @Override
    public Object getItem(int position) {
        return feed.getPosts().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.feed_list_item, parent, false);
            TextView title = (TextView)view.findViewById(R.id.text_view_title);
            TextView username = (TextView)view.findViewById(R.id.text_view_username);
            TextView score = (TextView)view.findViewById(R.id.text_view_score);
            TextView tags = (TextView)view.findViewById(R.id.text_view_tags);

            Post post = feed.getPosts().get(position);
            title.setText(post.getTitle());
            username.setText(post.getUsername());
            score.setText(post.getShareCount() + "");
            tags.setText(post.getTagsString());
        }else{
            view = convertView;
        }
        return view;
    }

    @Override
    public boolean isEmpty() {
        return feed.getPosts().isEmpty();
    }

    public void setFeed(Feed feed) {
        this.feed = feed;
    }
}

@@ -1183,32 +1183,85 @@
 nt, false);%0A    
+    %7Delse%7B%0A            view = convertView;%0A        %7D%0A
         TextView
@@ -1320,36 +1320,32 @@
 title);%0A        
- 
-   
 TextView usernam
@@ -1402,36 +1402,32 @@
 rname);%0A        
-    
 TextView score =
@@ -1482,28 +1482,24 @@
 e);%0A        
-  
-  
 TextView tag
@@ -1561,20 +1561,16 @@
         
-    
 Post pos
@@ -1612,20 +1612,16 @@
         
-  
-  
 title.se
@@ -1640,28 +1640,24 @@
 etTitle());%0A
-    
         user
@@ -1698,20 +1698,16 @@
         
-   
- 
 score.se
@@ -1748,20 +1748,16 @@
         
-    
 tags.set
@@ -1788,65 +1788,8 @@
 ));%0A
-        %7Delse%7B%0A            view = convertView;%0A        %7D%0A
     

Fix updating convertview in adapter