From b7a4134caafc318bc335f1426b3f6c7a7bbbffee Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 11 Jul 2018 09:07:05 -0700 Subject: [PATCH 01/36] Hide Facebook publicize option --- .../ui/publicize/PublicizeConstants.java | 1 + .../adapters/PublicizeServiceAdapter.java | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeConstants.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeConstants.java index 23a5e1620afe..8382f3a029c5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeConstants.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeConstants.java @@ -6,6 +6,7 @@ public class PublicizeConstants { public static final String ARG_CONNECTION_ARRAY_JSON = "connection_array_json"; public static final String GOOGLE_PLUS_ID = "google_plus"; + public static final String FACEBOOK_ID = "facebook"; public enum ConnectAction { CONNECT, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java index 072ab709702f..46bf3cbf6e99 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java @@ -44,12 +44,15 @@ public interface OnServiceClickListener { private OnAdapterLoadedListener mAdapterLoadedListener; private OnServiceClickListener mServiceClickListener; + private boolean mShouldHideGPlus; // G+ no longers supports authentication via a WebView, so we hide it here unless the user already has a connection + public PublicizeServiceAdapter(Context context, long siteId, long currentUserId) { super(); mSiteId = siteId; mBlavatarSz = context.getResources().getDimensionPixelSize(R.dimen.blavatar_sz_small); mCurrentUserId = currentUserId; + mShouldHideGPlus = true; ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0); @@ -174,21 +177,17 @@ protected void onCancelled() { @Override protected Boolean doInBackground(Void... params) { - // G+ no longers supports authentication via a WebView, so we hide it here unless the - // user already has a connection - boolean hideGPlus = true; - PublicizeConnectionList connections = PublicizeTable.getConnectionsForSite(mSiteId); for (PublicizeConnection connection : connections) { if (connection.getService().equals(PublicizeConstants.GOOGLE_PLUS_ID)) { - hideGPlus = false; + mShouldHideGPlus = false; } mTmpConnections.add(connection); } PublicizeServiceList services = PublicizeTable.getServiceList(); for (PublicizeService service : services) { - if (!service.getId().equals(PublicizeConstants.GOOGLE_PLUS_ID) || !hideGPlus) { + if (!isHiddenService(service)) { mTmpServices.add(service); } } @@ -236,4 +235,11 @@ public int compare(PublicizeService lhs, PublicizeService rhs) { }); } } + + private boolean isHiddenService(PublicizeService service) { + boolean shouldHideGooglePlus = service.getId().equals(PublicizeConstants.GOOGLE_PLUS_ID) || mShouldHideGPlus; + boolean isFacebook = service.getId().equals(PublicizeConstants.FACEBOOK_ID); + + return shouldHideGooglePlus || isFacebook; + } } From 194ee67a916685f7f251d0bf3ba70afafa101d80 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 11 Jul 2018 19:37:33 -0700 Subject: [PATCH 02/36] Reformat code with code style --- .../adapters/PublicizeServiceAdapter.java | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java index 46bf3cbf6e99..507f8f31118f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java @@ -25,26 +25,20 @@ import java.util.Comparator; public class PublicizeServiceAdapter extends RecyclerView.Adapter { - public interface OnAdapterLoadedListener { - void onAdapterLoaded(boolean isEmpty); - } - - public interface OnServiceClickListener { - void onServiceClicked(PublicizeService service); - } - private final PublicizeServiceList mServices = new PublicizeServiceList(); private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); - private final long mSiteId; private final int mBlavatarSz; private final ColorFilter mGrayScaleFilter; private final long mCurrentUserId; - private OnAdapterLoadedListener mAdapterLoadedListener; private OnServiceClickListener mServiceClickListener; + private boolean mShouldHideGPlus; - private boolean mShouldHideGPlus; // G+ no longers supports authentication via a WebView, so we hide it here unless the user already has a connection + /* + * AsyncTask to load services + */ + private boolean mIsTaskRunning = false; public PublicizeServiceAdapter(Context context, long siteId, long currentUserId) { super(); @@ -141,6 +135,21 @@ public void onClick(View v) { }); } + private boolean isHiddenService(PublicizeService service) { + boolean shouldHideGooglePlus = service.getId().equals(PublicizeConstants.GOOGLE_PLUS_ID) || mShouldHideGPlus; + boolean isFacebook = service.getId().equals(PublicizeConstants.FACEBOOK_ID); + + return shouldHideGooglePlus || isFacebook; + } + + public interface OnAdapterLoadedListener { + void onAdapterLoaded(boolean isEmpty); + } + + public interface OnServiceClickListener { + void onServiceClicked(PublicizeService service); + } + class SharingViewHolder extends RecyclerView.ViewHolder { private final TextView mTxtService; private final TextView mTxtUser; @@ -156,11 +165,6 @@ class SharingViewHolder extends RecyclerView.ViewHolder { } } - /* - * AsyncTask to load services - */ - private boolean mIsTaskRunning = false; - private class LoadServicesTask extends AsyncTask { private final PublicizeServiceList mTmpServices = new PublicizeServiceList(); private final PublicizeConnectionList mTmpConnections = new PublicizeConnectionList(); @@ -235,11 +239,4 @@ public int compare(PublicizeService lhs, PublicizeService rhs) { }); } } - - private boolean isHiddenService(PublicizeService service) { - boolean shouldHideGooglePlus = service.getId().equals(PublicizeConstants.GOOGLE_PLUS_ID) || mShouldHideGPlus; - boolean isFacebook = service.getId().equals(PublicizeConstants.FACEBOOK_ID); - - return shouldHideGooglePlus || isFacebook; - } } From cdde8593c64074a0b6d46ae775ec2a9a232c98b7 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Fri, 27 Jul 2018 13:49:18 -0700 Subject: [PATCH 03/36] Adding notice and text for facebook deprecation --- .../main/res/layout/publicize_detail_fragment.xml | 15 +++++++++++++++ WordPress/src/main/res/values/strings.xml | 1 + 2 files changed, 16 insertions(+) diff --git a/WordPress/src/main/res/layout/publicize_detail_fragment.xml b/WordPress/src/main/res/layout/publicize_detail_fragment.xml index 09c031cd744f..bb6c8e735304 100644 --- a/WordPress/src/main/res/layout/publicize_detail_fragment.xml +++ b/WordPress/src/main/res/layout/publicize_detail_fragment.xml @@ -98,6 +98,21 @@ android:layout_marginEnd="@dimen/margin_extra_large" android:layout_marginStart="@dimen/margin_extra_large"/> + + Connected accounts Publicize to %s Connect to automatically share your blog posts to %s. + As of August 1, 2018, Facebook no longer allows direct sharing of posts to Facebook Profiles. Connections to Facebook Pages remain unchaged. Connect Disconnect Reconnect From bf100848b79a1e300df088cbaac94822f49bb5fd Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Fri, 27 Jul 2018 13:49:50 -0700 Subject: [PATCH 04/36] Adding conditional view for facebook connections warning about the end of publicize on August 1 --- .../android/ui/publicize/PublicizeDetailFragment.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java index baa4aaa530d3..166d12e90bbc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java @@ -116,6 +116,13 @@ public void loadData() { String description = String.format(getString(R.string.connection_service_description), mService.getLabel()); TextView txtDescription = (TextView) mServiceCardView.findViewById(R.id.text_description); txtDescription.setText(description); + + if (mService.getId().equals(PublicizeConstants.FACEBOOK_ID)) { + String noticeText = getString(R.string.connection_service_facebook_notice); + TextView txtNotice = (TextView) mServiceCardView.findViewById(R.id.text_description_notice); + txtNotice.setText(noticeText); + txtNotice.setVisibility(View.VISIBLE); + } } long currentUserId = mAccountStore.getAccount().getUserId(); From 1a6b0e3ed770f19f2386897c529777b182499ad5 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Fri, 27 Jul 2018 14:08:52 -0700 Subject: [PATCH 05/36] Fixing conditional on whether to hide Google plus --- .../android/ui/publicize/adapters/PublicizeServiceAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java index 507f8f31118f..f9fbd554cf21 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java @@ -136,7 +136,7 @@ public void onClick(View v) { } private boolean isHiddenService(PublicizeService service) { - boolean shouldHideGooglePlus = service.getId().equals(PublicizeConstants.GOOGLE_PLUS_ID) || mShouldHideGPlus; + boolean shouldHideGooglePlus = service.getId().equals(PublicizeConstants.GOOGLE_PLUS_ID) && mShouldHideGPlus; boolean isFacebook = service.getId().equals(PublicizeConstants.FACEBOOK_ID); return shouldHideGooglePlus || isFacebook; From 8ceea997671c9cece62584cc2811e83020cb1a20 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Fri, 27 Jul 2018 14:24:05 -0700 Subject: [PATCH 06/36] Adding text to link to facebook sharing changes --- .../ui/publicize/PublicizeDetailFragment.java | 12 ++++++++++++ .../res/layout/publicize_detail_fragment.xml | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java index 166d12e90bbc..c1eab04578eb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java @@ -2,10 +2,13 @@ import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.Button; import android.widget.TextView; import org.wordpress.android.R; @@ -14,6 +17,7 @@ import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeService; +import org.wordpress.android.ui.WPWebViewActivity; import org.wordpress.android.ui.publicize.PublicizeConstants.ConnectAction; import org.wordpress.android.ui.publicize.adapters.PublicizeConnectionAdapter; import org.wordpress.android.util.ToastUtils; @@ -122,6 +126,14 @@ public void loadData() { TextView txtNotice = (TextView) mServiceCardView.findViewById(R.id.text_description_notice); txtNotice.setText(noticeText); txtNotice.setVisibility(View.VISIBLE); + + TextView learnMoreButton = (TextView) mServiceCardView.findViewById(R.id.learn_more_button); + learnMoreButton.setOnClickListener(new OnClickListener() { + @Override public void onClick(View v) { + WPWebViewActivity.openURL(getActivity(), "https://en.blog.wordpress.com/2018/07/23/sharing-options-from-wordpress-com-to-facebook-are-changing/"); + } + }); + learnMoreButton.setVisibility(View.VISIBLE); } } diff --git a/WordPress/src/main/res/layout/publicize_detail_fragment.xml b/WordPress/src/main/res/layout/publicize_detail_fragment.xml index bb6c8e735304..851e573523b3 100644 --- a/WordPress/src/main/res/layout/publicize_detail_fragment.xml +++ b/WordPress/src/main/res/layout/publicize_detail_fragment.xml @@ -105,6 +105,7 @@ android:layout_height="wrap_content" android:layout_marginLeft="@dimen/margin_extra_large" android:layout_marginRight="@dimen/margin_extra_large" + android:paddingTop="@dimen/margin_large" android:ellipsize="end" android:textColor="@color/grey_darken_20" android:textSize="@dimen/text_sz_medium" @@ -113,6 +114,23 @@ android:layout_marginEnd="@dimen/margin_extra_large" android:layout_marginStart="@dimen/margin_extra_large"/> + + Date: Sun, 29 Jul 2018 12:54:18 -0700 Subject: [PATCH 07/36] Adding new must_disconnect status for a connection --- .../java/org/wordpress/android/models/PublicizeConnection.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java index 3f33d30548da..e852029c7f33 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java @@ -20,6 +20,9 @@ public String toString() { public String toString() { return "broken"; } + }, + MUST_DISCONNECT { + public String toString() { return "must-disconnect"; } } } From d3733e93b966531aa2f7ca4c5d8f84c3799ffc3e Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 12:54:28 -0700 Subject: [PATCH 08/36] Making a constant --- .../android/ui/publicize/PublicizeDetailFragment.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java index c1eab04578eb..5f9910b76f42 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java @@ -26,6 +26,8 @@ public class PublicizeDetailFragment extends PublicizeBaseFragment implements PublicizeConnectionAdapter.OnAdapterLoadedListener { + public static final String FACEBOOK_SHARING_CHANGE_BLOG_POST = + "https://en.blog.wordpress.com/2018/07/23/sharing-options-from-wordpress-com-to-facebook-are-changing/"; private SiteModel mSite; private String mServiceId; @@ -130,7 +132,8 @@ public void loadData() { TextView learnMoreButton = (TextView) mServiceCardView.findViewById(R.id.learn_more_button); learnMoreButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - WPWebViewActivity.openURL(getActivity(), "https://en.blog.wordpress.com/2018/07/23/sharing-options-from-wordpress-com-to-facebook-are-changing/"); + WPWebViewActivity.openURL(getActivity(), + FACEBOOK_SHARING_CHANGE_BLOG_POST); } }); learnMoreButton.setVisibility(View.VISIBLE); From 9b83ef998491e2279705a4643eee8a45c964525c Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 15:03:49 -0700 Subject: [PATCH 09/36] Fixing formatting --- .../org/wordpress/android/models/PublicizeConnection.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java index e852029c7f33..3b75767e2f96 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java @@ -22,7 +22,9 @@ public String toString() { } }, MUST_DISCONNECT { - public String toString() { return "must-disconnect"; } + public String toString() { + return "must-disconnect"; + } } } From 9fee14f42cf7f8e5eaec80d393d672569d837512 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 15:10:15 -0700 Subject: [PATCH 10/36] Adding must_disconnect case for status --- .../java/org/wordpress/android/models/PublicizeConnection.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java index 3b75767e2f96..389f627ab402 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java @@ -131,6 +131,8 @@ public void setStatus(String status) { public ConnectStatus getStatusEnum() { if (getStatus().equalsIgnoreCase(ConnectStatus.BROKEN.toString())) { return ConnectStatus.BROKEN; + } else if (getStatus().equalsIgnoreCase(ConnectStatus.MUST_DISCONNECT.toString())) { + return ConnectStatus.MUST_DISCONNECT; } else { return ConnectStatus.OK; } From a947664890480d11952fd6576730722aa152d023 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 15:46:05 -0700 Subject: [PATCH 11/36] Adding additional fields from the JSON object response --- .../android/models/PublicizeService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java index 76626dfbef81..27b67f1c20ed 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java @@ -9,6 +9,8 @@ public class PublicizeService { private String mGenericon; private String mIconUrl; private String mConnectUrl; + private boolean mhasMultipleExternalUserIdSupport; + private boolean mIsExternalUsersOnly; private boolean mIsJetpackSupported; private boolean mIsMultiExternalUserIdSupported; @@ -61,6 +63,22 @@ public void setConnectUrl(String url) { mConnectUrl = StringUtils.notNullStr(url); } + public boolean getHasMultipleExternalUserIdSupport() { + return mhasMultipleExternalUserIdSupport; + } + + public void setHasMultipleExternalUserIdSupport(boolean hasMultipleExternalUserIdSupport) { + this.mhasMultipleExternalUserIdSupport = mhasMultipleExternalUserIdSupport; + } + + public boolean getIsExternalUsersOnly() { + return mIsExternalUsersOnly; + } + + public void setIsExternalUsersOnly(boolean isExternalUsersOnly) { + mIsExternalUsersOnly = isExternalUsersOnly; + } + public boolean isJetpackSupported() { return mIsJetpackSupported; } @@ -85,6 +103,8 @@ public boolean isSameAs(PublicizeService other) { && other.getGenericon().equals(this.getGenericon()) && other.getIconUrl().equals(this.getIconUrl()) && other.getConnectUrl().equals(this.getConnectUrl()) + && other.getHasMultipleExternalUserIdSupport() == this.getHasMultipleExternalUserIdSupport() + && other.getIsExternalUsersOnly() == this.getIsExternalUsersOnly(); && other.isJetpackSupported() == this.isJetpackSupported(); } } From 3834d18bbe5113499f724186d40e53fc14f0bc6d Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 16:05:29 -0700 Subject: [PATCH 12/36] Updating table --- .../android/datasets/PublicizeTable.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java index b4be318d1741..8dead5fe081a 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -25,6 +25,8 @@ public static void createTables(SQLiteDatabase db) { + " genericon TEXT NOT NULL," + " icon_url TEXT NOT NULL," + " connect_url TEXT NOT NULL," + + " has_multiple_external_user_id_support INTEGER DEFAULT 0," + + " is_external_users_only INTEGER DEFAULT 0," + " is_jetpack_supported INTEGER DEFAULT 0," + " is_multi_user_id_supported INTEGER DEFAULT 0," + " PRIMARY KEY (id))"); @@ -110,9 +112,11 @@ public static void setServiceList(final PublicizeServiceList serviceList) { + " genericon," // 4 + " icon_url," // 5 + " connect_url," // 6 - + " is_jetpack_supported," // 7 - + " is_multi_user_id_supported)" // 8 - + " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)"); + + " has_multiple_external_user_id_support," // 7 + + " is_external_users_only," // 8 + + " is_jetpack_supported," // 9 + + " is_multi_user_id_supported)" // 10 + + " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)"); for (PublicizeService service : serviceList) { stmt.bindString(1, service.getId()); stmt.bindString(2, service.getLabel()); @@ -120,8 +124,10 @@ public static void setServiceList(final PublicizeServiceList serviceList) { stmt.bindString(4, service.getGenericon()); stmt.bindString(5, service.getIconUrl()); stmt.bindString(6, service.getConnectUrl()); - stmt.bindLong(7, SqlUtils.boolToSql(service.isJetpackSupported())); - stmt.bindLong(8, SqlUtils.boolToSql(service.isMultiExternalUserIdSupported())); + stmt.bindLong(7, SqlUtils.boolToSql(service.getHasMultipleExternalUserIdSupport())); + stmt.bindLong(8, SqlUtils.boolToSql(service.getIsExternalUsersOnly())); + stmt.bindLong(9, SqlUtils.boolToSql(service.isJetpackSupported())); + stmt.bindLong(10, SqlUtils.boolToSql(service.isMultiExternalUserIdSupported())); stmt.executeInsert(); } @@ -141,6 +147,8 @@ private static PublicizeService getServiceFromCursor(Cursor c) { service.setGenericon(c.getString(c.getColumnIndex("genericon"))); service.setIconUrl(c.getString(c.getColumnIndex("icon_url"))); service.setConnectUrl(c.getString(c.getColumnIndex("connect_url"))); + service.setHasMultipleExternalUserIdSupport(SqlUtils.sqlToBool(c.getColumnIndex("has_multiple_external_user_id_support"))); + service.setHasMultipleExternalUserIdSupport(SqlUtils.sqlToBool(c.getColumnIndex("is_external_users_only"))); service.setIsJetpackSupported(SqlUtils.sqlToBool(c.getColumnIndex("is_jetpack_supported"))); service.setIsMultiExternalUserIdSupported(SqlUtils.sqlToBool(c.getColumnIndex("is_multi_user_id_supported"))); From ee2be5d04d51014e0c2c2f27dcb051bec1e76449 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 16:05:46 -0700 Subject: [PATCH 13/36] Creating the new model from services json --- .../android/models/PublicizeServiceList.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java index ecefd05a72cb..b80c6df7a483 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java @@ -40,22 +40,21 @@ public boolean isSameAs(PublicizeServiceList otherList) { /* * passed JSON is the response from /meta/external-services?type=publicize "services": { - "facebook": { - "ID": "facebook", - "label": "Facebook", - "type": "publicize", - "description": "Publish your posts to your Facebook timeline or page.", - "genericon": { - "class": "facebook-alt", - "unicode": "\\f203" - }, - "icon": "http://i.wordpress.com/wp-content/admin-plugins/publicize/assets/publicize-fb-2x.png", - "connect_URL": "https://public-api.wordpress.com/connect/?action=request - &kr_nonce=b2c86a0cdb&nonce=94557d1529&for=connect&service=facebook&kr_blog_nonce=5e399375f1 - &magic=keyring&blog=52451191", - "multiple_external_user_ID_support": true, - "jetpack_support": true, - "jetpack_module_required": "publicize" + "facebook":{ + "ID":"facebook", + "label":"Facebook", + "type":"publicize", + "description":"Publish your posts to your Facebook timeline or page.", + "genericon":{ + "class":"facebook-alt", + "unicode":"\\f203" + }, + "icon":"http:\/\/i.wordpress.com\/wp-content\/admin-plugins\/publicize\/assets\/publicize-fb-2x.png", + "connect_URL":"https:\/\/public-api.wordpress.com\/connect\/?action=request&kr_nonce=a1e2ad2b80&nonce=c4b69a25c1&for=connect&service=facebook&kr_blog_nonce=0ae2027be9&magic=keyring&blog=90298630", + "multiple_external_user_ID_support":true, + "external_users_only":true, + "jetpack_support":true, + "jetpack_module_required":"publicize" }, ... */ @@ -81,6 +80,8 @@ public static PublicizeServiceList fromJson(JSONObject json) { service.setDescription(jsonService.optString("description")); service.setIconUrl(jsonService.optString("icon")); service.setConnectUrl(jsonService.optString("connect_URL")); + service.setHasMultipleExternalUserIdSupport(jsonService.optBoolean("multiple_external_user_ID_support")); + service.setIsExternalUsersOnly(jsonService.optBoolean("external_users_only")); service.setIsJetpackSupported(jsonService.optBoolean("jetpack_support")); service.setIsMultiExternalUserIdSupported(jsonService.optBoolean("multiple_external_user_ID_support")); From 57e18e882197a972c10b3ba9ed8333cf0a23cb4e Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 16:06:22 -0700 Subject: [PATCH 14/36] Resetting the publicize services table on update --- .../src/main/java/org/wordpress/android/WordPressDB.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/WordPressDB.java b/WordPress/src/main/java/org/wordpress/android/WordPressDB.java index ae19f7529cf9..fb2ad6bf1f1c 100755 --- a/WordPress/src/main/java/org/wordpress/android/WordPressDB.java +++ b/WordPress/src/main/java/org/wordpress/android/WordPressDB.java @@ -6,6 +6,7 @@ import org.wordpress.android.datasets.NotificationsTable; import org.wordpress.android.datasets.PeopleTable; +import org.wordpress.android.datasets.PublicizeTable; import org.wordpress.android.datasets.SiteSettingsTable; import org.wordpress.android.datasets.SuggestionTable; import org.wordpress.android.models.SiteSettingsModel; @@ -21,7 +22,7 @@ import java.io.OutputStream; public class WordPressDB { - private static final int DATABASE_VERSION = 65; + private static final int DATABASE_VERSION = 66; // Warning if you rename DATABASE_NAME, that could break previous App backups (see: xml/backup_scheme.xml) @@ -170,6 +171,9 @@ public WordPressDB(Context ctx) { case 64: // add site icon mDb.execSQL(SiteSettingsModel.ADD_SITE_ICON); + case 65: + // reset publicize services table + PublicizeTable.reset(); } mDb.setVersion(DATABASE_VERSION); } From 51d9887735903b5485c1cd25b141982ccef79014 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 16:24:09 -0700 Subject: [PATCH 15/36] Removing extra semi-colon --- .../java/org/wordpress/android/models/PublicizeService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java index 27b67f1c20ed..82fca88739b6 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java @@ -104,7 +104,7 @@ public boolean isSameAs(PublicizeService other) { && other.getIconUrl().equals(this.getIconUrl()) && other.getConnectUrl().equals(this.getConnectUrl()) && other.getHasMultipleExternalUserIdSupport() == this.getHasMultipleExternalUserIdSupport() - && other.getIsExternalUsersOnly() == this.getIsExternalUsersOnly(); + && other.getIsExternalUsersOnly() == this.getIsExternalUsersOnly() && other.isJetpackSupported() == this.isJetpackSupported(); } } From 4fdea8eab523ada5fadacfeafbfeb877bff2b1d1 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 17:34:24 -0700 Subject: [PATCH 16/36] Revert "Updating table" This reverts commit 3834d18bbe5113499f724186d40e53fc14f0bc6d. --- .../android/datasets/PublicizeTable.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java index 8dead5fe081a..b4be318d1741 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -25,8 +25,6 @@ public static void createTables(SQLiteDatabase db) { + " genericon TEXT NOT NULL," + " icon_url TEXT NOT NULL," + " connect_url TEXT NOT NULL," - + " has_multiple_external_user_id_support INTEGER DEFAULT 0," - + " is_external_users_only INTEGER DEFAULT 0," + " is_jetpack_supported INTEGER DEFAULT 0," + " is_multi_user_id_supported INTEGER DEFAULT 0," + " PRIMARY KEY (id))"); @@ -112,11 +110,9 @@ public static void setServiceList(final PublicizeServiceList serviceList) { + " genericon," // 4 + " icon_url," // 5 + " connect_url," // 6 - + " has_multiple_external_user_id_support," // 7 - + " is_external_users_only," // 8 - + " is_jetpack_supported," // 9 - + " is_multi_user_id_supported)" // 10 - + " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10)"); + + " is_jetpack_supported," // 7 + + " is_multi_user_id_supported)" // 8 + + " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)"); for (PublicizeService service : serviceList) { stmt.bindString(1, service.getId()); stmt.bindString(2, service.getLabel()); @@ -124,10 +120,8 @@ public static void setServiceList(final PublicizeServiceList serviceList) { stmt.bindString(4, service.getGenericon()); stmt.bindString(5, service.getIconUrl()); stmt.bindString(6, service.getConnectUrl()); - stmt.bindLong(7, SqlUtils.boolToSql(service.getHasMultipleExternalUserIdSupport())); - stmt.bindLong(8, SqlUtils.boolToSql(service.getIsExternalUsersOnly())); - stmt.bindLong(9, SqlUtils.boolToSql(service.isJetpackSupported())); - stmt.bindLong(10, SqlUtils.boolToSql(service.isMultiExternalUserIdSupported())); + stmt.bindLong(7, SqlUtils.boolToSql(service.isJetpackSupported())); + stmt.bindLong(8, SqlUtils.boolToSql(service.isMultiExternalUserIdSupported())); stmt.executeInsert(); } @@ -147,8 +141,6 @@ private static PublicizeService getServiceFromCursor(Cursor c) { service.setGenericon(c.getString(c.getColumnIndex("genericon"))); service.setIconUrl(c.getString(c.getColumnIndex("icon_url"))); service.setConnectUrl(c.getString(c.getColumnIndex("connect_url"))); - service.setHasMultipleExternalUserIdSupport(SqlUtils.sqlToBool(c.getColumnIndex("has_multiple_external_user_id_support"))); - service.setHasMultipleExternalUserIdSupport(SqlUtils.sqlToBool(c.getColumnIndex("is_external_users_only"))); service.setIsJetpackSupported(SqlUtils.sqlToBool(c.getColumnIndex("is_jetpack_supported"))); service.setIsMultiExternalUserIdSupported(SqlUtils.sqlToBool(c.getColumnIndex("is_multi_user_id_supported"))); From 8d15e83db309119640829e04652876b8932459df Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 19:22:52 -0700 Subject: [PATCH 17/36] =?UTF-8?q?Only=20should=20hide=20google=20plus=20if?= =?UTF-8?q?=20it=E2=80=99s=20not=20already=20connected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../android/ui/publicize/adapters/PublicizeServiceAdapter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java index f9fbd554cf21..472497d24e23 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeServiceAdapter.java @@ -137,9 +137,8 @@ public void onClick(View v) { private boolean isHiddenService(PublicizeService service) { boolean shouldHideGooglePlus = service.getId().equals(PublicizeConstants.GOOGLE_PLUS_ID) && mShouldHideGPlus; - boolean isFacebook = service.getId().equals(PublicizeConstants.FACEBOOK_ID); - return shouldHideGooglePlus || isFacebook; + return shouldHideGooglePlus; } public interface OnAdapterLoadedListener { From 70a073053ccddc04e70247a9509bb098d6e1d659 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 19:23:04 -0700 Subject: [PATCH 18/36] Setting the name from either the display or normal name --- .../PublicizeAccountChooserListAdapter.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserListAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserListAdapter.java index c3802f303970..7ebe8eeba0ed 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserListAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserListAdapter.java @@ -41,7 +41,7 @@ public void onBindViewHolder(final ViewHolder holder, int position) { final PublicizeConnection connection = mConnectionItems.get(position); holder.mProfileImageView .setImageUrl(connection.getExternalProfilePictureUrl(), WPNetworkImageView.ImageType.PHOTO); - holder.mNameTextView.setText(connection.getExternalDisplayName()); + holder.mNameTextView.setText(getName(connection)); holder.mRadioButton.setChecked(position == mSelectedPosition); if (!mAreAccountsConnected) { @@ -82,4 +82,14 @@ public ViewHolder(View view) { public interface OnPublicizeAccountChooserListener { void onAccountSelected(int selectedIndex); } + + private String getName(PublicizeConnection connection) { + String name = connection.getExternalDisplayName(); + + if (name.isEmpty()) { + name = connection.getExternalName(); + } + + return name; + } } From e82db0bbbedf3d52cd0507d7d5df7dcf83d514d4 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 19:43:29 -0700 Subject: [PATCH 19/36] Add table modification in DB --- .../org/wordpress/android/WordPressDB.java | 4 +-- .../android/datasets/PublicizeTable.java | 11 ++++++-- .../android/models/PublicizeService.java | 28 ++++++------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/WordPressDB.java b/WordPress/src/main/java/org/wordpress/android/WordPressDB.java index fb2ad6bf1f1c..75985e22c3b8 100755 --- a/WordPress/src/main/java/org/wordpress/android/WordPressDB.java +++ b/WordPress/src/main/java/org/wordpress/android/WordPressDB.java @@ -172,8 +172,8 @@ public WordPressDB(Context ctx) { // add site icon mDb.execSQL(SiteSettingsModel.ADD_SITE_ICON); case 65: - // reset publicize services table - PublicizeTable.reset(); + // add external users only to publicize services table + mDb.execSQL(PublicizeTable.ADD_EXTERNAL_USERS_ONLY); } mDb.setVersion(DATABASE_VERSION); } diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java index b4be318d1741..0ecbaa50bbf6 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -16,6 +16,10 @@ public class PublicizeTable { private static final String SERVICES_TABLE = "tbl_publicize_services"; private static final String CONNECTIONS_TABLE = "tbl_publicize_connections"; + private static final String IS_EXTERNAL_USERS_ONLY_COLUMN_NAME = "is_external_users_only"; + + public static final String ADD_EXTERNAL_USERS_ONLY = "alter table " + SERVICES_TABLE + + " add " + IS_EXTERNAL_USERS_ONLY_COLUMN_NAME + " BOOLEAN;"; public static void createTables(SQLiteDatabase db) { db.execSQL("CREATE TABLE IF NOT EXISTS " + SERVICES_TABLE + " (" @@ -111,8 +115,9 @@ public static void setServiceList(final PublicizeServiceList serviceList) { + " icon_url," // 5 + " connect_url," // 6 + " is_jetpack_supported," // 7 - + " is_multi_user_id_supported)" // 8 - + " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)"); + + " is_multi_user_id_supported," // 8 + + " is_external_users_only)" // 9 + + " VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)"); for (PublicizeService service : serviceList) { stmt.bindString(1, service.getId()); stmt.bindString(2, service.getLabel()); @@ -122,6 +127,7 @@ public static void setServiceList(final PublicizeServiceList serviceList) { stmt.bindString(6, service.getConnectUrl()); stmt.bindLong(7, SqlUtils.boolToSql(service.isJetpackSupported())); stmt.bindLong(8, SqlUtils.boolToSql(service.isMultiExternalUserIdSupported())); + stmt.bindLong(9, SqlUtils.boolToSql(service.isExternalUsersOnly())); stmt.executeInsert(); } @@ -143,6 +149,7 @@ private static PublicizeService getServiceFromCursor(Cursor c) { service.setConnectUrl(c.getString(c.getColumnIndex("connect_url"))); service.setIsJetpackSupported(SqlUtils.sqlToBool(c.getColumnIndex("is_jetpack_supported"))); service.setIsMultiExternalUserIdSupported(SqlUtils.sqlToBool(c.getColumnIndex("is_multi_user_id_supported"))); + service.setIsExternalUsersOnly(SqlUtils.sqlToBool(c.getColumnIndex("is_external_users_only"))); return service; } diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java index 82fca88739b6..c833490b071c 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeService.java @@ -9,7 +9,6 @@ public class PublicizeService { private String mGenericon; private String mIconUrl; private String mConnectUrl; - private boolean mhasMultipleExternalUserIdSupport; private boolean mIsExternalUsersOnly; private boolean mIsJetpackSupported; @@ -63,22 +62,6 @@ public void setConnectUrl(String url) { mConnectUrl = StringUtils.notNullStr(url); } - public boolean getHasMultipleExternalUserIdSupport() { - return mhasMultipleExternalUserIdSupport; - } - - public void setHasMultipleExternalUserIdSupport(boolean hasMultipleExternalUserIdSupport) { - this.mhasMultipleExternalUserIdSupport = mhasMultipleExternalUserIdSupport; - } - - public boolean getIsExternalUsersOnly() { - return mIsExternalUsersOnly; - } - - public void setIsExternalUsersOnly(boolean isExternalUsersOnly) { - mIsExternalUsersOnly = isExternalUsersOnly; - } - public boolean isJetpackSupported() { return mIsJetpackSupported; } @@ -95,6 +78,14 @@ public void setIsMultiExternalUserIdSupported(boolean supported) { mIsMultiExternalUserIdSupported = supported; } + public boolean isExternalUsersOnly() { + return mIsExternalUsersOnly; + } + + public void setIsExternalUsersOnly(boolean isExternalUsersOnly) { + mIsExternalUsersOnly = isExternalUsersOnly; + } + public boolean isSameAs(PublicizeService other) { return other != null && other.getId().equals(this.getId()) @@ -103,8 +94,7 @@ public boolean isSameAs(PublicizeService other) { && other.getGenericon().equals(this.getGenericon()) && other.getIconUrl().equals(this.getIconUrl()) && other.getConnectUrl().equals(this.getConnectUrl()) - && other.getHasMultipleExternalUserIdSupport() == this.getHasMultipleExternalUserIdSupport() - && other.getIsExternalUsersOnly() == this.getIsExternalUsersOnly() + && other.isExternalUsersOnly() == this.isExternalUsersOnly() && other.isJetpackSupported() == this.isJetpackSupported(); } } From 8d5c455bcc0ca61762ac9853e7cba80260e7f800 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 19:43:45 -0700 Subject: [PATCH 20/36] Determine if the service is external users only --- .../org/wordpress/android/datasets/PublicizeTable.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java index 0ecbaa50bbf6..11bc1bf07fb2 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -154,6 +154,16 @@ private static PublicizeService getServiceFromCursor(Cursor c) { return service; } + public static boolean onlyExternalConnections(String serviceId) { + if (serviceId == null && serviceId.isEmpty()) { + return false; + } + + String sql = "SELECT is_external_users_only FROM " + SERVICES_TABLE + " WHERE id=?"; + String[] args = {serviceId}; + return SqlUtils.boolForQuery(getReadableDb(), sql, args); + } + public static String getConnectUrlForService(String serviceId) { if (TextUtils.isEmpty(serviceId)) { return ""; From edde2fb8c8fc2426e9223b355c454c9a80bd8840 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 19:43:58 -0700 Subject: [PATCH 21/36] Counting external accounts now --- .../PublicizeAccountChooserDialogFragment.java | 14 +++++++++++++- .../android/ui/publicize/PublicizeActions.java | 12 +++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java index 5d23dfb4600f..743914485ca2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java @@ -145,13 +145,25 @@ private void addConnectionsToLists(String jsonString) { JSONObject jsonObject = new JSONObject(jsonString); JSONArray jsonArray = jsonObject.getJSONArray("connections"); for (int i = 0; i < jsonArray.length(); i++) { - PublicizeConnection connection = PublicizeConnection.fromJson(jsonArray.getJSONObject(i)); + JSONObject currentConnectionJson = jsonArray.getJSONObject(i); + PublicizeConnection connection = PublicizeConnection.fromJson(currentConnectionJson); if (connection.getService().equals(mServiceId)) { if (connection.isInSite(mSite.getSiteId())) { mConnectedAccounts.add(connection); } else { mNotConnectedAccounts.add(connection); } + + JSONArray externalJsonArray = currentConnectionJson.getJSONArray("additional_external_users"); + for (int j = 0; j < externalJsonArray.length(); j++) { + JSONObject currentExternalConnectionJson = externalJsonArray.getJSONObject(j); + PublicizeConnection externalConnection = PublicizeConnection.fromJson(currentExternalConnectionJson); + if (connection.isInSite(mSite.getSiteId())) { + mConnectedAccounts.add(externalConnection); + } else { + mNotConnectedAccounts.add(externalConnection); + } + } } } } catch (JSONException e) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java index 9d99549be28c..d6208b114760 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java @@ -139,21 +139,31 @@ public void onErrorResponse(VolleyError volleyError) { private static boolean shouldShowChooserDialog(long siteId, String serviceId, JSONObject jsonObject) { JSONArray jsonConnectionList = jsonObject.optJSONArray("connections"); + if (jsonConnectionList == null || jsonConnectionList.length() <= 1) { return false; } int totalAccounts = 0; + int totalExternalAccounts = 0; try { for (int i = 0; i < jsonConnectionList.length(); i++) { JSONObject connectionObject = jsonConnectionList.getJSONObject(i); PublicizeConnection publicizeConnection = PublicizeConnection.fromJson(connectionObject); if (publicizeConnection.getService().equals(serviceId) && !publicizeConnection.isInSite(siteId)) { totalAccounts++; + JSONArray externalJsonArray = connectionObject.getJSONArray("additional_external_users"); + for (int j = 0; j < externalJsonArray.length(); j++) { + totalExternalAccounts++; + } } } - return totalAccounts > 0; + if (PublicizeTable.onlyExternalConnections(serviceId)) { + return totalAccounts > 0; + } else { + return totalAccounts > 0 || totalExternalAccounts > 0; + } } catch (JSONException e) { return false; } From 71bb66fbe273c9bc8ab4bd8e4dd2183b6f183f6a Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 19:45:52 -0700 Subject: [PATCH 22/36] Removing multiple external user --- .../org/wordpress/android/models/PublicizeServiceList.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java index b80c6df7a483..348118f0cba7 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java @@ -80,11 +80,10 @@ public static PublicizeServiceList fromJson(JSONObject json) { service.setDescription(jsonService.optString("description")); service.setIconUrl(jsonService.optString("icon")); service.setConnectUrl(jsonService.optString("connect_URL")); - service.setHasMultipleExternalUserIdSupport(jsonService.optBoolean("multiple_external_user_ID_support")); - service.setIsExternalUsersOnly(jsonService.optBoolean("external_users_only")); - + service.setIsJetpackSupported(jsonService.optBoolean("jetpack_support")); service.setIsMultiExternalUserIdSupported(jsonService.optBoolean("multiple_external_user_ID_support")); + service.setIsExternalUsersOnly(jsonService.optBoolean("external_users_only")); JSONObject jsonGenericon = jsonService.optJSONObject("genericon"); if (jsonGenericon != null) { From 18d252de6827f7a02cd3f9a65ab3fab5cb8ea5e6 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 19:49:04 -0700 Subject: [PATCH 23/36] Cleaning up spaces --- .../java/org/wordpress/android/models/PublicizeServiceList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java index 348118f0cba7..5f5db9a7f9bc 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java @@ -80,7 +80,7 @@ public static PublicizeServiceList fromJson(JSONObject json) { service.setDescription(jsonService.optString("description")); service.setIconUrl(jsonService.optString("icon")); service.setConnectUrl(jsonService.optString("connect_URL")); - + service.setIsJetpackSupported(jsonService.optBoolean("jetpack_support")); service.setIsMultiExternalUserIdSupported(jsonService.optBoolean("multiple_external_user_ID_support")); service.setIsExternalUsersOnly(jsonService.optBoolean("external_users_only")); From eaa792cc63911fcb92370fd1030fbafa2c6c019e Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 19:49:32 -0700 Subject: [PATCH 24/36] Only add non-external sites if there are multiple external sites --- .../PublicizeAccountChooserDialogFragment.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java index 743914485ca2..68ad554e6b2f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java @@ -19,8 +19,10 @@ import org.json.JSONObject; import org.wordpress.android.R; import org.wordpress.android.WordPress; +import org.wordpress.android.datasets.PublicizeTable; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.models.PublicizeConnection; +import org.wordpress.android.models.PublicizeService; import org.wordpress.android.util.ToastUtils; import java.util.ArrayList; @@ -148,10 +150,13 @@ private void addConnectionsToLists(String jsonString) { JSONObject currentConnectionJson = jsonArray.getJSONObject(i); PublicizeConnection connection = PublicizeConnection.fromJson(currentConnectionJson); if (connection.getService().equals(mServiceId)) { - if (connection.isInSite(mSite.getSiteId())) { - mConnectedAccounts.add(connection); - } else { - mNotConnectedAccounts.add(connection); + PublicizeService service = PublicizeTable.getService(mServiceId); + if (service != null && !service.isExternalUsersOnly()) { + if (connection.isInSite(mSite.getSiteId())) { + mConnectedAccounts.add(connection); + } else { + mNotConnectedAccounts.add(connection); + } } JSONArray externalJsonArray = currentConnectionJson.getJSONArray("additional_external_users"); From fddb151ee102bd0ce6bcf7f9aafea3058bfd0467 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Sun, 29 Jul 2018 20:20:27 -0700 Subject: [PATCH 25/36] Fixing typo --- WordPress/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 865ef5deca11..10e7218851a9 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1631,7 +1631,7 @@ Connected accounts Publicize to %s Connect to automatically share your blog posts to %s. - As of August 1, 2018, Facebook no longer allows direct sharing of posts to Facebook Profiles. Connections to Facebook Pages remain unchaged. + As of August 1, 2018, Facebook no longer allows direct sharing of posts to Facebook Profiles. Connections to Facebook Pages remain unchanged. Connect Disconnect Reconnect From 217f03ccce3c87079b3c23b2199663d1ba8d70c7 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 11:40:18 -0700 Subject: [PATCH 26/36] Allowing an external connection to change items of a connection --- .../wordpress/android/models/PublicizeConnection.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java index 389f627ab402..b509447d392b 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java @@ -238,6 +238,16 @@ public static PublicizeConnection fromJson(JSONObject json) { return connection; } + public static void updateConnectionfromExternalJson(PublicizeConnection connection, JSONObject json) { + if (connection == null) { + return; + } + + connection.mExternalId = json.optString("external_ID"); + connection.mExternalName = json.optString("external_name"); + connection.mExternalProfilePictureUrl = json.optString("external_profile_picture"); + } + private static long[] getSitesArrayFromJson(JSONArray jsonArray) throws JSONException { long[] sitesArray = new long[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { From 5f0146ba5a0d43f7484763f5e5614620e6aa77a1 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 11:40:42 -0700 Subject: [PATCH 27/36] Using current connection --- .../ui/publicize/PublicizeAccountChooserDialogFragment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java index 68ad554e6b2f..2cf29cc0a88b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java @@ -162,11 +162,11 @@ private void addConnectionsToLists(String jsonString) { JSONArray externalJsonArray = currentConnectionJson.getJSONArray("additional_external_users"); for (int j = 0; j < externalJsonArray.length(); j++) { JSONObject currentExternalConnectionJson = externalJsonArray.getJSONObject(j); - PublicizeConnection externalConnection = PublicizeConnection.fromJson(currentExternalConnectionJson); + PublicizeConnection.updateConnectionfromExternalJson(connection, currentExternalConnectionJson); if (connection.isInSite(mSite.getSiteId())) { - mConnectedAccounts.add(externalConnection); + mConnectedAccounts.add(connection); } else { - mNotConnectedAccounts.add(externalConnection); + mNotConnectedAccounts.add(connection); } } } From d9642e1374ac5c378c8597277a2faa5a9e56d5a2 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 11:40:54 -0700 Subject: [PATCH 28/36] Changing around the order for selection of name --- .../ui/publicize/PublicizeAccountChooserListAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserListAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserListAdapter.java index 7ebe8eeba0ed..613917010bc5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserListAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserListAdapter.java @@ -84,10 +84,10 @@ public interface OnPublicizeAccountChooserListener { } private String getName(PublicizeConnection connection) { - String name = connection.getExternalDisplayName(); + String name = connection.getExternalName(); if (name.isEmpty()) { - name = connection.getExternalName(); + name = connection.getExternalDisplayName(); } return name; From f4bc277162ec901e21ab132b9d1c2dbcabbcc904 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 12:18:54 -0700 Subject: [PATCH 29/36] Adding externalUserId as a parameter to pass to the server --- .../publicize/PublicizeAccountChooserDialogFragment.java | 3 ++- .../wordpress/android/ui/publicize/PublicizeActions.java | 5 +++-- .../wordpress/android/ui/publicize/PublicizeEvents.java | 8 +++++++- .../android/ui/publicize/PublicizeListActivity.java | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java index 2cf29cc0a88b..a79e83fe330a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java @@ -106,8 +106,9 @@ public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); int keychainId = mNotConnectedAccounts.get(mSelectedIndex).connectionId; String service = mNotConnectedAccounts.get(mSelectedIndex).getService(); + String externalUserId = mNotConnectedAccounts.get(mSelectedIndex).getExternalId(); EventBus.getDefault().post(new PublicizeEvents.ActionAccountChosen(mSite.getSiteId(), keychainId, - service)); + service, externalUserId)); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java index d6208b114760..7459a1d72351 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java @@ -93,7 +93,7 @@ public void onResponse(JSONObject jsonObject) { .post(new PublicizeEvents.ActionRequestChooseAccount(siteId, serviceId, jsonObject)); } else { long keyringConnectionId = parseServiceKeyringId(serviceId, currentUserId, jsonObject); - connectStepTwo(siteId, keyringConnectionId, serviceId); + connectStepTwo(siteId, keyringConnectionId, serviceId, ""); } } }; @@ -113,7 +113,7 @@ public void onErrorResponse(VolleyError volleyError) { * step two in creating a publicize connection: now that we have the keyring connection id, * create the actual connection */ - public static void connectStepTwo(final long siteId, long keyringConnectionId, final String serviceId) { + public static void connectStepTwo(final long siteId, long keyringConnectionId, final String serviceId, final String externalUserId) { RestRequest.Listener listener = new RestRequest.Listener() { @Override public void onResponse(JSONObject jsonObject) { @@ -133,6 +133,7 @@ public void onErrorResponse(VolleyError volleyError) { Map params = new HashMap<>(); params.put("keyring_connection_ID", Long.toString(keyringConnectionId)); + params.put("external_user_ID", externalUserId); String path = String.format(Locale.ROOT, "/sites/%d/publicize-connections/new", siteId); WordPress.getRestClientUtilsV1_1().post(path, params, null, listener, errorListener); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeEvents.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeEvents.java index 847c82706dfb..d3b9b522dd80 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeEvents.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeEvents.java @@ -42,11 +42,13 @@ public static class ActionAccountChosen { private long mSiteId; private int mKeychainId; private String mService; + private String mExternalUserId; - public ActionAccountChosen(long siteId, int keychainId, String service) { + public ActionAccountChosen(long siteId, int keychainId, String service, String externalUserId) { mSiteId = siteId; mKeychainId = keychainId; mService = service; + mExternalUserId = externalUserId; } public long getSiteId() { @@ -60,6 +62,10 @@ public int getKeychainId() { public String getService() { return mService; } + + public String getExternalUserId() { + return mExternalUserId; + } } public static class ActionRequestChooseAccount { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java index 28aa5ddd2afd..1e9df6f7f095 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java @@ -323,7 +323,7 @@ public void onEventMainThread(PublicizeEvents.ActionAccountChosen event) { return; } - PublicizeActions.connectStepTwo(event.getSiteId(), event.getKeychainId(), event.getService()); + PublicizeActions.connectStepTwo(event.getSiteId(), event.getKeychainId(), event.getService(), event.getExternalUserId()); mProgressDialog = new ProgressDialog(this); mProgressDialog.setMessage(getString(R.string.connecting_account)); mProgressDialog.show(); From d0b4d5688299eab0eb6ee310da73a1f92a2b86ff Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 16:34:30 -0700 Subject: [PATCH 30/36] Resetting the table if it exists instead of modifying it --- .../java/org/wordpress/android/WordPressDB.java | 2 +- .../android/datasets/PublicizeTable.java | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/WordPressDB.java b/WordPress/src/main/java/org/wordpress/android/WordPressDB.java index 75985e22c3b8..d9cde803df80 100755 --- a/WordPress/src/main/java/org/wordpress/android/WordPressDB.java +++ b/WordPress/src/main/java/org/wordpress/android/WordPressDB.java @@ -173,7 +173,7 @@ public WordPressDB(Context ctx) { mDb.execSQL(SiteSettingsModel.ADD_SITE_ICON); case 65: // add external users only to publicize services table - mDb.execSQL(PublicizeTable.ADD_EXTERNAL_USERS_ONLY); + PublicizeTable.resetServicesTable(mDb); } mDb.setVersion(DATABASE_VERSION); } diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java index 11bc1bf07fb2..8f9405481d5b 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -16,11 +16,7 @@ public class PublicizeTable { private static final String SERVICES_TABLE = "tbl_publicize_services"; private static final String CONNECTIONS_TABLE = "tbl_publicize_connections"; - private static final String IS_EXTERNAL_USERS_ONLY_COLUMN_NAME = "is_external_users_only"; - - public static final String ADD_EXTERNAL_USERS_ONLY = "alter table " + SERVICES_TABLE - + " add " + IS_EXTERNAL_USERS_ONLY_COLUMN_NAME + " BOOLEAN;"; - + public static void createTables(SQLiteDatabase db) { db.execSQL("CREATE TABLE IF NOT EXISTS " + SERVICES_TABLE + " (" + " id TEXT NOT NULL COLLATE NOCASE," @@ -31,6 +27,7 @@ public static void createTables(SQLiteDatabase db) { + " connect_url TEXT NOT NULL," + " is_jetpack_supported INTEGER DEFAULT 0," + " is_multi_user_id_supported INTEGER DEFAULT 0," + + " is_external_users_only INTEGER DEFAULT 0," + " PRIMARY KEY (id))"); db.execSQL("CREATE TABLE IF NOT EXISTS " + CONNECTIONS_TABLE + " (" @@ -59,13 +56,8 @@ private static SQLiteDatabase getWritableDb() { return WordPress.wpDB.getDatabase(); } - /* - * for testing purposes - clears then recreates tables - */ - public static void reset() { - getWritableDb().execSQL("DROP TABLE IF EXISTS " + SERVICES_TABLE); - getWritableDb().execSQL("DROP TABLE IF EXISTS " + CONNECTIONS_TABLE); - createTables(getWritableDb()); + public static void resetServicesTable(SQLiteDatabase db) { + db.execSQL("DROP TABLE IF EXISTS " + SERVICES_TABLE); } public static PublicizeService getService(String serviceId) { From 69fbdc1245a4d3e79b4b6fae2fecd1c2a37117fd Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 16:37:14 -0700 Subject: [PATCH 31/36] Fixing check for if there are only external accounts --- .../org/wordpress/android/ui/publicize/PublicizeActions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java index 7459a1d72351..3876c156bd15 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java @@ -161,7 +161,7 @@ private static boolean shouldShowChooserDialog(long siteId, String serviceId, JS } if (PublicizeTable.onlyExternalConnections(serviceId)) { - return totalAccounts > 0; + return totalExternalAccounts > 0; } else { return totalAccounts > 0 || totalExternalAccounts > 0; } From 0737a3e11a42f2bd9e1e75ef7aa64313cfb347f0 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 16:37:34 -0700 Subject: [PATCH 32/36] Cleaning up space --- .../java/org/wordpress/android/datasets/PublicizeTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java index 8f9405481d5b..1a7ac2b0a120 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -16,7 +16,7 @@ public class PublicizeTable { private static final String SERVICES_TABLE = "tbl_publicize_services"; private static final String CONNECTIONS_TABLE = "tbl_publicize_connections"; - + public static void createTables(SQLiteDatabase db) { db.execSQL("CREATE TABLE IF NOT EXISTS " + SERVICES_TABLE + " (" + " id TEXT NOT NULL COLLATE NOCASE," From 4c80d6a1fc28c7f24693b16442bbade15e881e61 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 16:38:13 -0700 Subject: [PATCH 33/36] Fixing null check --- .../ui/publicize/PublicizeAccountChooserDialogFragment.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java index a79e83fe330a..bd94b7108075 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeAccountChooserDialogFragment.java @@ -178,6 +178,10 @@ private void addConnectionsToLists(String jsonString) { } private void configureConnectionName() { + if (mNotConnectedAccounts.isEmpty()) { + return; + } + PublicizeConnection connection = mNotConnectedAccounts.get(0); if (connection != null) { mConnectionName = connection.getLabel(); From 5f426545e29ea02de826fb89b47747720b952166 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 30 Jul 2018 21:45:49 -0300 Subject: [PATCH 34/36] fixed int to bool conversion for boolean columns in Publicize when reading from Cursor --- .../wordpress/android/datasets/PublicizeTable.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java index 11bc1bf07fb2..1d69a440aefb 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -138,6 +138,11 @@ public static void setServiceList(final PublicizeServiceList serviceList) { } } + private static boolean getBooleanFromCursor(Cursor cursor, String columnName) { + int columnIndex = cursor.getColumnIndex(columnName); + return columnIndex != -1 && cursor.getInt(columnIndex) != 0; + } + private static PublicizeService getServiceFromCursor(Cursor c) { PublicizeService service = new PublicizeService(); @@ -147,9 +152,9 @@ private static PublicizeService getServiceFromCursor(Cursor c) { service.setGenericon(c.getString(c.getColumnIndex("genericon"))); service.setIconUrl(c.getString(c.getColumnIndex("icon_url"))); service.setConnectUrl(c.getString(c.getColumnIndex("connect_url"))); - service.setIsJetpackSupported(SqlUtils.sqlToBool(c.getColumnIndex("is_jetpack_supported"))); - service.setIsMultiExternalUserIdSupported(SqlUtils.sqlToBool(c.getColumnIndex("is_multi_user_id_supported"))); - service.setIsExternalUsersOnly(SqlUtils.sqlToBool(c.getColumnIndex("is_external_users_only"))); + service.setIsJetpackSupported(getBooleanFromCursor(c, "is_jetpack_supported")); + service.setIsMultiExternalUserIdSupported(getBooleanFromCursor(c, "is_multi_user_id_supported")); + service.setIsExternalUsersOnly(getBooleanFromCursor(c, "is_external_users_only")); return service; } From 81edf5d2770796273540dde77614f6d8f8880347 Mon Sep 17 00:00:00 2001 From: Mario Zorz Date: Mon, 30 Jul 2018 22:03:14 -0300 Subject: [PATCH 35/36] fixed line lengths and unused imports --- .../android/models/PublicizeServiceList.java | 29 ++++++++++--------- .../ui/publicize/PublicizeActions.java | 3 +- .../ui/publicize/PublicizeDetailFragment.java | 2 -- .../ui/publicize/PublicizeListActivity.java | 3 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java b/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java index 5f5db9a7f9bc..f56e2d2767b2 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeServiceList.java @@ -41,20 +41,21 @@ public boolean isSameAs(PublicizeServiceList otherList) { * passed JSON is the response from /meta/external-services?type=publicize "services": { "facebook":{ - "ID":"facebook", - "label":"Facebook", - "type":"publicize", - "description":"Publish your posts to your Facebook timeline or page.", - "genericon":{ - "class":"facebook-alt", - "unicode":"\\f203" - }, - "icon":"http:\/\/i.wordpress.com\/wp-content\/admin-plugins\/publicize\/assets\/publicize-fb-2x.png", - "connect_URL":"https:\/\/public-api.wordpress.com\/connect\/?action=request&kr_nonce=a1e2ad2b80&nonce=c4b69a25c1&for=connect&service=facebook&kr_blog_nonce=0ae2027be9&magic=keyring&blog=90298630", - "multiple_external_user_ID_support":true, - "external_users_only":true, - "jetpack_support":true, - "jetpack_module_required":"publicize" + "ID":"facebook", + "label":"Facebook", + "type":"publicize", + "description":"Publish your posts to your Facebook timeline or page.", + "genericon":{ + "class":"facebook-alt", + "unicode":"\\f203" + }, + "icon":"http:\/\/i.wordpress.com\/wp-content\/admin-plugins\/publicize\/assets\/publicize-fb-2x.png", + "connect_URL":"https:\/\/public-api.wordpress.com\/connect\/?action=request&kr_nonce=a1e2ad2b80 + &nonce=c4b69a25c1&for=connect&service=facebook&kr_blog_nonce=0ae2027be9&magic=keyring&blog=90298630", + "multiple_external_user_ID_support":true, + "external_users_only":true, + "jetpack_support":true, + "jetpack_module_required":"publicize" }, ... */ diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java index 3876c156bd15..d8dedddf71b1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java @@ -113,7 +113,8 @@ public void onErrorResponse(VolleyError volleyError) { * step two in creating a publicize connection: now that we have the keyring connection id, * create the actual connection */ - public static void connectStepTwo(final long siteId, long keyringConnectionId, final String serviceId, final String externalUserId) { + public static void connectStepTwo(final long siteId, long keyringConnectionId, + final String serviceId, final String externalUserId) { RestRequest.Listener listener = new RestRequest.Listener() { @Override public void onResponse(JSONObject jsonObject) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java index 5f9910b76f42..dd5d8484b703 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeDetailFragment.java @@ -2,13 +2,11 @@ import android.os.Bundle; import android.support.annotation.NonNull; -import android.support.v7.widget.AppCompatButton; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import android.widget.Button; import android.widget.TextView; import org.wordpress.android.R; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java index 1e9df6f7f095..6298a6a2ede1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java @@ -323,7 +323,8 @@ public void onEventMainThread(PublicizeEvents.ActionAccountChosen event) { return; } - PublicizeActions.connectStepTwo(event.getSiteId(), event.getKeychainId(), event.getService(), event.getExternalUserId()); + PublicizeActions.connectStepTwo(event.getSiteId(), event.getKeychainId(), + event.getService(), event.getExternalUserId()); mProgressDialog = new ProgressDialog(this); mProgressDialog.setMessage(getString(R.string.connecting_account)); mProgressDialog.show(); From b620788b3669e4ba38cfee2b06a6d914ee15a4c0 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Mon, 30 Jul 2018 18:09:33 -0700 Subject: [PATCH 36/36] Adding the external_user_ID parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit conditionally if it’s not empty --- .../org/wordpress/android/ui/publicize/PublicizeActions.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java index d8dedddf71b1..e46e5875645d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeActions.java @@ -134,7 +134,9 @@ public void onErrorResponse(VolleyError volleyError) { Map params = new HashMap<>(); params.put("keyring_connection_ID", Long.toString(keyringConnectionId)); - params.put("external_user_ID", externalUserId); + if (!externalUserId.isEmpty()) { + params.put("external_user_ID", externalUserId); + } String path = String.format(Locale.ROOT, "/sites/%d/publicize-connections/new", siteId); WordPress.getRestClientUtilsV1_1().post(path, params, null, listener, errorListener); }