Skip to content
Merged
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
22 changes: 10 additions & 12 deletions WordPress/src/main/java/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,6 @@ public static Blog getCurrentBlog() {
return currentBlog;
}

public static Blog getCurrentBlogEvenIfNotVisible() {
if (currentBlog == null) {
attemptToRestoreLastActiveBlog();
}

return currentBlog;
}

/**
* Get the blog with the specified ID.
*
Expand Down Expand Up @@ -439,11 +431,17 @@ public static Blog setCurrentBlogToLastActive() {
* Set the blog with the specified id as the current blog.
*
* @param id id of the blog to set as current
* @return the current blog
*/
public static Blog setCurrentBlog(int id) {
currentBlog = wpDB.instantiateBlogByLocalId(id);
return currentBlog;
public static void setCurrentBlog(int id) {
currentBlog = getBlog(id);
}

public static void setCurrentBlogAndSetVisible(int id) {
setCurrentBlog(id);

if (currentBlog != null && currentBlog.isHidden()) {
wpDB.setDotComBlogsVisibility(id, true);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case RequestCodes.SITE_PICKER:
// RESULT_OK = site picker changed the current blog
if (resultCode == Activity.RESULT_OK) {
setBlog(WordPress.getCurrentBlogEvenIfNotVisible());
setBlog(WordPress.getCurrentBlog());
}
// redisplay the hidden fab after a short delay
long delayMs = getResources().getInteger(android.R.integer.config_shortAnimTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void onSiteClick(SiteRecord site) {
if (mActionMode == null) {
mSearchView.hideSoftKeyboard();
AniUtils.showFab(mFabView, false);
WordPress.setCurrentBlog(site.localId);
WordPress.setCurrentBlogAndSetVisible(site.localId);
WordPress.wpDB.updateLastBlogId(site.localId);
setResult(RESULT_OK);
mDidUserSelectSite = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,10 @@ public void searchSites(String searchText) {

@Override
public void loadSites() {
loadSites("");
}

public void loadSites(String search) {
if (search == null) {
search = "";
}

if (mIsSearchTaskRunning) {
AppLog.w(AppLog.T.UTILS, "site picker > already loading sites");
} else {
if (search == null) {
search = "";
}
new LoadSearchSitesTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, search);
new LoadSearchSitesTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}

Expand All @@ -71,7 +60,8 @@ private SiteList filteredSitesByText(SiteList sites, String searchText) {
}

private boolean mIsSearchTaskRunning;
private class LoadSearchSitesTask extends AsyncTask<String, Void, SiteList> {

private class LoadSearchSitesTask extends AsyncTask<Void, Void, SiteList> {
@Override
protected void onPreExecute() {
super.onPreExecute();
Expand All @@ -85,8 +75,7 @@ protected void onCancelled() {
}

@Override
protected SiteList doInBackground(String... params) {
String searchText = params[0];
protected SiteList doInBackground(Void... params) {
List<Map<String, Object>> blogs = WordPress.wpDB.getAllBlogs();

SiteList sites = new SiteList(blogs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void configure(SitePickerActivity sitePickerActivity, Menu menu) {
MenuItemCompat.setOnActionExpandListener(menuSearch, new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
enableSearchMode(mSitePickerActivity.getLastSearch());
enableSearchMode();
return true;
}

Expand All @@ -61,12 +61,12 @@ public boolean onMenuItemActionCollapse(MenuItem item) {
}
}

public void enableSearchMode(String string) {
public void enableSearchMode() {
mMenuEdit.setVisible(false);
mSitePickerActivity.setIsInSearchModeAndNullifyAdapter(true);
SitePickerSearchAdapter adapter = (SitePickerSearchAdapter) mSitePickerActivity.getAdapter();
mSitePickerActivity.getRecycleView().swapAdapter(adapter, true);
adapter.loadSites(string);
adapter.loadSites();
}

public void disableSearchMode() {
Expand Down