2013-04-21 13:01:26 +00:00
|
|
|
package org.fox.ttrss;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
2015-02-10 12:08:17 +00:00
|
|
|
import android.app.Activity;
|
2013-04-21 13:01:26 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2015-02-07 13:35:44 +00:00
|
|
|
import android.content.res.Configuration;
|
2013-04-21 13:01:26 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
2015-06-03 21:30:35 +00:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2013-04-21 13:01:26 +00:00
|
|
|
import android.util.Log;
|
2014-10-15 09:29:20 +00:00
|
|
|
import android.view.MenuItem;
|
2014-11-25 15:17:36 +00:00
|
|
|
import android.view.View;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2014-10-30 13:23:39 +00:00
|
|
|
import org.fox.ttrss.types.Article;
|
|
|
|
import org.fox.ttrss.types.ArticleList;
|
|
|
|
import org.fox.ttrss.types.Feed;
|
|
|
|
|
2015-06-10 16:40:08 +00:00
|
|
|
public class DetailActivity extends OnlineActivity implements HeadlinesEventListener {
|
2013-04-21 13:01:26 +00:00
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
2015-02-10 13:04:23 +00:00
|
|
|
protected ArticleList m_articles = new ArticleList();
|
2015-02-10 12:08:17 +00:00
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
protected SharedPreferences m_prefs;
|
2015-02-10 12:22:48 +00:00
|
|
|
private Article m_activeArticle;
|
2014-10-31 11:11:47 +00:00
|
|
|
|
2015-02-10 12:22:48 +00:00
|
|
|
@SuppressLint("NewApi")
|
2013-04-21 13:01:26 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
m_prefs = PreferenceManager
|
|
|
|
.getDefaultSharedPreferences(getApplicationContext());
|
|
|
|
|
|
|
|
setAppTheme(m_prefs);
|
2015-02-12 09:41:25 +00:00
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2015-06-10 16:40:08 +00:00
|
|
|
setContentView(R.layout.activity_detail);
|
2014-10-31 11:11:47 +00:00
|
|
|
|
2015-06-10 16:24:24 +00:00
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
2015-06-03 21:30:35 +00:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
2015-02-13 12:11:38 +00:00
|
|
|
m_forceDisableActionMode = isPortrait() || isSmallScreen();
|
|
|
|
|
2014-10-31 11:11:47 +00:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
getSupportActionBar().setHomeButtonEnabled(true);
|
2014-10-17 05:59:03 +00:00
|
|
|
|
|
|
|
setSmallScreen(findViewById(R.id.sw600dp_anchor) == null);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2015-06-10 16:40:08 +00:00
|
|
|
Application.getInstance().load(savedInstanceState);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2015-02-07 13:35:44 +00:00
|
|
|
if (isPortrait() && !isSmallScreen()) {
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2015-02-10 12:50:47 +00:00
|
|
|
if (savedInstanceState != null) {
|
2015-02-10 13:04:23 +00:00
|
|
|
m_articles = savedInstanceState.getParcelable("articles");
|
2015-02-10 12:50:47 +00:00
|
|
|
} else {
|
2013-04-21 13:01:26 +00:00
|
|
|
Intent i = getIntent();
|
|
|
|
|
|
|
|
if (i.getExtras() != null) {
|
2013-10-17 06:37:32 +00:00
|
|
|
boolean shortcutMode = i.getBooleanExtra("shortcut_mode", false);
|
|
|
|
|
|
|
|
Log.d(TAG, "is_shortcut_mode: " + shortcutMode);
|
|
|
|
|
|
|
|
Feed tmpFeed;
|
|
|
|
|
|
|
|
if (shortcutMode) {
|
|
|
|
int feedId = i.getIntExtra("feed_id", 0);
|
|
|
|
boolean isCat = i.getBooleanExtra("feed_is_cat", false);
|
|
|
|
String feedTitle = i.getStringExtra("feed_title");
|
|
|
|
|
|
|
|
tmpFeed = new Feed(feedId, feedTitle, isCat);
|
2015-02-10 12:08:17 +00:00
|
|
|
|
2015-06-10 16:40:08 +00:00
|
|
|
//Application.getInstance().m_loadedArticles.clear();
|
2013-10-17 06:37:32 +00:00
|
|
|
} else {
|
|
|
|
tmpFeed = i.getParcelableExtra("feed");
|
|
|
|
}
|
|
|
|
|
|
|
|
final Feed feed = tmpFeed;
|
|
|
|
|
2015-07-17 07:31:41 +00:00
|
|
|
//final Article article = i.getParcelableExtra("article");
|
|
|
|
final Article article = Application.getInstance().tmpArticle;
|
2013-04-21 13:01:26 +00:00
|
|
|
final String searchQuery = i.getStringExtra("searchQuery");
|
2015-02-10 12:08:17 +00:00
|
|
|
|
2015-06-10 16:40:08 +00:00
|
|
|
ArticleList tmp = Application.getInstance().tmpArticleList;
|
2015-02-10 12:08:17 +00:00
|
|
|
|
|
|
|
if (tmp != null) {
|
|
|
|
m_articles.addAll(tmp);
|
|
|
|
}
|
|
|
|
|
2015-02-13 11:31:15 +00:00
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2015-02-12 09:41:25 +00:00
|
|
|
final HeadlinesFragment hf = new HeadlinesFragment();
|
|
|
|
hf.initialize(feed, article, true, m_articles);
|
|
|
|
hf.setSearchQuery(searchQuery);
|
|
|
|
|
|
|
|
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
|
|
|
|
|
2015-06-10 16:50:27 +00:00
|
|
|
ArticlePager af = new ArticlePager();
|
|
|
|
af.initialize(article != null ? hf.getArticleById(article.id) : new Article(), feed, m_articles);
|
|
|
|
af.setSearchQuery(searchQuery);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2015-06-10 16:50:27 +00:00
|
|
|
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2015-06-10 16:50:27 +00:00
|
|
|
ft.commit();
|
|
|
|
|
|
|
|
setTitle(feed.title);
|
2013-04-21 13:01:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-31 11:11:47 +00:00
|
|
|
|
2015-02-07 13:35:44 +00:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
|
|
|
if (!isSmallScreen()) {
|
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(isPortrait() ? View.GONE : View.VISIBLE);
|
|
|
|
}
|
2015-02-13 12:11:38 +00:00
|
|
|
|
|
|
|
m_forceDisableActionMode = isPortrait() || isSmallScreen();
|
|
|
|
invalidateOptionsMenu();
|
2015-02-07 13:35:44 +00:00
|
|
|
}
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
@Override
|
|
|
|
protected void refresh() {
|
|
|
|
super.refresh();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void loginSuccess(boolean refresh) {
|
|
|
|
Log.d(TAG, "loginSuccess");
|
2014-10-30 22:02:06 +00:00
|
|
|
|
2014-11-04 14:50:14 +00:00
|
|
|
invalidateOptionsMenu();
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
if (refresh) refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle out) {
|
|
|
|
super.onSaveInstanceState(out);
|
2015-02-10 13:04:23 +00:00
|
|
|
|
|
|
|
out.putParcelable("articles", m_articles);
|
2015-02-13 12:11:38 +00:00
|
|
|
|
2015-06-10 16:40:08 +00:00
|
|
|
Application.getInstance().save(out);
|
2013-04-21 13:01:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2014-10-31 11:11:47 +00:00
|
|
|
switch (item.getItemId()) {
|
2013-04-21 13:01:26 +00:00
|
|
|
case android.R.id.home:
|
2015-02-12 10:09:54 +00:00
|
|
|
onBackPressed();
|
2013-04-21 13:01:26 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
if (m_menu != null && getSessionId() != null) {
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_feeds, false);
|
|
|
|
|
2013-06-11 04:57:25 +00:00
|
|
|
//HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2013-11-28 20:47:38 +00:00
|
|
|
m_menu.setGroupVisible(R.id.menu_group_headlines, !isPortrait() && !isSmallScreen());
|
2014-10-31 11:11:47 +00:00
|
|
|
//m_menu.findItem(R.id.headlines_toggle_sidebar).setVisible(!isPortrait() && !isSmallScreen());
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
|
|
|
|
|
|
|
|
m_menu.setGroupVisible(R.id.menu_group_article, af != null);
|
|
|
|
|
|
|
|
if (af != null) {
|
|
|
|
if (af.getSelectedArticle() != null && af.getSelectedArticle().attachments != null && af.getSelectedArticle().attachments.size() > 0) {
|
2014-10-30 13:23:39 +00:00
|
|
|
/* if (!isCompatMode() && (isSmallScreen() || !isPortrait())) {
|
2013-04-21 13:01:26 +00:00
|
|
|
m_menu.findItem(R.id.toggle_attachments).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
2014-10-30 13:23:39 +00:00
|
|
|
} */
|
2013-04-21 13:01:26 +00:00
|
|
|
m_menu.findItem(R.id.toggle_attachments).setVisible(true);
|
|
|
|
} else {
|
2014-10-30 13:23:39 +00:00
|
|
|
/* if (!isCompatMode()) {
|
2013-04-21 13:01:26 +00:00
|
|
|
m_menu.findItem(R.id.toggle_attachments).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
2014-10-30 13:23:39 +00:00
|
|
|
} */
|
2013-04-21 13:01:26 +00:00
|
|
|
m_menu.findItem(R.id.toggle_attachments).setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_menu.findItem(R.id.search).setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onArticleListSelectionChange(ArticleList m_selectedArticles) {
|
2014-11-04 14:50:14 +00:00
|
|
|
invalidateOptionsMenu();
|
2013-04-21 13:01:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onArticleSelected(Article article) {
|
|
|
|
onArticleSelected(article, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onArticleSelected(Article article, boolean open) {
|
|
|
|
|
2013-06-07 08:53:00 +00:00
|
|
|
if (article == null) return;
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
if (article.unread) {
|
|
|
|
article.unread = false;
|
|
|
|
saveArticleUnread(article);
|
|
|
|
}
|
|
|
|
|
2015-05-10 21:34:24 +00:00
|
|
|
if (!getSupportActionBar().isShowing()) getSupportActionBar().show();
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
if (open) {
|
|
|
|
|
|
|
|
final Article fArticle = article;
|
|
|
|
|
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-10-31 11:11:47 +00:00
|
|
|
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
if (af != null) {
|
|
|
|
af.setActiveArticle(fArticle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 10);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
2013-06-03 05:23:33 +00:00
|
|
|
if (hf != null) {
|
|
|
|
hf.setActiveArticle(article);
|
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
}
|
|
|
|
|
2015-02-10 12:22:48 +00:00
|
|
|
m_activeArticle = article;
|
|
|
|
|
2015-06-10 16:40:08 +00:00
|
|
|
//Application.getInstance().m_activeArticle = article;
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2014-11-04 14:50:14 +00:00
|
|
|
invalidateOptionsMenu();
|
2013-04-21 13:01:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-25 15:17:36 +00:00
|
|
|
public void showSidebar(boolean show) {
|
2015-02-07 13:35:44 +00:00
|
|
|
if (!isSmallScreen() && !isPortrait()) {
|
2014-11-25 15:17:36 +00:00
|
|
|
findViewById(R.id.headlines_fragment).setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
@Override
|
|
|
|
public void onHeadlinesLoaded(boolean appended) {
|
|
|
|
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
2014-10-20 17:48:18 +00:00
|
|
|
ArticlePager ap = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
|
|
|
|
|
|
|
|
if (ap != null) {
|
|
|
|
ap.notifyUpdated();
|
|
|
|
}
|
|
|
|
|
2013-04-21 13:01:26 +00:00
|
|
|
if (hf != null) {
|
|
|
|
Article article = hf.getActiveArticle();
|
|
|
|
|
|
|
|
if (article == null && hf.getAllArticles().size() > 0) {
|
|
|
|
article = hf.getAllArticles().get(0);
|
|
|
|
|
|
|
|
hf.setActiveArticle(article);
|
|
|
|
|
|
|
|
FragmentTransaction ft = getSupportFragmentManager()
|
|
|
|
.beginTransaction();
|
|
|
|
|
2015-06-10 16:50:27 +00:00
|
|
|
ArticlePager af = new ArticlePager();
|
|
|
|
af.initialize(article, hf.getFeed(), m_articles);
|
2013-04-21 13:01:26 +00:00
|
|
|
|
2015-06-10 16:50:27 +00:00
|
|
|
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
|
|
|
|
ft.commitAllowingStateLoss();
|
2013-04-21 13:01:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2015-02-10 12:08:17 +00:00
|
|
|
Intent resultIntent = new Intent();
|
2015-02-10 12:50:47 +00:00
|
|
|
|
2015-06-10 16:40:08 +00:00
|
|
|
Application.getInstance().tmpArticleList = m_articles;
|
2015-02-10 12:22:48 +00:00
|
|
|
resultIntent.putExtra("activeArticle", m_activeArticle);
|
|
|
|
|
2015-02-10 12:08:17 +00:00
|
|
|
setResult(Activity.RESULT_OK, resultIntent);
|
|
|
|
|
2015-02-10 12:50:47 +00:00
|
|
|
super.onBackPressed();
|
2015-02-10 12:08:17 +00:00
|
|
|
}
|
2013-04-21 13:01:26 +00:00
|
|
|
}
|