remove separate list for selected articles

This commit is contained in:
Andrew Dolgov 2015-02-13 15:11:38 +03:00
parent f2b4da5089
commit 15aebd8d3a
6 changed files with 47 additions and 72 deletions

View File

@ -447,7 +447,6 @@ 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());
@ -500,14 +499,12 @@ 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 articles = data.getParcelableExtra("articles"); ArticleList articles = data.getParcelableExtra("articles");
ArticleList selectedArticles = data.getParcelableExtra("selectedArticles");
if (articles != 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(articles); hf.setArticles(articles);
hf.setSelectedArticles(selectedArticles);
hf.setActiveArticle(article); hf.setActiveArticle(article);
} }
} }

View File

@ -21,7 +21,6 @@ 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;
@ -38,6 +37,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
setContentView(R.layout.headlines_articles); setContentView(R.layout.headlines_articles);
m_forceDisableActionMode = isPortrait() || isSmallScreen();
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setHomeButtonEnabled(true);
@ -51,7 +52,6 @@ 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();
@ -85,22 +85,12 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
m_articles.addAll(tmp); m_articles.addAll(tmp);
} }
tmp = i.getParcelableExtra("selectedArticles");
if (tmp != null) {
m_selectedArticles.addAll(tmp);
}
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 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);
@ -133,6 +123,9 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
if (!isSmallScreen()) { if (!isSmallScreen()) {
findViewById(R.id.headlines_fragment).setVisibility(isPortrait() ? View.GONE : View.VISIBLE); findViewById(R.id.headlines_fragment).setVisibility(isPortrait() ? View.GONE : View.VISIBLE);
} }
m_forceDisableActionMode = isPortrait() || isSmallScreen();
invalidateOptionsMenu();
} }
@Override @Override
@ -156,8 +149,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);
} }
@ -317,17 +309,9 @@ 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();

View File

