draw separate views for active/unread/normal headlines and feeds

This commit is contained in:
Andrew Dolgov 2011-11-24 13:01:51 +03:00
parent d7dfd661ce
commit e9c02c8eca
12 changed files with 193 additions and 66 deletions

View File

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="width"
android:duration="500"
android:valueFrom="400"
android:valueTo="0"
android:valueType="intType"/>
</set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="-1280"
android:valueTo="0"
android:duration="500"/>
</set>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:background="?feedsSelectedBackground"
android:gravity="center_vertical"
android:id="@+id/feeds_row" android:layout_width="match_parent" android:paddingBottom="4dip" android:paddingLeft="8dip" android:paddingRight="8dip" android:paddingTop="4dip">
<TextView
android:id="@+id/title"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:paddingLeft="6dip"
android:text="{FEED}" android:layout_width="wrap_content" android:textSize="21dp"/>
<TextView
android:id="@+id/unread_counter"
android:gravity="right"
android:textStyle="bold"
android:paddingRight="6dip"
android:textColor="?unreadCounterColor"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="{123}" android:textSize="16dp"/>
</LinearLayout>

View File

@ -3,7 +3,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/headlines_fragment">
<ListView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/headlines" android:background="?headlinesBackground"></ListView>
<ListView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/headlines"></ListView>
<LinearLayout android:id="@+id/loading_container" android:gravity="center" android:layout_height="match_parent" android:layout_width="match_parent">
<ProgressBar android:layout_width="wrap_content" style="?android:attr/progressBarStyleLarge" android:id="@+id/loading_progress" android:layout_height="wrap_content"></ProgressBar>
<TextView android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:id="@+id/loading_message" android:layout_height="wrap_content" ></TextView>

View File

@ -2,14 +2,20 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:gravity="center_vertical"
android:padding="3dip" android:id="@+id/headlines_row" android:orientation="horizontal" android:layout_height="wrap_content">
android:id="@+id/headlines_row" android:orientation="horizontal" android:layout_height="wrap_content">
<ImageView android:background="?feedsSelectedBackground" android:paddingRight="4dip" android:layout_height="match_parent" android:layout_width="wrap_content"></ImageView>
<CheckBox android:focusable="false"
android:paddingLeft="6dip" android:paddingRight="6dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/selected"></CheckBox>
<ImageView android:layout_width="wrap_content" android:id="@+id/imageView1" android:layout_height="wrap_content" android:src="@android:drawable/star_off" android:paddingRight="5dip" android:clickable="true"></ImageView>
<LinearLayout android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_width="match_parent">
<TextView android:id="@+id/title" android:textSize="16sp" android:text="{Title...}" android:layout_width="match_parent" android:layout_height="match_parent"></TextView>
<TextView android:id="@+id/excerpt" android:textSize="13sp" android:textColor="#909090" android:text="{Content excerpt...}" android:layout_width="match_parent" android:layout_height="match_parent"></TextView>
</LinearLayout>
<LinearLayout android:orientation="vertical" android:id="@+id/linearLayout1" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:singleLine="true" android:ellipsize="end" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/title" android:text="{Title...}" android:textSize="16sp"></TextView>
<TextView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/excerpt" android:text="{Content excerpt...}" android:textSize="13sp" android:textColor="#909090"></TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linerLayout3"
android:layout_width="wrap_content" android:gravity="center"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/date" android:text="Jan 01"></TextView>
<ImageView android:clickable="true" android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/star_off"></ImageView>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:gravity="center_vertical"
android:background="?headlinesSelectedBackground"
android:padding="3dip" android:id="@+id/headlines_row" android:orientation="horizontal" android:layout_height="wrap_content">
<ImageView android:background="?feedsSelectedBackground" android:paddingRight="4dip" android:layout_height="match_parent" android:layout_width="wrap_content"></ImageView>
<CheckBox android:focusable="false"
android:paddingLeft="6dip" android:paddingRight="6dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/selected"></CheckBox>
<LinearLayout android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_width="match_parent">
<TextView android:singleLine="true" android:ellipsize="end" android:id="@+id/title" android:textSize="16sp" android:text="{Title...}" android:layout_width="match_parent" android:layout_height="match_parent"></TextView>
<TextView android:id="@+id/excerpt" android:textSize="13sp" android:textColor="#909090" android:text="{Content excerpt...}" android:layout_width="match_parent" android:layout_height="match_parent"></TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linerLayout3"
android:layout_width="wrap_content" android:gravity="center"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/date" android:text="Jan 01"></TextView>
<ImageView android:clickable="true" android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/star_off"></ImageView>
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:gravity="center_vertical"
android:background="@android:color/white"
android:padding="3dip" android:id="@+id/headlines_row" android:orientation="horizontal" android:layout_height="wrap_content">
<ImageView android:background="?feedsSelectedBackground" android:paddingRight="4dip" android:layout_height="match_parent" android:layout_width="wrap_content"></ImageView>
<CheckBox android:focusable="false"
android:paddingLeft="6dip" android:paddingRight="6dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/selected"></CheckBox>
<LinearLayout android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_width="match_parent">
<TextView android:singleLine="true" android:ellipsize="end" android:id="@+id/title" android:textSize="16sp" android:text="{Title...}" android:layout_width="match_parent" android:layout_height="match_parent"></TextView>
<TextView android:id="@+id/excerpt" android:textSize="13sp" android:textColor="#909090" android:text="{Content excerpt...}" android:layout_width="match_parent" android:layout_height="match_parent"></TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linerLayout3"
android:layout_width="wrap_content" android:gravity="center"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/date" android:text="Jan 01"></TextView>
<ImageView android:clickable="true" android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/star_off"></ImageView>
</LinearLayout>
</LinearLayout>

