tt-rss-android/src/org/fox/ttrss/HeadlinesActivity.java

218 lines
5.7 KiB
Java
Raw Normal View History

2012-09-16 09:25:28 +00:00
package org.fox.ttrss;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
import org.fox.ttrss.types.Feed;
2012-09-19 09:37:12 +00:00
import android.annotation.SuppressLint;
2012-09-16 09:25:28 +00:00
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
2012-09-16 09:25:28 +00:00
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
2012-09-17 12:28:32 +00:00
public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener {
private final String TAG = this.getClass().getSimpleName();
2012-09-16 09:25:28 +00:00
protected SharedPreferences m_prefs;
2012-09-19 09:37:12 +00:00
@SuppressLint("NewApi")
2012-09-16 09:25:28 +00:00
@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.headlines);
if (!isCompatMode()) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
setSmallScreen(findViewById(R.id.headlines_fragment) == null);
if (savedInstanceState == null) {
Intent i = getIntent();
if (i.getExtras() != null) {
final Feed feed = i.getParcelableExtra("feed");
final Article article = i.getParcelableExtra("article");
final String searchQuery = i.getStringExtra("searchQuery");
2012-09-16 17:00:09 +00:00
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
2012-09-16 09:25:28 +00:00
ft.replace(R.id.headlines_fragment, new LoadingFragment(), null);
ft.replace(R.id.article_fragment, new LoadingFragment(), null);
2012-09-16 17:00:09 +00:00
ft.commit();
setTitle(feed.title);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
HeadlinesFragment hf = new HeadlinesFragment(feed, article);
hf.setSearchQuery(searchQuery);
ArticlePager af = new ArticlePager(hf.getArticleById(article.id), feed);
af.setSearchQuery(searchQuery);
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
ft.commit();
}
2012-09-20 19:00:15 +00:00
}, 10);
2012-09-16 09:25:28 +00:00
}
}
}
@Override
protected void refresh() {
super.refresh();
}
2012-09-16 09:25:28 +00:00
@Override
protected void loginSuccess() {
Log.d(TAG, "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 boolean onOptionsItemSelected(MenuItem item) {
2012-09-17 19:35:52 +00:00
switch (item.getItemId()) {
2012-09-16 09:25:28 +00:00
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
protected void initMenu() {
super.initMenu();
2012-09-19 09:55:01 +00:00
if (m_menu != null && getSessionId() != null) {
2012-09-16 09:25:28 +00:00
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
m_menu.setGroupVisible(R.id.menu_group_headlines, hf != null && hf.getSelectedArticles().size() == 0);
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, hf != null && hf.getSelectedArticles().size() != 0);
Fragment af = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
m_menu.setGroupVisible(R.id.menu_group_article, af != null);
2012-09-18 11:35:24 +00:00
m_menu.findItem(R.id.search).setVisible(false);
2012-09-16 09:25:28 +00:00
}
}
@Override
public void onArticleListSelectionChange(ArticleList m_selectedArticles) {
initMenu();
}
@Override
public void onArticleSelected(Article article) {
onArticleSelected(article, true);
}
@Override
public void onArticleSelected(Article article, boolean open) {
if (article.unread) {
article.unread = false;
saveArticleUnread(article);
}
2012-09-16 09:25:28 +00:00
if (open) {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
2012-09-17 19:20:59 +00:00
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
af.setActiveArticle(article);
2012-09-16 09:25:28 +00:00
ft.commit();
} else {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) {
hf.setActiveArticle(article);
}
2012-09-16 09:25:28 +00:00
}
2012-09-17 19:20:59 +00:00
GlobalState.getInstance().m_activeArticle = article;
initMenu();
2012-09-16 09:25:28 +00:00
}
@Override
public void onHeadlinesLoaded(boolean appended) {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
2012-09-19 19:39:46 +00:00
if (hf != null) {
Article article = hf.getActiveArticle();
if (article == null) {
article = hf.getAllArticles().get(0);
hf.setActiveArticle(article);
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ft.replace(R.id.article_fragment, new LoadingFragment(), null);
ft.commit();
final Article fArticle = article;
final Feed fFeed = hf.getFeed();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ArticlePager af = new ArticlePager(fArticle, fFeed);
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
ft.commit();
}
}, 10);
}
}
}
2012-09-16 09:25:28 +00:00
}