From e9c02c8eca9079c57af6a9c941b50ab11259e3cd Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 24 Nov 2011 13:01:51 +0300 Subject: [PATCH] draw separate views for active/unread/normal headlines and feeds --- res/anim/slide_in_left.xml | 16 +++--- res/layout/feeds_row_selected.xml | 26 ++++++++++ res/layout/headlines_fragment.xml | 2 +- res/layout/headlines_row.xml | 20 ++++--- res/layout/headlines_row_selected.xml | 24 +++++++++ res/layout/headlines_row_unread.xml | 24 +++++++++ res/values/attrs.xml | 2 + res/values/style.xml | 26 +++------- src/org/fox/ttrss/ArticleFragment.java | 3 -- src/org/fox/ttrss/FeedsFragment.java | 47 ++++++++++++----- src/org/fox/ttrss/HeadlinesFragment.java | 66 +++++++++++++++++++----- src/org/fox/ttrss/MainActivity.java | 3 -- 12 files changed, 193 insertions(+), 66 deletions(-) create mode 100644 res/layout/feeds_row_selected.xml create mode 100644 res/layout/headlines_row_selected.xml create mode 100644 res/layout/headlines_row_unread.xml diff --git a/res/anim/slide_in_left.xml b/res/anim/slide_in_left.xml index 10a16677..11991019 100644 --- a/res/anim/slide_in_left.xml +++ b/res/anim/slide_in_left.xml @@ -1,11 +1,9 @@ - - - - + + \ No newline at end of file diff --git a/res/layout/feeds_row_selected.xml b/res/layout/feeds_row_selected.xml new file mode 100644 index 00000000..7ee526f7 --- /dev/null +++ b/res/layout/feeds_row_selected.xml @@ -0,0 +1,26 @@ + + + + + + \ No newline at end of file diff --git a/res/layout/headlines_fragment.xml b/res/layout/headlines_fragment.xml index c5536c5c..83174697 100644 --- a/res/layout/headlines_fragment.xml +++ b/res/layout/headlines_fragment.xml @@ -3,7 +3,7 @@ - + diff --git a/res/layout/headlines_row.xml b/res/layout/headlines_row.xml index 656ff80a..b47528d0 100644 --- a/res/layout/headlines_row.xml +++ b/res/layout/headlines_row.xml @@ -2,14 +2,20 @@ + android:id="@+id/headlines_row" android:orientation="horizontal" android:layout_height="wrap_content"> + - - - - - - + + + + + + + + \ No newline at end of file diff --git a/res/layout/headlines_row_selected.xml b/res/layout/headlines_row_selected.xml new file mode 100644 index 00000000..81760bc4 --- /dev/null +++ b/res/layout/headlines_row_selected.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/headlines_row_unread.xml b/res/layout/headlines_row_unread.xml new file mode 100644 index 00000000..e139cfad --- /dev/null +++ b/res/layout/headlines_row_unread.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 76647f0e..9a6bbea0 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -6,4 +6,6 @@ + + \ No newline at end of file diff --git a/res/values/style.xml b/res/values/style.xml index 4bc343e1..69c2e1d6 100644 --- a/res/values/style.xml +++ b/res/values/style.xml @@ -4,8 +4,10 @@ #fafafa #0000ff #ffffff - #f0f0f0 - #E8F2FF + #96c5ff + #ffffff + #fff7d5 + #96C5FF - - - - - - - - - + \ No newline at end of file diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index 720c2271..abde36a0 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -2,13 +2,10 @@ package org.fox.ttrss; import java.net.URLEncoder; -import org.jsoup.Jsoup; - import android.app.Activity; import android.app.Fragment; import android.content.SharedPreferences; import android.os.Bundle; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index ad2bd2ef..3b5fefbc 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -35,6 +35,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { private FeedListAdapter m_adapter; private List m_feeds = new ArrayList(); private OnFeedSelectedListener m_feedSelectedListener; + private int m_selectedFeedId; public interface OnFeedSelectedListener { public void onFeedSelected(Feed feed); @@ -64,7 +65,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { ListView list = (ListView)view.findViewById(R.id.feeds); m_adapter = new FeedListAdapter(getActivity(), R.layout.feeds_row, (ArrayList)m_feeds); list.setAdapter(m_adapter); - list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); + //list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); list.setOnItemClickListener(this); //if (m_sessionId != null) @@ -104,6 +105,8 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { if (list != null) { Feed feed = (Feed)list.getItemAtPosition(position); m_feedSelectedListener.onFeedSelected(feed); + m_selectedFeedId = feed.id; + m_adapter.notifyDataSetChanged(); } } @@ -217,34 +220,55 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { private class FeedListAdapter extends ArrayAdapter { private ArrayList items; + public static final int VIEW_NORMAL = 0; + public static final int VIEW_SELECTED = 1; + + public static final int VIEW_COUNT = VIEW_SELECTED+1; + public FeedListAdapter(Context context, int textViewResourceId, ArrayList items) { super(context, textViewResourceId, items); this.items = items; } - + + public int getViewTypeCount() { + return VIEW_COUNT; + } + + @Override + public int getItemViewType(int position) { + Feed feed = items.get(position); + + if (feed.id == m_selectedFeedId) { + return VIEW_SELECTED; + } else { + return VIEW_NORMAL; + } + } + @Override public View getView(int position, View convertView, ViewGroup parent) { - - Feed active_feed = ((MainActivity)getActivity()).getActiveFeed(); - View v = convertView; Feed feed = items.get(position); if (v == null) { + int layoutId = R.layout.feeds_row; + + switch (getItemViewType(position)) { + case VIEW_SELECTED: + layoutId = R.layout.feeds_row_selected; + break; + } + LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - v = vi.inflate(R.layout.feeds_row, null); + v = vi.inflate(layoutId, null); + } TextView tt = (TextView) v.findViewById(R.id.title); if (tt != null) { tt.setText(feed.title); - - if (active_feed != null && feed.id == active_feed.id) - tt.setTextAppearance(getContext(), R.style.SelectedFeed); - else - tt.setTextAppearance(getContext(), R.style.Feed); } TextView tu = (TextView) v.findViewById(R.id.unread_counter); @@ -257,5 +281,4 @@ public class FeedsFragment extends Fragment implements OnItemClickListener { return v; } } - } diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index 8aceb830..00e1448e 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -1,16 +1,17 @@ package org.fox.ttrss; import java.lang.reflect.Type; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; -import org.fox.ttrss.FeedsFragment.OnFeedSelectedListener; import org.jsoup.Jsoup; import android.app.Activity; import android.app.Fragment; -import android.app.FragmentTransaction; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; @@ -37,6 +38,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { private String m_sessionId; private Feed m_feed; //private int m_activeArticleId; + private int m_selectedArticleId; private ArticleListAdapter m_adapter; private List
m_articles = new ArrayList
(); @@ -98,6 +100,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { if (list != null) { Article article = (Article)list.getItemAtPosition(position); m_articleSelectedListener.onArticleSelected(article); + + article.unread = false; + m_selectedArticleId = article.id; + m_adapter.notifyDataSetChanged(); } } @@ -115,6 +121,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { put("limit", String.valueOf(30)); put("offset", String.valueOf(0)); put("view_mode", "adaptive"); + //put("view_mode", "all_articles"); } }; @@ -197,35 +204,62 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { private class ArticleListAdapter extends ArrayAdapter
{ private ArrayList
items; + + public static final int VIEW_NORMAL = 0; + public static final int VIEW_UNREAD = 1; + public static final int VIEW_SELECTED = 2; + + public static final int VIEW_COUNT = VIEW_SELECTED+1; public ArticleListAdapter(Context context, int textViewResourceId, ArrayList
items) { super(context, textViewResourceId, items); this.items = items; } + public int getViewTypeCount() { + return VIEW_COUNT; + } + + @Override + public int getItemViewType(int position) { + Article a = items.get(position); + + if (a.id == m_selectedArticleId) { + return VIEW_SELECTED; + } else if (a.unread) { + return VIEW_UNREAD; + } else { + return VIEW_NORMAL; + } + } + @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; Article article = items.get(position); - + if (v == null) { + int layoutId = R.layout.headlines_row; + + switch (getItemViewType(position)) { + case VIEW_UNREAD: + layoutId = R.layout.headlines_row_unread; + break; + case VIEW_SELECTED: + layoutId = R.layout.headlines_row_selected; + break; + } + LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - v = vi.inflate(R.layout.headlines_row, null); + v = vi.inflate(layoutId, null); } TextView tt = (TextView) v.findViewById(R.id.title); if (tt != null) { tt.setText(article.title); - //tt.setTextAppearance(getContext(), R.style.Connection); - - if (article.unread) - tt.setTextAppearance(getContext(), R.style.UnreadArticle); - else - tt.setTextAppearance(getContext(), R.style.Article); - } TextView te = (TextView) v.findViewById(R.id.excerpt); @@ -234,11 +268,19 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { String excerpt = Jsoup.parse(article.content).text(); if (excerpt.length() > 250) - excerpt = excerpt.substring(0, 250) + "..."; + excerpt = excerpt.substring(0, 100) + "..."; te.setText(excerpt); } + TextView dv = (TextView) v.findViewById(R.id.date); + + if (dv != null) { + Date d = new Date((long)article.updated * 1000); + DateFormat df = new SimpleDateFormat("MMM dd, HH:mm"); + dv.setText(df.format(d)); + } + return v; } } diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index e839c55b..35309338 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -315,9 +315,6 @@ public class MainActivity extends Activity implements FeedsFragment.OnFeedSelect m_selectedArticle = article; - article.unread = false; - - ArticleFragment frag = new ArticleFragment(); FragmentTransaction ft = getFragmentManager().beginTransaction();