Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Search Feature for PostsActivity... #49

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions res/menu/posts.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >



<item
android:id="@+id/menu_refresh"
android:icon="@drawable/ab_icon_refresh"
android:showAsAction="always"
android:menuCategory="container"
android:orderInCategory="2"
android:title="@string/refresh"/>
<item
android:id="@+id/menu_new_post"
android:icon="@drawable/ab_icon_new"
android:showAsAction="ifRoom"
android:showAsAction="always"
android:menuCategory="container"
android:orderInCategory="3"
android:title="@string/new_post"/>
<item
android:id="@+id/menu_post_search"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"
android:menuCategory="container"
android:orderInCategory="1"
android:showAsAction="always"
android:title="@string/search_post"/>
<item
android:id="@+id/menu_settings"
android:icon="@android:drawable/ic_menu_preferences"
android:showAsAction="never"
android:title="@string/settings"/>
<item
android:id="@+id/menu_signout"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:showAsAction="never"
android:title="@string/sign_out"/>
android:id="@+id/menu_signout"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:showAsAction="never"
android:title="@string/sign_out"/>

</menu>
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@
<!-- Menu Buttons -->
<string name="new_post">New Post</string>
<string name="new_page">New Page</string>
<string name="search_post">Search</string>
<string name="search_post_hint">Search Posts...</string>
<string name="quick_photo">Quick Photo</string>
<string name="quick_video">Quick Video</string>
<string name="wp_admin">Dashboard</string>
Expand Down
3 changes: 1 addition & 2 deletions res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<item name="android:panelBackground">@drawable/menu_hardkey_panel_wordpress</item>
<!-- Light.DarkActionBar specific -->
<item name="actionBarWidgetTheme">@style/Theme.wordpress.widget</item>

<item name="menuDrawerStyle">@style/MenuDrawer</item>
</style>

Expand Down Expand Up @@ -77,7 +76,7 @@
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.wordpress.widget" parent="Theme.Sherlock">
<item name="popupMenuStyle">@style/wordpress_PopupMenu</item>

<item name="android:textColorHint">#CCCCCC</item>
<item name="android:dropDownListViewStyle">@style/wordpress_DropDownListView</item>
<item name="dropDownListViewStyle">@style/wordpress_DropDownListView</item>
</style>
Expand Down
53 changes: 43 additions & 10 deletions src/org/wordpress/android/ui/posts/PostsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -19,12 +22,14 @@
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;

import org.xmlrpc.android.ApiHelper;
import org.xmlrpc.android.XMLRPCClient;
Expand All @@ -45,12 +50,16 @@
import org.wordpress.android.ui.notifications.NotificationsActivity;

public class PostsActivity extends WPActionBarActivity implements OnPostSelectedListener,
OnRefreshListener, OnPostActionListener, OnDetailPostActionListener, OnDialogConfirmListener {
OnRefreshListener, OnPostActionListener, OnDetailPostActionListener,
OnDialogConfirmListener, SearchView.OnQueryTextListener, SearchView.OnCloseListener {

private PostsListFragment postList;
private static final int ID_DIALOG_DELETING = 1, ID_DIALOG_SHARE = 2, ID_DIALOG_COMMENT = 3;
public static final int POST_DELETE = 0, POST_SHARE = 1, POST_EDIT = 2, POST_CLEAR = 3, POST_COMMENT = 4;
public ProgressDialog loadingDialog;
public SearchView searchView;
public SearchManager searchManager;
public SearchableInfo searchableInfo;
public boolean isPage = false;
public String errorMsg = "";
public boolean isRefreshing = false;
Expand Down Expand Up @@ -193,8 +202,12 @@ private void startNotificationsActivity(Bundle extras) {

private FragmentManager.OnBackStackChangedListener mOnBackStackChangedListener = new FragmentManager.OnBackStackChangedListener() {
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
if (getSupportFragmentManager().getBackStackEntryCount() == 0){
mMenuDrawer.setDrawerIndicatorEnabled(true);
searchView.setVisibility(View.VISIBLE);
searchView.setIconified(true);
}

}
};

Expand Down Expand Up @@ -281,7 +294,13 @@ public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.posts, menu);
refreshMenuItem = menu.findItem(R.id.menu_refresh);


searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView)menu.findItem(R.id.menu_post_search).getActionView();
searchView.setIconifiedByDefault(true);
searchView.setQueryHint(getResources().getString(R.string.search_post_hint));
searchView.setOnQueryTextListener(this);
searchView.setOnCloseListener(this);
if (isPage) {
menu.findItem(R.id.menu_new_post).setTitle(R.string.new_page);
}
Expand All @@ -296,11 +315,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.menu_refresh) {
checkForLocalChanges(true);
new ApiHelper.RefreshBlogContentTask(this, WordPress.currentBlog).execute(false);
return true;
} else if (itemId == R.id.menu_new_post) {
if (itemId == R.id.menu_new_post) {
Intent i = new Intent(this, EditPostActivity.class);
i.putExtra("id", WordPress.currentBlog.getId());
i.putExtra("isNew", true);
Expand Down Expand Up @@ -346,7 +361,7 @@ private void attemptToSelectPost() {
FragmentManager fm = getSupportFragmentManager();
ViewPostFragment f = (ViewPostFragment) fm
.findFragmentById(R.id.postDetail);

if (f != null && f.isInLayout()) {
postList.shouldSelectAfterLoad = true;
}
Expand All @@ -358,7 +373,7 @@ public void onPostSelected(Post post) {
FragmentManager fm = getSupportFragmentManager();
ViewPostFragment f = (ViewPostFragment) fm
.findFragmentById(R.id.postDetail);

searchView.setVisibility(View.GONE);
if (post != null) {

WordPress.currentPost = post;
Expand Down Expand Up @@ -860,4 +875,22 @@ public void onBlogChanged() {
postList.loadPosts(false);
new ApiHelper.RefreshBlogContentTask(this, WordPress.currentBlog).execute(false);
}

@Override
public boolean onQueryTextSubmit(String query) {
postList.filter(query);
return false;
}

@Override
public boolean onQueryTextChange(String query) {
postList.filter(query);
return false;
}

@Override
public boolean onClose() {
postList.closeSearch();
return false;
}
}
Loading