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

Facebook Publicize disable selection of profiles #8115

Merged
merged 37 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b7a4134
Hide Facebook publicize option
kwonye Jul 11, 2018
194ee67
Reformat code with code style
kwonye Jul 12, 2018
cdde859
Adding notice and text for facebook deprecation
kwonye Jul 27, 2018
bf10084
Adding conditional view for facebook connections
kwonye Jul 27, 2018
1a6b0e3
Fixing conditional on whether to hide Google plus
kwonye Jul 27, 2018
8ceea99
Adding text to link to facebook sharing changes
kwonye Jul 27, 2018
cd51f2f
Adding new must_disconnect status for a connection
kwonye Jul 29, 2018
d3733e9
Making a constant
kwonye Jul 29, 2018
9b83ef9
Fixing formatting
kwonye Jul 29, 2018
9fee14f
Adding must_disconnect case for status
kwonye Jul 29, 2018
a947664
Adding additional fields from the JSON object response
kwonye Jul 29, 2018
3834d18
Updating table
kwonye Jul 29, 2018
ee2be5d
Creating the new model from services json
kwonye Jul 29, 2018
57e18e8
Resetting the publicize services table on update
kwonye Jul 29, 2018
51d9887
Removing extra semi-colon
kwonye Jul 29, 2018
4fdea8e
Revert "Updating table"
kwonye Jul 30, 2018
8d15e83
Only should hide google plus if it’s not already connected
kwonye Jul 30, 2018
70a0730
Setting the name from either the display or normal name
kwonye Jul 30, 2018
e82db0b
Add table modification in DB
kwonye Jul 30, 2018
8d5c455
Determine if the service is external users only
kwonye Jul 30, 2018
edde2fb
Counting external accounts now
kwonye Jul 30, 2018
71bb66f
Removing multiple external user
kwonye Jul 30, 2018
18d252d
Cleaning up spaces
kwonye Jul 30, 2018
eaa792c
Only add non-external sites if there are multiple external sites
kwonye Jul 30, 2018
fddb151
Fixing typo
kwonye Jul 30, 2018
217f03c
Allowing an external connection to change items of a connection
kwonye Jul 30, 2018
5f0146b
Using current connection
kwonye Jul 30, 2018
d9642e1
Changing around the order for selection of name
kwonye Jul 30, 2018
f4bc277
Adding externalUserId as a parameter to pass to the server
kwonye Jul 30, 2018
d0b4d56
Resetting the table if it exists instead of modifying it
kwonye Jul 30, 2018
69fbdc1
Fixing check for if there are only external accounts
kwonye Jul 30, 2018
0737a3e
Cleaning up space
kwonye Jul 30, 2018
4c80d6a
Fixing null check
kwonye Jul 30, 2018
5f42654
fixed int to bool conversion for boolean columns in Publicize when re…
mzorz Jul 31, 2018
2e78b52
Merge branch 'fix/facebook-publicize-aug-1' of https://github.com/wor…
mzorz Jul 31, 2018
81edf5d
fixed line lengths and unused imports
mzorz Jul 31, 2018
b620788
Adding the external_user_ID parameter
kwonye Jul 31, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -170,6 +171,9 @@ public WordPressDB(Context ctx) {
case 64:
// add site icon
mDb.execSQL(SiteSettingsModel.ADD_SITE_ICON);
case 65:
// add external users only to publicize services table
mDb.execSQL(PublicizeTable.ADD_EXTERNAL_USERS_ONLY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crashes when there is no pre-existent PublicizeTable. Apparently, it is only created when PublicizeListActivity is first visited here . We should add a check that the table exists before creating it, or force creating it before this step execution by calling PublicizeTable.createTables(mDb); right above this ALTER TABLE statement.

}
mDb.setVersion(DATABASE_VERSION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + " ("
Expand Down Expand Up @@ -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());
Expand All @@ -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();
}

Expand All @@ -143,10 +149,21 @@ 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;
}

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 "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public String toString() {
public String toString() {
return "broken";
}
},
MUST_DISCONNECT {
public String toString() {
return "must-disconnect";
}
}
}

Expand Down Expand Up @@ -126,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class PublicizeService {
private String mGenericon;
private String mIconUrl;
private String mConnectUrl;
private boolean mIsExternalUsersOnly;

private boolean mIsJetpackSupported;
private boolean mIsMultiExternalUserIdSupported;
Expand Down Expand Up @@ -77,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())
Expand All @@ -85,6 +94,7 @@ public boolean isSameAs(PublicizeService other) {
&& other.getGenericon().equals(this.getGenericon())
&& other.getIconUrl().equals(this.getIconUrl())
&& other.getConnectUrl().equals(this.getConnectUrl())
&& other.isExternalUsersOnly() == this.isExternalUsersOnly()
&& other.isJetpackSupported() == this.isJetpackSupported();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
...
*/
Expand Down Expand Up @@ -84,6 +83,7 @@ public static PublicizeServiceList fromJson(JSONObject json) {

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,12 +147,27 @@ 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);
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");
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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use TextUtils.isEmpty(name) here so we also have null as a possibility

name = connection.getExternalName();
}

return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be return totalExternalAccounts > 0?

} else {
return totalAccounts > 0 || totalExternalAccounts > 0;
}
} catch (JSONException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -22,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;

Expand Down Expand Up @@ -116,6 +122,22 @@ 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);

TextView learnMoreButton = (TextView) mServiceCardView.findViewById(R.id.learn_more_button);
learnMoreButton.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
WPWebViewActivity.openURL(getActivity(),
FACEBOOK_SHARING_CHANGE_BLOG_POST);
}
});
learnMoreButton.setVisibility(View.VISIBLE);
}
}

long currentUserId = mAccountStore.getAccount().getUserId();
Expand Down
Loading