offline headlines: use view holder
headlines: prevent footer from being clickable
This commit is contained in:
parent
61f6713645
commit
82df9eb2ac
@ -696,6 +696,16 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
holder = (HeadlineViewHolder) v.getTag();
|
holder = (HeadlineViewHolder) v.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// block footer clicks to make button/selection clicking easier
|
||||||
|
if (holder.headlineFooter != null) {
|
||||||
|
holder.headlineFooter.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (holder.titleView != null) {
|
if (holder.titleView != null) {
|
||||||
holder.titleView.setText(Html.fromHtml(article.title));
|
holder.titleView.setText(Html.fromHtml(article.title));
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.fox.ttrss.CommonActivity;
|
import org.fox.ttrss.CommonActivity;
|
||||||
@ -425,6 +426,23 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
getActivity().setProgressBarIndeterminateVisibility(showProgress);
|
getActivity().setProgressBarIndeterminateVisibility(showProgress);
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
static class HeadlineViewHolder {
|
||||||
|
public TextView titleView;
|
||||||
|
public TextView feedTitleView;
|
||||||
|
public ImageView markedView;
|
||||||
|
public ImageView publishedView;
|
||||||
|
public TextView excerptView;
|
||||||
|
public ImageView flavorImageView;
|
||||||
|
public TextView authorView;
|
||||||
|
public TextView dateView;
|
||||||
|
public CheckBox selectionBoxView;
|
||||||
|
public ImageView menuButtonView;
|
||||||
|
public ViewGroup flavorImageHolder;
|
||||||
|
public ProgressBar flavorImageLoadingBar;
|
||||||
|
public View flavorImageArrow;
|
||||||
|
public View headlineFooter;
|
||||||
|
}
|
||||||
|
|
||||||
private class ArticleListAdapter extends SimpleCursorAdapter {
|
private class ArticleListAdapter extends SimpleCursorAdapter {
|
||||||
public static final int VIEW_NORMAL = 0;
|
public static final int VIEW_NORMAL = 0;
|
||||||
public static final int VIEW_UNREAD = 1;
|
public static final int VIEW_UNREAD = 1;
|
||||||
@ -474,6 +492,9 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
View v = convertView;
|
View v = convertView;
|
||||||
|
|
||||||
Cursor article = (Cursor)getItem(position);
|
Cursor article = (Cursor)getItem(position);
|
||||||
|
|
||||||
|
HeadlineViewHolder holder;
|
||||||
|
|
||||||
final int articleId = article.getInt(0);
|
final int articleId = article.getInt(0);
|
||||||
|
|
||||||
int headlineFontSize = Integer.parseInt(m_prefs.getString("headlines_font_size_sp", "13"));
|
int headlineFontSize = Integer.parseInt(m_prefs.getString("headlines_font_size_sp", "13"));
|
||||||
@ -500,59 +521,84 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
v = vi.inflate(layoutId, null);
|
v = vi.inflate(layoutId, null);
|
||||||
|
|
||||||
|
holder = new HeadlineViewHolder();
|
||||||
|
holder.titleView = (TextView)v.findViewById(R.id.title);
|
||||||
|
|
||||||
|
holder.feedTitleView = (TextView)v.findViewById(R.id.feed_title);
|
||||||
|
holder.markedView = (ImageView)v.findViewById(R.id.marked);
|
||||||
|
holder.publishedView = (ImageView)v.findViewById(R.id.published);
|
||||||
|
holder.excerptView = (TextView)v.findViewById(R.id.excerpt);
|
||||||
|
holder.flavorImageView = (ImageView) v.findViewById(R.id.flavor_image);
|
||||||
|
holder.authorView = (TextView)v.findViewById(R.id.author);
|
||||||
|
holder.dateView = (TextView) v.findViewById(R.id.date);
|
||||||
|
holder.selectionBoxView = (CheckBox) v.findViewById(R.id.selected);
|
||||||
|
holder.menuButtonView = (ImageView) v.findViewById(R.id.article_menu_button);
|
||||||
|
holder.flavorImageHolder = (ViewGroup) v.findViewById(R.id.flavorImageHolder);
|
||||||
|
holder.flavorImageLoadingBar = (ProgressBar) v.findViewById(R.id.flavorImageLoadingBar);
|
||||||
|
holder.flavorImageArrow = v.findViewById(R.id.flavorImageArrow);
|
||||||
|
holder.headlineFooter = v.findViewById(R.id.headline_footer);
|
||||||
|
|
||||||
|
v.setTag(holder);
|
||||||
|
|
||||||
// http://code.google.com/p/android/issues/detail?id=3414
|
// http://code.google.com/p/android/issues/detail?id=3414
|
||||||
((ViewGroup)v).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
((ViewGroup)v).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
||||||
|
} else {
|
||||||
|
holder = (HeadlineViewHolder) v.getTag();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView tt = (TextView)v.findViewById(R.id.title);
|
// block footer clicks to make button/selection clicking easier
|
||||||
|
if (holder.headlineFooter != null) {
|
||||||
|
holder.headlineFooter.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (tt != null) {
|
if (holder.titleView != null) {
|
||||||
|
|
||||||
tt.setText(Html.fromHtml(article.getString(article.getColumnIndex("title"))));
|
holder.titleView.setText(Html.fromHtml(article.getString(article.getColumnIndex("title"))));
|
||||||
|
|
||||||
if (m_prefs.getBoolean("enable_condensed_fonts", false)) {
|
if (m_prefs.getBoolean("enable_condensed_fonts", false)) {
|
||||||
Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", article.getInt(article.getColumnIndex("unread")) == 1 ? Typeface.BOLD : Typeface.NORMAL);
|
Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", article.getInt(article.getColumnIndex("unread")) == 1 ? Typeface.BOLD : Typeface.NORMAL);
|
||||||
|
|
||||||
if (tf != null && !tf.equals(tt.getTypeface())) {
|
if (tf != null && !tf.equals(holder.titleView.getTypeface())) {
|
||||||
tt.setTypeface(tf);
|
holder.titleView.setTypeface(tf);
|
||||||
}
|
}
|
||||||
|
|
||||||
tt.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 5));
|
holder.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 5));
|
||||||
} else {
|
} else {
|
||||||
tt.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 3));
|
holder.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
int scoreIndex = article.getColumnIndex("score");
|
int scoreIndex = article.getColumnIndex("score");
|
||||||
if (scoreIndex >= 0)
|
if (scoreIndex >= 0)
|
||||||
adjustTitleTextView(article.getInt(scoreIndex), tt, position);
|
adjustTitleTextView(article.getInt(scoreIndex), holder.titleView, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView ft = (TextView)v.findViewById(R.id.feed_title);
|
|
||||||
|
|
||||||
int feedTitleIndex = article.getColumnIndex("feed_title");
|
int feedTitleIndex = article.getColumnIndex("feed_title");
|
||||||
|
|
||||||
if (ft != null && feedTitleIndex != -1 && m_feedIsCat) {
|
if (holder.feedTitleView != null && feedTitleIndex != -1 && m_feedIsCat) {
|
||||||
String feedTitle = article.getString(feedTitleIndex);
|
String feedTitle = article.getString(feedTitleIndex);
|
||||||
|
|
||||||
if (feedTitle.length() > 20)
|
if (feedTitle.length() > 20)
|
||||||
feedTitle = feedTitle.substring(0, 20) + "...";
|
feedTitle = feedTitle.substring(0, 20) + "...";
|
||||||
|
|
||||||
if (feedTitle.length() > 0) {
|
if (feedTitle.length() > 0) {
|
||||||
ft.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
holder.feedTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
||||||
ft.setText(feedTitle);
|
holder.feedTitleView.setText(feedTitle);
|
||||||
} else {
|
} else {
|
||||||
ft.setVisibility(View.GONE);
|
holder.feedTitleView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
} else if (ft != null) {
|
} else if (holder.feedTitleView != null) {
|
||||||
ft.setVisibility(View.GONE);
|
holder.feedTitleView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView marked = (ImageView)v.findViewById(R.id.marked);
|
if (holder.markedView != null) {
|
||||||
|
holder.markedView.setImageResource(article.getInt(article.getColumnIndex("marked")) == 1 ? R.drawable.ic_star_full : R.drawable.ic_star_empty);
|
||||||
|
|
||||||
if (marked != null) {
|
holder.markedView.setOnClickListener(new OnClickListener() {
|
||||||
marked.setImageResource(article.getInt(article.getColumnIndex("marked")) == 1 ? R.drawable.ic_star_full : R.drawable.ic_star_empty);
|
|
||||||
|
|
||||||
marked.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -568,12 +614,10 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView published = (ImageView)v.findViewById(R.id.published);
|
if (holder.publishedView != null) {
|
||||||
|
holder.publishedView.setImageResource(article.getInt(article.getColumnIndex("published")) == 1 ? R.drawable.ic_published : R.drawable.ic_unpublished);
|
||||||
|
|
||||||
if (published != null) {
|
holder.publishedView.setOnClickListener(new OnClickListener() {
|
||||||
published.setImageResource(article.getInt(article.getColumnIndex("published")) == 1 ? R.drawable.ic_published : R.drawable.ic_unpublished);
|
|
||||||
|
|
||||||
published.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -589,64 +633,50 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView te = (TextView)v.findViewById(R.id.excerpt);
|
if (holder.excerptView != null) {
|
||||||
|
|
||||||
if (te != null) {
|
|
||||||
if (!m_prefs.getBoolean("headlines_show_content", true)) {
|
if (!m_prefs.getBoolean("headlines_show_content", true)) {
|
||||||
te.setVisibility(View.GONE);
|
holder.excerptView.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
String excerpt = Jsoup.parse(article.getString(article.getColumnIndex("content"))).text();
|
String excerpt = Jsoup.parse(article.getString(article.getColumnIndex("content"))).text();
|
||||||
|
|
||||||
if (excerpt.length() > CommonActivity.EXCERPT_MAX_SIZE)
|
if (excerpt.length() > CommonActivity.EXCERPT_MAX_SIZE)
|
||||||
excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_SIZE) + "...";
|
excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_SIZE) + "...";
|
||||||
|
|
||||||
te.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineFontSize);
|
holder.excerptView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineFontSize);
|
||||||
te.setText(excerpt);
|
holder.excerptView.setText(excerpt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView ta = (TextView)v.findViewById(R.id.author);
|
if (holder.authorView != null) {
|
||||||
|
|
||||||
if (ta != null) {
|
|
||||||
int authorIndex = article.getColumnIndex("author");
|
int authorIndex = article.getColumnIndex("author");
|
||||||
if (authorIndex >= 0) {
|
if (authorIndex >= 0) {
|
||||||
String author = article.getString(authorIndex);
|
String author = article.getString(authorIndex);
|
||||||
|
|
||||||
ta.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
holder.authorView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
||||||
|
|
||||||
if (author != null && author.length() > 0)
|
if (author != null && author.length() > 0)
|
||||||
ta.setText(getString(R.string.author_formatted, author));
|
holder.authorView.setText(getString(R.string.author_formatted, author));
|
||||||
else
|
else
|
||||||
ta.setText("");
|
holder.authorView.setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ImageView separator = (ImageView)v.findViewById(R.id.headlines_separator);
|
if (holder.dateView != null) {
|
||||||
|
holder.dateView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
||||||
if (separator != null && m_offlineServices.isSmallScreen()) {
|
|
||||||
separator.setVisibility(View.GONE);
|
|
||||||
} */
|
|
||||||
|
|
||||||
TextView dv = (TextView) v.findViewById(R.id.date);
|
|
||||||
|
|
||||||
if (dv != null) {
|
|
||||||
dv.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
|
||||||
|
|
||||||
Date d = new Date((long)article.getInt(article.getColumnIndex("updated")) * 1000);
|
Date d = new Date((long)article.getInt(article.getColumnIndex("updated")) * 1000);
|
||||||
DateFormat df = new SimpleDateFormat("MMM dd, HH:mm");
|
DateFormat df = new SimpleDateFormat("MMM dd, HH:mm");
|
||||||
df.setTimeZone(TimeZone.getDefault());
|
df.setTimeZone(TimeZone.getDefault());
|
||||||
dv.setText(df.format(d));
|
holder.dateView.setText(df.format(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckBox cb = (CheckBox) v.findViewById(R.id.selected);
|
if (holder.selectionBoxView != null) {
|
||||||
|
holder.selectionBoxView.setChecked(article.getInt(article.getColumnIndex("selected")) == 1);
|
||||||
if (cb != null) {
|
holder.selectionBoxView.setOnClickListener(new OnClickListener() {
|
||||||
cb.setChecked(article.getInt(article.getColumnIndex("selected")) == 1);
|
|
||||||
cb.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
CheckBox cb = (CheckBox)view;
|
CheckBox cb = (CheckBox) view;
|
||||||
|
|
||||||
SQLiteStatement stmtUpdate = m_activity.getWritableDb().compileStatement("UPDATE articles SET selected = ? " +
|
SQLiteStatement stmtUpdate = m_activity.getWritableDb().compileStatement("UPDATE articles SET selected = ? " +
|
||||||
"WHERE " + BaseColumns._ID + " = ?");
|
"WHERE " + BaseColumns._ID + " = ?");
|
||||||
@ -664,19 +694,15 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
View flavorImageHolder = v.findViewById(R.id.flavorImageHolder);
|
if (holder.flavorImageHolder != null) {
|
||||||
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
||||||
if (flavorImageHolder != null) {
|
|
||||||
flavorImageHolder.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView ib = (ImageView) v.findViewById(R.id.article_menu_button);
|
if (holder.menuButtonView != null) {
|
||||||
|
|
||||||
if (ib != null) {
|
|
||||||
//if (m_activity.isDarkTheme())
|
//if (m_activity.isDarkTheme())
|
||||||
// ib.setImageResource(R.drawable.ic_mailbox_collapsed_holo_dark);
|
// ib.setImageResource(R.drawable.ic_mailbox_collapsed_holo_dark);
|
||||||
|
|
||||||
ib.setOnClickListener(new OnClickListener() {
|
holder.menuButtonView.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
getActivity().openContextMenu(v);
|
getActivity().openContextMenu(v);
|
||||||
|
Loading…
Reference in New Issue
Block a user