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.putExtra("searchQuery", hf.getSearchQuery());
|
||||||
//intent.putParcelableArrayListExtra("articles", hf.getArticles());
|
//intent.putParcelableArrayListExtra("articles", hf.getArticles());
|
||||||
intent.putExtra("articles", (Parcelable)hf.getAllArticles());
|
intent.putExtra("articles", (Parcelable)hf.getAllArticles());
|
||||||
|
intent.putExtra("selectedArticles", (Parcelable)hf.getSelectedArticles());
|
||||||
|
|
||||||
/* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
/* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
startActivityForResult(intent, HEADLINES_REQUEST, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
|
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");
|
//ArrayList<Article> tmp = data.getParcelableArrayListExtra("articles");
|
||||||
Article article = data.getParcelableExtra("activeArticle");
|
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);
|
HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
||||||
|
|
||||||
if (hf != null) {
|
if (hf != null) {
|
||||||
hf.setArticles(tmp);
|
hf.setArticles(articles);
|
||||||
|
hf.setSelectedArticles(selectedArticles);
|
||||||
hf.setActiveArticle(article);
|
hf.setActiveArticle(article);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import org.fox.ttrss.types.Feed;
|
|||||||
public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener {
|
public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener {
|
||||||
private final String TAG = this.getClass().getSimpleName();
|
private final String TAG = this.getClass().getSimpleName();
|
||||||
protected ArticleList m_articles = new ArticleList();
|
protected ArticleList m_articles = new ArticleList();
|
||||||
|
protected ArticleList m_selectedArticles = new ArticleList();
|
||||||
|
|
||||||
protected SharedPreferences m_prefs;
|
protected SharedPreferences m_prefs;
|
||||||
private Article m_activeArticle;
|
private Article m_activeArticle;
|
||||||
@ -50,6 +51,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
|||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
m_articles = savedInstanceState.getParcelable("articles");
|
m_articles = savedInstanceState.getParcelable("articles");
|
||||||
|
m_selectedArticles = savedInstanceState.getParcelable("selectedArticles");
|
||||||
} else {
|
} else {
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
|
|
||||||
@ -83,12 +85,22 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
|||||||
m_articles.addAll(tmp);
|
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();
|
final HeadlinesFragment hf = new HeadlinesFragment();
|
||||||
hf.initialize(feed, article, true, m_articles);
|
hf.initialize(feed, article, true, m_articles);
|
||||||
hf.setSearchQuery(searchQuery);
|
hf.setSearchQuery(searchQuery);
|
||||||
|
|
||||||
|
if (!isPortrait() && !isSmallScreen()) {
|
||||||
|
hf.setSelectedArticles(m_selectedArticles);
|
||||||
|
}
|
||||||
|
|
||||||
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
|
ft.replace(R.id.headlines_fragment, hf, FRAG_HEADLINES);
|
||||||
ft.replace(R.id.article_fragment, new LoadingFragment(), null);
|
ft.replace(R.id.article_fragment, new LoadingFragment(), null);
|
||||||
|
|
||||||
@ -144,6 +156,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
|||||||
super.onSaveInstanceState(out);
|
super.onSaveInstanceState(out);
|
||||||
|
|
||||||
out.putParcelable("articles", m_articles);
|
out.putParcelable("articles", m_articles);
|
||||||
|
out.putParcelable("selectedArticles", m_selectedArticles);
|
||||||
|
|
||||||
GlobalState.getInstance().save(out);
|
GlobalState.getInstance().save(out);
|
||||||
}
|
}
|
||||||
@ -304,9 +317,17 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
|||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
Intent resultIntent = new Intent();
|
Intent resultIntent = new Intent();
|
||||||
|
|
||||||
|
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
|
||||||
|
|
||||||
resultIntent.putExtra("articles", (Parcelable) m_articles);
|
resultIntent.putExtra("articles", (Parcelable) m_articles);
|
||||||
resultIntent.putExtra("activeArticle", m_activeArticle);
|
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);
|
setResult(Activity.RESULT_OK, resultIntent);
|
||||||
|
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
|
@ -73,7 +73,7 @@ import java.util.HashMap;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public class HeadlinesFragment extends Fragment implements OnItemClickListener, OnScrollListener {
|
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_WIDTH = 128;
|
||||||
public static final int FLAVOR_IMG_MIN_HEIGHT = 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) {
|
private void updateTextCheckedState(HeadlineViewHolder holder, Article item) {
|
||||||
String tmp = item.title.length() > 0 ? item.title.substring(0, 1) : "?";
|
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.textImage.setImageDrawable(m_drawableBuilder.build(" ", 0xff616161));
|
||||||
|
|
||||||
holder.textChecked.setVisibility(View.VISIBLE);
|
holder.textChecked.setVisibility(View.VISIBLE);
|
||||||
@ -773,7 +773,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Log.d(TAG, "textImage : onclicked");
|
Log.d(TAG, "textImage : onclicked");
|
||||||
|
|
||||||
if (!m_selectedArticles.contains(article)) {
|
if (!m_selectedArticles.containsId(article.id)) {
|
||||||
m_selectedArticles.add(article);
|
m_selectedArticles.add(article);
|
||||||
} else {
|
} else {
|
||||||
m_selectedArticles.remove(article);
|
m_selectedArticles.remove(article);
|
||||||
@ -1053,7 +1053,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
|
|
||||||
|
|
||||||
if (holder.selectionBoxView != null) {
|
if (holder.selectionBoxView != null) {
|
||||||
holder.selectionBoxView.setChecked(m_selectedArticles.contains(article));
|
holder.selectionBoxView.setChecked(m_selectedArticles.containsId(article.id));
|
||||||
holder.selectionBoxView.setOnClickListener(new OnClickListener() {
|
holder.selectionBoxView.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1061,7 +1061,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
CheckBox cb = (CheckBox)view;
|
CheckBox cb = (CheckBox)view;
|
||||||
|
|
||||||
if (cb.isChecked()) {
|
if (cb.isChecked()) {
|
||||||
if (!m_selectedArticles.contains(article))
|
if (!m_selectedArticles.containsId(article.id))
|
||||||
m_selectedArticles.add(article);
|
m_selectedArticles.add(article);
|
||||||
} else {
|
} else {
|
||||||
m_selectedArticles.remove(article);
|
m_selectedArticles.remove(article);
|
||||||
@ -1150,10 +1150,25 @@ 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 {
|
try {
|
||||||
return m_adapter.getItem(position);
|
return m_adapter.getItem(position);
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
22
org.fox.ttrss/src/main/java/org/fox/ttrss/types/ArticleList.java
Normal file → Executable file
22
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;
|
package org.fox.ttrss.types;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Log;
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class ArticleList extends ArrayList<Article> implements Parcelable {
|
public class ArticleList extends ArrayList<Article> implements Parcelable {
|
||||||
@ -19,6 +17,14 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
|
|||||||
out.writeList(this);
|
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) {
|
public Article findById(int id) {
|
||||||
for (Article a : this) {
|
for (Article a : this) {
|
||||||
if (a.id == id)
|
if (a.id == id)
|
||||||
@ -37,14 +43,6 @@ public class ArticleList extends ArrayList<Article> implements Parcelable {
|
|||||||
readFromParcel(in);
|
readFromParcel(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsId(int id) {
|
|
||||||
for (Article a : this) {
|
|
||||||
if (a.id == id)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public static final Parcelable.Creator CREATOR =
|
public static final Parcelable.Creator CREATOR =
|
||||||
new Parcelable.Creator() {
|
new Parcelable.Creator() {
|
||||||
|
Loading…
Reference in New Issue
Block a user