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);
m_activity.initMenu();
m_activity.setTitle(R.string.app_name);
}
@Override

View File

@ -43,7 +43,43 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
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();
if (m_prefs.getBoolean("enable_cats", false)) {
@ -52,15 +88,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
ft.replace(R.id.feeds_fragment, new FeedsFragment(), FRAG_FEEDS);
}
ft.commit();
} /* else if (isSmallScreen()) {
Fragment frag = getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (frag != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.remove(frag);
ft.commit();
}
} */
}
@Override
@ -97,12 +126,20 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
TinyApplication.getInstance().m_loadedArticles.clear();
HeadlinesFragment hf = new HeadlinesFragment(feed);
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 {
HeadlinesFragment hf = new HeadlinesFragment(feed);
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
}
ft.commit();
@ -114,9 +151,20 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
.beginTransaction();
if (!openAsFeed) {
FeedsFragment ff = new FeedsFragment(cat);
if (isSmallScreen()) {
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 {
Feed feed = new Feed(cat.id, cat.title, true);
onFeedSelected(feed);
@ -199,39 +247,32 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
}
if (open) {
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (isSmallScreen()) {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
intent.putExtra("sessionId", m_sessionId);
intent.putExtra("apiLevel", m_apiLevel);
Fragment frag = new ArticlePager(article);
intent.putExtra("feedTitle", hf.getFeed().title);
intent.putExtra("article", article);
startActivityForResult(intent, 0);
ft.replace(R.id.feeds_fragment, frag, FRAG_ARTICLE);
ft.addToBackStack(null);
ft.commit();
} else {
Intent intent = new Intent(FeedsActivity.this, HeadlinesActivity.class);
intent.putExtra("sessionId", m_sessionId);
intent.putExtra("apiLevel", m_apiLevel);
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
intent.putExtra("feed", hf.getFeed());
intent.putParcelableArrayListExtra("articles", hf.getAllArticles());
intent.putExtra("activeArticle", 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);
}
} else {
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);
m_activity.initMenu();
m_activity.setTitle(R.string.app_name);
}
@Override

View File

@ -19,7 +19,7 @@ import android.view.MenuItem;
import android.view.View;
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;
@ -49,10 +49,9 @@ private final String TAG = this.getClass().getSimpleName();
if (i.getExtras() != null) {
Feed feed = i.getParcelableExtra("feed");
Article activeArticle = i.getParcelableExtra("activeArticle");
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));
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.commit();
setTitle(feed.title);
}
}
}
@ -142,7 +143,7 @@ private final String TAG = this.getClass().getSimpleName();
Fragment frag = new ArticlePager(article);
ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
//ft.addToBackStack(null);
// ft.addToBackStack(null);
hf.notifyUpdated();

View File

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

View File

@ -1,5 +1,6 @@
package org.fox.ttrss;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
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) {
int length = in.readInt();