use separate activities for views in small screen mode

This commit is contained in:
Andrew Dolgov 2012-09-17 12:45:52 +04:00
parent aac3d4b488
commit 4f8cc7aeeb
7 changed files with 91 additions and 44 deletions

View File

@ -180,8 +180,6 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
refresh(false); refresh(false);
m_activity.initMenu(); m_activity.initMenu();
m_activity.setTitle(R.string.app_name);
} }
@Override @Override

View File

@ -43,7 +43,43 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
setSmallScreen(findViewById(R.id.headlines_fragment) == null); setSmallScreen(findViewById(R.id.headlines_fragment) == null);
if (savedInstanceState == null) { Intent intent = getIntent();
if (intent.getParcelableExtra("feed") != null || intent.getParcelableExtra("category") != null ||
intent.getParcelableExtra("article") != null) {
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);
}
if (cat != null) {
FeedsFragment ff = new FeedsFragment(cat);
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
setTitle(cat.title);
}
if (article != null) {
Article original = TinyApplication.getInstance().m_loadedArticles.findById(article.id);
ArticlePager ap = new ArticlePager(original != null ? original : article);
ft.replace(R.id.feeds_fragment, ap, FRAG_ARTICLE);
setTitle(intent.getStringExtra("feedTitle"));
}
ft.commit();
} else if (savedInstanceState == null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (m_prefs.getBoolean("enable_cats", false)) { if (m_prefs.getBoolean("enable_cats", false)) {
@ -53,14 +89,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
} }
ft.commit(); ft.commit();
} /* else if (isSmallScreen()) { }
Fragment frag = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (frag != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.remove(frag);
ft.commit();
}
} */
} }
@Override @Override
@ -96,13 +125,21 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
.beginTransaction(); .beginTransaction();
TinyApplication.getInstance().m_loadedArticles.clear(); TinyApplication.getInstance().m_loadedArticles.clear();
HeadlinesFragment hf = new HeadlinesFragment(feed);
if (isSmallScreen()) { if (isSmallScreen()) {
ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES);
ft.addToBackStack(null); 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);
} else { } else {
HeadlinesFragment hf = new HeadlinesFragment(feed);
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES); ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
} }
ft.commit(); ft.commit();
@ -114,9 +151,20 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
.beginTransaction(); .beginTransaction();
if (!openAsFeed) { if (!openAsFeed) {
FeedsFragment ff = new FeedsFragment(cat);
if (isSmallScreen()) {
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
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 {
FeedsFragment ff = new FeedsFragment(cat);
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
}
} else { } else {
Feed feed = new Feed(cat.id, cat.title, true); Feed feed = new Feed(cat.id, cat.title, true);
onFeedSelected(feed); onFeedSelected(feed);
@ -198,40 +246,33 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
saveArticleUnread(article); saveArticleUnread(article);
} }
if (open) { if (open) {
if (isSmallScreen()) { HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
Fragment frag = new ArticlePager(article);
ft.replace(R.id.feeds_fragment, frag, FRAG_ARTICLE); if (isSmallScreen()) {
ft.addToBackStack(null);
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
intent.putExtra("sessionId", m_sessionId);
intent.putExtra("apiLevel", m_apiLevel);
intent.putExtra("feedTitle", hf.getFeed().title);
intent.putExtra("article", article);
startActivityForResult(intent, 0);
ft.commit();
} else { } else {
Intent intent = new Intent(FeedsActivity.this, HeadlinesActivity.class); Intent intent = new Intent(FeedsActivity.this, HeadlinesActivity.class);
intent.putExtra("sessionId", m_sessionId); intent.putExtra("sessionId", m_sessionId);
intent.putExtra("apiLevel", m_apiLevel); intent.putExtra("apiLevel", m_apiLevel);
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
intent.putExtra("feed", hf.getFeed()); intent.putExtra("feed", hf.getFeed());
intent.putParcelableArrayListExtra("articles", hf.getAllArticles());
intent.putExtra("activeArticle", article);
intent.putExtra("article", article); intent.putExtra("article", article);
//intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
startActivityForResult(intent, 0); startActivityForResult(intent, 0);
} }
} else { } else {
initMenu(); initMenu();
/* HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) hf.setActiveArticle(article); */
} }
} }

View File

@ -205,7 +205,6 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
refresh(false); refresh(false);
m_activity.initMenu(); m_activity.initMenu();
m_activity.setTitle(R.string.app_name);
} }
@Override @Override

View File

@ -19,7 +19,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener, ArticleEventListener { public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener, ArticleEventListener {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
protected SharedPreferences m_prefs; protected SharedPreferences m_prefs;
@ -49,10 +49,9 @@ private final String TAG = this.getClass().getSimpleName();
if (i.getExtras() != null) { if (i.getExtras() != null) {
Feed feed = i.getParcelableExtra("feed"); Feed feed = i.getParcelableExtra("feed");
Article activeArticle = i.getParcelableExtra("activeArticle");
Article article = i.getParcelableExtra("article"); Article article = i.getParcelableExtra("article");
HeadlinesFragment hf = new HeadlinesFragment(feed, activeArticle); HeadlinesFragment hf = new HeadlinesFragment(feed, article);
ArticlePager af = new ArticlePager(hf.getArticleById(article.id)); ArticlePager af = new ArticlePager(hf.getArticleById(article.id));
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
@ -61,6 +60,8 @@ private final String TAG = this.getClass().getSimpleName();
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE); ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
ft.commit(); ft.commit();
setTitle(feed.title);
} }
} }
} }
@ -142,7 +143,7 @@ private final String TAG = this.getClass().getSimpleName();
Fragment frag = new ArticlePager(article); Fragment frag = new ArticlePager(article);
ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE); ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
//ft.addToBackStack(null); // ft.addToBackStack(null);
hf.notifyUpdated(); hf.notifyUpdated();

View File

@ -312,7 +312,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
notifyUpdated(); notifyUpdated();
} }
m_activity.setTitle(m_feed.title);
m_activity.initMenu(); m_activity.initMenu();
} }

View File

@ -1,5 +1,6 @@
package org.fox.ttrss; package org.fox.ttrss;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList; import org.fox.ttrss.types.ArticleList;
import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.Feed;

View File

@ -21,6 +21,14 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
} }
} }
public Article findById(int id) {
for (Article a : this) {
if (a.id == id)
return a;
}
return null;
}
public void readFromParcel(Parcel in) { public void readFromParcel(Parcel in) {
int length = in.readInt(); int length = in.readInt();