feedsactivity: restore headline selection state when going back from headlinesactivity
This commit is contained in:
parent
697586c3a9
commit
84698a5133
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
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();
|
||||
|
@ -73,7 +73,7 @@ import java.util.HashMap;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class HeadlinesFragment extends Fragment implements OnItemClickListener, OnScrollListener {
|
||||
public static enum ArticlesSelection { ALL, NONE, UNREAD }
|
||||
public static enum ArticlesSelection { ALL, NONE, UNREAD }
|
||||
|
||||
public static final int FLAVOR_IMG_MIN_WIDTH = 128;
|
||||
public static final int FLAVOR_IMG_MIN_HEIGHT = 128;
|
||||
@ -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);
|
||||
@ -1149,11 +1149,26 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_adapter.notifyDataSetChanged();
|
||||
|
||||
if (m_adapter != null) {
|
||||
m_adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public Article getArticleAtPosition(int position) {
|
||||
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 {
|
||||
return m_adapter.getItem(position);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
|
26
org.fox.ttrss/src/main/java/org/fox/ttrss/types/ArticleList.java
Normal file → Executable file
26
org.fox.ttrss/src/main/java/org/fox/ttrss/types/ArticleList.java
Normal file → Executable 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 {
|
||||
@ -18,7 +16,15 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
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)
|
||||
@ -36,15 +42,7 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
|
||||
public ArticleList(Parcel in) {
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user