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;
|
2012-09-20 18:57:40 +00:00
|
|
|
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 {
|
2012-09-17 08:45:52 +00:00
|
|
|
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);
|
2012-11-30 16:21:31 +00:00
|
|
|
|
|
|
|
GlobalState.getInstance().load(savedInstanceState);
|
2012-10-09 08:55:26 +00:00
|
|
|
|
|
|
|
if (isPortrait()) {
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
}
|
2012-09-16 09:25:28 +00:00
|
|
|
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
Intent i = getIntent();
|
|
|
|
|
|
|
|
if (i.getExtras() != null) {
|
2012-09-20 18:57:40 +00:00
|
|
|
final Feed feed = i.getParcelableExtra("feed");
|
|
|
|
final Article article = i.getParcelableExtra("article");
|
|
|
|
final String searchQuery = i.getStringExtra("searchQuery");
|
2012-09-17 09:27:27 +00:00
|
|
|
|
2012-09-16 17:00:09 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2012-09-16 09:25:28 +00:00
|
|
|
|
2012-09-20 18:57:40 +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();
|
2012-09-17 08:45:52 +00:00
|
|
|
|
|
|
|
setTitle(feed.title);
|
2012-09-20 18:57:40 +00:00
|
|
|
|
2012-09-20 19:05:34 +00:00
|
|
|
new Handler().postDelayed(new Runnable() {
|
2012-09-20 18:57:40 +00:00
|
|
|
@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-23 09:14:31 +00:00
|
|
|
}, 25);
|
2012-09-20 18:57:40 +00:00
|
|
|
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
2012-09-20 19:19:50 +00:00
|
|
|
}
|
|
|
|
|
2012-09-23 09:14:31 +00:00
|
|
|
/* if (!isCompatMode()) {
|
2012-09-20 19:19:50 +00:00
|
|
|
((ViewGroup)findViewById(R.id.headlines_fragment)).setLayoutTransition(new LayoutTransition());
|
|
|
|
((ViewGroup)findViewById(R.id.article_fragment)).setLayoutTransition(new LayoutTransition());
|
2012-09-23 09:14:31 +00:00
|
|
|
} */
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 11:17:39 +00:00
|
|
|
@Override
|
|
|
|
protected void refresh() {
|
|
|
|
super.refresh();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-09-16 09:25:28 +00:00
|
|
|
@Override
|
2012-09-21 06:44:30 +00:00
|
|
|
protected void loginSuccess(boolean refresh) {
|
2012-09-16 09:25:28 +00:00
|
|
|
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-21 06:44:30 +00:00
|
|
|
|
|
|
|
if (refresh) refresh();
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle out) {
|
2012-11-30 16:21:31 +00:00
|
|
|
super.onSaveInstanceState(out);
|
|
|
|
|
|
|
|
GlobalState.getInstance().save(out);
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
2012-10-09 08:55:26 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, !isPortrait()&& hf != null && hf.getSelectedArticles().size() == 0);
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, !isPortrait() && hf != null && hf.getSelectedArticles().size() != 0);
|
2012-09-16 09:25:28 +00:00
|
|
|
|
|
|
|
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) {
|
|
|
|
|
2012-09-16 18:13:32 +00:00
|
|
|
if (article.unread) {
|
|
|
|
article.unread = false;
|
|
|
|
saveArticleUnread(article);
|
|
|
|
}
|
|
|
|
|
2012-09-16 09:25:28 +00:00
|
|
|
if (open) {
|
|
|
|
|
2012-09-20 19:10:23 +00:00
|
|
|
final Article fArticle = article;
|
2012-09-16 09:25:28 +00:00
|
|
|
|
2012-09-20 19:10:23 +00:00
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
|
|
|
|
|
|
|
|
if (af != null) {
|
|
|
|
af.setActiveArticle(fArticle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 10);
|
|
|
|
|
2012-09-16 09:25:28 +00:00
|
|
|
} else {
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
2012-10-09 08:55:26 +00:00
|
|
|
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
|
|
|
|
|
|
|
}
|
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
|
|
|
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
|
|
|
|
2012-09-19 19:39:46 +00:00
|
|
|
if (hf != null) {
|
2012-09-18 19:50:50 +00:00
|
|
|
Article article = hf.getActiveArticle();
|
|
|
|
|
|
|
|
if (article == null) {
|
|
|
|
article = hf.getAllArticles().get(0);
|
2012-09-18 11:17:39 +00:00
|
|
|
|
2012-09-18 19:50:50 +00:00
|
|
|
hf.setActiveArticle(article);
|
2012-09-18 11:17:39 +00:00
|
|
|
|
2012-09-18 19:50:50 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager()
|
|
|
|
.beginTransaction();
|
2012-09-18 11:17:39 +00:00
|
|
|
|
2012-09-20 19:05:34 +00:00
|
|
|
ft.replace(R.id.article_fragment, new LoadingFragment(), null);
|
2012-09-18 19:50:50 +00:00
|
|
|
|
|
|
|
ft.commit();
|
2012-09-20 19:05:34 +00:00
|
|
|
|
|
|
|
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-18 19:50:50 +00:00
|
|
|
}
|
2012-09-18 11:17:39 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-30 21:53:04 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
super.onBackPressed();
|
|
|
|
overridePendingTransition(0, R.anim.right_slide_out);
|
|
|
|
}
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|