implement contextual selection bar for HC articles
This commit is contained in:
parent
9951991e56
commit
e0012da1e9
21
res/menu/headlines_action_menu.xml
Normal file
21
res/menu/headlines_action_menu.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<item
|
||||
android:id="@+id/selection_toggle_unread"
|
||||
android:icon="@drawable/ic_menu_tick"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/selection_toggle_unread"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/selection_toggle_marked"
|
||||
android:icon="@drawable/ic_menu_marked"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/selection_toggle_marked"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/selection_toggle_published"
|
||||
android:icon="@drawable/ic_menu_rss"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/selection_toggle_published"/>
|
||||
|
||||
</menu>
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user