View File

@ -6,4 +6,6 @@
<attr name="headlinesBackground" format="reference|color" />
<attr name="articleHeader" format="reference|color" />
<attr name="articleDivider" format="reference|color" />
<attr name="headlinesSelectedBackground" format="reference|color" />
<attr name="feedsSelectedBackground" format="reference|color" />
</resources>

View File

@ -4,8 +4,10 @@
<item name="feedlistBackground">#fafafa</item>
<item name="unreadCounterColor">#0000ff</item>
<item name="headlinesBackground">#ffffff</item>
<item name="articleDivider">#f0f0f0</item>
<item name="articleHeader">#E8F2FF</item>
<item name="articleDivider">#96c5ff</item>
<item name="articleHeader">#ffffff</item>
<item name="headlinesSelectedBackground">#fff7d5</item>
<item name="feedsSelectedBackground">#96C5FF</item>
</style>
<style name="DarkTheme" parent="android:Theme.Holo">
@ -15,22 +17,8 @@
<item name="headlinesBackground">#000000</item>
<item name="articleDivider">#303030</item>
<item name="articleHeader">#101010</item>
<item name="headlinesSelectedBackground">#303060</item>
<item name="feedsSelectedBackground">#303060</item>
</style>
<style name="SelectedFeed">
<item name="android:textStyle">bold</item>
</style>
<style name="Feed">
<item name="android:textStyle">normal</item>
</style>
<style name="UnreadArticle">
<item name="android:textStyle">bold</item>
</style>
<style name="Article">
<item name="android:textStyle">normal</item>
</style>
</resources>

View File

@ -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;

View File

@ -35,6 +35,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
private FeedListAdapter m_adapter;
private List<Feed> m_feeds = new ArrayList<Feed>();
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<Feed>)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<Feed> {
private ArrayList<Feed> 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<Feed> 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;
}
}
}

View File

@ -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<Article> m_articles = new ArrayList<Article>();
@ -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<Article> {
private ArrayList<Article> 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<Article> 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;
}
}

View File

@ -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();