From 7604bb30e51f7716356e4124915567c4c9a30987 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 10 Feb 2015 15:50:47 +0300 Subject: [PATCH] various parcelable-related crap --- .../java/org/fox/ttrss/FeedsActivity.java | 8 ++++--- .../java/org/fox/ttrss/HeadlinesActivity.java | 22 +++++++++++-------- .../java/org/fox/ttrss/HeadlinesFragment.java | 20 +++++++++++------ 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java index 669bef08..4e81d26f 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java @@ -9,6 +9,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; +import android.os.Parcelable; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; @@ -26,7 +27,6 @@ import org.fox.ttrss.types.ArticleList; import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.FeedCategory; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -449,7 +449,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe intent.putExtra("feed", hf.getFeed()); intent.putExtra("article", article); intent.putExtra("searchQuery", hf.getSearchQuery()); - intent.putParcelableArrayListExtra("articles", hf.getArticles()); + //intent.putParcelableArrayListExtra("articles", hf.getArticles()); + intent.putExtra("articles", (Parcelable)hf.getAllArticles()); startActivityForResult(intent, HEADLINES_REQUEST); overridePendingTransition(R.anim.right_slide_in, 0); @@ -480,8 +481,9 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe if (requestCode == HEADLINES_REQUEST) { //GlobalState.getInstance().m_activeArticle = null; - ArrayList
tmp = data.getParcelableArrayListExtra("articles"); + //ArrayList
tmp = data.getParcelableArrayListExtra("articles"); Article article = data.getParcelableExtra("activeArticle"); + ArticleList tmp = data.getParcelableExtra("articles"); if (tmp != null) { HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java index cc7cc82f..52811172 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java @@ -7,6 +7,7 @@ import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; import android.os.Handler; +import android.os.Parcelable; import android.preference.PreferenceManager; import android.support.v4.app.FragmentTransaction; import android.util.Log; @@ -17,8 +18,6 @@ import org.fox.ttrss.types.Article; import org.fox.ttrss.types.ArticleList; import org.fox.ttrss.types.Feed; -import java.util.ArrayList; - public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener { private final String TAG = this.getClass().getSimpleName(); private ArticleList m_articles = new ArticleList(); @@ -49,7 +48,10 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL findViewById(R.id.headlines_fragment).setVisibility(View.GONE); } - if (savedInstanceState == null) { + if (savedInstanceState != null) { + // + + } else { Intent i = getIntent(); if (i.getExtras() != null) { @@ -76,7 +78,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL final Article article = i.getParcelableExtra("article"); final String searchQuery = i.getStringExtra("searchQuery"); - ArrayList
tmp = i.getParcelableArrayListExtra("articles"); + ArticleList tmp = i.getParcelableExtra("articles"); if (tmp != null) { m_articles.addAll(tmp); @@ -153,7 +155,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL case android.R.id.home: Intent resultIntent = new Intent(); - resultIntent.putParcelableArrayListExtra("articles", m_articles); + //resultIntent.putParcelableArrayListExtra("articles", m_articles); + resultIntent.putExtra("articles", (Parcelable)m_articles); resultIntent.putExtra("activeArticle", m_activeArticle); setResult(Activity.RESULT_OK, resultIntent); @@ -309,14 +312,15 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL @Override public void onBackPressed() { - super.onBackPressed(); - overridePendingTransition(0, R.anim.right_slide_out); - Intent resultIntent = new Intent(); - resultIntent.putParcelableArrayListExtra("articles", m_articles); + + resultIntent.putExtra("articles", (Parcelable) m_articles); resultIntent.putExtra("activeArticle", m_activeArticle); setResult(Activity.RESULT_OK, resultIntent); + super.onBackPressed(); + + overridePendingTransition(0, R.anim.right_slide_out); } } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java index 43fbb163..6733b363 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -301,7 +301,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, if (savedInstanceState != null) { m_feed = savedInstanceState.getParcelable("feed"); - //m_articles = savedInstanceState.getParcelable("articles"); + m_articles = savedInstanceState.getParcelable("articles"); m_activeArticle = savedInstanceState.getParcelable("activeArticle"); m_selectedArticles = savedInstanceState.getParcelable("selectedArticles"); m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery"); @@ -411,7 +411,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, m_listener.onArticleSelected(article); // only set active article when it makes sense (in HeadlinesActivity) - if (getActivity().findViewById(R.id.article_fragment) != null) { + if (getActivity() instanceof HeadlinesActivity) { m_activeArticle = article; } @@ -581,7 +581,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, out.setClassLoader(getClass().getClassLoader()); out.putParcelable("feed", m_feed); - //out.putParcelable("articles", m_articles); + out.putParcelable("articles", m_articles); out.putParcelable("activeArticle", m_activeArticle); out.putParcelable("selectedArticles", m_selectedArticles); out.putCharSequence("searchQuery", m_searchQuery); @@ -1078,11 +1078,17 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, return m_articles; } + // if setting active doesn't make sense, scroll to whatever is passed to us public void setActiveArticle(Article article) { if (article != m_activeArticle && article != null) { - m_activeArticle = article; - m_adapter.notifyDataSetChanged(); - + + // only set active article when it makes sense (in HeadlinesActivity) + if (getActivity() instanceof HeadlinesActivity) { + m_activeArticle = article; + } + + m_adapter.notifyDataSetChanged(); + ListView list = (ListView)getView().findViewById(R.id.headlines_list); if (list != null) { @@ -1204,7 +1210,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, return m_articles; } - public void setArticles(ArrayList
articles) { + public void setArticles(ArticleList articles) { m_articles.clear(); m_articles.addAll(articles); m_adapter.notifyDataSetChanged();