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
3 changes: 2 additions & 1 deletion res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
</PreferenceCategory>

<PreferenceCategory
android:title="@string/post_signature" >
android:title="@string/post_signature"
android:key="wp_post_signature">
<CheckBoxPreference
android:defaultValue="false"
android:key="wp_pref_signature_enabled"
Expand Down
4 changes: 2 additions & 2 deletions src/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public static Blog getCurrentBlog() {
setCurrentBlogToLastActive();

// fallback to just using the first blog
List<Map<String, Object>> accounts = WordPress.wpDB.getShownAccounts();
List<Map<String, Object>> accounts = WordPress.wpDB.getVisibleAccounts();
if (currentBlog == null && accounts.size() > 0) {
int id = Integer.valueOf(accounts.get(0).get("id").toString());
setCurrentBlog(id);
Expand Down Expand Up @@ -268,7 +268,7 @@ public static Blog getBlog(int id) {
* @return the current blog
*/
public static Blog setCurrentBlogToLastActive() {
List<Map<String, Object>> accounts = WordPress.wpDB.getShownAccounts();
List<Map<String, Object>> accounts = WordPress.wpDB.getVisibleAccounts();

int lastBlogId = WordPress.wpDB.getLastBlogId();
if (lastBlogId != -1) {
Expand Down
8 changes: 7 additions & 1 deletion src/org/wordpress/android/WordPressDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,16 @@ public List<Map<String, Object>> getAccountsBy(String byString, String[] extraFi
return accounts;
}

public List<Map<String, Object>> getShownAccounts() {
public List<Map<String, Object>> getVisibleAccounts() {
return getAccountsBy("isHidden = 0", null);
}

public int getNumVisibleAccounts() {
return SqlUtils.intForQuery(db, "SELECT COUNT(*) FROM " + SETTINGS_TABLE
+ " WHERE isHidden = 0", null);
}


public List<Map<String, Object>> getAllAccounts() {
return getAccountsBy(null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onCreate(Bundle savedInstanceState) {
}

private void displayAccounts() {
accounts = WordPress.wpDB.getShownAccounts();
accounts = WordPress.wpDB.getVisibleAccounts();

ListView listView = (ListView) findViewById(android.R.id.list);

Expand Down Expand Up @@ -100,7 +100,7 @@ private void displayAccounts() {
}

if (validBlogCtr < accounts.size()){
accounts = WordPress.wpDB.getShownAccounts();
accounts = WordPress.wpDB.getVisibleAccounts();
}

setListAdapter(new HomeListAdapter());
Expand Down Expand Up @@ -181,7 +181,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ADD_ACCOUNT_REQUEST:
if (resultCode == RESULT_OK) {
accounts = WordPress.wpDB.getShownAccounts();
accounts = WordPress.wpDB.getVisibleAccounts();
if (accounts.size() > 0) {
displayAccounts();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void onBackPressed() {
}

private String[] getBlogNames() {
List<Map<String, Object>> accounts = WordPress.wpDB.getShownAccounts();
List<Map<String, Object>> accounts = WordPress.wpDB.getVisibleAccounts();

if (accounts.size() > 0) {

Expand Down
109 changes: 74 additions & 35 deletions src/org/wordpress/android/ui/WPActionBarActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.models.Blog;
import org.wordpress.android.ui.accounts.NewBlogActivity;
import org.wordpress.android.ui.accounts.WelcomeActivity;
import org.wordpress.android.ui.comments.CommentsActivity;
import org.wordpress.android.ui.media.MediaBrowserActivity;
Expand Down Expand Up @@ -343,7 +342,6 @@ public void onClick(View v) {
}

protected void startActivityWithDelay(final Intent i) {

if (mIsXLargeDevice && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// Tablets in landscape don't need a delay because the menu drawer doesn't close
startActivity(i);
Expand Down Expand Up @@ -445,7 +443,7 @@ public void onBackPressed() {
* @return array of blog names
*/
private static String[] getBlogNames() {
List<Map<String, Object>> accounts = WordPress.wpDB.getShownAccounts();
List<Map<String, Object>> accounts = WordPress.wpDB.getVisibleAccounts();

int blogCount = accounts.size();
blogIDs = new int[blogCount];
Expand All @@ -469,37 +467,49 @@ private static String[] getBlogNames() {
return blogNames;
}

private int getNumVisibleAccounts() {
return WordPress.wpDB.getNumVisibleAccounts();
}

protected boolean isSignedIn() {
if (WordPress.hasValidWPComCredentials(WPActionBarActivity.this)) {
return true;
}
return getNumVisibleAccounts() != 0;
}

private boolean askToSignInIfNot() {
if (!isSignedIn()) {
Log.d(TAG, "No accounts configured. Sending user to set up an account");
mShouldFinish = false;
Intent intent = new Intent(this, WelcomeActivity.class);
intent.putExtra("request", WelcomeActivity.SIGN_IN_REQUEST);
startActivityForResult(intent, ADD_ACCOUNT_REQUEST);
return false;
}
return true;
}

/**
* Setup the global state tracking which blog is currently active.
* <p>
* If the global state is not already set, try and determine the last active
* blog from the last time the application was used. If we're not able to
* determine the last active blog, just select the first one.
* <p>
* If no blogs are configured, display the "new account" activity to allow
* the user to setup a blog.
* Setup the global state tracking which blog is currently active if the user is signed in.q
*/
public void setupCurrentBlog() {
Blog currentBlog = WordPress.getCurrentBlog();
if (askToSignInIfNot()) {
WordPress.getCurrentBlog();
}
}

if (currentBlog == null || getBlogNames().length == 0) {
Log.d(TAG, "No accounts configured. Sending user to set up an account");
mShouldFinish = false;
if (WordPress.hasValidWPComCredentials(WPActionBarActivity.this)) {
// Ugly workaround to prevent onResume to call this a second time
if (!mNewBlogActivityRunning) {
mNewBlogActivityRunning = true;
Intent intent = new Intent(this, NewBlogActivity.class);
intent.putExtra(NewBlogActivity.KEY_START_MODE,
NewBlogActivity.CREATE_BLOG_LOGOUT_ON_CANCEL);
startActivityForResult(intent, ADD_ACCOUNT_REQUEST);
}
} else {
Intent intent = new Intent(this, WelcomeActivity.class);
intent.putExtra(WelcomeActivity.START_FRAGMENT_KEY,
WelcomeActivity.SIGN_IN_REQUEST);
startActivityForResult(intent, ADD_ACCOUNT_REQUEST);
}
private void showReader() {
Intent intent;
intent = new Intent(WPActionBarActivity.this, NativeReaderActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}

protected void showReaderIfNoBlog() {
// If logged in without blog, redirect to the Reader view
if (getNumVisibleAccounts() == 0) {
showReader();
}
}

Expand All @@ -516,8 +526,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
initMenuDrawer();
mMenuDrawer.openMenu(false);
WordPress.registerForCloudMessaging(this);
} else if (resultCode == NEW_BLOG_CANCELED) {
// Do nothing and don't finish(), this will start a WelcomeActivity
// If logged in without blog, redirect to the Reader view
showReaderIfNoBlog();
} else {
finish();
}
Expand Down Expand Up @@ -710,14 +720,11 @@ public Boolean isSelected(){
}
@Override
public void onSelectItem(){
int readerBlogID = WordPress.wpDB.getWPCOMBlogID();
Intent intent;
intent = new Intent(WPActionBarActivity.this, NativeReaderActivity.class);
intent.putExtra("id", readerBlogID);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityWithDelay(intent);
}

}

private class PostsMenuItem extends MenuDrawerItem {
Expand All @@ -740,6 +747,10 @@ public void onSelectItem() {
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityWithDelay(intent);
}
@Override
public Boolean isVisible() {
return getNumVisibleAccounts() != 0;
}
}

private class MediaMenuItem extends MenuDrawerItem {
Expand All @@ -758,6 +769,10 @@ public void onSelectItem(){
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityWithDelay(intent);
}
@Override
public Boolean isVisible() {
return getNumVisibleAccounts() != 0;
}
}

private class PagesMenuItem extends MenuDrawerItem {
Expand All @@ -779,6 +794,10 @@ public void onSelectItem(){
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityWithDelay(intent);
}
@Override
public Boolean isVisible() {
return getNumVisibleAccounts() != 0;
}
}

private class CommentsMenuItem extends MenuDrawerItem {
Expand Down Expand Up @@ -814,6 +833,10 @@ public void configureView(View view){
bagdeTextView.setText(String.valueOf(commentCount));
}
}
@Override
public Boolean isVisible() {
return getNumVisibleAccounts() != 0;
}
}

private class ThemesMenuItem extends MenuDrawerItem {
Expand Down Expand Up @@ -861,6 +884,10 @@ public void onSelectItem(){
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityWithDelay(intent);
}
@Override
public Boolean isVisible() {
return getNumVisibleAccounts() != 0;
}
}

private class QuickPhotoMenuItem extends MenuDrawerItem {
Expand All @@ -877,6 +904,10 @@ public void onSelectItem(){
intent.putExtra("isNew", true);
startActivityWithDelay(intent);
}
@Override
public Boolean isVisible() {
return getNumVisibleAccounts() != 0;
}
}

private class QuickVideoMenuItem extends MenuDrawerItem {
Expand All @@ -893,6 +924,10 @@ public void onSelectItem(){
intent.putExtra("isNew", true);
startActivityWithDelay(intent);
}
@Override
public Boolean isVisible() {
return getNumVisibleAccounts() != 0;
}
}

private class ViewSiteMenuItem extends MenuDrawerItem {
Expand All @@ -911,6 +946,10 @@ public void onSelectItem(){
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityWithDelay(intent);
}
@Override
public Boolean isVisible() {
return getNumVisibleAccounts() != 0;
}
}

private class NotificationsMenuItem extends MenuDrawerItem {
Expand Down
4 changes: 3 additions & 1 deletion src/org/wordpress/android/ui/posts/PostsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public class PostsActivity extends WPActionBarActivity implements OnPostSelected
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Special check for a null database (see #507)
if (WordPress.wpDB == null) {
Toast.makeText(this, R.string.fatal_db_error, Toast.LENGTH_LONG).show();
Expand Down Expand Up @@ -273,6 +272,9 @@ protected void popPostDetail() {
@Override
protected void onResume() {
super.onResume();
if (isSignedIn()) {
showReaderIfNoBlog();
}
if (postList.getListView().getCount() == 0)
postList.loadPosts(false);
if (WordPress.postsShouldRefresh) {
Expand Down
Loading