From 72e9280fefe0859ef611968fc6f3c75c0444d9c3 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 30 Nov 2012 10:08:00 +0400 Subject: [PATCH] serialize GlobalState data on small devices --- src/org/fox/ttrss/FeedsActivity.java | 12 ++++++++++-- src/org/fox/ttrss/GlobalState.java | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/org/fox/ttrss/FeedsActivity.java b/src/org/fox/ttrss/FeedsActivity.java index 4472873b..2e44f62b 100644 --- a/src/org/fox/ttrss/FeedsActivity.java +++ b/src/org/fox/ttrss/FeedsActivity.java @@ -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 diff --git a/src/org/fox/ttrss/GlobalState.java b/src/org/fox/ttrss/GlobalState.java index ba13e776..bc185326 100644 --- a/src/org/fox/ttrss/GlobalState.java +++ b/src/org/fox/ttrss/GlobalState.java @@ -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 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"); + } + + } }