various parcelable-related crap

This commit is contained in:
Andrew Dolgov 2015-02-10 15:50:47 +03:00
parent 568ab61fad
commit 7604bb30e5
3 changed files with 31 additions and 19 deletions

View File

@ -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<Article> tmp = data.getParcelableArrayListExtra("articles");
//ArrayList<Article> tmp = data.getParcelableArrayListExtra("articles");
Article article = data.getParcelableExtra("activeArticle");
ArticleList tmp = data.getParcelableExtra("articles");
if (tmp != null) {
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);

View File

@ -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<Article> 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);
}
}

View File

@ -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,9 +1078,15 @@ 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) {
// 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);
@ -1204,7 +1210,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
return m_articles;
}
public void setArticles(ArrayList<Article> articles) {
public void setArticles(ArticleList articles) {
m_articles.clear();
m_articles.addAll(articles);
m_adapter.notifyDataSetChanged();