serialize GlobalState data on small devices

This commit is contained in:
Andrew Dolgov 2012-11-30 10:08:00 +04:00
parent 251c648196
commit 72e9280fef
2 changed files with 36 additions and 2 deletions

View File

@ -46,6 +46,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
setSmallScreen(findViewById(R.id.headlines_fragment) == null); setSmallScreen(findViewById(R.id.headlines_fragment) == null);
if (isSmallScreen()) {
GlobalState.getInstance().load(savedInstanceState);
}
Intent intent = getIntent(); Intent intent = getIntent();
if (savedInstanceState == null) { if (savedInstanceState == null) {
@ -245,6 +249,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
@Override @Override
public void onSaveInstanceState(Bundle out) { public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out); super.onSaveInstanceState(out);
if (isSmallScreen()) {
GlobalState.getInstance().save(out);
}
} }
@Override @Override

View File

@ -1,10 +1,14 @@
package org.fox.ttrss; package org.fox.ttrss;
import java.util.ArrayList;
import org.fox.ttrss.types.Article; 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;
import android.app.Application; import android.app.Application;
import android.os.Bundle;
import android.os.Parcelable;
public class GlobalState extends Application { public class GlobalState extends Application {
private static GlobalState m_singleton; private static GlobalState m_singleton;
@ -28,4 +32,26 @@ public class GlobalState extends Application {
super.onCreate(); super.onCreate();
m_singleton = this; m_singleton = this;
} }
public void save(Bundle out) {
out.putParcelableArrayList("gs:loadedArticles", m_loadedArticles);
out.putParcelable("gs:activeFeed", m_activeFeed);
out.putParcelable("gs:activeArticle", m_activeArticle);
out.putString("gs:sessionId", m_sessionId);
}
public void load(Bundle in) {
if (m_loadedArticles.size() == 0 && in != null) {
ArrayList<Parcelable> list = in.getParcelableArrayList("gs:loadedArticles");
for (Parcelable p : list) {
m_loadedArticles.add((Article)p);
}
m_activeFeed = (Feed) in.getParcelable("gs:activeFeed");
m_activeArticle = (Article) in.getParcelable("gs:activeArticle");
m_sessionId = in.getString("gs:sessionId");
}
}
} }