Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
605d313
Always showing connect button
May 9, 2016
b29c690
Configure connect button for adding another account
May 9, 2016
3f372fb
Move Connect button below RecyclerView
kwonye May 9, 2016
a564f54
Always clear cookies before loading the connect url
kwonye May 10, 2016
2940999
Removing unused visibility and app namespace
kwonye May 10, 2016
584f42f
Updating support library as its required to address a RecyclerView bug
kwonye May 10, 2016
d4efbf9
making RelativeLayout full height so that the empty text will be in t…
kwonye May 10, 2016
c1fbe49
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye May 12, 2016
abc0f60
Updating to support library 23.4.0
kwonye May 11, 2016
a5f711c
Moving the removal of cookies to a Utility class and calling when fra…
kwonye May 12, 2016
ea12ec2
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye May 12, 2016
068a6cf
Change minSdkVersion to 16 so that ImageView.setImgAlpha() can be called
kwonye May 12, 2016
a925ce7
Clearing cookies after connection request
kwonye May 16, 2016
a7ebbeb
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye May 16, 2016
9854084
Only getting keyringConnectionId automatically if there is one account
kwonye May 17, 2016
cf54dde
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye May 17, 2016
f613d9c
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jun 10, 2016
8fab135
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jun 17, 2016
2b69fb1
Making connectStepTwo public so that it can be called after the user …
kwonye Jun 19, 2016
26e60b1
Instead of picking the first one, we have the user pick the correct a…
kwonye Jun 19, 2016
aced5a6
If we receive the "choose account" action, we show a chooser dialog
kwonye Jun 19, 2016
3dcf16b
Adding JSONObject handling so that the dialog can use the list
kwonye Jun 20, 2016
f8acfd6
Showing Publicize Account Chooser Dialog when there are multiple acco…
kwonye Jun 20, 2016
59f21b1
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jun 22, 2016
dd64a50
Removing JSONObject parameter/variable in ActionCompleted
kwonye Jun 22, 2016
bd98cbd
Reverting back to this method listening to all connectaction events
kwonye Jun 22, 2016
f460e1f
Removing unnecessary onStop() override
kwonye Jun 22, 2016
9187d49
Adding new Event, ConnectionChooserRequired with an array of Connecti…
kwonye Jun 22, 2016
0084d10
All logic has been removed from this class for parsing out the json. …
kwonye Jun 22, 2016
b38cdb0
Adding title/message/listview of layout
kwonye Jun 23, 2016
c4c844c
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jun 23, 2016
c17ea77
enabling data binding
kwonye Jun 24, 2016
2df394c
Using the new PublicizeEvent of ConnectionChooserRequired when there …
kwonye Jun 24, 2016
19da55a
Retrieving list item binding from data binder
kwonye Jun 24, 2016
45a7d82
Chaging member variables to not have the m prefix as data binding req…
kwonye Jun 24, 2016
2ea590e
Data-binding list item for publicize connections
kwonye Jun 24, 2016
444a417
Adding connection variable for data binding
kwonye Jun 24, 2016
04d0a93
Adding connections member variable to DialogFragment
kwonye Jun 25, 2016
5b7bf40
Using ListAdapter that has list of Connections
kwonye Jun 25, 2016
eb0efa3
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jun 25, 2016
210ee14
Converting PublicizeAccountChooserListAdapter to extend from ArrayAda…
kwonye Jun 25, 2016
2c32735
Removing data binding
kwonye Jun 25, 2016
effbe76
Changing type to image so that it isn't rounded
kwonye Jun 25, 2016
2f62473
Adding the sites that the connection is connected to
kwonye Jun 25, 2016
f23c4cb
Adding sites from JSON object
kwonye Jun 25, 2016
33a04df
Deleting Connection model and using PublicizeConnection
kwonye Jun 25, 2016
1e1e7f8
Adding connected/not_connected boolean parameter for whether or not t…
kwonye Jun 25, 2016
7622a08
Removing <layout> item since we removed data binding
kwonye Jun 26, 2016
3173a52
Splitting listview into two that show connected and not connected yet…
kwonye Jun 26, 2016
cd08570
Removing unnecessary line in gradle
kwonye Jun 26, 2016
1e1dd89
Converting connected/not connected accounts to arraylists
kwonye Jun 26, 2016
b0e4fb5
Removing errant ArrayAdapter
kwonye Jun 26, 2016
3c9bc21
Close web fragment before showing chooser
kwonye Jun 26, 2016
593a98b
Shortcut that allows me not to sign in every time
kwonye Jun 26, 2016
8451485
Having the RadioButton pass the click to the LinearLayout
kwonye Jun 26, 2016
41b46e2
Adding CheckableLinearLayout that implements Checkable
kwonye Jun 28, 2016
0be8d1c
Converting to RecyclerViewAdapter
kwonye Jun 28, 2016
22bd7b0
Putting ids on top
kwonye Jun 28, 2016
a4e9e4c
Removing checkablelinearlayout
kwonye Jun 28, 2016
601ae7b
Using the new RecyclerViews
kwonye Jun 28, 2016
acff3b9
Adding message about social network
kwonye Jun 28, 2016
6286f75
Using external display name instead of just name
kwonye Jun 28, 2016
a7d0890
Adding current social network
kwonye Jun 28, 2016
a3b2822
Dismissing after connection request
kwonye Jun 28, 2016
5f94382
Using connection id (which is same as keychain id)
kwonye Jun 28, 2016
7a6d437
Fixing padding and using message/title
kwonye Jun 28, 2016
0b3e9a1
formatting styles
kwonye Jun 28, 2016
04b017c
Adding divider view in Connected dialog
kwonye Jun 28, 2016
e5a0642
Passing back selected index in case no one clicks anything
kwonye Jun 28, 2016
0852afe
Showing progress dialog when adding new account
kwonye Jun 29, 2016
de45ef3
Sending request
kwonye Jun 29, 2016
3cb5679
Sending onRequestConnect when clicking button
kwonye Jun 29, 2016
0862b84
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jun 29, 2016
d98c8a7
Showing toast when cancelling
kwonye Jun 29, 2016
bff28c8
Converting logic so that progress dialog can be shown
kwonye Jun 29, 2016
23b4fe9
Removing extra spaces
kwonye Jun 29, 2016
5472f16
Cleaning up class. No functional changes.
kwonye Jun 29, 2016
77d349e
Removing unused CHOOSE_ACCOUNT enum value
kwonye Jun 29, 2016
6e78728
Removing unused method
kwonye Jun 29, 2016
453f9a9
Renaming class to be consistent with the rest
kwonye Jun 29, 2016
da270a8
Converting magic strings
kwonye Jun 29, 2016
d1cb875
Cleaning up strings/dimension
kwonye Jun 29, 2016
5773983
Can't use same linearLayoutManager for two recyclerviews
kwonye Jun 29, 2016
ccab771
Passing in JSONObject as String args to PublicizeAccountChooserDialog…
kwonye Jun 29, 2016
30c4149
Making sure only the correct type of account is connected
kwonye Jun 29, 2016
2a145e5
Only showing connection dialog if there is at least one unconnected s…
kwonye Jun 29, 2016
30e0989
Hiding connected text if there are no connected accounts
kwonye Jul 5, 2016
e22d218
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jul 5, 2016
73a5503
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jul 7, 2016
a6b15f9
Merge branch 'feature/sharing-master' into feature/4071-sharing-multi…
kwonye Jul 10, 2016
c5c7d90
Fixing resource that is being hidden
kwonye Jul 13, 2016
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
1 change: 0 additions & 1 deletion WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }

}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.support.annotation.NonNull;
import android.text.TextUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wordpress.android.util.JSONUtils;
import org.wordpress.android.util.StringUtils;
Expand Down Expand Up @@ -39,6 +41,7 @@ public String toString() {
private String mExternalName;
private String mExternalDisplayName;
private String mExternalProfilePictureUrl;
private int[] mSites;

// `status` can be `ok` or `broken` -- `broken` means the connection needs to be re-established via the `refresh_URL`
private String mStatus;
Expand Down Expand Up @@ -136,6 +139,24 @@ public boolean isSameAs(PublicizeConnection other) {
&& other.getService().equals(this.getService());
}

public void setSites(int[] sites) {
mSites = sites;
}

public int[] getSites() {
return mSites;
}

public boolean isInSite(int siteId) {
for (int i = 0; i < mSites.length; i++) {
if (siteId == mSites[i]) {
return true;
}
}

return false;
}

/*
* passed JSON is a single connection from the response to sites/%d/publicize-connections
{"ID":12783250,
Expand Down Expand Up @@ -185,6 +206,23 @@ public static PublicizeConnection fromJson(JSONObject json) {
connection.mStatus = json.optString("status");
connection.mRefreshUrl = json.optString("refresh_URL");

try {
JSONArray jsonSitesArray = json.getJSONArray("sites");
connection.mSites = getSitesArrayFromJson(jsonSitesArray);
} catch (JSONException e) {
connection.mSites = new int[0];
e.printStackTrace();
}

return connection;
}

private static int[] getSitesArrayFromJson(JSONArray jsonArray) throws JSONException {
int[] sitesArray = new int[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
sitesArray[i] = jsonArray.getInt(i);
}

return sitesArray;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ private void updateView() {
textColorResId = R.color.white;
captionResId = R.string.share_btn_reconnect;
break;
case CONNECT_ANOTHER_ACCOUNT:
normalColorResId = R.color.blue_medium;
pressedColorResId = R.color.blue_light;
textColorResId = R.color.white;
captionResId = R.string.share_btn_connect_another_account;
break;
default:
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package org.wordpress.android.ui.publicize;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wordpress.android.R;
import org.wordpress.android.models.PublicizeConnection;
import org.wordpress.android.util.ToastUtils;

import java.util.ArrayList;

import de.greenrobot.event.EventBus;

public class PublicizeAccountChooserDialogFragment extends DialogFragment implements PublicizeAccountChooserListAdapter.OnPublicizeAccountChooserListener {
public static String TAG = "publicize-account-chooser-dialog-fragment";
private RecyclerView mNotConnectedRecyclerView;
private ArrayList<PublicizeConnection> mNotConnectedAccounts;
private ArrayList<PublicizeConnection> mConnectedAccounts;
private String mConnectionName = "";
private String mServiceId = "";
private int mSelectedIndex = 0;
private int mSiteId = 0;

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
retrieveCurrentSiteFromArgs();
configureConnectionName();

LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.publicize_account_chooser_dialog, null);

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
configureAlertDialog(view, builder);
configureRecyclerViews(view);

return builder.create();
}

@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
Activity activity = getActivity();
if (activity != null && activity instanceof DialogInterface.OnDismissListener) {
((DialogInterface.OnDismissListener) activity).onDismiss(dialog);
}
}

private void configureRecyclerViews(View view) {
PublicizeAccountChooserListAdapter notConnectedAdapter = new PublicizeAccountChooserListAdapter(mNotConnectedAccounts, this, false);
notConnectedAdapter.setHasStableIds(true);
mNotConnectedRecyclerView = (RecyclerView) view.findViewById(R.id.not_connected_recyclerview);
mNotConnectedRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mNotConnectedRecyclerView.setAdapter(notConnectedAdapter);

if (mConnectedAccounts.isEmpty()) {
hideConnectedView(view);
} else {
populateConnectedListView(view);
}
}

private void hideConnectedView(View view) {
LinearLayout connectedHeader = (LinearLayout) view.findViewById(R.id.connected_header);
connectedHeader.setVisibility(View.GONE);
}

private void populateConnectedListView(View view) {
RecyclerView listViewConnected = (RecyclerView) view.findViewById(R.id.connected_recyclerview);
PublicizeAccountChooserListAdapter connectedAdapter = new PublicizeAccountChooserListAdapter(mConnectedAccounts, null, true);

listViewConnected.setLayoutManager(new LinearLayoutManager(getActivity()));
listViewConnected.setAdapter(connectedAdapter);
}

private void configureAlertDialog(View view, AlertDialog.Builder builder) {
builder.setView(view);
builder.setTitle(getString(R.string.connecting_social_network, mConnectionName));
builder.setMessage(getString(R.string.connection_chooser_message));
builder.setPositiveButton(R.string.share_btn_connect, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
int keychainId = mNotConnectedAccounts.get(mSelectedIndex).connectionId;
EventBus.getDefault().post(new PublicizeEvents.ActionAccountChosen(mSiteId, keychainId));
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
ToastUtils.showToast(getActivity(), getActivity().getString(R.string.cannot_connect_account_error, mConnectionName));
}
});
}

private boolean containsSiteId(int[] array) {
for (int a : array) {
if (a == mSiteId) {
return true;
}
}

return false;
}

private void retrieveCurrentSiteFromArgs() {
Bundle args = getArguments();
if (args != null) {
mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID);
mServiceId = args.getString(PublicizeConstants.ARG_SERVICE_ID);
String jsonString = args.getString(PublicizeConstants.ARG_CONNECTION_ARRAY_JSON);
addConnectionsToLists(jsonString);
}
}

private void addConnectionsToLists(String jsonString) {
mNotConnectedAccounts = new ArrayList<>();
mConnectedAccounts = new ArrayList<>();
try {
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));
if (connection.getService().equals(mServiceId)) {
if (connection.isInSite(mSiteId)) {
mConnectedAccounts.add(connection);
} else {
mNotConnectedAccounts.add(connection);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}

private void configureConnectionName() {
PublicizeConnection connection = mNotConnectedAccounts.get(0);
if (connection != null) {
mConnectionName = connection.getLabel();
}
}

@Override
public void onAccountSelected(int selectedIndex) {
mSelectedIndex = selectedIndex;
mNotConnectedRecyclerView.getAdapter().notifyDataSetChanged();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.wordpress.android.ui.publicize;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

import org.wordpress.android.R;
import org.wordpress.android.models.PublicizeConnection;
import org.wordpress.android.widgets.WPNetworkImageView;

import java.util.List;

public class PublicizeAccountChooserListAdapter extends RecyclerView.Adapter<PublicizeAccountChooserListAdapter.ViewHolder> {
private List<PublicizeConnection> mConnectionItems;
private OnPublicizeAccountChooserListener mListener;
private boolean mAreAccountsConnected;
private int mSelectedPosition;

public PublicizeAccountChooserListAdapter(List<PublicizeConnection> connectionItems, OnPublicizeAccountChooserListener listener, boolean isConnected) {
mConnectionItems = connectionItems;
mListener = listener;
mAreAccountsConnected = isConnected;
mSelectedPosition = 0;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.publicize_connection_list_item, parent, false);

return new ViewHolder(view);
}

@Override
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.mRadioButton.setChecked(position == mSelectedPosition);

if (!mAreAccountsConnected) {
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mListener != null) {
mSelectedPosition = holder.getAdapterPosition();
mListener.onAccountSelected(mSelectedPosition);
}
}
});
} else {
holder.mRadioButton.setVisibility(View.INVISIBLE);
}
}

@Override
public int getItemCount() {
return mConnectionItems.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final RadioButton mRadioButton;
public final WPNetworkImageView mProfileImageView;
public final TextView mNameTextView;

public ViewHolder(View view) {
super(view);
mView = view;
mRadioButton = (RadioButton) view.findViewById(R.id.radio_button);
mProfileImageView = (WPNetworkImageView) view.findViewById(R.id.profile_pic);
mNameTextView = (TextView) view.findViewById(R.id.name);
}
}

public interface OnPublicizeAccountChooserListener {
void onAccountSelected(int selectedIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.wordpress.rest.RestRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.wordpress.android.WordPress;
import org.wordpress.android.datasets.PublicizeTable;
Expand Down Expand Up @@ -83,8 +84,13 @@ private static void connectStepOne(final int siteId, final String serviceId) {
RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
int keyringConnectionId = parseServiceKeyringId(serviceId, jsonObject);
connectStepTwo(siteId, keyringConnectionId);
if (shouldShowChooserDialog(siteId, serviceId, jsonObject)) {
// show dialog showing multiple options
EventBus.getDefault().post(new PublicizeEvents.ActionRequestChooseAccount(siteId, serviceId, jsonObject));
} else {
int keyringConnectionId = parseServiceKeyringId(serviceId, jsonObject);
connectStepTwo(siteId, keyringConnectionId);
}
}
};
RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {
Expand All @@ -103,7 +109,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
*/
private static void connectStepTwo(int siteId, int keyringConnectionId) {
public static void connectStepTwo(int siteId, int keyringConnectionId) {
RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
Expand All @@ -127,6 +133,28 @@ public void onErrorResponse(VolleyError volleyError) {
WordPress.getRestClientUtilsV1_1().post(path, params, null, listener, errorListener);
}

private static boolean shouldShowChooserDialog(int siteId, String serviceId, JSONObject jsonObject) {
JSONArray jsonConnectionList = jsonObject.optJSONArray("connections");
if (jsonConnectionList == null || jsonConnectionList.length() <= 1) {
return false;
}

int totalAccounts = 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++;
}
}

return totalAccounts > 0;
} catch (JSONException e) {
return false;
}
}

/*
* extract the keyring connection for the passed service from the response
* to /me/keyring-connections
Expand Down
Loading