2013-04-21 13:01:26 +00:00
|
|
|
|
package org.fox.ttrss;
|
|
|
|
|
|
2014-10-31 10:18:27 +00:00
|
|
|
|
import android.annotation.TargetApi;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.content.Context;
|
2014-01-16 12:21:19 +00:00
|
|
|
|
import android.content.Intent;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.content.SharedPreferences;
|
2013-04-24 13:48:44 +00:00
|
|
|
|
import android.content.res.Resources.Theme;
|
2014-10-15 21:21:49 +00:00
|
|
|
|
import android.graphics.Bitmap;
|
2013-04-24 13:48:44 +00:00
|
|
|
|
import android.graphics.Paint;
|
2014-01-16 12:21:19 +00:00
|
|
|
|
import android.net.Uri;
|
2014-10-31 10:18:27 +00:00
|
|
|
|
import android.os.Build;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.preference.PreferenceManager;
|
2015-02-12 07:48:50 +00:00
|
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
|
|
import android.support.v4.app.ActivityOptionsCompat;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.support.v4.app.Fragment;
|
2015-02-12 07:48:50 +00:00
|
|
|
|
import android.support.v4.view.ViewCompat;
|
2014-10-15 12:41:33 +00:00
|
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.text.Html;
|
2015-02-12 10:09:54 +00:00
|
|
|
|
import android.transition.Fade;
|
|
|
|
|
import android.transition.Transition;
|
2014-10-15 13:04:52 +00:00
|
|
|
|
import android.util.DisplayMetrics;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.util.Log;
|
2013-04-24 13:48:44 +00:00
|
|
|
|
import android.util.TypedValue;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.view.ContextMenu;
|
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2014-10-31 10:00:54 +00:00
|
|
|
|
import android.view.Display;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
|
import android.view.ViewGroup;
|
2014-10-31 10:00:54 +00:00
|
|
|
|
import android.view.WindowManager;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.widget.AbsListView;
|
|
|
|
|
import android.widget.AbsListView.OnScrollListener;
|
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
|
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.ListView;
|
2014-10-28 18:58:56 +00:00
|
|
|
|
import android.widget.ProgressBar;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
2014-11-16 09:13:39 +00:00
|
|
|
|
import com.amulyakhare.textdrawable.TextDrawable;
|
|
|
|
|
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
import com.google.gson.JsonElement;
|
2014-10-15 21:21:49 +00:00
|
|
|
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
|
|
import com.nostra13.universalimageloader.core.assist.FailReason;
|
2014-10-28 18:04:41 +00:00
|
|
|
|
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
|
|
|
|
|
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
|
2014-10-15 21:21:49 +00:00
|
|
|
|
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2014-10-24 21:32:57 +00:00
|
|
|
|
import org.fox.ttrss.types.Article;
|
|
|
|
|
import org.fox.ttrss.types.ArticleList;
|
|
|
|
|
import org.fox.ttrss.types.Feed;
|
|
|
|
|
import org.fox.ttrss.util.HeadlinesRequest;
|
|
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
|
import org.jsoup.nodes.Element;
|
2014-10-29 05:59:33 +00:00
|
|
|
|
import org.jsoup.select.Elements;
|
2014-10-24 21:32:57 +00:00
|
|
|
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
public class HeadlinesFragment extends Fragment implements OnItemClickListener, OnScrollListener {
|
2015-02-13 11:31:15 +00:00
|
|
|
|
public static enum ArticlesSelection { ALL, NONE, UNREAD }
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2014-11-09 16:04:03 +00:00
|
|
|
|
public static final int FLAVOR_IMG_MIN_WIDTH = 128;
|
|
|
|
|
public static final int FLAVOR_IMG_MIN_HEIGHT = 128;
|
|
|
|
|
|
2014-10-31 10:42:19 +00:00
|
|
|
|
public static final int HEADLINES_REQUEST_SIZE = 30;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
public static final int HEADLINES_BUFFER_MAX = 500;
|
2014-11-28 16:23:58 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
|
|
|
|
|
private Feed m_feed;
|
|
|
|
|
private Article m_activeArticle;
|
|
|
|
|
private String m_searchQuery = "";
|
|
|
|
|
private boolean m_refreshInProgress = false;
|
2013-08-29 09:15:11 +00:00
|
|
|
|
private boolean m_autoCatchupDisabled = false;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
private SharedPreferences m_prefs;
|
|
|
|
|
|
|
|
|
|
private ArticleListAdapter m_adapter;
|
2015-02-10 12:08:17 +00:00
|
|
|
|
private ArticleList m_articles = new ArticleList(); //GlobalState.getInstance().m_loadedArticles;
|
2015-02-13 12:11:38 +00:00
|
|
|
|
//private ArticleList m_selectedArticles = new ArticleList();
|
2013-04-21 13:01:26 +00:00
|
|
|
|
private ArticleList m_readArticles = new ArticleList();
|
|
|
|
|
private HeadlinesEventListener m_listener;
|
|
|
|
|
private OnlineActivity m_activity;
|
2014-10-15 12:41:33 +00:00
|
|
|
|
private SwipeRefreshLayout m_swipeLayout;
|
2014-10-15 13:04:52 +00:00
|
|
|
|
private int m_maxImageSize = 0;
|
2014-10-31 11:11:47 +00:00
|
|
|
|
private boolean m_compactLayoutMode = false;
|
2015-05-11 08:18:27 +00:00
|
|
|
|
private int m_listPreviousVisibleItem;
|
2015-05-11 09:30:12 +00:00
|
|
|
|
private ListView m_list;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
public ArticleList getSelectedArticles() {
|
2015-02-13 12:11:38 +00:00
|
|
|
|
ArticleList tmp = new ArticleList();
|
|
|
|
|
|
|
|
|
|
for (Article a : m_articles) {
|
|
|
|
|
if (a.selected) tmp.add(a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tmp;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-26 09:16:53 +00:00
|
|
|
|
public void initialize(Feed feed) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_feed = feed;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 12:08:17 +00:00
|
|
|
|
public void initialize(Feed feed, Article activeArticle, boolean compactMode, ArticleList articles) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_feed = feed;
|
2014-10-31 11:11:47 +00:00
|
|
|
|
m_compactLayoutMode = compactMode;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
if (activeArticle != null) {
|
|
|
|
|
m_activeArticle = getArticleById(activeArticle.id);
|
|
|
|
|
}
|
2015-02-10 12:08:17 +00:00
|
|
|
|
|
|
|
|
|
if (articles != null) {
|
|
|
|
|
m_articles = articles;
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
2015-02-10 12:08:17 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
@Override
|
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
|
|
|
|
.getMenuInfo();
|
|
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.set_labels:
|
|
|
|
|
if (true) {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
|
|
|
|
|
if (article != null) {
|
2013-11-27 15:09:21 +00:00
|
|
|
|
if (m_activity.getApiLevel() != 7) {
|
|
|
|
|
m_activity.editArticleLabels(article);
|
|
|
|
|
} else {
|
|
|
|
|
m_activity.toast(R.string.server_function_not_available);
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.article_set_note:
|
|
|
|
|
if (true) {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
|
|
|
|
|
if (article != null) {
|
|
|
|
|
m_activity.editArticleNote(article);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case R.id.headlines_article_link_copy:
|
|
|
|
|
if (true) {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
|
|
|
|
|
if (article != null) {
|
|
|
|
|
m_activity.copyToClipboard(article.link);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2014-01-16 12:21:19 +00:00
|
|
|
|
case R.id.headlines_article_link_open:
|
|
|
|
|
if (true) {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
|
|
|
|
|
if (article != null) {
|
|
|
|
|
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(article.link));
|
|
|
|
|
startActivity(browserIntent);
|
|
|
|
|
|
|
|
|
|
if (article.unread) {
|
|
|
|
|
article.unread = false;
|
|
|
|
|
m_activity.saveArticleUnread(article);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
case R.id.selection_toggle_marked:
|
|
|
|
|
if (true) {
|
|
|
|
|
ArticleList selected = getSelectedArticles();
|
|
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
|
for (Article a : selected)
|
|
|
|
|
a.marked = !a.marked;
|
|
|
|
|
|
|
|
|
|
m_activity.toggleArticlesMarked(selected);
|
|
|
|
|
//updateHeadlines();
|
|
|
|
|
} else {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
if (article != null) {
|
|
|
|
|
article.marked = !article.marked;
|
|
|
|
|
m_activity.saveArticleMarked(article);
|
|
|
|
|
//updateHeadlines();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.selection_toggle_published:
|
|
|
|
|
if (true) {
|
|
|
|
|
ArticleList selected = getSelectedArticles();
|
|
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
|
for (Article a : selected)
|
|
|
|
|
a.published = !a.published;
|
|
|
|
|
|
|
|
|
|
m_activity.toggleArticlesPublished(selected);
|
|
|
|
|
//updateHeadlines();
|
|
|
|
|
} else {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
if (article != null) {
|
|
|
|
|
article.published = !article.published;
|
|
|
|
|
m_activity.saveArticlePublished(article);
|
|
|
|
|
//updateHeadlines();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.selection_toggle_unread:
|
|
|
|
|
if (true) {
|
|
|
|
|
ArticleList selected = getSelectedArticles();
|
|
|
|
|
|
|
|
|
|
if (selected.size() > 0) {
|
|
|
|
|
for (Article a : selected)
|
|
|
|
|
a.unread = !a.unread;
|
|
|
|
|
|
|
|
|
|
m_activity.toggleArticlesUnread(selected);
|
|
|
|
|
//updateHeadlines();
|
|
|
|
|
} else {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
if (article != null) {
|
|
|
|
|
article.unread = !article.unread;
|
|
|
|
|
m_activity.saveArticleUnread(article);
|
|
|
|
|
//updateHeadlines();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.headlines_share_article:
|
|
|
|
|
if (true) {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
if (article != null)
|
|
|
|
|
m_activity.shareArticle(article);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case R.id.catchup_above:
|
|
|
|
|
if (true) {
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
|
|
|
|
if (article != null) {
|
|
|
|
|
ArticleList articles = getAllArticles();
|
|
|
|
|
ArticleList tmp = new ArticleList();
|
|
|
|
|
for (Article a : articles) {
|
2014-01-23 12:03:38 +00:00
|
|
|
|
if (article.id == a.id)
|
|
|
|
|
break;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2014-01-23 12:03:38 +00:00
|
|
|
|
if (a.unread) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
a.unread = false;
|
|
|
|
|
tmp.add(a);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tmp.size() > 0) {
|
|
|
|
|
m_activity.toggleArticlesUnread(tmp);
|
|
|
|
|
//updateHeadlines();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
Log.d(TAG, "onContextItemSelected, unhandled id=" + item.getItemId());
|
|
|
|
|
return super.onContextItemSelected(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 10:09:54 +00:00
|
|
|
|
public HeadlinesFragment() {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
|
Transition fade = new Fade();
|
|
|
|
|
|
|
|
|
|
setEnterTransition(fade);
|
|
|
|
|
setReenterTransition(fade);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
|
|
|
|
ContextMenuInfo menuInfo) {
|
|
|
|
|
|
|
|
|
|
getActivity().getMenuInflater().inflate(R.menu.headlines_context_menu, menu);
|
|
|
|
|
|
2015-02-13 12:11:38 +00:00
|
|
|
|
if (getSelectedArticles().size() > 0) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
menu.setHeaderTitle(R.string.headline_context_multiple);
|
|
|
|
|
menu.setGroupVisible(R.id.menu_group_single_article, false);
|
|
|
|
|
} else {
|
|
|
|
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo;
|
|
|
|
|
Article article = getArticleAtPosition(info.position);
|
2014-11-02 14:15:34 +00:00
|
|
|
|
|
|
|
|
|
menu.setHeaderTitle(Html.fromHtml(article.title));
|
|
|
|
|
menu.setGroupVisible(R.id.menu_group_single_article, true);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu.findItem(R.id.set_labels).setEnabled(m_activity.getApiLevel() >= 1);
|
2014-10-15 15:11:18 +00:00
|
|
|
|
menu.findItem(R.id.article_set_note).setEnabled(m_activity.getApiLevel() >= 1);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
super.onCreateContextMenu(menu, v, menuInfo);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-02-12 10:09:54 +00:00
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_feed = savedInstanceState.getParcelable("feed");
|
2015-02-10 13:04:23 +00:00
|
|
|
|
|
|
|
|
|
if (! (m_activity instanceof HeadlinesActivity)) {
|
|
|
|
|
m_articles = savedInstanceState.getParcelable("articles");
|
|
|
|
|
} else {
|
|
|
|
|
m_articles = ((HeadlinesActivity)m_activity).m_articles;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_activeArticle = savedInstanceState.getParcelable("activeArticle");
|
2015-02-13 12:11:38 +00:00
|
|
|
|
//m_selectedArticles = savedInstanceState.getParcelable("selectedArticles");
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery");
|
2014-10-31 11:11:47 +00:00
|
|
|
|
m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode");
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 18:42:10 +00:00
|
|
|
|
if ("HL_COMPACT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT")))
|
|
|
|
|
m_compactLayoutMode = true;
|
|
|
|
|
|
2014-10-15 13:04:52 +00:00
|
|
|
|
DisplayMetrics metrics = new DisplayMetrics();
|
|
|
|
|
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
|
|
|
|
m_maxImageSize = (int) (128 * metrics.density + 0.5);
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "maxImageSize=" + m_maxImageSize);
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
View view = inflater.inflate(R.layout.headlines_fragment, container, false);
|
|
|
|
|
|
2014-10-15 12:41:33 +00:00
|
|
|
|
m_swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.headlines_swipe_container);
|
2014-10-16 20:25:39 +00:00
|
|
|
|
|
2014-10-15 12:41:33 +00:00
|
|
|
|
m_swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onRefresh() {
|
2014-10-16 05:44:41 +00:00
|
|
|
|
refresh(false, true);
|
2014-10-15 12:41:33 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-11 09:30:12 +00:00
|
|
|
|
m_list = (ListView)view.findViewById(R.id.headlines_list);
|
2014-11-13 18:42:10 +00:00
|
|
|
|
|
2014-10-31 10:00:54 +00:00
|
|
|
|
if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) {
|
|
|
|
|
WindowManager wm = (WindowManager) m_activity.getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
|
Display display = wm.getDefaultDisplay();
|
|
|
|
|
int screenHeight = display.getHeight();
|
|
|
|
|
|
|
|
|
|
View layout = inflater.inflate(R.layout.headlines_footer, container, false);
|
|
|
|
|
|
|
|
|
|
layout.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, screenHeight));
|
|
|
|
|
|
2015-05-11 09:30:12 +00:00
|
|
|
|
m_list.addFooterView(layout, null, false);
|
2014-10-31 10:00:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 08:18:27 +00:00
|
|
|
|
if (m_activity.isSmallScreen()) {
|
2015-05-11 09:30:12 +00:00
|
|
|
|
View layout = inflater.inflate(R.layout.headlines_heading_spacer, m_list, false);
|
|
|
|
|
m_list.addHeaderView(layout);
|
2015-05-12 13:18:31 +00:00
|
|
|
|
|
|
|
|
|
m_swipeLayout.setProgressViewOffset(false, 0,
|
|
|
|
|
m_activity.getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material) +
|
|
|
|
|
m_activity.getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_padding_material));
|
2015-05-11 08:18:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
m_adapter = new ArticleListAdapter(getActivity(), R.layout.headlines_row, (ArrayList<Article>)m_articles);
|
2014-10-31 10:00:54 +00:00
|
|
|
|
|
2015-05-11 09:30:12 +00:00
|
|
|
|
m_list.setAdapter(m_adapter);
|
|
|
|
|
m_list.setOnItemClickListener(this);
|
|
|
|
|
m_list.setOnScrollListener(this);
|
|
|
|
|
registerForContextMenu(m_list);
|
2014-10-25 08:22:30 +00:00
|
|
|
|
|
|
|
|
|
if (m_activity.isSmallScreen()) {
|
|
|
|
|
m_activity.setTitle(m_feed.title);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
Log.d(TAG, "onCreateView, feed=" + m_feed);
|
2015-02-12 09:09:52 +00:00
|
|
|
|
|
|
|
|
|
return view;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
|
2015-02-10 12:22:48 +00:00
|
|
|
|
/* if (GlobalState.getInstance().m_activeArticle != null) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_activeArticle = GlobalState.getInstance().m_activeArticle;
|
|
|
|
|
GlobalState.getInstance().m_activeArticle = null;
|
2015-02-10 12:22:48 +00:00
|
|
|
|
} */
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
if (m_activeArticle != null) {
|
|
|
|
|
setActiveArticle(m_activeArticle);
|
|
|
|
|
}
|
2015-02-12 09:09:52 +00:00
|
|
|
|
|
|
|
|
|
/* if (!(m_activity instanceof HeadlinesActivity)) {
|
|
|
|
|
refresh(false);
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
if (m_articles.size() == 0) {
|
|
|
|
|
refresh(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if (m_articles.size() == 0 || !m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
if (m_activity.getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_ARTICLE) == null) {
|
|
|
|
|
refresh(false);
|
|
|
|
|
GlobalState.getInstance().m_activeFeed = m_feed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
notifyUpdated();
|
2015-02-12 09:09:52 +00:00
|
|
|
|
} */
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2014-11-04 14:50:14 +00:00
|
|
|
|
m_activity.invalidateOptionsMenu();
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
2014-10-25 08:22:30 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
|
super.onAttach(activity);
|
|
|
|
|
m_prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
|
|
|
|
|
m_activity = (OnlineActivity) activity;
|
|
|
|
|
m_listener = (HeadlinesEventListener) activity;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
@Override
|
2013-04-21 13:01:26 +00:00
|
|
|
|
public void onItemClick(AdapterView<?> av, View view, int position, long id) {
|
|
|
|
|
ListView list = (ListView)av;
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "onItemClick=" + position);
|
|
|
|
|
|
|
|
|
|
if (list != null) {
|
|
|
|
|
Article article = (Article)list.getItemAtPosition(position);
|
2014-10-31 10:00:54 +00:00
|
|
|
|
|
|
|
|
|
// could be footer or w/e
|
|
|
|
|
if (article != null && article.id >= 0) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_listener.onArticleSelected(article);
|
|
|
|
|
|
|
|
|
|
// only set active article when it makes sense (in HeadlinesActivity)
|
2015-02-10 12:50:47 +00:00
|
|
|
|
if (getActivity() instanceof HeadlinesActivity) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_activeArticle = article;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-24 10:15:26 +00:00
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
public void refresh(boolean append) {
|
2014-10-16 05:44:41 +00:00
|
|
|
|
refresh(append, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({ "serial" })
|
|
|
|
|
public void refresh(boolean append, boolean userInitiated) {
|
2013-06-03 18:52:51 +00:00
|
|
|
|
if (m_activity != null && m_feed != null) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_refreshInProgress = true;
|
|
|
|
|
|
2014-10-16 20:25:39 +00:00
|
|
|
|
if (m_swipeLayout != null) m_swipeLayout.setRefreshing(true);
|
2014-10-31 10:42:19 +00:00
|
|
|
|
|
2015-02-12 09:09:52 +00:00
|
|
|
|
/* if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
append = false;
|
2015-02-12 09:09:52 +00:00
|
|
|
|
} */
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2013-08-26 08:56:06 +00:00
|
|
|
|
// new stuff may appear on top, scroll back to show it
|
|
|
|
|
if (!append) {
|
|
|
|
|
if (getView() != null) {
|
|
|
|
|
Log.d(TAG, "scroll hack");
|
2014-10-31 10:18:27 +00:00
|
|
|
|
ListView list = (ListView)getView().findViewById(R.id.headlines_list);
|
2013-08-29 09:15:11 +00:00
|
|
|
|
m_autoCatchupDisabled = true;
|
2014-10-24 10:15:26 +00:00
|
|
|
|
list.setSelection(0);
|
2013-08-29 09:15:11 +00:00
|
|
|
|
m_autoCatchupDisabled = false;
|
2014-10-24 10:15:26 +00:00
|
|
|
|
list.setEmptyView(null);
|
2013-10-07 14:32:42 +00:00
|
|
|
|
m_adapter.clear();
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
2013-08-26 08:56:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
final boolean fappend = append;
|
|
|
|
|
final String sessionId = m_activity.getSessionId();
|
|
|
|
|
final boolean isCat = m_feed.is_cat;
|
|
|
|
|
|
2015-02-10 12:08:17 +00:00
|
|
|
|
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity, m_feed, m_articles) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
@Override
|
|
|
|
|
protected void onProgressUpdate(Integer... progress) {
|
|
|
|
|
m_activity.setProgress(Math.round((((float)progress[0] / (float)progress[1]) * 10000)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPostExecute(JsonElement result) {
|
2015-02-16 11:31:42 +00:00
|
|
|
|
if (isDetached() || !isAdded()) return;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2015-05-11 09:30:12 +00:00
|
|
|
|
super.onPostExecute(result);
|
2013-10-16 11:28:59 +00:00
|
|
|
|
|
|
|
|
|
if (isAdded()) {
|
2014-10-16 20:25:39 +00:00
|
|
|
|
if (m_swipeLayout != null) m_swipeLayout.setRefreshing(false);
|
2014-10-15 12:41:33 +00:00
|
|
|
|
}
|
2013-10-16 11:28:59 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
if (result != null) {
|
|
|
|
|
m_refreshInProgress = false;
|
|
|
|
|
|
|
|
|
|
if (m_articles.indexOf(m_activeArticle) == -1)
|
|
|
|
|
m_activeArticle = null;
|
|
|
|
|
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
m_listener.onHeadlinesLoaded(fappend);
|
2013-10-16 08:53:08 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (m_lastError == ApiError.LOGIN_FAILED) {
|
2014-01-16 12:07:30 +00:00
|
|
|
|
m_activity.login(true);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
} else {
|
2014-10-30 22:07:56 +00:00
|
|
|
|
m_activity.toast(getErrorMessage());
|
2014-10-30 22:02:06 +00:00
|
|
|
|
//m_activity.setLoadingStatus(getErrorMessage(), false);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int skip = 0;
|
|
|
|
|
|
|
|
|
|
if (append) {
|
2013-09-01 10:08:11 +00:00
|
|
|
|
// adaptive, all_articles, marked, published, unread
|
|
|
|
|
String viewMode = m_activity.getViewMode();
|
|
|
|
|
int numUnread = 0;
|
|
|
|
|
int numAll = m_articles.size();
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
for (Article a : m_articles) {
|
2013-09-01 10:08:11 +00:00
|
|
|
|
if (a.unread) ++numUnread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ("marked".equals(viewMode)) {
|
|
|
|
|
skip = numAll;
|
|
|
|
|
} else if ("published".equals(viewMode)) {
|
|
|
|
|
skip = numAll;
|
|
|
|
|
} else if ("unread".equals(viewMode)) {
|
|
|
|
|
skip = numUnread;
|
|
|
|
|
} else if (m_searchQuery != null && m_searchQuery.length() > 0) {
|
|
|
|
|
skip = numAll;
|
|
|
|
|
} else if ("adaptive".equals(viewMode)) {
|
|
|
|
|
skip = numUnread > 0 ? numUnread : numAll;
|
|
|
|
|
} else {
|
|
|
|
|
skip = numAll;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
2014-10-30 22:02:06 +00:00
|
|
|
|
//m_activity.setLoadingStatus(R.string.blank, true);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int fskip = skip;
|
|
|
|
|
|
2014-10-16 05:44:41 +00:00
|
|
|
|
final boolean allowForceUpdate = m_activity.getApiLevel() >= 9 &&
|
|
|
|
|
!m_feed.is_cat && m_feed.id > 0 && !append && userInitiated &&
|
|
|
|
|
skip == 0;
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "allowForceUpdate=" + allowForceUpdate + " userInitiated=" + userInitiated);
|
2014-11-29 17:18:03 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
req.setOffset(skip);
|
|
|
|
|
|
|
|
|
|
HashMap<String,String> map = new HashMap<String,String>() {
|
|
|
|
|
{
|
|
|
|
|
put("op", "getHeadlines");
|
|
|
|
|
put("sid", sessionId);
|
|
|
|
|
put("feed_id", String.valueOf(m_feed.id));
|
2014-11-29 17:18:03 +00:00
|
|
|
|
put("show_excerpt", "true");
|
|
|
|
|
put("excerpt_length", String.valueOf(CommonActivity.EXCERPT_MAX_LENGTH));
|
2013-04-21 13:01:26 +00:00
|
|
|
|
put("show_content", "true");
|
|
|
|
|
put("include_attachments", "true");
|
|
|
|
|
put("view_mode", m_activity.getViewMode());
|
|
|
|
|
put("limit", String.valueOf(HEADLINES_REQUEST_SIZE));
|
|
|
|
|
put("offset", String.valueOf(0));
|
|
|
|
|
put("skip", String.valueOf(fskip));
|
|
|
|
|
put("include_nested", "true");
|
2014-11-25 10:46:00 +00:00
|
|
|
|
put("has_sandbox", "true");
|
2014-11-04 14:27:11 +00:00
|
|
|
|
put("order_by", m_activity.getSortMode());
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
if (isCat) put("is_cat", "true");
|
2014-10-16 05:44:41 +00:00
|
|
|
|
|
|
|
|
|
if (allowForceUpdate) {
|
|
|
|
|
put("force_update", "true");
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
if (m_searchQuery != null && m_searchQuery.length() != 0) {
|
|
|
|
|
put("search", m_searchQuery);
|
|
|
|
|
put("search_mode", "");
|
|
|
|
|
put("match_on", "both");
|
|
|
|
|
}
|
2014-10-16 05:44:41 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2014-10-20 17:48:18 +00:00
|
|
|
|
|
|
|
|
|
Log.d(TAG, "[HP] request more headlines...");
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
req.execute(map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onSaveInstanceState (Bundle out) {
|
|
|
|
|
super.onSaveInstanceState(out);
|
|
|
|
|
|
2013-10-22 14:34:21 +00:00
|
|
|
|
out.setClassLoader(getClass().getClassLoader());
|
2013-04-21 13:01:26 +00:00
|
|
|
|
out.putParcelable("feed", m_feed);
|
2015-02-10 12:50:47 +00:00
|
|
|
|
out.putParcelable("articles", m_articles);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
out.putParcelable("activeArticle", m_activeArticle);
|
2015-02-13 12:11:38 +00:00
|
|
|
|
//out.putParcelable("selectedArticles", m_selectedArticles);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
out.putCharSequence("searchQuery", m_searchQuery);
|
2014-10-31 11:11:47 +00:00
|
|
|
|
out.putBoolean("compactLayoutMode", m_compactLayoutMode);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
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;
|
2014-10-28 18:58:56 +00:00
|
|
|
|
public ProgressBar flavorImageLoadingBar;
|
2014-10-29 13:23:07 +00:00
|
|
|
|
public View flavorImageArrow;
|
2014-10-31 11:11:47 +00:00
|
|
|
|
public View headlineFooter;
|
2014-11-16 09:13:39 +00:00
|
|
|
|
public ImageView textImage;
|
|
|
|
|
public ImageView textChecked;
|
2014-10-31 11:11:47 +00:00
|
|
|
|
}
|
2014-10-24 10:15:26 +00:00
|
|
|
|
|
|
|
|
|
private class ArticleListAdapter extends ArrayAdapter<Article> {
|
|
|
|
|
private ArrayList<Article> items;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
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_SELECTED_UNREAD = 3;
|
|
|
|
|
public static final int VIEW_LOADMORE = 4;
|
|
|
|
|
|
|
|
|
|
public static final int VIEW_COUNT = VIEW_LOADMORE+1;
|
|
|
|
|
|
2013-04-24 13:48:44 +00:00
|
|
|
|
private final Integer[] origTitleColors = new Integer[VIEW_COUNT];
|
|
|
|
|
private final int titleHighScoreUnreadColor;
|
|
|
|
|
|
2014-11-16 09:13:39 +00:00
|
|
|
|
private ColorGenerator m_colorGenerator = ColorGenerator.DEFAULT;
|
|
|
|
|
private TextDrawable.IBuilder m_drawableBuilder = TextDrawable.builder().round();
|
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
public ArticleListAdapter(Context context, int textViewResourceId, ArrayList<Article> items) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
super(context, textViewResourceId, items);
|
|
|
|
|
this.items = items;
|
2013-04-25 15:54:52 +00:00
|
|
|
|
|
2013-04-24 13:48:44 +00:00
|
|
|
|
Theme theme = context.getTheme();
|
|
|
|
|
TypedValue tv = new TypedValue();
|
|
|
|
|
theme.resolveAttribute(R.attr.headlineTitleHighScoreUnreadTextColor, tv, true);
|
|
|
|
|
titleHighScoreUnreadColor = tv.data;
|
2014-10-24 10:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
|
return VIEW_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewType(int position) {
|
2014-10-24 10:15:26 +00:00
|
|
|
|
Article a = items.get(position);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
if (a.id == -1) {
|
|
|
|
|
return VIEW_LOADMORE;
|
|
|
|
|
} else if (m_activeArticle != null && a.id == m_activeArticle.id && a.unread) {
|
|
|
|
|
return VIEW_SELECTED_UNREAD;
|
|
|
|
|
} else if (m_activeArticle != null && a.id == m_activeArticle.id) {
|
|
|
|
|
return VIEW_SELECTED;
|
|
|
|
|
} else if (a.unread) {
|
|
|
|
|
return VIEW_UNREAD;
|
|
|
|
|
} else {
|
|
|
|
|
return VIEW_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-16 09:13:39 +00:00
|
|
|
|
private void updateTextCheckedState(HeadlineViewHolder holder, Article item) {
|
|
|
|
|
String tmp = item.title.length() > 0 ? item.title.substring(0, 1) : "?";
|
|
|
|
|
|
2015-02-13 12:11:38 +00:00
|
|
|
|
if (item.selected) {
|
2014-11-16 09:13:39 +00:00
|
|
|
|
holder.textImage.setImageDrawable(m_drawableBuilder.build(" ", 0xff616161));
|
|
|
|
|
|
|
|
|
|
holder.textChecked.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
holder.textImage.setImageDrawable(m_drawableBuilder.build(tmp, m_colorGenerator.getColor(item.title)));
|
|
|
|
|
|
|
|
|
|
holder.textChecked.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
@Override
|
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
View v = convertView;
|
|
|
|
|
|
|
|
|
|
final Article article = items.get(position);
|
2014-11-16 09:13:39 +00:00
|
|
|
|
final HeadlineViewHolder holder;
|
2014-10-24 10:15:26 +00:00
|
|
|
|
|
2014-01-25 09:17:27 +00:00
|
|
|
|
int headlineFontSize = Integer.parseInt(m_prefs.getString("headlines_font_size_sp", "13"));
|
|
|
|
|
int headlineSmallFontSize = Math.max(10, Math.min(18, headlineFontSize - 2));
|
2014-10-24 10:15:26 +00:00
|
|
|
|
|
|
|
|
|
if (v == null) {
|
2014-11-13 18:42:10 +00:00
|
|
|
|
int layoutId = m_compactLayoutMode ? R.layout.headlines_row_compact : R.layout.headlines_row;
|
|
|
|
|
|
|
|
|
|
switch (getItemViewType(position)) {
|
2014-10-24 10:15:26 +00:00
|
|
|
|
case VIEW_LOADMORE:
|
|
|
|
|
layoutId = R.layout.headlines_row_loadmore;
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_UNREAD:
|
2014-11-13 18:42:10 +00:00
|
|
|
|
layoutId = m_compactLayoutMode ? R.layout.headlines_row_unread_compact : R.layout.headlines_row_unread;
|
2014-10-24 10:15:26 +00:00
|
|
|
|
break;
|
|
|
|
|
case VIEW_SELECTED:
|
2015-02-12 11:50:13 +00:00
|
|
|
|
layoutId = m_compactLayoutMode ? R.layout.headlines_row_selected_compact : R.layout.headlines_row;
|
2014-10-24 10:15:26 +00:00
|
|
|
|
break;
|
|
|
|
|
case VIEW_SELECTED_UNREAD:
|
2015-02-12 11:50:13 +00:00
|
|
|
|
layoutId = m_compactLayoutMode ? R.layout.headlines_row_selected_unread_compact : R.layout.headlines_row_unread;
|
2014-10-24 10:15:26 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
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);
|
2014-10-28 18:58:56 +00:00
|
|
|
|
holder.flavorImageLoadingBar = (ProgressBar) v.findViewById(R.id.flavorImageLoadingBar);
|
2014-10-29 13:23:07 +00:00
|
|
|
|
holder.flavorImageArrow = v.findViewById(R.id.flavorImageArrow);
|
2014-10-31 11:11:47 +00:00
|
|
|
|
holder.headlineFooter = v.findViewById(R.id.headline_footer);
|
2014-11-16 09:13:39 +00:00
|
|
|
|
holder.textImage = (ImageView) v.findViewById(R.id.text_image);
|
|
|
|
|
holder.textChecked = (ImageView) v.findViewById(R.id.text_checked);
|
2014-10-24 10:15:26 +00:00
|
|
|
|
|
|
|
|
|
v.setTag(holder);
|
|
|
|
|
|
|
|
|
|
// http://code.google.com/p/android/issues/detail?id=3414
|
|
|
|
|
((ViewGroup)v).setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
|
|
|
|
} else {
|
|
|
|
|
holder = (HeadlineViewHolder) v.getTag();
|
|
|
|
|
}
|
2014-11-09 12:27:54 +00:00
|
|
|
|
|
|
|
|
|
// block footer clicks to make button/selection clicking easier
|
|
|
|
|
if (holder.headlineFooter != null) {
|
|
|
|
|
holder.headlineFooter.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-11-16 09:13:39 +00:00
|
|
|
|
|
|
|
|
|
if (holder.textImage != null) {
|
|
|
|
|
updateTextCheckedState(holder, article);
|
|
|
|
|
|
|
|
|
|
holder.textImage.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
Log.d(TAG, "textImage : onclicked");
|
|
|
|
|
|
2015-02-13 12:11:38 +00:00
|
|
|
|
article.selected = !article.selected;
|
2014-11-16 09:13:39 +00:00
|
|
|
|
|
|
|
|
|
updateTextCheckedState(holder, article);
|
|
|
|
|
|
2015-02-13 12:11:38 +00:00
|
|
|
|
m_listener.onArticleListSelectionChange(getSelectedArticles());
|
2014-11-16 09:13:39 +00:00
|
|
|
|
|
2015-02-13 12:11:38 +00:00
|
|
|
|
Log.d(TAG, "num selected: " + getSelectedArticles().size());
|
2014-11-16 09:13:39 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
if (holder.titleView != null) {
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.titleView.setText(Html.fromHtml(article.title));
|
2014-01-25 17:34:50 +00:00
|
|
|
|
|
2015-02-12 12:17:11 +00:00
|
|
|
|
/* if (m_prefs.getBoolean("enable_condensed_fonts", false)) {
|
2014-01-25 17:34:50 +00:00
|
|
|
|
Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", article.unread ? Typeface.BOLD : Typeface.NORMAL);
|
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
if (tf != null && !tf.equals(holder.titleView.getTypeface())) {
|
|
|
|
|
holder.titleView.setTypeface(tf);
|
2014-01-25 17:34:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 5));
|
2014-01-25 17:34:50 +00:00
|
|
|
|
} else {
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 3));
|
2015-02-12 12:17:11 +00:00
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
holder.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, headlineFontSize + 3));
|
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
adjustTitleTextView(article.score, holder.titleView, position);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
if (holder.feedTitleView != null) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
if (article.feed_title != null && (m_feed.is_cat || m_feed.id < 0)) {
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.feedTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
|
|
|
|
holder.feedTitleView.setText(article.feed_title);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
} else {
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.feedTitleView.setVisibility(View.GONE);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2015-06-01 16:10:12 +00:00
|
|
|
|
|
2015-06-01 20:43:03 +00:00
|
|
|
|
TypedValue tvAccent = new TypedValue();
|
|
|
|
|
m_activity.getTheme().resolveAttribute(R.attr.colorAccent, tvAccent, true);
|
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
if (holder.markedView != null) {
|
2015-06-01 16:10:12 +00:00
|
|
|
|
TypedValue tv = new TypedValue();
|
|
|
|
|
m_activity.getTheme().resolveAttribute(article.marked ? R.attr.ic_star : R.attr.ic_star_outline, tv, true);
|
|
|
|
|
|
|
|
|
|
holder.markedView.setImageResource(tv.resourceId);
|
2015-06-01 20:43:03 +00:00
|
|
|
|
|
|
|
|
|
if (article.marked)
|
|
|
|
|
holder.markedView.setColorFilter(tvAccent.data);
|
|
|
|
|
else
|
|
|
|
|
holder.markedView.setColorFilter(null);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.markedView.setOnClickListener(new OnClickListener() {
|
2015-06-01 16:10:12 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
article.marked = !article.marked;
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
2015-06-01 16:10:12 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
m_activity.saveArticleMarked(article);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-06-01 16:10:12 +00:00
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
|
|
|
|
|
if (holder.publishedView != null) {
|
2015-06-01 16:10:12 +00:00
|
|
|
|
TypedValue tv = new TypedValue();
|
|
|
|
|
m_activity.getTheme().resolveAttribute(article.published ? R.attr.ic_checkbox_marked : R.attr.ic_rss_box, tv, true);
|
|
|
|
|
|
|
|
|
|
holder.publishedView.setImageResource(tv.resourceId);
|
2015-06-01 20:43:03 +00:00
|
|
|
|
|
|
|
|
|
if (article.published)
|
|
|
|
|
holder.publishedView.setColorFilter(tvAccent.data);
|
|
|
|
|
else
|
|
|
|
|
holder.publishedView.setColorFilter(null);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.publishedView.setOnClickListener(new OnClickListener() {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
article.published = !article.published;
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
|
|
m_activity.saveArticlePublished(article);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-29 08:18:43 +00:00
|
|
|
|
String articleContent = article.content != null ? article.content : "";
|
|
|
|
|
|
|
|
|
|
String articleContentReduced = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ?
|
|
|
|
|
articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent;
|
|
|
|
|
|
2015-04-29 18:13:06 +00:00
|
|
|
|
if (article.articleDoc == null)
|
|
|
|
|
article.articleDoc = Jsoup.parse(articleContentReduced);
|
2014-11-29 08:18:43 +00:00
|
|
|
|
|
|
|
|
|
if (holder.excerptView != null) {
|
2014-11-01 06:23:20 +00:00
|
|
|
|
if (!m_prefs.getBoolean("headlines_show_content", true)) {
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.excerptView.setVisibility(View.GONE);
|
2014-11-29 17:18:03 +00:00
|
|
|
|
} else {
|
|
|
|
|
String excerpt;
|
|
|
|
|
|
|
|
|
|
if (m_activity.getApiLevel() >= 11) {
|
|
|
|
|
excerpt = article.excerpt != null ? article.excerpt : "";
|
2014-11-29 17:34:35 +00:00
|
|
|
|
excerpt = excerpt.replace("…", "…");
|
|
|
|
|
excerpt = excerpt.replace("]]>", "");
|
|
|
|
|
excerpt = Jsoup.parse(excerpt).text();
|
2014-11-29 17:18:03 +00:00
|
|
|
|
} else {
|
2015-04-29 18:13:06 +00:00
|
|
|
|
excerpt = article.articleDoc.text();
|
2014-11-29 17:34:35 +00:00
|
|
|
|
|
|
|
|
|
if (excerpt.length() > CommonActivity.EXCERPT_MAX_LENGTH)
|
|
|
|
|
excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…";
|
2014-11-29 17:18:03 +00:00
|
|
|
|
}
|
2014-11-28 16:23:58 +00:00
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.excerptView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineFontSize);
|
|
|
|
|
holder.excerptView.setText(excerpt);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
2014-10-15 21:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
if (!m_compactLayoutMode) {
|
2014-11-29 08:31:45 +00:00
|
|
|
|
boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT"));
|
2014-11-13 18:42:10 +00:00
|
|
|
|
|
2015-04-29 18:13:06 +00:00
|
|
|
|
if (showFlavorImage && holder.flavorImageView != null) {
|
|
|
|
|
|
|
|
|
|
holder.flavorImageArrow.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
|
|
if (article.noValidFlavorImage) {
|
|
|
|
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
|
|
|
|
} else if (article.articleDoc != null) {
|
|
|
|
|
|
|
|
|
|
if (article.flavorImage == null) {
|
|
|
|
|
|
|
|
|
|
Elements imgs = article.articleDoc.select("img");
|
|
|
|
|
|
|
|
|
|
for (Element tmp : imgs) {
|
|
|
|
|
try {
|
|
|
|
|
if (Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_WIDTH && Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_HEIGHT) {
|
|
|
|
|
article.flavorImage = tmp;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (article.flavorImage == null)
|
|
|
|
|
article.flavorImage = imgs.first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (article.flavorImage != null) {
|
|
|
|
|
|
|
|
|
|
String imgSrc = article.flavorImage.attr("src");
|
|
|
|
|
final String imgSrcFirst = imgSrc;
|
|
|
|
|
|
|
|
|
|
// retarded schema-less urls
|
|
|
|
|
if (imgSrc.indexOf("//") == 0)
|
|
|
|
|
imgSrc = "http:" + imgSrc;
|
|
|
|
|
|
|
|
|
|
DisplayImageOptions options = new DisplayImageOptions.Builder()
|
|
|
|
|
.cacheInMemory(true)
|
|
|
|
|
.resetViewBeforeLoading(true)
|
|
|
|
|
.cacheOnDisk(true)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
ViewCompat.setTransitionName(holder.flavorImageView, "TRANSITION:ARTICLE_IMAGES_PAGER");
|
|
|
|
|
|
|
|
|
|
holder.flavorImageView.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(m_activity, ArticleImagesPagerActivity.class);
|
|
|
|
|
intent.putExtra("firstSrc", imgSrcFirst);
|
|
|
|
|
intent.putExtra("title", article.title);
|
|
|
|
|
intent.putExtra("content", article.content);
|
|
|
|
|
|
|
|
|
|
ActivityOptionsCompat options =
|
|
|
|
|
ActivityOptionsCompat.makeSceneTransitionAnimation(m_activity,
|
|
|
|
|
holder.flavorImageView, // The view which starts the transition
|
|
|
|
|
"TRANSITION:ARTICLE_IMAGES_PAGER" // The transitionName of the view we’re transitioning to
|
|
|
|
|
);
|
|
|
|
|
ActivityCompat.startActivity(m_activity, intent, options.toBundle());
|
|
|
|
|
|
|
|
|
|
//startActivityForResult(intent, 0);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final ViewGroup flavorImageHolder = holder.flavorImageHolder;
|
|
|
|
|
final ProgressBar flavorImageLoadingBar = holder.flavorImageLoadingBar;
|
|
|
|
|
|
|
|
|
|
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
|
|
|
|
|
|
|
|
|
|
ImageLoader.getInstance().displayImage(imgSrc, imageAware, options, new ImageLoadingListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoadingCancelled(String arg0,
|
|
|
|
|
View arg1) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoadingComplete(String arg0,
|
|
|
|
|
View arg1, Bitmap arg2) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
if (!isAdded() || arg2 == null) return;
|
|
|
|
|
|
|
|
|
|
flavorImageLoadingBar.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
|
|
|
|
if (arg2.getWidth() > FLAVOR_IMG_MIN_WIDTH && arg2.getHeight() > FLAVOR_IMG_MIN_HEIGHT) {
|
|
|
|
|
flavorImageHolder.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
flavorImageHolder.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoadingFailed(String arg0,
|
|
|
|
|
View arg1, FailReason arg2) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
flavorImageHolder.setVisibility(View.GONE);
|
|
|
|
|
article.noValidFlavorImage = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoadingStarted(String arg0,
|
|
|
|
|
View arg1) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2015-04-29 18:17:09 +00:00
|
|
|
|
} else{
|
|
|
|
|
article.noValidFlavorImage = true;
|
|
|
|
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
2015-04-29 18:13:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
article.noValidFlavorImage = true;
|
|
|
|
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 04:04:06 +00:00
|
|
|
|
} else if (holder.flavorImageHolder != null) {
|
|
|
|
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
2015-04-29 18:13:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if (holder.flavorImageView != null && showFlavorImage) {
|
2014-10-31 11:11:47 +00:00
|
|
|
|
holder.flavorImageArrow.setVisibility(View.GONE);
|
2014-10-29 13:51:54 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
boolean loadableImageFound = false;
|
2014-10-29 05:59:33 +00:00
|
|
|
|
|
2015-04-29 18:13:06 +00:00
|
|
|
|
if (article.articleDoc != null) {
|
|
|
|
|
|
|
|
|
|
Elements imgs = article.articleDoc.select("img");
|
|
|
|
|
|
2014-11-09 16:04:03 +00:00
|
|
|
|
Element img = null;
|
|
|
|
|
|
|
|
|
|
for (Element tmp : imgs) {
|
|
|
|
|
try {
|
|
|
|
|
if (Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_WIDTH && Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_HEIGHT) {
|
|
|
|
|
img = tmp;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (img == null)
|
|
|
|
|
img = imgs.first();
|
2014-10-29 13:23:07 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
if (img != null) {
|
|
|
|
|
String imgSrc = img.attr("src");
|
2014-11-29 08:18:43 +00:00
|
|
|
|
final String imgSrcFirst = imgSrc;
|
2014-10-29 13:23:07 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
// retarded schema-less urls
|
|
|
|
|
if (imgSrc.indexOf("//") == 0)
|
|
|
|
|
imgSrc = "http:" + imgSrc;
|
2014-10-29 13:23:07 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
DisplayImageOptions options = new DisplayImageOptions.Builder()
|
2015-04-29 18:13:06 +00:00
|
|
|
|
.displayer(new FadeInBitmapDisplayer(500))
|
2014-10-31 11:11:47 +00:00
|
|
|
|
.cacheInMemory(true)
|
|
|
|
|
.resetViewBeforeLoading(true)
|
|
|
|
|
.cacheOnDisk(true)
|
|
|
|
|
.build();
|
2014-10-29 13:23:07 +00:00
|
|
|
|
|
2015-02-12 07:48:50 +00:00
|
|
|
|
ViewCompat.setTransitionName(holder.flavorImageView, "TRANSITION:ARTICLE_IMAGES_PAGER");
|
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
holder.flavorImageView.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
2014-10-29 13:23:07 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
Intent intent = new Intent(m_activity, ArticleImagesPagerActivity.class);
|
2014-11-29 08:18:43 +00:00
|
|
|
|
intent.putExtra("firstSrc", imgSrcFirst);
|
2014-10-31 11:11:47 +00:00
|
|
|
|
intent.putExtra("title", article.title);
|
2014-11-03 15:15:37 +00:00
|
|
|
|
intent.putExtra("content", article.content);
|
2014-10-29 13:23:07 +00:00
|
|
|
|
|
2015-02-12 07:48:50 +00:00
|
|
|
|
ActivityOptionsCompat options =
|
|
|
|
|
ActivityOptionsCompat.makeSceneTransitionAnimation(m_activity,
|
|
|
|
|
holder.flavorImageView, // The view which starts the transition
|
|
|
|
|
"TRANSITION:ARTICLE_IMAGES_PAGER" // The transitionName of the view we’re transitioning to
|
|
|
|
|
);
|
|
|
|
|
ActivityCompat.startActivity(m_activity, intent, options.toBundle());
|
|
|
|
|
|
|
|
|
|
//startActivityForResult(intent, 0);
|
2014-10-31 11:11:47 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-10-28 18:58:56 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
final ViewGroup flavorImageHolder = holder.flavorImageHolder;
|
|
|
|
|
final ImageView flavorImageView = holder.flavorImageView;
|
|
|
|
|
final ProgressBar flavorImageLoadingBar = holder.flavorImageLoadingBar;
|
2014-10-29 05:59:33 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
|
2014-10-28 18:58:56 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
flavorImageHolder.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
if (imgs.size() > 1 && holder.flavorImageArrow != null) {
|
|
|
|
|
holder.flavorImageArrow.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
2014-10-16 05:44:41 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
final boolean weNeedAnimation = MemoryCacheUtils.findCachedBitmapsForImageUri(imgSrc, ImageLoader.getInstance().getMemoryCache()).size() == 0;
|
2014-10-15 21:21:49 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
loadableImageFound = true;
|
|
|
|
|
ImageLoader.getInstance().displayImage(imgSrc, imageAware, options, new ImageLoadingListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoadingCancelled(String arg0,
|
|
|
|
|
View arg1) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
}
|
2014-10-28 18:58:56 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoadingComplete(String arg0,
|
|
|
|
|
View arg1, Bitmap arg2) {
|
|
|
|
|
// TODO Auto-generated method stub
|
2014-10-28 18:58:56 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
if (!isAdded() || arg2 == null) return;
|
2014-10-28 18:58:56 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
flavorImageLoadingBar.setVisibility(View.INVISIBLE);
|
2014-10-28 18:58:56 +00:00
|
|
|
|
|
2014-11-09 16:04:03 +00:00
|
|
|
|
if (arg2.getWidth() > FLAVOR_IMG_MIN_WIDTH && arg2.getHeight() > FLAVOR_IMG_MIN_HEIGHT) {
|
2015-01-27 09:02:04 +00:00
|
|
|
|
if (weNeedAnimation) {
|
2014-10-31 11:11:47 +00:00
|
|
|
|
ObjectAnimator anim = ObjectAnimator.ofFloat(flavorImageView, "alpha", 0f, 1f);
|
|
|
|
|
anim.setDuration(200);
|
|
|
|
|
anim.start();
|
|
|
|
|
}
|
|
|
|
|
//flavorImageHolder.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
flavorImageHolder.setVisibility(View.GONE);
|
2014-10-28 18:58:56 +00:00
|
|
|
|
}
|
2014-10-31 11:11:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLoadingFailed(String arg0,
|
|
|
|
|
View arg1, FailReason arg2) {
|
|
|
|
|
// TODO Auto-generated method stub
|
2014-10-28 18:58:56 +00:00
|
|
|
|
flavorImageHolder.setVisibility(View.GONE);
|
|
|
|
|
}
|
2014-10-16 05:44:41 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onLoadingStarted(String arg0,
|
|
|
|
|
View arg1) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
|
|
}
|
2014-10-16 05:44:41 +00:00
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2014-10-28 18:58:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
|
if (!loadableImageFound && holder.flavorImageHolder != null) {
|
|
|
|
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
} else if (holder.flavorImageHolder != null) {
|
2014-10-28 18:58:56 +00:00
|
|
|
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
|
|
|
|
}
|
2014-11-02 06:34:00 +00:00
|
|
|
|
} else if (holder.flavorImageHolder != null) {
|
2015-04-29 18:13:06 +00:00
|
|
|
|
holder.flavorImageHolder.setVisibility(View.GONE); */
|
2014-10-31 11:11:47 +00:00
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
String articleAuthor = article.author != null ? article.author : "";
|
|
|
|
|
|
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
if (holder.authorView != null) {
|
|
|
|
|
holder.authorView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
2014-01-25 09:17:27 +00:00
|
|
|
|
|
2013-05-23 18:19:59 +00:00
|
|
|
|
if (articleAuthor.length() > 0) {
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.authorView.setText(getString(R.string.author_formatted, articleAuthor));
|
2013-05-23 18:19:59 +00:00
|
|
|
|
} else {
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.authorView.setText("");
|
2013-05-23 18:19:59 +00:00
|
|
|
|
}
|
2014-01-25 09:17:27 +00:00
|
|
|
|
}
|
2014-10-16 09:53:44 +00:00
|
|
|
|
|
|
|
|
|
if (holder.dateView != null) {
|
|
|
|
|
holder.dateView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineSmallFontSize);
|
2014-01-25 09:17:27 +00:00
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
Date d = new Date((long)article.updated * 1000);
|
2014-11-13 18:58:30 +00:00
|
|
|
|
Date now = new Date();
|
|
|
|
|
|
|
|
|
|
DateFormat df;
|
|
|
|
|
|
|
|
|
|
if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDay() == d.getDay()) {
|
|
|
|
|
df = new SimpleDateFormat("HH:mm");
|
|
|
|
|
} else {
|
|
|
|
|
df = new SimpleDateFormat("MMM dd");
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
df.setTimeZone(TimeZone.getDefault());
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.dateView.setText(df.format(d));
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
if (holder.selectionBoxView != null) {
|
2015-02-13 12:11:38 +00:00
|
|
|
|
holder.selectionBoxView.setChecked(article.selected);
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.selectionBoxView.setOnClickListener(new OnClickListener() {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
CheckBox cb = (CheckBox)view;
|
|
|
|
|
|
|
|
|
|
if (cb.isChecked()) {
|
2015-02-13 12:11:38 +00:00
|
|
|
|
article.selected = true;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
} else {
|
2015-02-13 12:11:38 +00:00
|
|
|
|
article.selected = false;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 12:11:38 +00:00
|
|
|
|
m_listener.onArticleListSelectionChange(getSelectedArticles());
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
2015-02-13 12:11:38 +00:00
|
|
|
|
Log.d(TAG, "num selected: " + getSelectedArticles().size());
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-10-16 09:53:44 +00:00
|
|
|
|
|
|
|
|
|
if (holder.menuButtonView != null) {
|
2013-09-09 09:34:53 +00:00
|
|
|
|
//if (m_activity.isDarkTheme())
|
|
|
|
|
// ib.setImageResource(R.drawable.ic_mailbox_collapsed_holo_dark);
|
2013-05-18 09:19:16 +00:00
|
|
|
|
|
2014-10-16 09:53:44 +00:00
|
|
|
|
holder.menuButtonView.setOnClickListener(new OnClickListener() {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
getActivity().openContextMenu(v);
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-05-18 09:19:16 +00:00
|
|
|
|
}
|
2014-10-31 11:11:47 +00:00
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
return v;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
2013-04-24 13:48:44 +00:00
|
|
|
|
|
2013-04-25 16:03:43 +00:00
|
|
|
|
private void adjustTitleTextView(int score, TextView tv, int position) {
|
2013-04-24 13:48:44 +00:00
|
|
|
|
int viewType = getItemViewType(position);
|
2013-04-25 15:54:52 +00:00
|
|
|
|
if (origTitleColors[viewType] == null)
|
2013-04-24 13:48:44 +00:00
|
|
|
|
// store original color
|
|
|
|
|
origTitleColors[viewType] = Integer.valueOf(tv.getCurrentTextColor());
|
|
|
|
|
|
2013-04-25 16:03:43 +00:00
|
|
|
|
if (score < -500) {
|
2013-04-24 13:48:44 +00:00
|
|
|
|
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
2013-04-25 15:54:52 +00:00
|
|
|
|
} else if (score > 500) {
|
2013-04-25 16:03:43 +00:00
|
|
|
|
tv.setTextColor(titleHighScoreUnreadColor);
|
2013-04-24 13:48:44 +00:00
|
|
|
|
tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
|
} else {
|
|
|
|
|
tv.setTextColor(origTitleColors[viewType].intValue());
|
|
|
|
|
tv.setPaintFlags(tv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void notifyUpdated() {
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ArticleList getAllArticles() {
|
|
|
|
|
return m_articles;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 12:50:47 +00:00
|
|
|
|
// if setting active doesn't make sense, scroll to whatever is passed to us
|
2013-04-21 13:01:26 +00:00
|
|
|
|
public void setActiveArticle(Article article) {
|
2015-02-10 12:22:48 +00:00
|
|
|
|
if (article != m_activeArticle && article != null) {
|
2015-02-10 12:50:47 +00:00
|
|
|
|
|
|
|
|
|
// only set active article when it makes sense (in HeadlinesActivity)
|
|
|
|
|
if (getActivity() instanceof HeadlinesActivity) {
|
|
|
|
|
m_activeArticle = article;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
|
2014-10-31 10:18:27 +00:00
|
|
|
|
ListView list = (ListView)getView().findViewById(R.id.headlines_list);
|
2015-02-10 12:22:48 +00:00
|
|
|
|
|
|
|
|
|
if (list != null) {
|
|
|
|
|
int position = getArticlePositionById(article.id);
|
|
|
|
|
|
|
|
|
|
if (position != -1) {
|
|
|
|
|
list.smoothScrollToPosition(position);
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSelection(ArticlesSelection select) {
|
2015-02-13 12:11:38 +00:00
|
|
|
|
for (Article a : m_articles)
|
|
|
|
|
a.selected = false;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
if (select != ArticlesSelection.NONE) {
|
|
|
|
|
for (Article a : m_articles) {
|
|
|
|
|
if (select == ArticlesSelection.ALL || select == ArticlesSelection.UNREAD && a.unread) {
|
2015-02-13 12:11:38 +00:00
|
|
|
|
a.selected = true;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-13 11:31:15 +00:00
|
|
|
|
|
|
|
|
|
if (m_adapter != null) {
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 11:31:15 +00:00
|
|
|
|
public Article getArticleAtPosition(int position) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
try {
|
2015-05-11 09:30:12 +00:00
|
|
|
|
return (Article) m_list.getItemAtPosition(position);
|
|
|
|
|
} catch (ClassCastException e) {
|
|
|
|
|
return null;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
return null;
|
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Article getArticleById(int id) {
|
|
|
|
|
for (Article a : m_articles) {
|
|
|
|
|
if (a.id == id)
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ArticleList getUnreadArticles() {
|
|
|
|
|
ArticleList tmp = new ArticleList();
|
|
|
|
|
for (Article a : m_articles) {
|
|
|
|
|
if (a.unread) tmp.add(a);
|
|
|
|
|
}
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 10:15:26 +00:00
|
|
|
|
@Override
|
2013-04-21 13:01:26 +00:00
|
|
|
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
|
if (!m_refreshInProgress && m_articles.findById(-1) != null && firstVisibleItem + visibleItemCount == m_articles.size()) {
|
|
|
|
|
refresh(true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 08:18:27 +00:00
|
|
|
|
if (m_prefs.getBoolean("headlines_mark_read_scroll", false) && firstVisibleItem > (m_activity.isSmallScreen() ? 1 : 0) && !m_autoCatchupDisabled) {
|
|
|
|
|
Article a = (Article) view.getItemAtPosition(firstVisibleItem - 1);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
if (a != null && a.unread) {
|
2015-05-11 08:18:27 +00:00
|
|
|
|
Log.d(TAG, "title=" + a.title);
|
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
|
a.unread = false;
|
|
|
|
|
m_readArticles.add(a);
|
|
|
|
|
m_feed.unread--;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-11 08:18:27 +00:00
|
|
|
|
|
2015-05-11 08:31:06 +00:00
|
|
|
|
if (!m_activity.isTablet()) {
|
2015-05-11 08:18:27 +00:00
|
|
|
|
if (m_adapter.getCount() > 0) {
|
|
|
|
|
if (firstVisibleItem > m_listPreviousVisibleItem) {
|
|
|
|
|
m_activity.getSupportActionBar().hide();
|
|
|
|
|
} else if (firstVisibleItem < m_listPreviousVisibleItem) {
|
|
|
|
|
m_activity.getSupportActionBar().show();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
m_activity.getSupportActionBar().show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_listPreviousVisibleItem = firstVisibleItem;
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
|
if (scrollState == SCROLL_STATE_IDLE && m_prefs.getBoolean("headlines_mark_read_scroll", false)) {
|
|
|
|
|
if (!m_readArticles.isEmpty()) {
|
|
|
|
|
m_activity.toggleArticlesUnread(m_readArticles);
|
|
|
|
|
m_activity.refresh(false);
|
|
|
|
|
m_readArticles.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-24 10:15:26 +00:00
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
public Article getActiveArticle() {
|
|
|
|
|
return m_activeArticle;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 12:22:48 +00:00
|
|
|
|
public int getArticlePositionById(int id) {
|
|
|
|
|
for (Article a : m_adapter.items) {
|
|
|
|
|
if (a.id == id) {
|
2015-05-11 09:30:12 +00:00
|
|
|
|
return m_adapter.getPosition(a) + m_list.getHeaderViewsCount();
|
2015-02-10 12:22:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 09:30:12 +00:00
|
|
|
|
/* public int getArticlePosition(Article article) {
|
2013-04-21 13:01:26 +00:00
|
|
|
|
try {
|
|
|
|
|
return m_adapter.getPosition(article);
|
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2015-05-11 09:30:12 +00:00
|
|
|
|
} */
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
|
|
public String getSearchQuery() {
|
|
|
|
|
return m_searchQuery;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSearchQuery(String query) {
|
|
|
|
|
if (!m_searchQuery.equals(query)) {
|
|
|
|
|
m_searchQuery = query;
|
|
|
|
|
refresh(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Feed getFeed() {
|
|
|
|
|
return m_feed;
|
|
|
|
|
}
|
2015-02-10 12:08:17 +00:00
|
|
|
|
|
|
|
|
|
public ArticleList getArticles() {
|
|
|
|
|
return m_articles;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-10 12:50:47 +00:00
|
|
|
|
public void setArticles(ArticleList articles) {
|
2015-02-10 12:08:17 +00:00
|
|
|
|
m_articles.clear();
|
|
|
|
|
m_articles.addAll(articles);
|
|
|
|
|
m_adapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
|
}
|