From 15aebd8d3aba78dfe40cb2bd019969641f81df81 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 13 Feb 2015 15:11:38 +0300 Subject: [PATCH] remove separate list for selected articles --- .../java/org/fox/ttrss/FeedsActivity.java | 3 - .../java/org/fox/ttrss/HeadlinesActivity.java | 28 ++------- .../java/org/fox/ttrss/HeadlinesFragment.java | 57 ++++++++----------- .../java/org/fox/ttrss/OnlineActivity.java | 26 +++++---- .../java/org/fox/ttrss/types/Article.java | 3 + org.fox.ttrss/src/main/res/values/strings.xml | 2 +- 6 files changed, 47 insertions(+), 72 deletions(-) mode change 100644 => 100755 org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java index 50678d81..a37ff0f2 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java @@ -447,7 +447,6 @@ 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()); @@ -500,14 +499,12 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe //ArrayList
tmp = data.getParcelableArrayListExtra("articles"); Article article = data.getParcelableExtra("activeArticle"); ArticleList articles = data.getParcelableExtra("articles"); - ArticleList selectedArticles = data.getParcelableExtra("selectedArticles"); if (articles != null) { HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); if (hf != null) { hf.setArticles(articles); - hf.setSelectedArticles(selectedArticles); hf.setActiveArticle(article); } } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java index 68826434..62c092e2 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesActivity.java @@ -21,7 +21,6 @@ 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; @@ -38,6 +37,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL setContentView(R.layout.headlines_articles); + m_forceDisableActionMode = isPortrait() || isSmallScreen(); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); @@ -51,7 +52,6 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL if (savedInstanceState != null) { m_articles = savedInstanceState.getParcelable("articles"); - m_selectedArticles = savedInstanceState.getParcelable("selectedArticles"); } else { Intent i = getIntent(); @@ -85,22 +85,12 @@ 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); @@ -133,6 +123,9 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL if (!isSmallScreen()) { findViewById(R.id.headlines_fragment).setVisibility(isPortrait() ? View.GONE : View.VISIBLE); } + + m_forceDisableActionMode = isPortrait() || isSmallScreen(); + invalidateOptionsMenu(); } @Override @@ -156,8 +149,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); } @@ -317,17 +309,9 @@ 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(); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java index a88e6348..14f0f1ff 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -93,7 +93,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, private ArticleListAdapter m_adapter; 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 HeadlinesEventListener m_listener; private OnlineActivity m_activity; @@ -102,7 +102,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, private boolean m_compactLayoutMode = false; 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) { @@ -291,7 +297,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, 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.setGroupVisible(R.id.menu_group_single_article, false); } else { @@ -322,7 +328,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, } m_activeArticle = savedInstanceState.getParcelable("activeArticle"); - m_selectedArticles = savedInstanceState.getParcelable("selectedArticles"); + //m_selectedArticles = savedInstanceState.getParcelable("selectedArticles"); m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery"); m_compactLayoutMode = savedInstanceState.getBoolean("compactLayoutMode"); } @@ -610,7 +616,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, out.putParcelable("feed", m_feed); out.putParcelable("articles", m_articles); out.putParcelable("activeArticle", m_activeArticle); - out.putParcelable("selectedArticles", m_selectedArticles); + //out.putParcelable("selectedArticles", m_selectedArticles); out.putCharSequence("searchQuery", m_searchQuery); out.putBoolean("compactLayoutMode", m_compactLayoutMode); } @@ -685,7 +691,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.containsId(item.id)) { + if (item.selected) { holder.textImage.setImageDrawable(m_drawableBuilder.build(" ", 0xff616161)); holder.textChecked.setVisibility(View.VISIBLE); @@ -773,17 +779,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, public void onClick(View view) { Log.d(TAG, "textImage : onclicked"); - if (!m_selectedArticles.containsId(article.id)) { - m_selectedArticles.add(article); - } else { - m_selectedArticles.remove(m_selectedArticles.findById(article.id)); - } + article.selected = !article.selected; 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) { - holder.selectionBoxView.setChecked(m_selectedArticles.containsId(article.id)); + holder.selectionBoxView.setChecked(article.selected); holder.selectionBoxView.setOnClickListener(new OnClickListener() { @Override @@ -1061,15 +1063,14 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, CheckBox cb = (CheckBox)view; if (cb.isChecked()) { - if (!m_selectedArticles.containsId(article.id)) - m_selectedArticles.add(article); + article.selected = true; } 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) { - m_selectedArticles.clear(); + for (Article a : m_articles) + a.selected = false; if (select != ArticlesSelection.NONE) { for (Article a : m_articles) { 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) { try { return m_adapter.getItem(position); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java index 9963db2a..da696509 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java @@ -64,6 +64,7 @@ public class OnlineActivity extends CommonActivity { protected Menu m_menu; protected int m_offlineModeStatus = 0; + protected boolean m_forceDisableActionMode = false; private ActionMode m_headlinesActionMode; private HeadlinesActionModeCallback m_headlinesActionModeCallback; @@ -107,16 +108,15 @@ public class OnlineActivity extends CommonActivity { public void onDestroyActionMode(ActionMode mode) { m_headlinesActionMode = null; - HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); - - if (hf != null) { - ArticleList selected = hf.getSelectedArticles(); - if (selected.size() > 0) { - selected.clear(); - invalidateOptionsMenu(); - hf.notifyUpdated(); - } - } + if (!m_forceDisableActionMode) { + HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); + + if (hf != null) { + hf.setSelection(HeadlinesFragment.ArticlesSelection.NONE); + } + } + + invalidateOptionsMenu(); } @Override @@ -1569,13 +1569,15 @@ public class OnlineActivity extends CommonActivity { HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); - if (hf != null) { + if (hf != null && !m_forceDisableActionMode) { if (hf.getSelectedArticles().size() > 0 && m_headlinesActionMode == null) { m_headlinesActionMode = startSupportActionMode(m_headlinesActionModeCallback); } else if (hf.getSelectedArticles().size() == 0 && m_headlinesActionMode != null) { m_headlinesActionMode.finish(); } - } + } else if (m_forceDisableActionMode && m_headlinesActionMode != null) { + m_headlinesActionMode.finish(); + } } } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java old mode 100644 new mode 100755 index 9c34487b..98f28427 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/types/Article.java @@ -29,6 +29,7 @@ public class Article implements Parcelable { public boolean always_display_attachments; public String author; public String note; + public boolean selected; public Article(Parcel in) { readFromParcel(in); @@ -72,6 +73,7 @@ public class Article implements Parcelable { out.writeInt(always_display_attachments ? 1 : 0); out.writeString(author); out.writeString(note); + out.writeInt(selected ? 1 : 0); } public void readFromParcel(Parcel in) { @@ -102,6 +104,7 @@ public class Article implements Parcelable { always_display_attachments = in.readInt() == 1; author = in.readString(); note = in.readString(); + selected = in.readInt() == 1; } @SuppressWarnings("rawtypes") diff --git a/org.fox.ttrss/src/main/res/values/strings.xml b/org.fox.ttrss/src/main/res/values/strings.xml index be97e90e..865bd687 100755 --- a/org.fox.ttrss/src/main/res/values/strings.xml +++ b/org.fox.ttrss/src/main/res/values/strings.xml @@ -35,7 +35,7 @@ (Un)Publish Select articles Select articles - Everything + Select all Unread Deselect all (Un)Star