2012-09-16 09:25:28 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import org.fox.ttrss.types.Article;
|
|
|
|
import org.fox.ttrss.types.ArticleList;
|
|
|
|
import org.fox.ttrss.types.Feed;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
Feed feed = i.getParcelableExtra("feed");
|
|
|
|
Article article = i.getParcelableExtra("article");
|
2012-09-17 09:27:27 +00:00
|
|
|
String searchQuery = i.getStringExtra("searchQuery");
|
2012-09-16 09:25:28 +00:00
|
|
|
|
2012-09-17 08:45:52 +00:00
|
|
|
HeadlinesFragment hf = new HeadlinesFragment(feed, article);
|
2012-09-16 17:59:03 +00:00
|
|
|
ArticlePager af = new ArticlePager(hf.getArticleById(article.id));
|
2012-09-16 17:00:09 +00:00
|
|
|
|
2012-09-17 09:27:27 +00:00
|
|
|
hf.setSearchQuery(searchQuery);
|
|
|
|
af.setSearchQuery(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, hf, FRAG_HEADLINES);
|
|
|
|
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
|
2012-09-16 17:00:09 +00:00
|
|
|
|
|
|
|
ft.commit();
|
2012-09-17 08:45:52 +00:00
|
|
|
|
|
|
|
setTitle(feed.title);
|
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) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
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-16 15:25:47 +00:00
|
|
|
if (m_menu != null && m_sessionId != 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager()
|
|
|
|
.beginTransaction();
|
|
|
|
|
2012-09-16 15:25:47 +00:00
|
|
|
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
|
|
|
|
2012-09-16 17:59:03 +00:00
|
|
|
Fragment frag = new ArticlePager(article);
|
2012-09-16 09:25:28 +00:00
|
|
|
|
|
|
|
ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
|
2012-09-17 08:45:52 +00:00
|
|
|
// ft.addToBackStack(null);
|
2012-09-16 18:13:32 +00:00
|
|
|
|
|
|
|
hf.notifyUpdated();
|
2012-09-16 09:25:28 +00:00
|
|
|
|
|
|
|
ft.commit();
|
|
|
|
} else {
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
2012-09-16 18:13:32 +00:00
|
|
|
hf.setActiveArticle(article);
|
|
|
|
|
2012-09-16 17:59:03 +00:00
|
|
|
initMenu();
|
2012-09-16 09:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|