2012-09-16 09:25:28 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import org.fox.ttrss.types.Article;
|
|
|
|
import org.fox.ttrss.types.ArticleList;
|
|
|
|
import org.fox.ttrss.types.Feed;
|
|
|
|
import org.fox.ttrss.types.FeedCategory;
|
2012-09-18 09:08:57 +00:00
|
|
|
import org.fox.ttrss.util.AppRater;
|
2012-09-16 09:25:28 +00:00
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.Window;
|
2012-09-16 16:46:54 +00:00
|
|
|
import android.widget.ShareActionProvider;
|
2012-09-16 09:25:28 +00:00
|
|
|
|
2012-09-17 12:28:32 +00:00
|
|
|
public class FeedsActivity extends OnlineActivity implements HeadlinesEventListener {
|
2012-09-16 09:25:28 +00:00
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
|
|
|
protected SharedPreferences m_prefs;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
m_prefs = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
|
|
|
|
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
|
|
|
setTheme(R.style.DarkTheme);
|
|
|
|
} else {
|
|
|
|
setTheme(R.style.LightTheme);
|
|
|
|
}
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
setContentView(R.layout.feeds);
|
|
|
|
|
|
|
|
setSmallScreen(findViewById(R.id.headlines_fragment) == null);
|
|
|
|
|
2012-09-17 08:45:52 +00:00
|
|
|
Intent intent = getIntent();
|
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
if (savedInstanceState == null) {
|
2012-09-17 08:45:52 +00:00
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
if (intent.getParcelableExtra("feed") != null || intent.getParcelableExtra("category") != null ||
|
|
|
|
intent.getParcelableExtra("article") != null) {
|
2012-09-17 08:45:52 +00:00
|
|
|
|
2012-09-17 19:20:59 +00:00
|
|
|
if (!isCompatMode()) {
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
}
|
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
Feed feed = (Feed) intent.getParcelableExtra("feed");
|
|
|
|
FeedCategory cat = (FeedCategory) intent.getParcelableExtra("category");
|
|
|
|
Article article = (Article) intent.getParcelableExtra("article");
|
|
|
|
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
|
|
|
|
|
|
if (feed != null) {
|
|
|
|
HeadlinesFragment hf = new HeadlinesFragment(feed);
|
|
|
|
ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES);
|
|
|
|
|
|
|
|
setTitle(feed.title);
|
|
|
|
}
|
2012-09-17 08:45:52 +00:00
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
if (cat != null) {
|
|
|
|
FeedsFragment ff = new FeedsFragment(cat);
|
|
|
|
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
|
|
|
|
|
|
|
|
setTitle(cat.title);
|
|
|
|
}
|
2012-09-17 08:45:52 +00:00
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
if (article != null) {
|
2012-09-17 19:20:59 +00:00
|
|
|
Article original = GlobalState.getInstance().m_loadedArticles.findById(article.id);
|
2012-09-17 09:27:27 +00:00
|
|
|
|
|
|
|
ArticlePager ap = new ArticlePager(original != null ? original : article);
|
|
|
|
ft.replace(R.id.feeds_fragment, ap, FRAG_ARTICLE);
|
|
|
|
|
|
|
|
ap.setSearchQuery(intent.getStringExtra("searchQuery"));
|
|
|
|
|
|
|
|
setTitle(intent.getStringExtra("feedTitle"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ft.commit();
|
2012-09-17 08:45:52 +00:00
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
} else {
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2012-09-16 09:25:28 +00:00
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
if (m_prefs.getBoolean("enable_cats", false)) {
|
|
|
|
ft.replace(R.id.feeds_fragment, new FeedCategoriesFragment(), FRAG_CATS);
|
|
|
|
} else {
|
|
|
|
ft.replace(R.id.feeds_fragment, new FeedsFragment(), FRAG_FEEDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
ft.commit();
|
2012-09-18 09:08:57 +00:00
|
|
|
|
|
|
|
AppRater.appLaunched(this);
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
2012-09-17 08:45:52 +00:00
|
|
|
}
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void initMenu() {
|
|
|
|
super.initMenu();
|
2012-09-16 15:25:47 +00:00
|
|
|
|
|
|
|
if (m_menu != null && m_sessionId != null) {
|
2012-09-16 09:25:28 +00:00
|
|
|
Fragment ff = getSupportFragmentManager().findFragmentByTag(FRAG_FEEDS);
|
|
|
|
Fragment cf = getSupportFragmentManager().findFragmentByTag(FRAG_CATS);
|
2012-09-16 16:46:54 +00:00
|
|
|
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
|
2012-09-16 15:25:47 +00:00
|
|
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
|
|
|
|
2012-09-16 18:36:55 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_feeds, (ff != null && ff.isAdded()) || (cf != null && cf.isAdded()));
|
2012-09-16 09:25:28 +00:00
|
|
|
|
2012-09-16 18:36:55 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_article, af != null && af.isAdded());
|
2012-09-16 09:25:28 +00:00
|
|
|
|
2012-09-16 18:36:55 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, hf != null && hf.isAdded() && hf.getSelectedArticles().size() == 0);
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, hf != null && hf.isAdded() && hf.getSelectedArticles().size() != 0);
|
2012-09-16 15:25:47 +00:00
|
|
|
|
2012-09-18 11:17:39 +00:00
|
|
|
if (isSmallScreen()) {
|
|
|
|
m_menu.findItem(R.id.update_headlines).setVisible(hf != null && hf.isAdded());
|
|
|
|
} else {
|
|
|
|
m_menu.findItem(R.id.update_headlines).setVisible(false);
|
|
|
|
}
|
2012-09-18 09:16:03 +00:00
|
|
|
|
2012-09-16 15:25:47 +00:00
|
|
|
MenuItem item = m_menu.findItem(R.id.show_feeds);
|
|
|
|
|
|
|
|
if (getUnreadOnly()) {
|
|
|
|
item.setTitle(R.string.menu_all_feeds);
|
|
|
|
} else {
|
|
|
|
item.setTitle(R.string.menu_unread_feeds);
|
|
|
|
}
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onFeedSelected(Feed feed) {
|
2012-09-17 19:20:59 +00:00
|
|
|
GlobalState.getInstance().m_loadedArticles.clear();
|
2012-09-16 09:25:28 +00:00
|
|
|
|
|
|
|
if (isSmallScreen()) {
|
2012-09-17 08:45:52 +00:00
|
|
|
|
|
|
|
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
|
|
|
|
intent.putExtra("sessionId", m_sessionId);
|
|
|
|
intent.putExtra("apiLevel", m_apiLevel);
|
|
|
|
intent.putExtra("feed", feed);
|
|
|
|
|
|
|
|
startActivityForResult(intent, 0);
|
|
|
|
|
|
|
|
//HeadlinesFragment hf = new HeadlinesFragment(feed);
|
|
|
|
//ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES);
|
|
|
|
//ft.addToBackStack(null);
|
2012-09-16 09:25:28 +00:00
|
|
|
} else {
|
2012-09-17 15:32:33 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager()
|
|
|
|
.beginTransaction();
|
|
|
|
|
2012-09-17 08:45:52 +00:00
|
|
|
HeadlinesFragment hf = new HeadlinesFragment(feed);
|
2012-09-16 09:25:28 +00:00
|
|
|
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
|
2012-09-17 15:32:33 +00:00
|
|
|
|
|
|
|
ft.commit();
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onCatSelected(FeedCategory cat, boolean openAsFeed) {
|
|
|
|
|
|
|
|
if (!openAsFeed) {
|
2012-09-17 08:45:52 +00:00
|
|
|
|
|
|
|
if (isSmallScreen()) {
|
|
|
|
|
|
|
|
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
|
|
|
|
intent.putExtra("sessionId", m_sessionId);
|
|
|
|
intent.putExtra("apiLevel", m_apiLevel);
|
|
|
|
intent.putExtra("category", cat);
|
|
|
|
|
|
|
|
startActivityForResult(intent, 0);
|
|
|
|
|
|
|
|
} else {
|
2012-09-17 15:32:33 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager()
|
|
|
|
.beginTransaction();
|
|
|
|
|
2012-09-17 08:45:52 +00:00
|
|
|
FeedsFragment ff = new FeedsFragment(cat);
|
|
|
|
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
|
2012-09-17 15:32:33 +00:00
|
|
|
|
|
|
|
ft.addToBackStack(null);
|
|
|
|
ft.commit();
|
2012-09-17 08:45:52 +00:00
|
|
|
}
|
2012-09-16 09:25:28 +00:00
|
|
|
} else {
|
|
|
|
Feed feed = new Feed(cat.id, cat.title, true);
|
|
|
|
onFeedSelected(feed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onCatSelected(FeedCategory cat) {
|
|
|
|
onCatSelected(cat, m_prefs.getBoolean("browse_cats_like_feeds", false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2012-09-16 15:25:47 +00:00
|
|
|
case R.id.show_feeds:
|
|
|
|
m_unreadOnly = !m_unreadOnly;
|
|
|
|
initMenu();
|
|
|
|
refresh();
|
|
|
|
return true;
|
|
|
|
case R.id.update_feeds:
|
|
|
|
refresh();
|
|
|
|
return true;
|
2012-09-16 09:25:28 +00:00
|
|
|
default:
|
|
|
|
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
2012-09-16 18:36:55 +00:00
|
|
|
|
2012-09-16 09:25:28 +00:00
|
|
|
@Override
|
|
|
|
protected void loginSuccess() {
|
|
|
|
setLoadingStatus(R.string.blank, false);
|
|
|
|
findViewById(R.id.loading_container).setVisibility(View.GONE);
|
2012-09-16 15:25:47 +00:00
|
|
|
initMenu();
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle out) {
|
|
|
|
super.onSaveInstanceState(out);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2012-09-16 18:36:55 +00:00
|
|
|
initMenu();
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onArticleListSelectionChange(ArticleList m_selectedArticles) {
|
|
|
|
initMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onArticleSelected(Article article, boolean open) {
|
|
|
|
if (article.unread) {
|
|
|
|
article.unread = false;
|
|
|
|
saveArticleUnread(article);
|
|
|
|
}
|
|
|
|
|
2012-09-17 08:45:52 +00:00
|
|
|
if (open) {
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
|
|
|
|
2012-09-16 09:25:28 +00:00
|
|
|
if (isSmallScreen()) {
|
2012-09-17 08:45:52 +00:00
|
|
|
|
|
|
|
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
|
|
|
|
intent.putExtra("sessionId", m_sessionId);
|
|
|
|
intent.putExtra("apiLevel", m_apiLevel);
|
2012-09-16 09:25:28 +00:00
|
|
|
|
2012-09-17 08:45:52 +00:00
|
|
|
intent.putExtra("feedTitle", hf.getFeed().title);
|
|
|
|
intent.putExtra("article", article);
|
2012-09-17 09:27:27 +00:00
|
|
|
intent.putExtra("searchQuery", hf.getSearchQuery());
|
2012-09-17 08:45:52 +00:00
|
|
|
|
|
|
|
startActivityForResult(intent, 0);
|
2012-09-16 15:25:47 +00:00
|
|
|
|
2012-09-16 09:25:28 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
Intent intent = new Intent(FeedsActivity.this, HeadlinesActivity.class);
|
|
|
|
intent.putExtra("sessionId", m_sessionId);
|
|
|
|
intent.putExtra("apiLevel", m_apiLevel);
|
|
|
|
|
|
|
|
intent.putExtra("feed", hf.getFeed());
|
|
|
|
intent.putExtra("article", article);
|
2012-09-17 09:27:27 +00:00
|
|
|
intent.putExtra("searchQuery", hf.getSearchQuery());
|
2012-09-16 09:25:28 +00:00
|
|
|
|
|
|
|
startActivityForResult(intent, 0);
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-16 16:46:54 +00:00
|
|
|
initMenu();
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onArticleSelected(Article article) {
|
|
|
|
onArticleSelected(article, true);
|
|
|
|
}
|
|
|
|
|
2012-09-16 16:46:54 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public void catchupFeed(final Feed feed) {
|
|
|
|
super.catchupFeed(feed);
|
|
|
|
refresh();
|
|
|
|
}
|
2012-09-18 11:17:39 +00:00
|
|
|
|
|
|
|
@Override
|
2012-09-18 19:50:50 +00:00
|
|
|
public void onHeadlinesLoaded(boolean appended) {
|
2012-09-18 11:17:39 +00:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|