diff --git a/res/menu/headlines_action_menu.xml b/res/menu/headlines_action_menu.xml new file mode 100644 index 00000000..3c812f5d --- /dev/null +++ b/res/menu/headlines_action_menu.xml @@ -0,0 +1,21 @@ +
\ No newline at end of file diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 4daab3da..38cf4098 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -5,6 +5,9 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; +import javax.crypto.spec.DESedeKeySpec; + +import android.app.ActionBar; import android.app.AlertDialog; import android.app.Dialog; import android.content.BroadcastReceiver; @@ -23,6 +26,7 @@ import android.preference.PreferenceManager; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.util.Log; +import android.view.ActionMode; import android.view.Display; import android.view.KeyEvent; import android.view.Menu; @@ -63,6 +67,36 @@ public class MainActivity extends FragmentActivity implements OnlineServices { private SQLiteDatabase m_readableDb; private SQLiteDatabase m_writableDb; + private ActionMode m_headlinesActionMode; + private ActionMode.Callback m_headlinesActionModeCallback = new ActionMode.Callback() { + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + deselectAllArticles(); + m_headlinesActionMode = null; + } + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.headlines_action_menu, menu); + + return true; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + onOptionsItemSelected(item); + return false; + } + }; + private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() { @Override @@ -771,7 +805,22 @@ public class MainActivity extends FragmentActivity implements OnlineServices { initMainMenu(); refreshCategories(); } + + private void deselectAllArticles() { + HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager() + .findFragmentById(R.id.headlines_fragment); + if (hf != null) { + ArticleList selected = hf.getSelectedArticles(); + if (selected.size() > 0) { + selected.clear(); + initMainMenu(); + hf.notifyUpdated(); + } + } + } + + @SuppressWarnings("unchecked") @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -877,14 +926,7 @@ public class MainActivity extends FragmentActivity implements OnlineServices { } return true; case R.id.selection_select_none: - if (hf != null) { - ArticleList selected = hf.getSelectedArticles(); - if (selected.size() > 0) { - selected.clear(); - initMainMenu(); - hf.notifyUpdated(); - } - } + deselectAllArticles(); return true; case R.id.selection_toggle_unread: if (hf != null) { @@ -1053,7 +1095,13 @@ public class MainActivity extends FragmentActivity implements OnlineServices { numSelected = hf.getSelectedArticles().size(); if (numSelected != 0) { - m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true); + if (m_compatMode) { + m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true); + } else { + if (m_headlinesActionMode == null) + m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); + } + } else if (m_selectedArticle != null) { m_menu.setGroupVisible(R.id.menu_group_article, true); } else if (m_activeFeed != null || m_activeCategory != null) { @@ -1062,6 +1110,10 @@ public class MainActivity extends FragmentActivity implements OnlineServices { m_menu.setGroupVisible(R.id.menu_group_feeds, true); } + if (numSelected == 0 && m_headlinesActionMode != null) { + m_headlinesActionMode.finish(); + } + } else { m_menu.setGroupVisible(R.id.menu_group_logged_in, false); m_menu.setGroupVisible(R.id.menu_group_logged_out, true); diff --git a/src/org/fox/ttrss/OfflineActivity.java b/src/org/fox/ttrss/OfflineActivity.java index 51cdf911..58e84fbd 100644 --- a/src/org/fox/ttrss/OfflineActivity.java +++ b/src/org/fox/ttrss/OfflineActivity.java @@ -17,6 +17,7 @@ import android.provider.BaseColumns; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.util.Log; +import android.view.ActionMode; import android.view.Display; import android.view.KeyEvent; import android.view.Menu; @@ -52,6 +53,36 @@ public class OfflineActivity extends FragmentActivity implements return m_smallScreenMode; } + private ActionMode m_headlinesActionMode; + private ActionMode.Callback m_headlinesActionModeCallback = new ActionMode.Callback() { + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + deselectAllArticles(); + m_headlinesActionMode = null; + } + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.headlines_action_menu, menu); + + return true; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + onOptionsItemSelected(item); + return false; + } + }; + @Override public void onCreate(Bundle savedInstanceState) { initDatabase(); @@ -622,7 +653,12 @@ public class OfflineActivity extends FragmentActivity implements m_menu.setGroupVisible(R.id.menu_group_article, false); if (numSelected != 0) { - m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true); + if (m_compatMode) { + m_menu.setGroupVisible(R.id.menu_group_headlines_selection, true); + } else { + if (m_headlinesActionMode == null) + m_headlinesActionMode = startActionMode(m_headlinesActionModeCallback); + } } else if (m_selectedArticleId != 0) { m_menu.setGroupVisible(R.id.menu_group_article, true); } else if (m_activeFeedId != 0 /*|| m_activeCategory != null */) { @@ -630,6 +666,10 @@ public class OfflineActivity extends FragmentActivity implements } else { m_menu.setGroupVisible(R.id.menu_group_feeds, true); } + + if (numSelected == 0 && m_headlinesActionMode != null) { + m_headlinesActionMode.finish(); + } } }