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

@ -45,7 +45,11 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
setContentView(R.layout.feeds);
setSmallScreen(findViewById(R.id.headlines_fragment) == null);
if (isSmallScreen()) {
GlobalState.getInstance().load(savedInstanceState);
}
Intent intent = getIntent();
if (savedInstanceState == null) {
@ -244,7 +248,11 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
@Override
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
super.onSaveInstanceState(out);
if (isSmallScreen()) {
GlobalState.getInstance().save(out);
}
}
@Override

View File

@ -1,10 +1,14 @@
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.app.Application;
import android.os.Bundle;
import android.os.Parcelable;
public class GlobalState extends Application {
private static GlobalState m_singleton;
@ -28,4 +32,26 @@ public class GlobalState extends Application {
super.onCreate();
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");
}
}
}