feedsactivity: restore headline selection state when going back from headlinesactivity

This commit is contained in:
Andrew Dolgov 2015-02-13 14:31:15 +03:00
parent 697586c3a9
commit 84698a5133
4 changed files with 63 additions and 26 deletions

View File

@ -447,6 +447,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
intent.putExtra("searchQuery", hf.getSearchQuery());
//intent.putParcelableArrayListExtra("articles", hf.getArticles());
intent.putExtra("articles", (Parcelable)hf.getAllArticles());
intent.putExtra("selectedArticles", (Parcelable)hf.getSelectedArticles());
/* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
startActivityForResult(intent, HEADLINES_REQUEST, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
@ -498,13 +499,15 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
//ArrayList<Article> tmp = data.getParcelableArrayListExtra("articles");
Article article = data.getParcelableExtra("activeArticle");
ArticleList tmp = data.getParcelableExtra("articles");
ArticleList articles = data.getParcelableExtra("articles");
ArticleList selectedArticles = data.getParcelableExtra("selectedArticles");
if (tmp != null) {
if (articles != null) {
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) {
hf.setArticles(tmp);
hf.setArticles(articles);
hf.setSelectedArticles(selectedArticles);
hf.setActiveArticle(article);
}
}

View File

@ -21,6 +21,7 @@ import org.fox.ttrss.types.Feed;
public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener {
private final String TAG = this.getClass().getSimpleName();
protected ArticleList m_articles = new ArticleList();
protected ArticleList m_selectedArticles = new ArticleList();
protected SharedPreferences m_prefs;
private Article m_activeArticle;
@ -50,6 +51,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
if (savedInstanceState != null) {
m_articles = savedInstanceState.getParcelable("articles");
m_selectedArticles = savedInstanceState.getParcelable("selectedArticles");
} else {
Intent i = getIntent();
@ -83,12 +85,22 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
m_articles.addAll(tmp);
}
tmp = i.getParcelableExtra("selectedArticles");
if (tmp != null) {
m_selectedArticles.addAll(tmp);
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
final HeadlinesFragment hf = new HeadlinesFragment();
hf.initialize(feed, article, true, m_articles);
hf.setSearchQuery(searchQuery);
if (!isPortrait() && !isSmallScreen()) {
hf.setSelectedArticles(m_selectedArticles);
}
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
ft.replace(R.id.article_fragment, new LoadingFragment(), null);
@ -144,6 +156,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
super.onSaveInstanceState(out);
out.putParcelable("articles", m_articles);
out.putParcelable("selectedArticles", m_selectedArticles);
GlobalState.getInstance().save(out);
}
@ -304,9 +317,17 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
public void onBackPressed() {
Intent resultIntent = new Intent();
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
resultIntent.putExtra("articles", (Parcelable) m_articles);
resultIntent.putExtra("activeArticle", m_activeArticle);
if (hf != null && !isPortrait() && !isSmallScreen()) {
resultIntent.putExtra("selectedArticles", (Parcelable) hf.getSelectedArticles());
} else {
resultIntent.putExtra("selectedArticles", (Parcelable) m_selectedArticles);
}
setResult(Activity.RESULT_OK, resultIntent);
super.onBackPressed();

View File

@ -685,7 +685,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private void updateTextCheckedState(HeadlineViewHolder holder, Article item) {
String tmp = item.title.length() > 0 ? item.title.substring(0, 1) : "?";
if (m_selectedArticles.contains(item)) {
if (m_selectedArticles.containsId(item.id)) {
holder.textImage.setImageDrawable(m_drawableBuilder.build(" ", 0xff616161));
holder.textChecked.setVisibility(View.VISIBLE);
@ -773,7 +773,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public void onClick(View view) {
Log.d(TAG, "textImage : onclicked");
if (!m_selectedArticles.contains(article)) {
if (!m_selectedArticles.containsId(article.id)) {
m_selectedArticles.add(article);
} else {
m_selectedArticles.remove(article);
@ -1053,7 +1053,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (holder.selectionBoxView != null) {
holder.selectionBoxView.setChecked(m_selectedArticles.contains(article));
holder.selectionBoxView.setChecked(m_selectedArticles.containsId(article.id));
holder.selectionBoxView.setOnClickListener(new OnClickListener() {
@Override
@ -1061,7 +1061,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
CheckBox cb = (CheckBox)view;
if (cb.isChecked()) {
if (!m_selectedArticles.contains(article))
if (!m_selectedArticles.containsId(article.id))
m_selectedArticles.add(article);
} else {
m_selectedArticles.remove(article);
@ -1150,8 +1150,23 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
}
}
if (m_adapter != null) {
m_adapter.notifyDataSetChanged();
}
}
public void setSelectedArticles(ArticleList selectedArticles) {
if (selectedArticles != null) {
m_selectedArticles.clear();
m_selectedArticles.addAll(selectedArticles);
if (m_adapter != null) {
m_adapter.notifyDataSetChanged();
}
}
}
public Article getArticleAtPosition(int position) {
try {

View File

@ -1,11 +1,9 @@
package org.fox.ttrss.types;
import java.util.ArrayList;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import java.util.ArrayList;
@SuppressWarnings("serial")
public class ArticleList extends ArrayList<Article> implements Parcelable {
@ -19,6 +17,14 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
out.writeList(this);
}
public boolean containsId(int id) {
return findById(id) != null;
}
public boolean contains(Article article) {
return containsId(article.id);
}
public Article findById(int id) {
for (Article a : this) {
if (a.id == id)
@ -37,14 +43,6 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
readFromParcel(in);
}
public boolean containsId(int id) {
for (Article a : this) {
if (a.id == id)
return true;
}
return false;
}
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR =
new Parcelable.Creator() {