@ -93,7 +93,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private ArticleListAdapter m_adapter; private ArticleListAdapter m_adapter;
private ArticleList m_articles = new ArticleList(); //GlobalState.getInstance().m_loadedArticles; private ArticleList m_articles = new ArticleList(); //GlobalState.getInstance().m_loadedArticles;
private ArticleList m_selectedArticles = new ArticleList(); //private ArticleList m_selectedArticles = new ArticleList();
private ArticleList m_readArticles = new ArticleList(); private ArticleList m_readArticles = new ArticleList();
private HeadlinesEventListener m_listener; private HeadlinesEventListener m_listener;
private OnlineActivity m_activity; private OnlineActivity m_activity;
@ -102,7 +102,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private boolean m_compactLayoutMode = false; private boolean m_compactLayoutMode = false;
public ArticleList getSelectedArticles() { public ArticleList getSelectedArticles() {
return m_selectedArticles; ArticleList tmp = new ArticleList();
for (Article a : m_articles) {
if (a.selected) tmp.add(a);
}
return tmp;
} }
public void initialize(Feed feed) { public void initialize(Feed feed) {
@ -291,7 +297,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
getActivity().getMenuInflater().inflate(R.menu.headlines_context_menu, menu); getActivity().getMenuInflater().inflate(R.menu.headlines_context_menu, menu);
if (m_selectedArticles.size() > 0) { if (getSelectedArticles().size() > 0) {
menu.setHeaderTitle(R.string.headline_context_multiple); menu.setHeaderTitle(R.string.headline_context_multiple);
menu.setGroupVisible(R.id.menu_group_single_article, false); menu.setGroupVisible(R.id.menu_group_single_article, false);
} else { } else {
@ -322,7 +328,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
m_activeArticle = savedInstanceState.getParcelable("activeArticle"); m_activeArticle = savedInstanceState.getParcelable("activeArticle");
m_selectedArticles = savedInstanceState.getParcelable("selectedArticles"); //m_selectedArticles = savedInstanceState.getParcelable("selectedArticles");
m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery"); m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery");
m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode"); m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode");
} }
@ -610,7 +616,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
out.putParcelable("feed", m_feed); out.putParcelable("feed", m_feed);
out.putParcelable("articles", m_articles); out.putParcelable("articles", m_articles);
out.putParcelable("activeArticle", m_activeArticle); out.putParcelable("activeArticle", m_activeArticle);
out.putParcelable("selectedArticles", m_selectedArticles); //out.putParcelable("selectedArticles", m_selectedArticles);
out.putCharSequence("searchQuery", m_searchQuery); out.putCharSequence("searchQuery", m_searchQuery);
out.putBoolean("compactLayoutMode", m_compactLayoutMode); out.putBoolean("compactLayoutMode", m_compactLayoutMode);
} }
@ -685,7 +691,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.containsId(item.id)) { if (item.selected) {
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,17 +779,13 @@ 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.containsId(article.id)) { article.selected = !article.selected;
m_selectedArticles.add(article);
} else {
m_selectedArticles.remove(m_selectedArticles.findById(article.id));
}
updateTextCheckedState(holder, article); updateTextCheckedState(holder, article);
m_listener.onArticleListSelectionChange(m_selectedArticles); m_listener.onArticleListSelectionChange(getSelectedArticles());
Log.d(TAG, "num selected: " + m_selectedArticles.size()); Log.d(TAG, "num selected: " + getSelectedArticles().size());
} }
}); });
@ -1053,7 +1055,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (holder.selectionBoxView != null) { if (holder.selectionBoxView != null) {
holder.selectionBoxView.setChecked(m_selectedArticles.containsId(article.id)); holder.selectionBoxView.setChecked(article.selected);
holder.selectionBoxView.setOnClickListener(new OnClickListener() { holder.selectionBoxView.setOnClickListener(new OnClickListener() {
@Override @Override
@ -1061,15 +1063,14 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
CheckBox cb = (CheckBox)view; CheckBox cb = (CheckBox)view;
if (cb.isChecked()) { if (cb.isChecked()) {
if (!m_selectedArticles.containsId(article.id)) article.selected = true;
m_selectedArticles.add(article);
} else { } else {
m_selectedArticles.remove(m_selectedArticles.findById(article.id)); article.selected = false;
} }
m_listener.onArticleListSelectionChange(m_selectedArticles); m_listener.onArticleListSelectionChange(getSelectedArticles());
Log.d(TAG, "num selected: " + m_selectedArticles.size()); Log.d(TAG, "num selected: " + getSelectedArticles().size());
} }
}); });
} }
@ -1140,12 +1141,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
public void setSelection(ArticlesSelection select) { public void setSelection(ArticlesSelection select) {
m_selectedArticles.clear(); for (Article a : m_articles)
a.selected = false;
if (select != ArticlesSelection.NONE) { if (select != ArticlesSelection.NONE) {
for (Article a : m_articles) { for (Article a : m_articles) {
if (select == ArticlesSelection.ALL || select == ArticlesSelection.UNREAD && a.unread) { if (select == ArticlesSelection.ALL || select == ArticlesSelection.UNREAD && a.unread) {
m_selectedArticles.add(a); a.selected = true;
} }
} }
} }
@ -1155,19 +1157,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
} }
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) { public Article getArticleAtPosition(int position) {
try { try {
return m_adapter.getItem(position); return m_adapter.getItem(position);

View File

@ -64,6 +64,7 @@ public class OnlineActivity extends CommonActivity {
protected Menu m_menu; protected Menu m_menu;
protected int m_offlineModeStatus = 0; protected int m_offlineModeStatus = 0;
protected boolean m_forceDisableActionMode = false;
private ActionMode m_headlinesActionMode; private ActionMode m_headlinesActionMode;
private HeadlinesActionModeCallback m_headlinesActionModeCallback; private HeadlinesActionModeCallback m_headlinesActionModeCallback;
@ -107,16 +108,15 @@ public class OnlineActivity extends CommonActivity {
public void onDestroyActionMode(ActionMode mode) { public void onDestroyActionMode(ActionMode mode) {
m_headlinesActionMode = null; m_headlinesActionMode = null;
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); if (!m_forceDisableActionMode) {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) {
ArticleList selected = hf.getSelectedArticles(); if (hf != null) {
if (selected.size() > 0) { hf.setSelection(HeadlinesFragment.ArticlesSelection.NONE);
selected.clear(); }
invalidateOptionsMenu(); }
hf.notifyUpdated();
} invalidateOptionsMenu();
}
} }
@Override @Override
@ -1569,13 +1569,15 @@ public class OnlineActivity extends CommonActivity {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) { if (hf != null && !m_forceDisableActionMode) {
if (hf.getSelectedArticles().size() > 0 && m_headlinesActionMode == null) { if (hf.getSelectedArticles().size() > 0 && m_headlinesActionMode == null) {
m_headlinesActionMode = startSupportActionMode(m_headlinesActionModeCallback); m_headlinesActionMode = startSupportActionMode(m_headlinesActionModeCallback);
} else if (hf.getSelectedArticles().size() == 0 && m_headlinesActionMode != null) { } else if (hf.getSelectedArticles().size() == 0 && m_headlinesActionMode != null) {
m_headlinesActionMode.finish(); m_headlinesActionMode.finish();
} }
} } else if (m_forceDisableActionMode && m_headlinesActionMode != null) {
m_headlinesActionMode.finish();
}
} }
} }

View File

@ -29,6 +29,7 @@ public class Article implements Parcelable {
public boolean always_display_attachments; public boolean always_display_attachments;
public String author; public String author;
public String note; public String note;
public boolean selected;
public Article(Parcel in) { public Article(Parcel in) {
readFromParcel(in); readFromParcel(in);
@ -72,6 +73,7 @@ public class Article implements Parcelable {
out.writeInt(always_display_attachments ? 1 : 0); out.writeInt(always_display_attachments ? 1 : 0);
out.writeString(author); out.writeString(author);
out.writeString(note); out.writeString(note);
out.writeInt(selected ? 1 : 0);
} }
public void readFromParcel(Parcel in) { public void readFromParcel(Parcel in) {
@ -102,6 +104,7 @@ public class Article implements Parcelable {
always_display_attachments = in.readInt() == 1; always_display_attachments = in.readInt() == 1;
author = in.readString(); author = in.readString();
note = in.readString(); note = in.readString();
selected = in.readInt() == 1;
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")

View File

@ -35,7 +35,7 @@
<string name="article_toggle_published">(Un)Publish</string> <string name="article_toggle_published">(Un)Publish</string>
<string name="headlines_select">Select articles</string> <string name="headlines_select">Select articles</string>
<string name="headlines_select_dialog">Select articles</string> <string name="headlines_select_dialog">Select articles</string>
<string name="headlines_select_all">Everything</string> <string name="headlines_select_all">Select all</string>
<string name="headlines_select_unread">Unread</string> <string name="headlines_select_unread">Unread</string>
<string name="headlines_select_none">Deselect all</string> <string name="headlines_select_none">Deselect all</string>
<string name="selection_toggle_marked">(Un)Star</string> <string name="selection_toggle_marked">(Un)Star</string>