From 1008e501e7a95e1c8d9090684673045b71b4dfee Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 3 May 2017 14:18:32 -0700 Subject: [PATCH 01/38] Fix merge issue that overwrote viewBlogSettings function --- .../org/wordpress/android/ui/ActivityLauncher.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java index 9641fd71add4..2bd6f4107ecf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java @@ -133,18 +133,6 @@ public static void viewCurrentBlogPeople(Context context, SiteModel site) { } public static void viewBlogSettingsForResult(Activity activity, SiteModel site) { - if (site == null) return; - public static void viewBlogSharing(Context context, Blog blog) { - if (blog == null) return; - - Intent intent = new Intent(context, PublicizeListActivity.class); - intent.putExtra(PublicizeConstants.ARG_SITE_ID, blog.getRemoteBlogId()); - context.startActivity(intent); - } - - public static void viewBlogSettingsForResult(Activity activity, Blog blog) { - if (blog == null) return; - Intent intent = new Intent(activity, BlogPreferencesActivity.class); intent.putExtra(WordPress.SITE, site); activity.startActivityForResult(intent, RequestCodes.SITE_SETTINGS); From f3635101bcf0a6fcd32a9423a2810d710bbeebb8 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 3 May 2017 14:21:32 -0700 Subject: [PATCH 02/38] Calling a new method for viewing Sharing screen with SiteModel instead of blog --- .../java/org/wordpress/android/ui/ActivityLauncher.java | 6 ++++++ .../java/org/wordpress/android/ui/main/MySiteFragment.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java index 2bd6f4107ecf..9a642e8667c3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java @@ -139,6 +139,12 @@ public static void viewBlogSettingsForResult(Activity activity, SiteModel site) AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.OPENED_BLOG_SETTINGS, site); } + public static void viewBlogSharing(Context context, SiteModel site) { + Intent intent = new Intent(context, PublicizeListActivity.class); + intent.putExtra(WordPress.SITE, site); + context.startActivity(intent); + } + public static void viewCurrentSite(Context context, SiteModel site, boolean openFromHeader) { if (site == null) { Toast.makeText(context, context.getText(R.string.blog_not_found), Toast.LENGTH_SHORT).show(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java index 9a8be4a5a6c0..4fd253ae4aa4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java @@ -249,7 +249,7 @@ public void onClick(View v) { mSharingView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - ActivityLauncher.viewBlogSharing(getActivity(), WordPress.getBlog(mBlogLocalId)); + ActivityLauncher.viewBlogSharing(getActivity(), getSelectedSite()); } }); From 343a833674a1c5a2f5aa09803184ef84d797bcec Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 3 May 2017 14:27:55 -0700 Subject: [PATCH 03/38] Retrieving siteId from SiteModel passed in --- .../java/org/wordpress/android/modules/AppComponent.java | 2 ++ .../android/ui/publicize/PublicizeListActivity.java | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java index 8ec33a36ede8..77a542f8bc44 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java @@ -62,6 +62,7 @@ import org.wordpress.android.ui.prefs.SiteSettingsFragment; import org.wordpress.android.ui.prefs.SiteSettingsInterface; import org.wordpress.android.ui.prefs.notifications.NotificationsSettingsFragment; +import org.wordpress.android.ui.publicize.PublicizeListActivity; import org.wordpress.android.ui.reader.ReaderCommentListActivity; import org.wordpress.android.ui.reader.ReaderPostDetailFragment; import org.wordpress.android.ui.reader.ReaderPostListFragment; @@ -148,6 +149,7 @@ public interface AppComponent { void inject(MediaGalleryEditFragment object); void inject(MediaGalleryPickerActivity object); void inject(MediaPreviewActivity object); + void inject(PublicizeListActivity object); void inject(EditPostActivity object); void inject(EditPostSettingsFragment object); 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 9e153077e892..5dd060d15b6e 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 @@ -15,9 +15,9 @@ 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.ui.ActivityLauncher; import org.wordpress.android.ui.prefs.SettingsFragment; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.services.PublicizeUpdateService; @@ -37,6 +37,8 @@ public class PublicizeListActivity extends AppCompatActivity @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ((WordPress) getApplication()).component().inject(this); + setContentView(R.layout.publicize_list_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); @@ -48,9 +50,11 @@ public void onCreate(Bundle savedInstanceState) { actionBar.setDisplayHomeAsUpEnabled(true); } + final SiteModel site; if (savedInstanceState == null) { + site = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); PublicizeTable.createTables(WordPress.wpDB.getDatabase()); - mSiteId = getIntent().getIntExtra(PublicizeConstants.ARG_SITE_ID, 0); + mSiteId = site.getId(); showListFragment(mSiteId); PublicizeUpdateService.updateConnectionsForSite(this, mSiteId); } else { From bc87343610aeb45c4e07a8f8ac9baf1cef964559 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 3 May 2017 15:10:11 -0700 Subject: [PATCH 04/38] Matching to develop branch --- .../ui/prefs/SiteSettingsFragment.java | 78 +++++++++++++++++-- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java index 1eb1880bfad3..86f2227a0072 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java @@ -8,9 +8,12 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.res.Resources; import android.os.Bundle; +import android.os.Handler; import android.preference.EditTextPreference; import android.preference.Preference; +import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.provider.ContactsContract; import android.support.annotation.NonNull; @@ -27,6 +30,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager.LayoutParams; import android.widget.AdapterView; @@ -90,6 +94,13 @@ public class SiteSettingsFragment extends PreferenceFragment public static final int RESULT_BLOG_REMOVED = Activity.RESULT_FIRST_USER; + /** + * Provides the regex to identify domain HTTP(S) protocol and/or 'www' sub-domain. + * + * Used to format user-facing {@link String}'s in certain preferences. + */ + public static final String ADDRESS_FORMAT_REGEX = "^(https?://(w{3})?|www\\.)"; + /** * url that points to wordpress.com purchases */ @@ -133,6 +144,9 @@ public class SiteSettingsFragment extends PreferenceFragment // Reference to the list of items being edited in the current list editor private List mEditingList; + // Used to ensure that settings are only fetched once throughout the lifecycle of the fragment + private boolean mShouldFetch; + // General settings private EditTextPreference mTitlePref; private EditTextPreference mTaglinePref; @@ -324,6 +338,22 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, + Bundle savedInstanceState) { + // use a wrapper to apply the Calypso theme + Context themer = new ContextThemeWrapper(getActivity(), R.style.Calypso_SiteSettingsTheme); + LayoutInflater localInflater = inflater.cloneInContext(themer); + View view = super.onCreateView(localInflater, container, savedInstanceState); + + if (view != null) { + setupPreferenceList((ListView) view.findViewById(android.R.id.list), getResources()); + } + + return view; + } + @Override public void onSaveInstanceState(Bundle outState) { removeMoreScreenToolbar(); @@ -338,6 +368,24 @@ public void onActivityCreated(Bundle savedInstanceState) { if (savedInstanceState != null) setupMorePreferenceScreen(); } + @Override + public void onChildViewAdded(View parent, View child) { + if (child.getId() == android.R.id.title && child instanceof TextView) { + // style preference category title views + TextView title = (TextView) child; + WPPrefUtils.layoutAsBody2(title); + } else { + // style preference title views + TextView title = (TextView) child.findViewById(android.R.id.title); + if (title != null) WPPrefUtils.layoutAsSubhead(title); + } + } + + @Override + public void onChildViewRemoved(View parent, View child) { + // NOP + } + @Override public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) { super.onPreferenceTreeClick(screen, preference); @@ -596,8 +644,7 @@ private void setupPreferenceList(ListView prefList, Resources res) { /** * Helper method to retrieve {@link Preference} references and initialize any data. */ - @Override - protected void initPreferences() { + private void initPreferences() { mTitlePref = (EditTextPreference) getChangePref(R.string.pref_key_site_title); mTaglinePref = (EditTextPreference) getChangePref(R.string.pref_key_site_tagline); mAddressPref = (EditTextPreference) getChangePref(R.string.pref_key_site_address); @@ -664,7 +711,6 @@ protected void initPreferences() { getLabelForImageQualityValue(mSiteSettings.getImageQuality())); } - @Override public void setEditingEnabled(boolean enabled) { // excludes mAddressPref, mMorePreference final Preference[] editablePreference = { @@ -963,11 +1009,6 @@ private void setPreferencesFromSiteSettings() { mBlacklistPref.setSummary(mSiteSettings.getBlacklistDescription()); } - @Override - protected void addPreferencesFromResource() { - addPreferencesFromResource(R.xml.site_settings); - } - private void setCategories() { // Ignore if there are no changes if (mSiteSettings.isSameCategoryList(mCategoryPref.getEntryValues())) { @@ -1036,6 +1077,27 @@ private void setReceivePingbacks(boolean newValue) { mReceivePingbacksNested.setChecked(newValue); } + private void setDetailListPreferenceValue(DetailListPreference pref, String value, String summary) { + pref.setValue(value); + pref.setSummary(summary); + pref.refreshAdapter(); + } + + /** + * Helper method to perform validation and set multiple properties on an EditTextPreference. + * If newValue is equal to the current preference text no action will be taken. + */ + private void changeEditTextPreferenceValue(EditTextPreference pref, String newValue) { + if (newValue == null || pref == null || pref.getEditText().isInEditMode()) return; + + if (!newValue.equals(pref.getSummary())) { + String formattedValue = StringUtils.unescapeHTML(newValue.replaceFirst(ADDRESS_FORMAT_REGEX, "")); + + pref.setText(formattedValue); + pref.setSummary(formattedValue); + } + } + /** * Detail strings for the dialog are generated in the selected language. * From bb83af6da69a0cda2ad8c8815de7bcf8bccfca64 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 3 May 2017 15:35:47 -0700 Subject: [PATCH 05/38] Removing fetching of account in PublicizeActions and adding a parameter instead that the WebViewFragment passes in --- .../android/ui/publicize/PublicizeActions.java | 13 +++++-------- .../ui/publicize/PublicizeWebViewFragment.java | 8 ++++++-- 2 files changed, 11 insertions(+), 10 deletions(-) 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 d42b15669f86..09d9cf0d7571 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 @@ -11,7 +11,6 @@ import org.json.JSONObject; import org.wordpress.android.WordPress; import org.wordpress.android.datasets.PublicizeTable; -import org.wordpress.android.models.AccountHelper; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.publicize.PublicizeConstants.ConnectAction; @@ -28,7 +27,6 @@ * API calls to connect/disconnect publicize services */ public class PublicizeActions { - public interface OnPublicizeActionListener { void onRequestConnect(PublicizeService service); void onRequestDisconnect(PublicizeConnection connection); @@ -66,21 +64,21 @@ public void onErrorResponse(VolleyError volleyError) { /* * create a new publicize service connection for a specific site */ - public static void connect(int siteId, String serviceId){ + public static void connect(int siteId, String serviceId, long currentUserId){ if (TextUtils.isEmpty(serviceId)) { AppLog.w(AppLog.T.SHARING, "cannot connect without service"); EventBus.getDefault().post(new ActionCompleted(false, ConnectAction.CONNECT)); return; } - connectStepOne(siteId, serviceId); + connectStepOne(siteId, serviceId, currentUserId); } /* * step one in creating a publicize connection: request the list of keyring connections * and find the one for the passed service */ - private static void connectStepOne(final int siteId, final String serviceId) { + private static void connectStepOne(final int siteId, final String serviceId, long currentUserId) { RestRequest.Listener listener = new RestRequest.Listener() { @Override public void onResponse(JSONObject jsonObject) { @@ -88,7 +86,7 @@ public void onResponse(JSONObject jsonObject) { // show dialog showing multiple options EventBus.getDefault().post(new PublicizeEvents.ActionRequestChooseAccount(siteId, serviceId, jsonObject)); } else { - int keyringConnectionId = parseServiceKeyringId(serviceId, jsonObject); + int keyringConnectionId = parseServiceKeyringId(serviceId, currentUserId, jsonObject); connectStepTwo(siteId, keyringConnectionId); } } @@ -159,13 +157,12 @@ private static boolean shouldShowChooserDialog(int siteId, String serviceId, JSO * extract the keyring connection for the passed service from the response * to /me/keyring-connections */ - private static int parseServiceKeyringId(String serviceId, JSONObject json) { + private static int parseServiceKeyringId(String serviceId, long currentUserId, JSONObject json) { JSONArray jsonConnectionList = json.optJSONArray("connections"); if (jsonConnectionList == null) { return 0; } - long currentUserId = AccountHelper.getDefaultAccount().getUserId(); for (int i = 0; i < jsonConnectionList.length(); i++) { JSONObject jsonConnection = jsonConnectionList.optJSONObject(i); String service = JSONUtils.getString(jsonConnection, "service"); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index afe7285e3948..5b2553161cf0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -15,6 +15,7 @@ import org.wordpress.android.R; import org.wordpress.android.datasets.PublicizeTable; +import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.AccountHelper; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeService; @@ -23,10 +24,12 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.WebViewUtils; +import javax.inject.Inject; + import de.greenrobot.event.EventBus; public class PublicizeWebViewFragment extends PublicizeBaseFragment { - + @Inject AccountStore mAccountStore; private int mSiteId; private String mServiceId; private int mConnectionId; @@ -173,8 +176,9 @@ public void onPageFinished(WebView view, String url) { return; } + long currentUserId = mAccountStore.getAccount().getUserId(); // call the endpoint to make the actual connection - PublicizeActions.connect(mSiteId, mServiceId); + PublicizeActions.connect(mSiteId, mServiceId, currentUserId); WebViewUtils.clearCookiesAsync(); } } From 439a184be2b4d62cb63a2ef7928287c8e5d9ce26 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 3 May 2017 15:57:47 -0700 Subject: [PATCH 06/38] Replacing use of AccountHelper with AccountStore --- .../ui/publicize/adapters/PublicizeConnectionAdapter.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java index e943dc4a24ba..b346877d5a28 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java @@ -9,7 +9,7 @@ import org.wordpress.android.R; import org.wordpress.android.datasets.PublicizeTable; -import org.wordpress.android.models.AccountHelper; +import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeConnectionList; import org.wordpress.android.ui.publicize.ConnectButton; @@ -19,12 +19,16 @@ import org.wordpress.android.util.StringUtils; import org.wordpress.android.widgets.WPNetworkImageView; +import javax.inject.Inject; + public class PublicizeConnectionAdapter extends RecyclerView.Adapter { public interface OnAdapterLoadedListener { void onAdapterLoaded(boolean isEmpty); } + @Inject AccountStore mAccountStore; + private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); private final int mSiteId; @@ -40,7 +44,7 @@ public PublicizeConnectionAdapter(Context context, int siteId, String serviceId) mSiteId = siteId; mAvatarSz = context.getResources().getDimensionPixelSize(R.dimen.avatar_sz_extra_small); mServiceId = StringUtils.notNullStr(serviceId); - mCurrentUserId = AccountHelper.getDefaultAccount().getUserId(); + mCurrentUserId = mAccountStore.getAccount().getUserId(); setHasStableIds(true); } From 4590c8f08b7c37eaa942041ede9b3d9fce4dde36 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Wed, 3 May 2017 15:58:46 -0700 Subject: [PATCH 07/38] Replacing WPButton with Button --- .../android/ui/publicize/PublicizeListFragment.java | 8 ++++---- WordPress/src/main/res/layout/publicize_list_fragment.xml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java index c5ef869dc19e..f95317d2b9be 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java @@ -6,6 +6,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.TextView; import org.wordpress.android.R; @@ -15,7 +16,6 @@ import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.widgets.RecyclerItemDecoration; -import org.wordpress.android.widgets.WPButton; public class PublicizeListFragment extends PublicizeBaseFragment { public interface PublicizeManageConnectionsListener { @@ -27,7 +27,7 @@ public interface PublicizeManageConnectionsListener { private PublicizeServiceAdapter mAdapter; private RecyclerView mRecycler; private TextView mEmptyView; - private WPButton mManageButton; + private Button mManageButton; public static PublicizeListFragment newInstance(int siteId) { Bundle args = new Bundle(); @@ -64,7 +64,7 @@ public void onResume() { } getAdapter().refresh(); setTitle(R.string.sharing); - setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); + setNavigationIcon(R.drawable.ic_arrow_left); } @Override @@ -79,7 +79,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa mRecycler = (RecyclerView) rootView.findViewById(R.id.recycler_view); mEmptyView = (TextView) rootView.findViewById(R.id.empty_view); - mManageButton = (WPButton) rootView.findViewById(R.id.manage_button); + mManageButton = (Button) rootView.findViewById(R.id.manage_button); int spacingHorizontal = 0; int spacingVertical = DisplayUtils.dpToPx(getActivity(), 1); diff --git a/WordPress/src/main/res/layout/publicize_list_fragment.xml b/WordPress/src/main/res/layout/publicize_list_fragment.xml index 6abf39a4b858..69ef07e237b1 100644 --- a/WordPress/src/main/res/layout/publicize_list_fragment.xml +++ b/WordPress/src/main/res/layout/publicize_list_fragment.xml @@ -51,7 +51,7 @@ android:textColor="@color/grey_dark" android:textSize="@dimen/text_sz_medium" /> - Date: Wed, 3 May 2017 16:02:01 -0700 Subject: [PATCH 08/38] Replacing use of AccountHelper with AccountStore --- .../ui/publicize/adapters/PublicizeServiceAdapter.java | 8 ++++++-- 1 file changed, 6 insertions(+), 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 51882010efe4..26008b0bc12f 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 @@ -13,7 +13,7 @@ import org.wordpress.android.R; import org.wordpress.android.datasets.PublicizeTable; -import org.wordpress.android.models.AccountHelper; +import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnectionList; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.models.PublicizeServiceList; @@ -23,6 +23,8 @@ import java.util.Collections; import java.util.Comparator; +import javax.inject.Inject; + public class PublicizeServiceAdapter extends RecyclerView.Adapter { public interface OnAdapterLoadedListener { @@ -32,6 +34,8 @@ public interface OnServiceClickListener { void onServiceClicked(PublicizeService service); } + @Inject AccountStore mAccountStore; + private final PublicizeServiceList mServices = new PublicizeServiceList(); private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); @@ -50,7 +54,7 @@ public PublicizeServiceAdapter(Context context, int siteId) { mSiteId = siteId; mBlavatarSz = context.getResources().getDimensionPixelSize(R.dimen.blavatar_sz_small); - mCurrentUserId = AccountHelper.getDefaultAccount().getUserId(); + mCurrentUserId = mAccountStore.getAccount().getUserId(); mColorConnected = context.getResources().getColor(R.color.grey_dark); mColorNotConnected = context.getResources().getColor(R.color.grey_lighten_10); From ed37a4f728ea3e063ab6982bcaeaf31bb49aed8c Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Thu, 4 May 2017 13:44:50 -0700 Subject: [PATCH 09/38] Converting the use of SettingsFragment to AccountSettingsFragment --- .../android/ui/prefs/SettingsFragment.java | 276 ------------------ .../ui/publicize/PublicizeListActivity.java | 6 - .../PublicizeManageConnectionsFragment.java | 4 +- 3 files changed, 2 insertions(+), 284 deletions(-) delete mode 100644 WordPress/src/main/java/org/wordpress/android/ui/prefs/SettingsFragment.java diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SettingsFragment.java deleted file mode 100644 index d1345b1aa9c8..000000000000 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SettingsFragment.java +++ /dev/null @@ -1,276 +0,0 @@ -package org.wordpress.android.ui.prefs; - -import android.app.Activity; -import android.app.Dialog; -import android.content.Context; -import android.content.res.Resources; -import android.os.Bundle; -import android.os.Handler; -import android.preference.EditTextPreference; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.support.annotation.NonNull; -import android.view.ContextThemeWrapper; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ListAdapter; -import android.widget.ListView; -import android.widget.TextView; - -import org.wordpress.android.R; -import org.wordpress.android.WordPress; -import org.wordpress.android.analytics.AnalyticsTracker; -import org.wordpress.android.models.Blog; -import org.wordpress.android.util.AnalyticsUtils; -import org.wordpress.android.util.CoreEvents; -import org.wordpress.android.util.NetworkUtils; -import org.wordpress.android.util.StringUtils; -import org.wordpress.android.util.ToastUtils; -import org.wordpress.android.util.WPPrefUtils; - -import java.util.HashMap; - -import de.greenrobot.event.EventBus; - -public abstract class SettingsFragment extends PreferenceFragment implements - ViewGroup.OnHierarchyChangeListener, - Preference.OnPreferenceChangeListener, - Preference.OnPreferenceClickListener, - AdapterView.OnItemLongClickListener, - SiteSettingsInterface.SiteSettingsListener { - protected abstract void initPreferences(); - protected abstract void setEditingEnabled(boolean enabled); - protected abstract void setPreferencesFromSiteSettings(); - protected abstract void addPreferencesFromResource(); - - /** - * Use this argument to pass the {@link Integer} local blog ID to this fragment. - */ - public static final String ARG_LOCAL_BLOG_ID = "local_blog_id"; - - /** - * Provides the regex to identify domain HTTP(S) protocol and/or 'www' sub-domain. - * - * Used to format user-facing {@link String}'s in certain preferences. - */ - public static final String ADDRESS_FORMAT_REGEX = "^(https?://(w{3})?|www\\.)"; - - private static final long FETCH_DELAY = 1000; - - protected SiteSettingsInterface mSiteSettings; - protected boolean mShouldFetch; - - // Reference to blog obtained from passed ID (ARG_LOCAL_BLOG_ID) - protected Blog mBlog; - - // Reference to the state of the fragment - protected boolean mIsFragmentPaused = false; - - protected boolean mEditingEnabled = true; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Activity activity = getActivity(); - - // make sure we have local site data and a network connection, otherwise finish activity - mBlog = WordPress.getBlog(getArguments().getInt(ARG_LOCAL_BLOG_ID, -1)); - if (mBlog == null || !NetworkUtils.checkConnection(activity)) { - getActivity().finish(); - return; - } - - // track successful settings screen access - AnalyticsUtils.trackWithCurrentBlogDetails( - AnalyticsTracker.Stat.SITE_SETTINGS_ACCESSED); - - // setup state to fetch remote settings - mShouldFetch = true; - - // initialize the appropriate settings interface (WP.com or WP.org) - mSiteSettings = SiteSettingsInterface.getInterface(activity, mBlog, this); - - setRetainInstance(true); - addPreferencesFromResource(); - - // toggle which preferences are shown and set references - initPreferences(); - } - - @Override - public void onResume() { - super.onResume(); - - // Fragment#onResume() is called after FragmentActivity#onPostResume(). - // The latter is the most secure way of keeping track of the activity's state, and avoid calls to commitAllowingStateLoss. - mIsFragmentPaused = false; - - // always load cached settings - mSiteSettings.init(false); - - if (mShouldFetch) { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - // initialize settings with locally cached values, fetch remote on first pass - mSiteSettings.init(true); - } - }, FETCH_DELAY); - // stop future calls from fetching remote settings - mShouldFetch = false; - } - } - - @Override - public void onPause() { - super.onPause(); - WordPress.wpDB.saveBlog(mBlog); - mIsFragmentPaused = true; - } - - @Override - public View onCreateView(@NonNull LayoutInflater inflater, - ViewGroup container, - Bundle savedInstanceState) { - // use a wrapper to apply the Calypso theme - Context themer = new ContextThemeWrapper(getActivity(), R.style.Calypso_SiteSettingsTheme); - LayoutInflater localInflater = inflater.cloneInContext(themer); - View view = super.onCreateView(localInflater, container, savedInstanceState); - - if (view != null) { - setupPreferenceList((ListView) view.findViewById(android.R.id.list), getResources()); - } - - return view; - } - - protected void setupPreferenceList(ListView prefList, Resources res) { - if (prefList == null || res == null) return; - - // customize list dividers - //noinspection deprecation - prefList.setDivider(res.getDrawable(R.drawable.preferences_divider)); - prefList.setDividerHeight(res.getDimensionPixelSize(R.dimen.site_settings_divider_height)); - // handle long clicks on preferences to display hints - prefList.setOnItemLongClickListener(this); - // required to customize (Calypso) preference views - prefList.setOnHierarchyChangeListener(this); - // remove footer divider bar - prefList.setFooterDividersEnabled(false); - //noinspection deprecation - prefList.setOverscrollFooter(res.getDrawable(R.color.transparent)); - } - - protected void setDetailListPreferenceValue(DetailListPreference pref, String value, String summary) { - pref.setValue(value); - pref.setSummary(summary); - pref.refreshAdapter(); - } - - protected boolean shouldShowListPreference(DetailListPreference preference) { - return preference != null && preference.getEntries() != null && preference.getEntries().length > 0; - } - - protected Preference getChangePref(int id) { - return WPPrefUtils.getPrefAndSetChangeListener(this, id, this); - } - - protected Preference getClickPref(int id) { - return WPPrefUtils.getPrefAndSetClickListener(this, id, this); - } - - /** - * Helper method to perform validation and set multiple properties on an EditTextPreference. - * If newValue is equal to the current preference text no action will be taken. - */ - protected void changeEditTextPreferenceValue(EditTextPreference pref, String newValue) { - if (newValue == null || pref == null || pref.getEditText().isInEditMode()) return; - - if (!newValue.equals(pref.getSummary())) { - String formattedValue = StringUtils.unescapeHTML(newValue.replaceFirst(ADDRESS_FORMAT_REGEX, "")); - - pref.setText(formattedValue); - pref.setSummary(formattedValue); - } - } - - @Override - public void onChildViewAdded(View parent, View child) { - if (child.getId() == android.R.id.title && child instanceof TextView) { - // style preference category title views - TextView title = (TextView) child; - WPPrefUtils.layoutAsBody2(title); - } else { - // style preference title views - TextView title = (TextView) child.findViewById(android.R.id.title); - if (title != null) WPPrefUtils.layoutAsSubhead(title); - } - } - - @Override - public void onChildViewRemoved(View parent, View child) { - // NOP - } - - @Override - public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { - ListView listView = (ListView) parent; - ListAdapter listAdapter = listView.getAdapter(); - Object obj = listAdapter.getItem(position); - - if (obj != null) { - if (obj instanceof View.OnLongClickListener) { - View.OnLongClickListener longListener = (View.OnLongClickListener) obj; - return longListener.onLongClick(view); - } else if (obj instanceof PreferenceHint) { - PreferenceHint hintObj = (PreferenceHint) obj; - if (hintObj.hasHint()) { - HashMap properties = new HashMap<>(); - properties.put("hint_shown", hintObj.getHint()); - AnalyticsUtils.trackWithCurrentBlogDetails( - AnalyticsTracker.Stat.SITE_SETTINGS_HINT_TOAST_SHOWN, properties); - ToastUtils.showToast(getActivity(), hintObj.getHint(), ToastUtils.Duration.SHORT); - } - return true; - } - } - - return false; - } - - @Override - public void onSettingsUpdated(Exception error) { - if (error != null) { - ToastUtils.showToast(getActivity(), R.string.error_fetch_remote_site_settings); - getActivity().finish(); - return; - } - - if (isAdded()) setPreferencesFromSiteSettings(); - } - - @Override - public void onCredentialsValidated(Exception error) { - if (error != null) { - ToastUtils.showToast(WordPress.getContext(), R.string.username_or_password_incorrect); - } - } - - @Override - public void onSettingsSaved(Exception error) { - if (error != null) { - ToastUtils.showToast(WordPress.getContext(), R.string.error_post_remote_site_settings); - return; - } - mBlog.setBlogName(mSiteSettings.getTitle()); - WordPress.wpDB.saveBlog(mBlog); - - // update the global current Blog so WordPress.getCurrentBlog() callers will get the updated object - WordPress.setCurrentBlog(mBlog.getLocalTableBlogId()); - - EventBus.getDefault().post(new CoreEvents.BlogListChanged()); - } -} 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 5dd060d15b6e..d409efe54aec 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 @@ -18,7 +18,6 @@ import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeService; -import org.wordpress.android.ui.prefs.SettingsFragment; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.services.PublicizeUpdateService; import org.wordpress.android.util.ToastUtils; @@ -298,12 +297,7 @@ public void onEventMainThread(PublicizeEvents.ActionRequestChooseAccount event) @Override public void onManageConnectionsClicked() { - int localBlogId = WordPress.wpDB.getLocalTableBlogIdForRemoteBlogId(mSiteId); - Bundle args = new Bundle(); - args.putInt(SettingsFragment.ARG_LOCAL_BLOG_ID, localBlogId); - PublicizeManageConnectionsFragment manageConnectionsFragment = new PublicizeManageConnectionsFragment(); - manageConnectionsFragment.setArguments(args); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, manageConnectionsFragment); fragmentTransaction.addToBackStack(null); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java index c907c6058711..9161d0a5d684 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java @@ -14,8 +14,8 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; import org.wordpress.android.models.PublicizeButton; +import org.wordpress.android.ui.prefs.AccountSettingsFragment; import org.wordpress.android.ui.prefs.DetailListPreference; -import org.wordpress.android.ui.prefs.SettingsFragment; import org.wordpress.android.ui.prefs.SummaryEditTextPreference; import org.wordpress.android.ui.prefs.WPSwitchPreference; import org.wordpress.android.util.AppLog; @@ -24,7 +24,7 @@ import java.util.HashSet; -public class PublicizeManageConnectionsFragment extends SettingsFragment { +public class PublicizeManageConnectionsFragment extends AccountSettingsFragment { private static final String TWITTER_PREFIX = "@"; private static final String SHARING_BUTTONS_KEY = "sharing_buttons"; public static final String TWITTER_ID = "twitter"; From 627eac5061b1a6cbbccdcc5e46a2c8b22a7abf27 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Thu, 4 May 2017 13:49:36 -0700 Subject: [PATCH 10/38] Using the accountStore to get info --- .../android/ui/publicize/PublicizeWebViewFragment.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index 5b2553161cf0..456d0555971d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -16,7 +16,6 @@ import org.wordpress.android.R; import org.wordpress.android.datasets.PublicizeTable; import org.wordpress.android.fluxc.store.AccountStore; -import org.wordpress.android.models.AccountHelper; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.WPWebViewActivity; @@ -141,9 +140,9 @@ private void loadConnectUrl() { String postData = WPWebViewActivity.getAuthenticationPostData( WPWebViewActivity.WPCOM_LOGIN_URL, connectUrl, - AccountHelper.getDefaultAccount().getUserName(), + mAccountStore.getAccount().getUserName(), "", - AccountHelper.getDefaultAccount().getAccessToken()); + mAccountStore.getAccessToken()); mWebView.postUrl(WPWebViewActivity.WPCOM_LOGIN_URL, postData.getBytes()); } From e3baa0390ff4b7aa59d68739f58d24c5ef308d8a Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Thu, 4 May 2017 13:54:26 -0700 Subject: [PATCH 11/38] Showing to .com sites only --- .../main/java/org/wordpress/android/ui/main/MySiteFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java index 4fd253ae4aa4..276be4581c38 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/MySiteFragment.java @@ -357,7 +357,7 @@ private void refreshSelectedSiteDetails() { mThemesContainer.setVisibility(themesVisibility); // sharing is only exposed for wp.com blogs - int sharingVisibility = blog.isDotcomFlag() ? View.VISIBLE : View.GONE; + int sharingVisibility = getSelectedSite().isWPCom() ? View.VISIBLE : View.GONE; mSharingView.setVisibility(sharingVisibility); // show settings for all self-hosted to expose Delete Site From 2c5521a64181b68ab284533173af4034b57f13f2 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Thu, 4 May 2017 14:16:13 -0700 Subject: [PATCH 12/38] Declaring parameter final --- .../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 09d9cf0d7571..cdc4a2e44f1a 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 @@ -78,7 +78,7 @@ public static void connect(int siteId, String serviceId, long currentUserId){ * step one in creating a publicize connection: request the list of keyring connections * and find the one for the passed service */ - private static void connectStepOne(final int siteId, final String serviceId, long currentUserId) { + private static void connectStepOne(final int siteId, final String serviceId, final long currentUserId) { RestRequest.Listener listener = new RestRequest.Listener() { @Override public void onResponse(JSONObject jsonObject) { From 8d8c0634e3306ab86d5ae87f27454354e27ae007 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Thu, 4 May 2017 14:16:52 -0700 Subject: [PATCH 13/38] Updating to use left --- .../wordpress/android/ui/publicize/PublicizeDetailFragment.java | 2 +- .../wordpress/android/ui/publicize/PublicizeListFragment.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 67ec98c401a6..ffbbe5ca2188 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 @@ -88,7 +88,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa public void onResume() { super.onResume(); loadData(); - setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); + setNavigationIcon(R.drawable.ic_arrow_left_white_24dp); } public void loadData() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java index f95317d2b9be..6c6f53eb9f92 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java @@ -64,7 +64,7 @@ public void onResume() { } getAdapter().refresh(); setTitle(R.string.sharing); - setNavigationIcon(R.drawable.ic_arrow_left); + setNavigationIcon(R.drawable.ic_arrow_left_white_24dp); } @Override From 78f98f5c812d98d2435232e81c36e964cdf08284 Mon Sep 17 00:00:00 2001 From: Will Kwon Date: Thu, 11 May 2017 12:47:29 -0700 Subject: [PATCH 14/38] Updating gradle plugin --- WordPress/build.gradle | 2 +- libs/analytics/WordPressAnalytics/build.gradle | 2 +- libs/editor/WordPressEditor/build.gradle | 2 +- libs/editor/example/build.gradle | 2 +- libs/networking/WordPressNetworking/build.gradle | 2 +- libs/utils/WordPressUtils/build.gradle | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 8af6774dfb2a..3556dcaf64aa 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -4,7 +4,7 @@ buildscript { maven { url 'https://maven.fabric.io/public' } } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:2.3.2' classpath 'io.fabric.tools:gradle:1.+' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } diff --git a/libs/analytics/WordPressAnalytics/build.gradle b/libs/analytics/WordPressAnalytics/build.gradle index de1c3d8c6a72..e4a4b60ed3e7 100644 --- a/libs/analytics/WordPressAnalytics/build.gradle +++ b/libs/analytics/WordPressAnalytics/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:2.3.2' } } diff --git a/libs/editor/WordPressEditor/build.gradle b/libs/editor/WordPressEditor/build.gradle index 5e9b90c79ad6..8d05060bae0c 100644 --- a/libs/editor/WordPressEditor/build.gradle +++ b/libs/editor/WordPressEditor/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:2.3.2' } } diff --git a/libs/editor/example/build.gradle b/libs/editor/example/build.gradle index 6deb8f034249..7dd3e256a5b4 100644 --- a/libs/editor/example/build.gradle +++ b/libs/editor/example/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:2.3.2' } } diff --git a/libs/networking/WordPressNetworking/build.gradle b/libs/networking/WordPressNetworking/build.gradle index 669a83a8465a..c1d4ee978116 100644 --- a/libs/networking/WordPressNetworking/build.gradle +++ b/libs/networking/WordPressNetworking/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:2.3.2' } } diff --git a/libs/utils/WordPressUtils/build.gradle b/libs/utils/WordPressUtils/build.gradle index 367730e2f5ec..f73f29476561 100644 --- a/libs/utils/WordPressUtils/build.gradle +++ b/libs/utils/WordPressUtils/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:2.3.2' classpath 'com.novoda:bintray-release:0.3.4' } } From 0107fcf2bd725a75f9556cfb7ca4f3531354c3f6 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 14:35:26 -0400 Subject: [PATCH 15/38] Pass site to PublicizeManageConnectionsFragment --- .../ui/publicize/PublicizeListActivity.java | 15 ++++++------ .../PublicizeManageConnectionsFragment.java | 24 ++++++++++++++++--- 2 files changed, 29 insertions(+), 10 deletions(-) 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 d409efe54aec..414fccd9ff45 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 @@ -31,6 +31,7 @@ public class PublicizeListActivity extends AppCompatActivity PublicizeListFragment.PublicizeManageConnectionsListener { private int mSiteId; + private SiteModel mSite; private ProgressDialog mProgressDialog; @Override @@ -49,22 +50,22 @@ public void onCreate(Bundle savedInstanceState) { actionBar.setDisplayHomeAsUpEnabled(true); } - final SiteModel site; if (savedInstanceState == null) { - site = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); + mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); PublicizeTable.createTables(WordPress.wpDB.getDatabase()); - mSiteId = site.getId(); showListFragment(mSiteId); PublicizeUpdateService.updateConnectionsForSite(this, mSiteId); } else { - mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); + mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); } + + mSiteId = mSite.getId(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(PublicizeConstants.ARG_SITE_ID, mSiteId); + outState.putSerializable(WordPress.SITE, mSite); } @Override @@ -297,9 +298,9 @@ public void onEventMainThread(PublicizeEvents.ActionRequestChooseAccount event) @Override public void onManageConnectionsClicked() { - PublicizeManageConnectionsFragment manageConnectionsFragment = new PublicizeManageConnectionsFragment(); + PublicizeManageConnectionsFragment fragment = PublicizeManageConnectionsFragment.newInstance(mSite); FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); - fragmentTransaction.replace(R.id.fragment_container, manageConnectionsFragment); + fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java index 9161d0a5d684..b0a59b0aad39 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java @@ -1,9 +1,11 @@ package org.wordpress.android.ui.publicize; +import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.MultiSelectListPreference; import android.preference.Preference; import android.preference.PreferenceCategory; +import android.support.annotation.NonNull; import com.android.volley.VolleyError; import com.wordpress.rest.RestRequest; @@ -13,12 +15,14 @@ import org.json.JSONObject; import org.wordpress.android.R; import org.wordpress.android.WordPress; +import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.models.PublicizeButton; import org.wordpress.android.ui.prefs.AccountSettingsFragment; import org.wordpress.android.ui.prefs.DetailListPreference; import org.wordpress.android.ui.prefs.SummaryEditTextPreference; import org.wordpress.android.ui.prefs.WPSwitchPreference; import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.ToastUtils; import java.util.ArrayList; import java.util.HashSet; @@ -40,7 +44,21 @@ public class PublicizeManageConnectionsFragment extends AccountSettingsFragment private PreferenceCategory mTwitterPreferenceCategory; private ArrayList mPublicizeButtons; - public PublicizeManageConnectionsFragment() { + private SiteModel mSite; + + public static PublicizeManageConnectionsFragment newInstance(@NonNull SiteModel site) { + PublicizeManageConnectionsFragment fragment = new PublicizeManageConnectionsFragment(); + Bundle args = new Bundle(); + args.putSerializable(WordPress.SITE, site); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + mSite = (SiteModel) getArguments().getSerializable(WordPress.SITE); } private void saveSharingButtons(HashSet values, boolean isVisible) { @@ -66,7 +84,7 @@ private void saveSharingButtons(HashSet values, boolean isVisible) { e.printStackTrace(); } - WordPress.getRestClientUtilsV1_1().setSharingButtons(mBlog.getDotComBlogId(), jsonObject, new RestRequest.Listener() { + WordPress.getRestClientUtilsV1_1().setSharingButtons(Long.toString(mSite.getSiteId()), jsonObject, new RestRequest.Listener() { @Override public void onResponse(JSONObject response) { try { @@ -115,7 +133,7 @@ private void configureSharingAndMoreButtonsPreferences() { mPublicizeButtons = new ArrayList<>(); mSharingButtonsPreference = (MultiSelectListPreference) getChangePref(R.string.pref_key_sharing_buttons); mMoreButtonsPreference = (MultiSelectListPreference) getChangePref(R.string.pref_key_more_buttons); - WordPress.getRestClientUtilsV1_1().getSharingButtons(mBlog.getDotComBlogId(), new RestRequest.Listener() { + WordPress.getRestClientUtilsV1_1().getSharingButtons(Long.toString(mSite.getSiteId()), new RestRequest.Listener() { @Override public void onResponse(JSONObject response) { try { From 8593aca8600b2d5f8ec10e04fc5cf8cf92f67f15 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 14:36:49 -0400 Subject: [PATCH 16/38] Remove mSiteId from PublicizeListActivity --- .../android/ui/publicize/PublicizeListActivity.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 414fccd9ff45..f4e0b561acb0 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 @@ -30,7 +30,6 @@ public class PublicizeListActivity extends AppCompatActivity PublicizeServiceAdapter.OnServiceClickListener, PublicizeListFragment.PublicizeManageConnectionsListener { - private int mSiteId; private SiteModel mSite; private ProgressDialog mProgressDialog; @@ -53,13 +52,11 @@ public void onCreate(Bundle savedInstanceState) { if (savedInstanceState == null) { mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); PublicizeTable.createTables(WordPress.wpDB.getDatabase()); - showListFragment(mSiteId); - PublicizeUpdateService.updateConnectionsForSite(this, mSiteId); + showListFragment(mSite.getId()); + PublicizeUpdateService.updateConnectionsForSite(this, mSite.getId()); } else { mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); } - - mSiteId = mSite.getId(); } @Override @@ -202,7 +199,7 @@ public void onBackPressed() { */ @Override public void onServiceClicked(PublicizeService service) { - showDetailFragment(mSiteId, service); + showDetailFragment(mSite.getId(), service); } /* @@ -210,7 +207,7 @@ public void onServiceClicked(PublicizeService service) { */ @Override public void onRequestConnect(PublicizeService service) { - showWebViewFragment(mSiteId, service, null); + showWebViewFragment(mSite.getId(), service, null); } /* @@ -218,7 +215,7 @@ public void onRequestConnect(PublicizeService service) { */ @Override public void onRequestReconnect(PublicizeService service, PublicizeConnection publicizeConnection) { - showWebViewFragment(mSiteId, service, publicizeConnection); + showWebViewFragment(mSite.getId(), service, publicizeConnection); } /* From bda1fe7f5aad22b3439c28370e7fd1eb7a2530d3 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 14:42:32 -0400 Subject: [PATCH 17/38] Retrieve site settings --- .../ui/publicize/PublicizeManageConnectionsFragment.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java index b0a59b0aad39..4f1e3c516dea 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java @@ -19,6 +19,7 @@ import org.wordpress.android.models.PublicizeButton; import org.wordpress.android.ui.prefs.AccountSettingsFragment; import org.wordpress.android.ui.prefs.DetailListPreference; +import org.wordpress.android.ui.prefs.SiteSettingsInterface; import org.wordpress.android.ui.prefs.SummaryEditTextPreference; import org.wordpress.android.ui.prefs.WPSwitchPreference; import org.wordpress.android.util.AppLog; @@ -45,6 +46,7 @@ public class PublicizeManageConnectionsFragment extends AccountSettingsFragment private ArrayList mPublicizeButtons; private SiteModel mSite; + private SiteSettingsInterface mSiteSettings; public static PublicizeManageConnectionsFragment newInstance(@NonNull SiteModel site) { PublicizeManageConnectionsFragment fragment = new PublicizeManageConnectionsFragment(); @@ -55,10 +57,10 @@ public static PublicizeManageConnectionsFragment newInstance(@NonNull SiteModel } @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); mSite = (SiteModel) getArguments().getSerializable(WordPress.SITE); + mSiteSettings = SiteSettingsInterface.getInterface(getActivity(), mSite, null); } private void saveSharingButtons(HashSet values, boolean isVisible) { From 014ec3b22bcfc6369d2332f1c5c24ed11730eea9 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 14:48:05 -0400 Subject: [PATCH 18/38] Use findPreference rather than getChangePref --- .../PublicizeManageConnectionsFragment.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java index 4f1e3c516dea..50556ace983d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java @@ -133,8 +133,8 @@ private void toggleTwitterPreferenceVisiblity() { private void configureSharingAndMoreButtonsPreferences() { mPublicizeButtons = new ArrayList<>(); - mSharingButtonsPreference = (MultiSelectListPreference) getChangePref(R.string.pref_key_sharing_buttons); - mMoreButtonsPreference = (MultiSelectListPreference) getChangePref(R.string.pref_key_more_buttons); + mSharingButtonsPreference = (MultiSelectListPreference) findPreference(getString(R.string.pref_key_sharing_buttons)); + mMoreButtonsPreference = (MultiSelectListPreference) findPreference(getString(R.string.pref_key_more_buttons)); WordPress.getRestClientUtilsV1_1().getSharingButtons(Long.toString(mSite.getSiteId()), new RestRequest.Listener() { @Override public void onResponse(JSONObject response) { @@ -190,16 +190,16 @@ private void configureSharingButtons(JSONObject response) throws JSONException { @Override protected void initPreferences() { configureSharingAndMoreButtonsPreferences(); - mLabelPreference = (SummaryEditTextPreference) getChangePref(R.string.publicize_label); - mButtonStylePreference = (DetailListPreference) getChangePref(R.string.publicize_button_style); + mLabelPreference = (SummaryEditTextPreference) findPreference(getString(R.string.publicize_label)); + mButtonStylePreference = (DetailListPreference) findPreference(getString((R.string.publicize_button_style)); setDetailListPreferenceValue(mButtonStylePreference, mSiteSettings.getSharingButtonStyle(getActivity()), mSiteSettings.getSharingButtonStyleDisplayText(getActivity())); mButtonStylePreference.setEntries(getResources().getStringArray(R.array.sharing_button_style_display_array)); mButtonStylePreference.setEntryValues(getResources().getStringArray(R.array.sharing_button_style_array)); - mReblogButtonPreference = (WPSwitchPreference) getChangePref(R.string.pref_key_reblog); - mLikeButtonPreference = (WPSwitchPreference) getChangePref(R.string.pref_key_like); - mCommentLikesPreference = (WPSwitchPreference) getChangePref(R.string.pref_key_comment_likes); - mTwitterUsernamePreference = (SummaryEditTextPreference) getChangePref(R.string.pref_key_twitter_username); - mTwitterPreferenceCategory = (PreferenceCategory) getChangePref(R.string.pref_key_twitter_category); + mReblogButtonPreference = (WPSwitchPreference) findPreference(getString(R.string.pref_key_reblog)); + mLikeButtonPreference = (WPSwitchPreference) findPreference(getString(R.string.pref_key_like)); + mCommentLikesPreference = (WPSwitchPreference) findPreference(getString(R.string.pref_key_comment_likes)); + mTwitterUsernamePreference = (SummaryEditTextPreference) findPreference(getString(R.string.pref_key_twitter_username)); + mTwitterPreferenceCategory = (PreferenceCategory) findPreference(getString(R.string.pref_key_twitter_category)); } @Override From 80a921e8de1c51f25ceabcb1b6bba9f22053cfdb Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 14:59:28 -0400 Subject: [PATCH 19/38] PublicizeManageConnectionsFragment now inherits from SiteSettingsFragment --- .../ui/prefs/SiteSettingsFragment.java | 8 ++++---- .../PublicizeManageConnectionsFragment.java | 19 +++++-------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java index 5fb45246f466..452f277f67ec 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java @@ -136,10 +136,10 @@ public class SiteSettingsFragment extends PreferenceFragment @Inject SiteStore mSiteStore; @Inject Dispatcher mDispatcher; - private SiteModel mSite; + public SiteModel mSite; // Can interface with WP.com or WP.org - private SiteSettingsInterface mSiteSettings; + public SiteSettingsInterface mSiteSettings; // Reference to the list of items being edited in the current list editor private List mEditingList; @@ -196,7 +196,7 @@ public class SiteSettingsFragment extends PreferenceFragment private Preference mExportSitePref; private Preference mDeleteSitePref; - private boolean mEditingEnabled = true; + public boolean mEditingEnabled = true; // Reference to the state of the fragment private boolean mIsFragmentPaused = false; @@ -1087,7 +1087,7 @@ private void setDetailListPreferenceValue(DetailListPreference pref, String valu * Helper method to perform validation and set multiple properties on an EditTextPreference. * If newValue is equal to the current preference text no action will be taken. */ - private void changeEditTextPreferenceValue(EditTextPreference pref, String newValue) { + public void changeEditTextPreferenceValue(EditTextPreference pref, String newValue) { if (newValue == null || pref == null || pref.getEditText().isInEditMode()) return; if (!newValue.equals(pref.getSummary())) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java index 50556ace983d..c08d299aa383 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java @@ -19,6 +19,7 @@ import org.wordpress.android.models.PublicizeButton; import org.wordpress.android.ui.prefs.AccountSettingsFragment; import org.wordpress.android.ui.prefs.DetailListPreference; +import org.wordpress.android.ui.prefs.SiteSettingsFragment; import org.wordpress.android.ui.prefs.SiteSettingsInterface; import org.wordpress.android.ui.prefs.SummaryEditTextPreference; import org.wordpress.android.ui.prefs.WPSwitchPreference; @@ -29,10 +30,10 @@ import java.util.HashSet; -public class PublicizeManageConnectionsFragment extends AccountSettingsFragment { +public class PublicizeManageConnectionsFragment extends SiteSettingsFragment { private static final String TWITTER_PREFIX = "@"; private static final String SHARING_BUTTONS_KEY = "sharing_buttons"; - public static final String TWITTER_ID = "twitter"; + private static final String TWITTER_ID = "twitter"; private MultiSelectListPreference mSharingButtonsPreference; private MultiSelectListPreference mMoreButtonsPreference; @@ -45,9 +46,6 @@ public class PublicizeManageConnectionsFragment extends AccountSettingsFragment private PreferenceCategory mTwitterPreferenceCategory; private ArrayList mPublicizeButtons; - private SiteModel mSite; - private SiteSettingsInterface mSiteSettings; - public static PublicizeManageConnectionsFragment newInstance(@NonNull SiteModel site) { PublicizeManageConnectionsFragment fragment = new PublicizeManageConnectionsFragment(); Bundle args = new Bundle(); @@ -56,13 +54,6 @@ public static PublicizeManageConnectionsFragment newInstance(@NonNull SiteModel return fragment; } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mSite = (SiteModel) getArguments().getSerializable(WordPress.SITE); - mSiteSettings = SiteSettingsInterface.getInterface(getActivity(), mSite, null); - } - private void saveSharingButtons(HashSet values, boolean isVisible) { JSONArray jsonArray = new JSONArray(); for (PublicizeButton button: mPublicizeButtons) { @@ -191,7 +182,7 @@ private void configureSharingButtons(JSONObject response) throws JSONException { protected void initPreferences() { configureSharingAndMoreButtonsPreferences(); mLabelPreference = (SummaryEditTextPreference) findPreference(getString(R.string.publicize_label)); - mButtonStylePreference = (DetailListPreference) findPreference(getString((R.string.publicize_button_style)); + mButtonStylePreference = (DetailListPreference) findPreference(getString(R.string.publicize_button_style)); setDetailListPreferenceValue(mButtonStylePreference, mSiteSettings.getSharingButtonStyle(getActivity()), mSiteSettings.getSharingButtonStyleDisplayText(getActivity())); mButtonStylePreference.setEntries(getResources().getStringArray(R.array.sharing_button_style_display_array)); mButtonStylePreference.setEntryValues(getResources().getStringArray(R.array.sharing_button_style_array)); @@ -264,7 +255,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { } @Override - protected void changeEditTextPreferenceValue(EditTextPreference pref, String newValue) { + public void changeEditTextPreferenceValue(EditTextPreference pref, String newValue) { if (pref != null && pref == mTwitterUsernamePreference && newValue != null && !newValue.isEmpty()) { newValue = TWITTER_PREFIX + newValue; } From 413a2851ee55e2d8acb429be0eb8a941bc8ee160 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 15:03:27 -0400 Subject: [PATCH 20/38] PublicizeManageConnectionsFragment now compiles --- .../android/ui/prefs/SiteSettingsFragment.java | 14 +++++++++----- .../PublicizeManageConnectionsFragment.java | 11 ++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java index 452f277f67ec..9082b9cd99f4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsFragment.java @@ -243,12 +243,16 @@ public void onCreate(Bundle savedInstanceState) { mSiteSettings = SiteSettingsInterface.getInterface(activity, mSite, this); setRetainInstance(true); - addPreferencesFromResource(R.xml.site_settings); + addPreferencesFromResource(); // toggle which preferences are shown and set references initPreferences(); } + public void addPreferencesFromResource() { + addPreferencesFromResource(R.xml.site_settings); + } + @Override public void onPause() { super.onPause(); @@ -644,7 +648,7 @@ private void setupPreferenceList(ListView prefList, Resources res) { /** * Helper method to retrieve {@link Preference} references and initialize any data. */ - private void initPreferences() { + public void initPreferences() { mTitlePref = (EditTextPreference) getChangePref(R.string.pref_key_site_title); mTaglinePref = (EditTextPreference) getChangePref(R.string.pref_key_site_tagline); mAddressPref = (EditTextPreference) getChangePref(R.string.pref_key_site_address); @@ -965,7 +969,7 @@ private void showMultipleLinksDialog() { showNumberPickerDialog(args, MULTIPLE_LINKS_REQUEST_CODE, "multiple-links-dialog"); } - private void setPreferencesFromSiteSettings() { + public void setPreferencesFromSiteSettings() { mOptimizedImage.setChecked(mSiteSettings.getOptimizedImage()); setDetailListPreferenceValue(mImageWidthPref, String.valueOf(mSiteSettings.getMaxImageWidth()), @@ -1077,7 +1081,7 @@ private void setReceivePingbacks(boolean newValue) { mReceivePingbacksNested.setChecked(newValue); } - private void setDetailListPreferenceValue(DetailListPreference pref, String value, String summary) { + public void setDetailListPreferenceValue(DetailListPreference pref, String value, String summary) { pref.setValue(value); pref.setSummary(summary); pref.refreshAdapter(); @@ -1281,7 +1285,7 @@ public void onDismiss(DialogInterface dialog) { return view; } - private boolean shouldShowListPreference(DetailListPreference preference) { + public boolean shouldShowListPreference(DetailListPreference preference) { return preference != null && preference.getEntries() != null && preference.getEntries().length > 0; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java index c08d299aa383..be134c7173d7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeManageConnectionsFragment.java @@ -17,14 +17,11 @@ import org.wordpress.android.WordPress; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.models.PublicizeButton; -import org.wordpress.android.ui.prefs.AccountSettingsFragment; import org.wordpress.android.ui.prefs.DetailListPreference; import org.wordpress.android.ui.prefs.SiteSettingsFragment; -import org.wordpress.android.ui.prefs.SiteSettingsInterface; import org.wordpress.android.ui.prefs.SummaryEditTextPreference; import org.wordpress.android.ui.prefs.WPSwitchPreference; import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.ToastUtils; import java.util.ArrayList; import java.util.HashSet; @@ -179,7 +176,7 @@ private void configureSharingButtons(JSONObject response) throws JSONException { } @Override - protected void initPreferences() { + public void initPreferences() { configureSharingAndMoreButtonsPreferences(); mLabelPreference = (SummaryEditTextPreference) findPreference(getString(R.string.publicize_label)); mButtonStylePreference = (DetailListPreference) findPreference(getString(R.string.publicize_button_style)); @@ -194,7 +191,7 @@ protected void initPreferences() { } @Override - protected void setEditingEnabled(boolean enabled) { + public void setEditingEnabled(boolean enabled) { final Preference[] editablePreference = { mSharingButtonsPreference, mMoreButtonsPreference, mLabelPreference, mButtonStylePreference, mReblogButtonPreference, mLikeButtonPreference, mCommentLikesPreference, @@ -209,7 +206,7 @@ protected void setEditingEnabled(boolean enabled) { } @Override - protected void setPreferencesFromSiteSettings() { + public void setPreferencesFromSiteSettings() { changeEditTextPreferenceValue(mLabelPreference, mSiteSettings.getSharingLabel()); setDetailListPreferenceValue(mButtonStylePreference, mSiteSettings.getSharingButtonStyle(getActivity()), mSiteSettings.getSharingButtonStyleDisplayText(getActivity())); mReblogButtonPreference.setChecked(mSiteSettings.getAllowReblogButton()); @@ -219,7 +216,7 @@ protected void setPreferencesFromSiteSettings() { } @Override - protected void addPreferencesFromResource() { + public void addPreferencesFromResource() { addPreferencesFromResource(R.xml.publicize_preferences); } From 449c84dd0b23cd26e3e98c5182cb01fccef55c79 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 16:04:31 -0400 Subject: [PATCH 21/38] Pass current user ID to PublicizeServiceAdapter --- .../android/ui/publicize/PublicizeConstants.java | 1 + .../android/ui/publicize/PublicizeListActivity.java | 8 +++++++- .../android/ui/publicize/PublicizeListFragment.java | 9 +++++++-- .../android/ui/publicize/PublicizeWebViewFragment.java | 4 ---- .../ui/publicize/adapters/PublicizeServiceAdapter.java | 9 ++------- 5 files changed, 17 insertions(+), 14 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 5197ddcd88d7..2a225bc93140 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 @@ -2,6 +2,7 @@ public class PublicizeConstants { public static final String ARG_SITE_ID = "site_id"; + public static final String ARG_USER_ID = "user_id"; public static final String ARG_SERVICE_ID = "service_id"; public static final String ARG_CONNECTION_ID = "connection_id"; public static final String ARG_CONNECTION_ARRAY_JSON = "connection_array_json"; 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 f4e0b561acb0..f7a51efd14ae 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 @@ -16,12 +16,15 @@ import org.wordpress.android.WordPress; import org.wordpress.android.datasets.PublicizeTable; import org.wordpress.android.fluxc.model.SiteModel; +import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.services.PublicizeUpdateService; import org.wordpress.android.util.ToastUtils; +import javax.inject.Inject; + import de.greenrobot.event.EventBus; public class PublicizeListActivity extends AppCompatActivity @@ -33,6 +36,8 @@ public class PublicizeListActivity extends AppCompatActivity private SiteModel mSite; private ProgressDialog mProgressDialog; + @Inject AccountStore mAccountStore; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -80,8 +85,9 @@ protected void onResume() { private void showListFragment(int siteId) { if (isFinishing()) return; + long currentUserId = mAccountStore.getAccount().getUserId(); String tag = getString(R.string.fragment_tag_publicize_list); - Fragment fragment = PublicizeListFragment.newInstance(siteId); + Fragment fragment = PublicizeListFragment.newInstance(siteId, currentUserId); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment, tag) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java index 6c6f53eb9f92..7797a2c22c5d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java @@ -24,14 +24,16 @@ public interface PublicizeManageConnectionsListener { private PublicizeManageConnectionsListener mListener; private int mSiteId; + private long mCurrentUserId; private PublicizeServiceAdapter mAdapter; private RecyclerView mRecycler; private TextView mEmptyView; private Button mManageButton; - public static PublicizeListFragment newInstance(int siteId) { + public static PublicizeListFragment newInstance(int siteId, long currentUserId) { Bundle args = new Bundle(); args.putInt(PublicizeConstants.ARG_SITE_ID, siteId); + args.putLong(PublicizeConstants.ARG_USER_ID, currentUserId); PublicizeListFragment fragment = new PublicizeListFragment(); fragment.setArguments(args); @@ -45,6 +47,7 @@ public void setArguments(Bundle args) { if (args != null) { mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID); + mCurrentUserId = args.getLong(PublicizeConstants.ARG_USER_ID); } } @@ -53,6 +56,7 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); + mCurrentUserId = savedInstanceState.getLong(PublicizeConstants.ARG_USER_ID); } } @@ -71,6 +75,7 @@ public void onResume() { public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(PublicizeConstants.ARG_SITE_ID, mSiteId); + outState.putLong(PublicizeConstants.ARG_USER_ID, mCurrentUserId); } @Override @@ -132,7 +137,7 @@ public void onAdapterLoaded(boolean isEmpty) { private PublicizeServiceAdapter getAdapter() { if (mAdapter == null) { - mAdapter = new PublicizeServiceAdapter(getActivity(), mSiteId); + mAdapter = new PublicizeServiceAdapter(getActivity(), mSiteId, mCurrentUserId); mAdapter.setOnAdapterLoadedListener(mAdapterLoadedListener); if (getActivity() instanceof OnServiceClickListener) { mAdapter.setOnServiceClickListener((OnServiceClickListener) getActivity()); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index 456d0555971d..a6e3c33399ff 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -20,7 +20,6 @@ import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.WPWebViewActivity; import org.wordpress.android.ui.publicize.PublicizeConstants.ConnectAction; -import org.wordpress.android.util.AppLog; import org.wordpress.android.util.WebViewUtils; import javax.inject.Inject; @@ -159,9 +158,6 @@ private class PublicizeWebViewClient extends WebViewClient { public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); - // TODO: remove logging from final - only here for debugging - AppLog.d(AppLog.T.SHARING, "onPageFinished > " + url); - // does this url denotes that we made it past the auth stage? if (isAdded() && url != null) { Uri uri = Uri.parse(url); 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 26008b0bc12f..19c24e4bc299 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 @@ -13,7 +13,6 @@ import org.wordpress.android.R; import org.wordpress.android.datasets.PublicizeTable; -import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnectionList; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.models.PublicizeServiceList; @@ -23,8 +22,6 @@ import java.util.Collections; import java.util.Comparator; -import javax.inject.Inject; - public class PublicizeServiceAdapter extends RecyclerView.Adapter { public interface OnAdapterLoadedListener { @@ -34,8 +31,6 @@ public interface OnServiceClickListener { void onServiceClicked(PublicizeService service); } - @Inject AccountStore mAccountStore; - private final PublicizeServiceList mServices = new PublicizeServiceList(); private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); @@ -49,12 +44,12 @@ public interface OnServiceClickListener { private OnAdapterLoadedListener mAdapterLoadedListener; private OnServiceClickListener mServiceClickListener; - public PublicizeServiceAdapter(Context context, int siteId) { + public PublicizeServiceAdapter(Context context, int siteId, long currentUserId) { super(); mSiteId = siteId; mBlavatarSz = context.getResources().getDimensionPixelSize(R.dimen.blavatar_sz_small); - mCurrentUserId = mAccountStore.getAccount().getUserId(); + mCurrentUserId = currentUserId; mColorConnected = context.getResources().getColor(R.color.grey_dark); mColorNotConnected = context.getResources().getColor(R.color.grey_lighten_10); From f75a342eff5897fe9a08ef50f0c17380f0c2be3b Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 16:10:23 -0400 Subject: [PATCH 22/38] Pass current user ID to PublicizeConnectionAdapter --- .../ui/publicize/PublicizeDetailFragment.java | 16 +++++++++------- .../ui/publicize/PublicizeListActivity.java | 3 ++- .../adapters/PublicizeConnectionAdapter.java | 9 ++------- 3 files changed, 13 insertions(+), 15 deletions(-) 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 ffbbe5ca2188..05ff5667b9dd 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 @@ -7,24 +7,21 @@ import android.view.ViewGroup; import android.widget.TextView; -import org.json.JSONException; -import org.json.JSONObject; import org.wordpress.android.R; import org.wordpress.android.datasets.PublicizeTable; import org.wordpress.android.models.PublicizeService; -import org.wordpress.android.ui.publicize.adapters.PublicizeConnectionAdapter; import org.wordpress.android.ui.publicize.PublicizeConstants.ConnectAction; +import org.wordpress.android.ui.publicize.adapters.PublicizeConnectionAdapter; import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.PhotonUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.widgets.RecyclerItemDecoration; import org.wordpress.android.widgets.WPNetworkImageView; -import de.greenrobot.event.EventBus; - public class PublicizeDetailFragment extends PublicizeBaseFragment implements PublicizeConnectionAdapter.OnAdapterLoadedListener { private int mSiteId; private String mServiceId; + private long mCurrentUserId; private PublicizeService mService; @@ -32,10 +29,11 @@ public class PublicizeDetailFragment extends PublicizeBaseFragment implements Pu private RecyclerView mRecycler; private ViewGroup mLayoutConnections; - public static PublicizeDetailFragment newInstance(int siteId, PublicizeService service) { + public static PublicizeDetailFragment newInstance(int siteId, PublicizeService service, long currentUserId) { Bundle args = new Bundle(); args.putInt(PublicizeConstants.ARG_SITE_ID, siteId); args.putString(PublicizeConstants.ARG_SERVICE_ID, service.getId()); + args.putLong(PublicizeConstants.ARG_USER_ID, currentUserId); PublicizeDetailFragment fragment = new PublicizeDetailFragment(); fragment.setArguments(args); @@ -49,6 +47,7 @@ public void setArguments(Bundle args) { if (args != null) { mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID); mServiceId = args.getString(PublicizeConstants.ARG_SERVICE_ID); + mCurrentUserId = args.getLong(PublicizeConstants.ARG_USER_ID); } } @@ -59,6 +58,7 @@ public void onCreate(Bundle savedInstanceState) { if (savedInstanceState != null) { mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); mServiceId = savedInstanceState.getString(PublicizeConstants.ARG_SERVICE_ID); + mCurrentUserId = savedInstanceState.getLong(PublicizeConstants.ARG_USER_ID); } } @@ -67,6 +67,7 @@ public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(PublicizeConstants.ARG_SITE_ID, mSiteId); outState.putString(PublicizeConstants.ARG_SERVICE_ID, mServiceId); + outState.putLong(PublicizeConstants.ARG_USER_ID, mCurrentUserId); } @Override @@ -113,7 +114,8 @@ public void loadData() { String iconUrl = PhotonUtils.getPhotonImageUrl(mService.getIconUrl(), avatarSz, avatarSz); imgIcon.setImageUrl(iconUrl, WPNetworkImageView.ImageType.BLAVATAR); - PublicizeConnectionAdapter adapter = new PublicizeConnectionAdapter(getActivity(), mSiteId, mServiceId); + PublicizeConnectionAdapter adapter = + new PublicizeConnectionAdapter(getActivity(), mSiteId, mServiceId, mCurrentUserId); adapter.setOnPublicizeActionListener(getOnPublicizeActionListener()); adapter.setOnAdapterLoadedListener(this); 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 f7a51efd14ae..d15ae28d5c71 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 @@ -125,7 +125,8 @@ private void showDetailFragment(int siteId, PublicizeService service) { if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_detail); - Fragment detailFragment = PublicizeDetailFragment.newInstance(siteId, service); + long currentUserId = mAccountStore.getAccount().getUserId(); + Fragment detailFragment = PublicizeDetailFragment.newInstance(siteId, service, currentUserId); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, detailFragment, tag) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java index b346877d5a28..486306b79786 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java @@ -9,7 +9,6 @@ import org.wordpress.android.R; import org.wordpress.android.datasets.PublicizeTable; -import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeConnectionList; import org.wordpress.android.ui.publicize.ConnectButton; @@ -19,16 +18,12 @@ import org.wordpress.android.util.StringUtils; import org.wordpress.android.widgets.WPNetworkImageView; -import javax.inject.Inject; - public class PublicizeConnectionAdapter extends RecyclerView.Adapter { public interface OnAdapterLoadedListener { void onAdapterLoaded(boolean isEmpty); } - @Inject AccountStore mAccountStore; - private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); private final int mSiteId; @@ -39,12 +34,12 @@ public interface OnAdapterLoadedListener { private PublicizeActions.OnPublicizeActionListener mActionListener; private OnAdapterLoadedListener mLoadedListener; - public PublicizeConnectionAdapter(Context context, int siteId, String serviceId) { + public PublicizeConnectionAdapter(Context context, int siteId, String serviceId, long currentUserId) { super(); mSiteId = siteId; mAvatarSz = context.getResources().getDimensionPixelSize(R.dimen.avatar_sz_extra_small); mServiceId = StringUtils.notNullStr(serviceId); - mCurrentUserId = mAccountStore.getAccount().getUserId(); + mCurrentUserId = currentUserId; setHasStableIds(true); } From d3992dbc54c289c8d9c9a32585ebff17f96a1ad8 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 17:18:20 -0400 Subject: [PATCH 23/38] Inject AccountStore into PublicizeWebViewFragment --- .../java/org/wordpress/android/modules/AppComponent.java | 2 ++ .../android/ui/publicize/PublicizeWebViewFragment.java | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java index 0a20384a1c88..bb266104065a 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java @@ -61,6 +61,7 @@ import org.wordpress.android.ui.prefs.SiteSettingsInterface; import org.wordpress.android.ui.prefs.notifications.NotificationsSettingsFragment; import org.wordpress.android.ui.publicize.PublicizeListActivity; +import org.wordpress.android.ui.publicize.PublicizeWebViewFragment; import org.wordpress.android.ui.reader.ReaderCommentListActivity; import org.wordpress.android.ui.reader.ReaderPostDetailFragment; import org.wordpress.android.ui.reader.ReaderPostListFragment; @@ -146,6 +147,7 @@ public interface AppComponent { void inject(MediaEditFragment object); void inject(MediaPreviewActivity object); void inject(PublicizeListActivity object); + void inject(PublicizeWebViewFragment object); void inject(EditPostActivity object); void inject(EditPostSettingsFragment object); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index a6e3c33399ff..b5bca5b1fb8d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -14,6 +14,7 @@ import android.widget.ProgressBar; import org.wordpress.android.R; +import org.wordpress.android.WordPress; import org.wordpress.android.datasets.PublicizeTable; import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnection; @@ -27,13 +28,14 @@ import de.greenrobot.event.EventBus; public class PublicizeWebViewFragment extends PublicizeBaseFragment { - @Inject AccountStore mAccountStore; private int mSiteId; private String mServiceId; private int mConnectionId; private WebView mWebView; private ProgressBar mProgress; + @Inject AccountStore mAccountStore; + /* * returns a new webView fragment to connect to a publicize service - if passed connection * is non-null then we're reconnecting a broken connection, otherwise we're creating a @@ -70,6 +72,8 @@ public void setArguments(Bundle args) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ((WordPress) getActivity().getApplication()).component().inject(this); + if (savedInstanceState != null) { mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); mServiceId = savedInstanceState.getString(PublicizeConstants.ARG_SERVICE_ID); From 79ee0768d764b0188c98dc77e2cc6298a24ad9d3 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 17:25:27 -0400 Subject: [PATCH 24/38] Inject AccountStore into PublicizeDetailFragment --- .../android/modules/AppComponent.java | 7 +++++-- .../ui/publicize/PublicizeConstants.java | 1 - .../ui/publicize/PublicizeDetailFragment.java | 18 +++++++++++------- .../ui/publicize/PublicizeListActivity.java | 12 ++---------- .../ui/publicize/PublicizeListFragment.java | 10 ++++------ .../ui/publicize/PublicizeWebViewFragment.java | 1 - 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java index bb266104065a..3541c8641a13 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java @@ -60,7 +60,8 @@ import org.wordpress.android.ui.prefs.SiteSettingsFragment; import org.wordpress.android.ui.prefs.SiteSettingsInterface; import org.wordpress.android.ui.prefs.notifications.NotificationsSettingsFragment; -import org.wordpress.android.ui.publicize.PublicizeListActivity; +import org.wordpress.android.ui.publicize.PublicizeDetailFragment; +import org.wordpress.android.ui.publicize.PublicizeListFragment; import org.wordpress.android.ui.publicize.PublicizeWebViewFragment; import org.wordpress.android.ui.reader.ReaderCommentListActivity; import org.wordpress.android.ui.reader.ReaderPostDetailFragment; @@ -146,8 +147,10 @@ public interface AppComponent { void inject(MediaGridFragment object); void inject(MediaEditFragment object); void inject(MediaPreviewActivity object); - void inject(PublicizeListActivity object); + void inject(PublicizeWebViewFragment object); + void inject(PublicizeDetailFragment object); + void inject(PublicizeListFragment object); void inject(EditPostActivity object); void inject(EditPostSettingsFragment object); 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 2a225bc93140..5197ddcd88d7 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 @@ -2,7 +2,6 @@ public class PublicizeConstants { public static final String ARG_SITE_ID = "site_id"; - public static final String ARG_USER_ID = "user_id"; public static final String ARG_SERVICE_ID = "service_id"; public static final String ARG_CONNECTION_ID = "connection_id"; public static final String ARG_CONNECTION_ARRAY_JSON = "connection_array_json"; 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 05ff5667b9dd..eae917bc2bed 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 @@ -8,7 +8,9 @@ import android.widget.TextView; import org.wordpress.android.R; +import org.wordpress.android.WordPress; import org.wordpress.android.datasets.PublicizeTable; +import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.publicize.PublicizeConstants.ConnectAction; import org.wordpress.android.ui.publicize.adapters.PublicizeConnectionAdapter; @@ -18,10 +20,11 @@ import org.wordpress.android.widgets.RecyclerItemDecoration; import org.wordpress.android.widgets.WPNetworkImageView; +import javax.inject.Inject; + public class PublicizeDetailFragment extends PublicizeBaseFragment implements PublicizeConnectionAdapter.OnAdapterLoadedListener { private int mSiteId; private String mServiceId; - private long mCurrentUserId; private PublicizeService mService; @@ -29,11 +32,13 @@ public class PublicizeDetailFragment extends PublicizeBaseFragment implements Pu private RecyclerView mRecycler; private ViewGroup mLayoutConnections; - public static PublicizeDetailFragment newInstance(int siteId, PublicizeService service, long currentUserId) { + @Inject AccountStore mAccountStore; + + public static PublicizeDetailFragment newInstance(int siteId, PublicizeService service) { Bundle args = new Bundle(); args.putInt(PublicizeConstants.ARG_SITE_ID, siteId); args.putString(PublicizeConstants.ARG_SERVICE_ID, service.getId()); - args.putLong(PublicizeConstants.ARG_USER_ID, currentUserId); + PublicizeDetailFragment fragment = new PublicizeDetailFragment(); fragment.setArguments(args); @@ -47,18 +52,17 @@ public void setArguments(Bundle args) { if (args != null) { mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID); mServiceId = args.getString(PublicizeConstants.ARG_SERVICE_ID); - mCurrentUserId = args.getLong(PublicizeConstants.ARG_USER_ID); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ((WordPress) getActivity().getApplication()).component().inject(this); if (savedInstanceState != null) { mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); mServiceId = savedInstanceState.getString(PublicizeConstants.ARG_SERVICE_ID); - mCurrentUserId = savedInstanceState.getLong(PublicizeConstants.ARG_USER_ID); } } @@ -67,7 +71,6 @@ public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(PublicizeConstants.ARG_SITE_ID, mSiteId); outState.putString(PublicizeConstants.ARG_SERVICE_ID, mServiceId); - outState.putLong(PublicizeConstants.ARG_USER_ID, mCurrentUserId); } @Override @@ -114,8 +117,9 @@ public void loadData() { String iconUrl = PhotonUtils.getPhotonImageUrl(mService.getIconUrl(), avatarSz, avatarSz); imgIcon.setImageUrl(iconUrl, WPNetworkImageView.ImageType.BLAVATAR); + long currentUserId = mAccountStore.getAccount().getUserId(); PublicizeConnectionAdapter adapter = - new PublicizeConnectionAdapter(getActivity(), mSiteId, mServiceId, mCurrentUserId); + new PublicizeConnectionAdapter(getActivity(), mSiteId, mServiceId, currentUserId); adapter.setOnPublicizeActionListener(getOnPublicizeActionListener()); adapter.setOnAdapterLoadedListener(this); 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 d15ae28d5c71..19497d31bdc8 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 @@ -16,15 +16,12 @@ import org.wordpress.android.WordPress; import org.wordpress.android.datasets.PublicizeTable; import org.wordpress.android.fluxc.model.SiteModel; -import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.services.PublicizeUpdateService; import org.wordpress.android.util.ToastUtils; -import javax.inject.Inject; - import de.greenrobot.event.EventBus; public class PublicizeListActivity extends AppCompatActivity @@ -36,12 +33,9 @@ public class PublicizeListActivity extends AppCompatActivity private SiteModel mSite; private ProgressDialog mProgressDialog; - @Inject AccountStore mAccountStore; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ((WordPress) getApplication()).component().inject(this); setContentView(R.layout.publicize_list_activity); @@ -85,9 +79,8 @@ protected void onResume() { private void showListFragment(int siteId) { if (isFinishing()) return; - long currentUserId = mAccountStore.getAccount().getUserId(); String tag = getString(R.string.fragment_tag_publicize_list); - Fragment fragment = PublicizeListFragment.newInstance(siteId, currentUserId); + Fragment fragment = PublicizeListFragment.newInstance(siteId); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment, tag) @@ -125,8 +118,7 @@ private void showDetailFragment(int siteId, PublicizeService service) { if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_detail); - long currentUserId = mAccountStore.getAccount().getUserId(); - Fragment detailFragment = PublicizeDetailFragment.newInstance(siteId, service, currentUserId); + Fragment detailFragment = PublicizeDetailFragment.newInstance(siteId, service); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, detailFragment, tag) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java index 7797a2c22c5d..ccad225df1df 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java @@ -10,6 +10,7 @@ import android.widget.TextView; import org.wordpress.android.R; +import org.wordpress.android.WordPress; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter.OnAdapterLoadedListener; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter.OnServiceClickListener; @@ -24,16 +25,14 @@ public interface PublicizeManageConnectionsListener { private PublicizeManageConnectionsListener mListener; private int mSiteId; - private long mCurrentUserId; private PublicizeServiceAdapter mAdapter; private RecyclerView mRecycler; private TextView mEmptyView; private Button mManageButton; - public static PublicizeListFragment newInstance(int siteId, long currentUserId) { + public static PublicizeListFragment newInstance(int siteId) { Bundle args = new Bundle(); args.putInt(PublicizeConstants.ARG_SITE_ID, siteId); - args.putLong(PublicizeConstants.ARG_USER_ID, currentUserId); PublicizeListFragment fragment = new PublicizeListFragment(); fragment.setArguments(args); @@ -47,16 +46,16 @@ public void setArguments(Bundle args) { if (args != null) { mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID); - mCurrentUserId = args.getLong(PublicizeConstants.ARG_USER_ID); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ((WordPress) getActivity().getApplication()).component().inject(this); + if (savedInstanceState != null) { mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); - mCurrentUserId = savedInstanceState.getLong(PublicizeConstants.ARG_USER_ID); } } @@ -75,7 +74,6 @@ public void onResume() { public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(PublicizeConstants.ARG_SITE_ID, mSiteId); - outState.putLong(PublicizeConstants.ARG_USER_ID, mCurrentUserId); } @Override diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index b5bca5b1fb8d..4e1916b1a071 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -71,7 +71,6 @@ public void setArguments(Bundle args) { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ((WordPress) getActivity().getApplication()).component().inject(this); if (savedInstanceState != null) { From a6572fbb38c39d759d4bc5aaa6f9d5f562e3d578 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 17:26:26 -0400 Subject: [PATCH 25/38] Inject AccountStore into PublicizeListFragment --- .../android/ui/publicize/PublicizeListFragment.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java index ccad225df1df..e23c8f3f6593 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java @@ -11,6 +11,7 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; +import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter.OnAdapterLoadedListener; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter.OnServiceClickListener; @@ -18,6 +19,8 @@ import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.widgets.RecyclerItemDecoration; +import javax.inject.Inject; + public class PublicizeListFragment extends PublicizeBaseFragment { public interface PublicizeManageConnectionsListener { void onManageConnectionsClicked(); @@ -30,6 +33,8 @@ public interface PublicizeManageConnectionsListener { private TextView mEmptyView; private Button mManageButton; + @Inject AccountStore mAccountStore; + public static PublicizeListFragment newInstance(int siteId) { Bundle args = new Bundle(); args.putInt(PublicizeConstants.ARG_SITE_ID, siteId); @@ -135,7 +140,10 @@ public void onAdapterLoaded(boolean isEmpty) { private PublicizeServiceAdapter getAdapter() { if (mAdapter == null) { - mAdapter = new PublicizeServiceAdapter(getActivity(), mSiteId, mCurrentUserId); + mAdapter = new PublicizeServiceAdapter( + getActivity(), + mSiteId, + mAccountStore.getAccount().getUserId()); mAdapter.setOnAdapterLoadedListener(mAdapterLoadedListener); if (getActivity() instanceof OnServiceClickListener) { mAdapter.setOnServiceClickListener((OnServiceClickListener) getActivity()); From b0d6df0d11d8d5614a35d5c5f01b1a7a14d94ccb Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 17:34:06 -0400 Subject: [PATCH 26/38] Pass SiteModel to PublicizeListFragment --- .../ui/publicize/PublicizeListActivity.java | 2 +- .../ui/publicize/PublicizeListFragment.java | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) 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 19497d31bdc8..6c10a738ed26 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 @@ -80,7 +80,7 @@ private void showListFragment(int siteId) { if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_list); - Fragment fragment = PublicizeListFragment.newInstance(siteId); + Fragment fragment = PublicizeListFragment.newInstance(mSite); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment, tag) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java index e23c8f3f6593..18a5524a1d7c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java @@ -2,6 +2,7 @@ import android.content.Context; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -11,6 +12,7 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; +import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter.OnAdapterLoadedListener; @@ -27,7 +29,7 @@ public interface PublicizeManageConnectionsListener { } private PublicizeManageConnectionsListener mListener; - private int mSiteId; + private SiteModel mSite; private PublicizeServiceAdapter mAdapter; private RecyclerView mRecycler; private TextView mEmptyView; @@ -35,9 +37,9 @@ public interface PublicizeManageConnectionsListener { @Inject AccountStore mAccountStore; - public static PublicizeListFragment newInstance(int siteId) { + public static PublicizeListFragment newInstance(@NonNull SiteModel site) { Bundle args = new Bundle(); - args.putInt(PublicizeConstants.ARG_SITE_ID, siteId); + args.putSerializable(WordPress.SITE, site); PublicizeListFragment fragment = new PublicizeListFragment(); fragment.setArguments(args); @@ -50,7 +52,7 @@ public void setArguments(Bundle args) { super.setArguments(args); if (args != null) { - mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID); + mSite = (SiteModel) args.getSerializable(WordPress.SITE); } } @@ -60,7 +62,7 @@ public void onCreate(Bundle savedInstanceState) { ((WordPress) getActivity().getApplication()).component().inject(this); if (savedInstanceState != null) { - mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); + mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); } } @@ -78,7 +80,7 @@ public void onResume() { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(PublicizeConstants.ARG_SITE_ID, mSiteId); + outState.putSerializable(WordPress.SITE, mSite); } @Override @@ -142,7 +144,7 @@ private PublicizeServiceAdapter getAdapter() { if (mAdapter == null) { mAdapter = new PublicizeServiceAdapter( getActivity(), - mSiteId, + mSite.getId(), mAccountStore.getAccount().getUserId()); mAdapter.setOnAdapterLoadedListener(mAdapterLoadedListener); if (getActivity() instanceof OnServiceClickListener) { From b9ef8c2bf27d7e47622d59b6c640772c19a53f9b Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 17:40:54 -0400 Subject: [PATCH 27/38] Pass SiteModel to PublicizeWebViewFragment --- .../ui/publicize/PublicizeListActivity.java | 9 ++++----- .../ui/publicize/PublicizeWebViewFragment.java | 15 ++++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) 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 6c10a738ed26..6357b8f0c459 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 @@ -144,13 +144,12 @@ private void reloadDetailFragment() { } } - private void showWebViewFragment(int siteId, - PublicizeService service, + private void showWebViewFragment(PublicizeService service, PublicizeConnection publicizeConnection) { if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_webview); - Fragment webViewFragment = PublicizeWebViewFragment.newInstance(siteId, service, publicizeConnection); + Fragment webViewFragment = PublicizeWebViewFragment.newInstance(mSite, service, publicizeConnection); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, webViewFragment, tag) @@ -206,7 +205,7 @@ public void onServiceClicked(PublicizeService service) { */ @Override public void onRequestConnect(PublicizeService service) { - showWebViewFragment(mSite.getId(), service, null); + showWebViewFragment(service, null); } /* @@ -214,7 +213,7 @@ public void onRequestConnect(PublicizeService service) { */ @Override public void onRequestReconnect(PublicizeService service, PublicizeConnection publicizeConnection) { - showWebViewFragment(mSite.getId(), service, publicizeConnection); + showWebViewFragment(service, publicizeConnection); } /* diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index 4e1916b1a071..0e77f13298b3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -16,6 +16,7 @@ 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.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeService; @@ -28,7 +29,7 @@ import de.greenrobot.event.EventBus; public class PublicizeWebViewFragment extends PublicizeBaseFragment { - private int mSiteId; + private SiteModel mSite; private String mServiceId; private int mConnectionId; private WebView mWebView; @@ -41,11 +42,11 @@ public class PublicizeWebViewFragment extends PublicizeBaseFragment { * is non-null then we're reconnecting a broken connection, otherwise we're creating a * new connection to the service */ - public static PublicizeWebViewFragment newInstance(int siteId, + public static PublicizeWebViewFragment newInstance(@NonNull SiteModel site, @NonNull PublicizeService service, PublicizeConnection connection) { Bundle args = new Bundle(); - args.putInt(PublicizeConstants.ARG_SITE_ID, siteId); + args.putSerializable(WordPress.SITE, site); args.putString(PublicizeConstants.ARG_SERVICE_ID, service.getId()); if (connection != null) { args.putInt(PublicizeConstants.ARG_CONNECTION_ID, connection.connectionId); @@ -62,7 +63,7 @@ public void setArguments(Bundle args) { super.setArguments(args); if (args != null) { - mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID); + mSite = (SiteModel) args.getSerializable(WordPress.SITE); mServiceId = args.getString(PublicizeConstants.ARG_SERVICE_ID); mConnectionId = args.getInt(PublicizeConstants.ARG_CONNECTION_ID); } @@ -74,7 +75,7 @@ public void onCreate(Bundle savedInstanceState) { ((WordPress) getActivity().getApplication()).component().inject(this); if (savedInstanceState != null) { - mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); + mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); mServiceId = savedInstanceState.getString(PublicizeConstants.ARG_SERVICE_ID); mConnectionId = savedInstanceState.getInt(PublicizeConstants.ARG_CONNECTION_ID); } @@ -83,7 +84,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(PublicizeConstants.ARG_SITE_ID, mSiteId); + outState.putSerializable(WordPress.SITE, mSite); outState.putString(PublicizeConstants.ARG_SERVICE_ID, mServiceId); outState.putInt(PublicizeConstants.ARG_CONNECTION_ID, mConnectionId); mWebView.saveState(outState); @@ -176,7 +177,7 @@ public void onPageFinished(WebView view, String url) { long currentUserId = mAccountStore.getAccount().getUserId(); // call the endpoint to make the actual connection - PublicizeActions.connect(mSiteId, mServiceId, currentUserId); + PublicizeActions.connect(mSite.getId(), mServiceId, currentUserId); WebViewUtils.clearCookiesAsync(); } } From c2a5c25fa3cacd2fbdaa50af54c892899cac1736 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 17:43:59 -0400 Subject: [PATCH 28/38] Pass SiteModel to PublicizeDetailFragment --- .../ui/publicize/PublicizeDetailFragment.java | 16 +++++++++------- .../ui/publicize/PublicizeListActivity.java | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) 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 eae917bc2bed..6a3e66125f3a 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 @@ -1,6 +1,7 @@ package org.wordpress.android.ui.publicize; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -10,6 +11,7 @@ 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.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.publicize.PublicizeConstants.ConnectAction; @@ -23,7 +25,7 @@ import javax.inject.Inject; public class PublicizeDetailFragment extends PublicizeBaseFragment implements PublicizeConnectionAdapter.OnAdapterLoadedListener { - private int mSiteId; + private SiteModel mSite; private String mServiceId; private PublicizeService mService; @@ -34,9 +36,9 @@ public class PublicizeDetailFragment extends PublicizeBaseFragment implements Pu @Inject AccountStore mAccountStore; - public static PublicizeDetailFragment newInstance(int siteId, PublicizeService service) { + public static PublicizeDetailFragment newInstance(@NonNull SiteModel site, PublicizeService service) { Bundle args = new Bundle(); - args.putInt(PublicizeConstants.ARG_SITE_ID, siteId); + args.putSerializable(WordPress.SITE, site); args.putString(PublicizeConstants.ARG_SERVICE_ID, service.getId()); PublicizeDetailFragment fragment = new PublicizeDetailFragment(); @@ -50,7 +52,7 @@ public void setArguments(Bundle args) { super.setArguments(args); if (args != null) { - mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID); + mSite = (SiteModel) args.getSerializable(WordPress.SITE); mServiceId = args.getString(PublicizeConstants.ARG_SERVICE_ID); } } @@ -61,7 +63,7 @@ public void onCreate(Bundle savedInstanceState) { ((WordPress) getActivity().getApplication()).component().inject(this); if (savedInstanceState != null) { - mSiteId = savedInstanceState.getInt(PublicizeConstants.ARG_SITE_ID); + mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); mServiceId = savedInstanceState.getString(PublicizeConstants.ARG_SERVICE_ID); } } @@ -69,7 +71,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(PublicizeConstants.ARG_SITE_ID, mSiteId); + outState.putSerializable(WordPress.SITE, mSite); outState.putString(PublicizeConstants.ARG_SERVICE_ID, mServiceId); } @@ -119,7 +121,7 @@ public void loadData() { long currentUserId = mAccountStore.getAccount().getUserId(); PublicizeConnectionAdapter adapter = - new PublicizeConnectionAdapter(getActivity(), mSiteId, mServiceId, currentUserId); + new PublicizeConnectionAdapter(getActivity(), mSite.getId(), mServiceId, currentUserId); adapter.setOnPublicizeActionListener(getOnPublicizeActionListener()); adapter.setOnAdapterLoadedListener(this); 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 6357b8f0c459..2246567cd7dd 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 @@ -114,11 +114,11 @@ private void returnToListFragment() { getFragmentManager().popBackStack(tag, FragmentManager.POP_BACK_STACK_INCLUSIVE); } - private void showDetailFragment(int siteId, PublicizeService service) { + private void showDetailFragment(PublicizeService service) { if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_detail); - Fragment detailFragment = PublicizeDetailFragment.newInstance(siteId, service); + Fragment detailFragment = PublicizeDetailFragment.newInstance(mSite, service); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, detailFragment, tag) @@ -197,7 +197,7 @@ public void onBackPressed() { */ @Override public void onServiceClicked(PublicizeService service) { - showDetailFragment(mSite.getId(), service); + showDetailFragment(service); } /* From f7e2ce2dda2ad384e90f92312c5bd76c56c46892 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 19:08:38 -0400 Subject: [PATCH 29/38] Use long siteId --- .../android/models/PublicizeConnection.java | 16 ++++++++-------- .../PublicizeAccountChooserDialogFragment.java | 8 ++++---- .../android/ui/publicize/PublicizeActions.java | 16 ++++++++-------- .../android/ui/publicize/PublicizeEvents.java | 12 ++++++------ .../ui/publicize/PublicizeListActivity.java | 2 +- .../ui/publicize/PublicizeWebViewFragment.java | 5 +++-- 6 files changed, 30 insertions(+), 29 deletions(-) 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 393981dc59fa..2e6992b95e9d 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java @@ -41,7 +41,7 @@ public String toString() { private String mExternalName; private String mExternalDisplayName; private String mExternalProfilePictureUrl; - private int[] mSites; + private long[] mSites; // `status` can be `ok` or `broken` -- `broken` means the connection needs to be re-established via the `refresh_URL` private String mStatus; @@ -139,15 +139,15 @@ public boolean isSameAs(PublicizeConnection other) { && other.getService().equals(this.getService()); } - public void setSites(int[] sites) { + public void setSites(long[] sites) { mSites = sites; } - public int[] getSites() { + public long[] getSites() { return mSites; } - public boolean isInSite(int siteId) { + public boolean isInSite(long siteId) { for (int i = 0; i < mSites.length; i++) { if (siteId == mSites[i]) { return true; @@ -210,17 +210,17 @@ public static PublicizeConnection fromJson(JSONObject json) { JSONArray jsonSitesArray = json.getJSONArray("sites"); connection.mSites = getSitesArrayFromJson(jsonSitesArray); } catch (JSONException e) { - connection.mSites = new int[0]; + connection.mSites = new long[0]; e.printStackTrace(); } return connection; } - private static int[] getSitesArrayFromJson(JSONArray jsonArray) throws JSONException { - int[] sitesArray = new int[jsonArray.length()]; + private static long[] getSitesArrayFromJson(JSONArray jsonArray) throws JSONException { + long[] sitesArray = new long[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { - sitesArray[i] = jsonArray.getInt(i); + sitesArray[i] = jsonArray.getLong(i); } return sitesArray; 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 d79e82d822fa..bd0bc0adb85b 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 @@ -32,7 +32,7 @@ public class PublicizeAccountChooserDialogFragment extends DialogFragment implem private String mConnectionName = ""; private String mServiceId = ""; private int mSelectedIndex = 0; - private int mSiteId = 0; + private long mSiteId = 0; @NonNull @Override @@ -107,8 +107,8 @@ public void onClick(DialogInterface dialogInterface, int i) { }); } - private boolean containsSiteId(int[] array) { - for (int a : array) { + private boolean containsSiteId(long[] array) { + for (long a : array) { if (a == mSiteId) { return true; } @@ -120,7 +120,7 @@ private boolean containsSiteId(int[] array) { private void retrieveCurrentSiteFromArgs() { Bundle args = getArguments(); if (args != null) { - mSiteId = args.getInt(PublicizeConstants.ARG_SITE_ID); + mSiteId = args.getLong(PublicizeConstants.ARG_SITE_ID); mServiceId = args.getString(PublicizeConstants.ARG_SERVICE_ID); String jsonString = args.getString(PublicizeConstants.ARG_CONNECTION_ARRAY_JSON); addConnectionsToLists(jsonString); 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 cdc4a2e44f1a..b31ea9ac07b4 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 @@ -64,7 +64,7 @@ public void onErrorResponse(VolleyError volleyError) { /* * create a new publicize service connection for a specific site */ - public static void connect(int siteId, String serviceId, long currentUserId){ + public static void connect(long siteId, String serviceId, long currentUserId){ if (TextUtils.isEmpty(serviceId)) { AppLog.w(AppLog.T.SHARING, "cannot connect without service"); EventBus.getDefault().post(new ActionCompleted(false, ConnectAction.CONNECT)); @@ -78,7 +78,7 @@ public static void connect(int siteId, String serviceId, long currentUserId){ * step one in creating a publicize connection: request the list of keyring connections * and find the one for the passed service */ - private static void connectStepOne(final int siteId, final String serviceId, final long currentUserId) { + private static void connectStepOne(final long siteId, final String serviceId, final long currentUserId) { RestRequest.Listener listener = new RestRequest.Listener() { @Override public void onResponse(JSONObject jsonObject) { @@ -86,7 +86,7 @@ public void onResponse(JSONObject jsonObject) { // show dialog showing multiple options EventBus.getDefault().post(new PublicizeEvents.ActionRequestChooseAccount(siteId, serviceId, jsonObject)); } else { - int keyringConnectionId = parseServiceKeyringId(serviceId, currentUserId, jsonObject); + long keyringConnectionId = parseServiceKeyringId(serviceId, currentUserId, jsonObject); connectStepTwo(siteId, keyringConnectionId); } } @@ -107,7 +107,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(int siteId, int keyringConnectionId) { + public static void connectStepTwo(long siteId, long keyringConnectionId) { RestRequest.Listener listener = new RestRequest.Listener() { @Override public void onResponse(JSONObject jsonObject) { @@ -126,12 +126,12 @@ public void onErrorResponse(VolleyError volleyError) { }; Map params = new HashMap<>(); - params.put("keyring_connection_ID", Integer.toString(keyringConnectionId)); + params.put("keyring_connection_ID", Long.toString(keyringConnectionId)); String path = String.format("/sites/%d/publicize-connections/new", siteId); WordPress.getRestClientUtilsV1_1().post(path, params, null, listener, errorListener); } - private static boolean shouldShowChooserDialog(int siteId, String serviceId, JSONObject jsonObject) { + private static boolean shouldShowChooserDialog(long siteId, String serviceId, JSONObject jsonObject) { JSONArray jsonConnectionList = jsonObject.optJSONArray("connections"); if (jsonConnectionList == null || jsonConnectionList.length() <= 1) { return false; @@ -157,7 +157,7 @@ private static boolean shouldShowChooserDialog(int siteId, String serviceId, JSO * extract the keyring connection for the passed service from the response * to /me/keyring-connections */ - private static int parseServiceKeyringId(String serviceId, long currentUserId, JSONObject json) { + private static long parseServiceKeyringId(String serviceId, long currentUserId, JSONObject json) { JSONArray jsonConnectionList = json.optJSONArray("connections"); if (jsonConnectionList == null) { return 0; @@ -170,7 +170,7 @@ private static int parseServiceKeyringId(String serviceId, long currentUserId, J // make sure userId matches the current user, or is zero (shared) long userId = jsonConnection.optLong("user_ID"); if (userId == 0 || userId == currentUserId) { - return jsonConnection.optInt("ID"); + return jsonConnection.optLong("ID"); } } } 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 5a08bb007ea0..99a9afa90e4e 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 @@ -33,15 +33,15 @@ public boolean didSucceed() { } public static class ActionAccountChosen { - private int mSiteId; + private long mSiteId; private int mKeychainId; - public ActionAccountChosen(int siteId, int keychainId) { + public ActionAccountChosen(long siteId, int keychainId) { mSiteId = siteId; mKeychainId = keychainId; } - public int getSiteId() { + public long getSiteId() { return mSiteId; } @@ -51,11 +51,11 @@ public int getKeychainId() { } public static class ActionRequestChooseAccount { - private int mSiteId; + private long mSiteId; private String mServiceId; private JSONObject mJSONObject; - public ActionRequestChooseAccount(int siteId, String serviceId, JSONObject jsonObject) { + public ActionRequestChooseAccount(long siteId, String serviceId, JSONObject jsonObject) { mSiteId = siteId; mServiceId = serviceId; mJSONObject = jsonObject; @@ -65,7 +65,7 @@ public JSONObject getJSONObject() { return mJSONObject; } - public int getSiteId() { + public long getSiteId() { return mSiteId; } 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 2246567cd7dd..901f854c81b2 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 @@ -285,7 +285,7 @@ public void onEventMainThread(PublicizeEvents.ActionRequestChooseAccount event) PublicizeAccountChooserDialogFragment dialogFragment = new PublicizeAccountChooserDialogFragment(); Bundle args = new Bundle(); args.putString(PublicizeConstants.ARG_CONNECTION_ARRAY_JSON, event.getJSONObject().toString()); - args.putInt(PublicizeConstants.ARG_SITE_ID, event.getSiteId()); + args.putLong(PublicizeConstants.ARG_SITE_ID, event.getSiteId()); args.putString(PublicizeConstants.ARG_SERVICE_ID, event.getServiceId()); dialogFragment.setArguments(args); dialogFragment.show(getSupportFragmentManager(), PublicizeAccountChooserDialogFragment.TAG); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index 0e77f13298b3..c569bc2c0fca 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -177,8 +177,9 @@ public void onPageFinished(WebView view, String url) { long currentUserId = mAccountStore.getAccount().getUserId(); // call the endpoint to make the actual connection - PublicizeActions.connect(mSite.getId(), mServiceId, currentUserId); - WebViewUtils.clearCookiesAsync(); + PublicizeActions.connect(mSite.getSiteId(), mServiceId, currentUserId); + // TODO: uncomment the line below + //WebViewUtils.clearCookiesAsync(); } } } From fe92de56c00fa84e2f8488d5d6017cfa1db9f905 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 19:22:36 -0400 Subject: [PATCH 30/38] Use correct long siteId for PublicizeTable and PublicizeConnection --- .../org/wordpress/android/datasets/PublicizeTable.java | 10 +++++----- .../wordpress/android/models/PublicizeConnection.java | 4 ++-- .../android/ui/publicize/PublicizeDetailFragment.java | 2 +- .../publicize/adapters/PublicizeConnectionAdapter.java | 4 ++-- 4 files changed, 10 insertions(+), 10 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 8fdfe5d2744c..ea296aa2282b 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -209,9 +209,9 @@ public static void addOrUpdateConnection(PublicizeConnection connection) { getReadableDb().insertWithOnConflict(CONNECTIONS_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); } - public static PublicizeConnectionList getConnectionsForSite(int siteId) { + public static PublicizeConnectionList getConnectionsForSite(long siteId) { PublicizeConnectionList connectionList= new PublicizeConnectionList(); - String args[] = {Integer.toString(siteId)}; + String args[] = {Long.toString(siteId)}; Cursor c = getReadableDb().rawQuery("SELECT * FROM " + CONNECTIONS_TABLE + " WHERE site_id=?", args); try { while (c.moveToNext()) { @@ -223,12 +223,12 @@ public static PublicizeConnectionList getConnectionsForSite(int siteId) { } } - public static void setConnectionsForSite(int siteId, PublicizeConnectionList connectionList) { + public static void setConnectionsForSite(long siteId, PublicizeConnectionList connectionList) { SQLiteStatement stmt = null; SQLiteDatabase db = getWritableDb(); db.beginTransaction(); try { - db.delete(CONNECTIONS_TABLE, "site_id=?", new String[] {Integer.toString(siteId)}); + db.delete(CONNECTIONS_TABLE, "site_id=?", new String[] {Long.toString(siteId)}); stmt = db.compileStatement( "INSERT INTO " + CONNECTIONS_TABLE @@ -278,7 +278,7 @@ public static void setConnectionsForSite(int siteId, PublicizeConnectionList con private static PublicizeConnection getConnectionFromCursor(Cursor c) { PublicizeConnection connection = new PublicizeConnection(); - connection.siteId = c.getInt(c.getColumnIndex("site_id")); + connection.siteId = c.getLong(c.getColumnIndex("site_id")); connection.connectionId = c.getInt(c.getColumnIndex("id")); connection.userId = c.getInt(c.getColumnIndex("user_id")); connection.keyringConnectionId = c.getInt(c.getColumnIndex("keyring_connection_id")); 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 2e6992b95e9d..69b33d352739 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java @@ -25,7 +25,7 @@ public String toString() { } public int connectionId; - public int siteId; + public long siteId; public int keyringConnectionId; public int keyringConnectionUserId; @@ -190,7 +190,7 @@ public static PublicizeConnection fromJson(JSONObject json) { PublicizeConnection connection = new PublicizeConnection(); connection.connectionId = json.optInt("ID"); - connection.siteId = json.optInt("site_ID"); + connection.siteId = json.optLong("site_ID"); connection.userId = json.optInt("user_ID"); connection.keyringConnectionId = json.optInt("keyring_connection_ID"); connection.keyringConnectionUserId = json.optInt("keyring_connection_user_ID"); 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 6a3e66125f3a..aea1a39dbcac 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 @@ -121,7 +121,7 @@ public void loadData() { long currentUserId = mAccountStore.getAccount().getUserId(); PublicizeConnectionAdapter adapter = - new PublicizeConnectionAdapter(getActivity(), mSite.getId(), mServiceId, currentUserId); + new PublicizeConnectionAdapter(getActivity(), mSite.getSiteId(), mServiceId, currentUserId); adapter.setOnPublicizeActionListener(getOnPublicizeActionListener()); adapter.setOnAdapterLoadedListener(this); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java index 486306b79786..c269578adf8e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java @@ -26,7 +26,7 @@ public interface OnAdapterLoadedListener { private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); - private final int mSiteId; + private final long mSiteId; private final int mAvatarSz; private final long mCurrentUserId; private final String mServiceId; @@ -34,7 +34,7 @@ public interface OnAdapterLoadedListener { private PublicizeActions.OnPublicizeActionListener mActionListener; private OnAdapterLoadedListener mLoadedListener; - public PublicizeConnectionAdapter(Context context, int siteId, String serviceId, long currentUserId) { + public PublicizeConnectionAdapter(Context context, long siteId, String serviceId, long currentUserId) { super(); mSiteId = siteId; mAvatarSz = context.getResources().getDimensionPixelSize(R.dimen.avatar_sz_extra_small); From 5fd74994c851cb0d409be41041ec4b5e11ec05da Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 19:24:36 -0400 Subject: [PATCH 31/38] Revert "Use correct long siteId for PublicizeTable and PublicizeConnection" This reverts commit fe92de56c00fa84e2f8488d5d6017cfa1db9f905. --- .../org/wordpress/android/datasets/PublicizeTable.java | 10 +++++----- .../wordpress/android/models/PublicizeConnection.java | 4 ++-- .../android/ui/publicize/PublicizeDetailFragment.java | 2 +- .../publicize/adapters/PublicizeConnectionAdapter.java | 4 ++-- 4 files changed, 10 insertions(+), 10 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 ea296aa2282b..8fdfe5d2744c 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -209,9 +209,9 @@ public static void addOrUpdateConnection(PublicizeConnection connection) { getReadableDb().insertWithOnConflict(CONNECTIONS_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); } - public static PublicizeConnectionList getConnectionsForSite(long siteId) { + public static PublicizeConnectionList getConnectionsForSite(int siteId) { PublicizeConnectionList connectionList= new PublicizeConnectionList(); - String args[] = {Long.toString(siteId)}; + String args[] = {Integer.toString(siteId)}; Cursor c = getReadableDb().rawQuery("SELECT * FROM " + CONNECTIONS_TABLE + " WHERE site_id=?", args); try { while (c.moveToNext()) { @@ -223,12 +223,12 @@ public static PublicizeConnectionList getConnectionsForSite(long siteId) { } } - public static void setConnectionsForSite(long siteId, PublicizeConnectionList connectionList) { + public static void setConnectionsForSite(int siteId, PublicizeConnectionList connectionList) { SQLiteStatement stmt = null; SQLiteDatabase db = getWritableDb(); db.beginTransaction(); try { - db.delete(CONNECTIONS_TABLE, "site_id=?", new String[] {Long.toString(siteId)}); + db.delete(CONNECTIONS_TABLE, "site_id=?", new String[] {Integer.toString(siteId)}); stmt = db.compileStatement( "INSERT INTO " + CONNECTIONS_TABLE @@ -278,7 +278,7 @@ public static void setConnectionsForSite(long siteId, PublicizeConnectionList co private static PublicizeConnection getConnectionFromCursor(Cursor c) { PublicizeConnection connection = new PublicizeConnection(); - connection.siteId = c.getLong(c.getColumnIndex("site_id")); + connection.siteId = c.getInt(c.getColumnIndex("site_id")); connection.connectionId = c.getInt(c.getColumnIndex("id")); connection.userId = c.getInt(c.getColumnIndex("user_id")); connection.keyringConnectionId = c.getInt(c.getColumnIndex("keyring_connection_id")); 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 69b33d352739..2e6992b95e9d 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java @@ -25,7 +25,7 @@ public String toString() { } public int connectionId; - public long siteId; + public int siteId; public int keyringConnectionId; public int keyringConnectionUserId; @@ -190,7 +190,7 @@ public static PublicizeConnection fromJson(JSONObject json) { PublicizeConnection connection = new PublicizeConnection(); connection.connectionId = json.optInt("ID"); - connection.siteId = json.optLong("site_ID"); + connection.siteId = json.optInt("site_ID"); connection.userId = json.optInt("user_ID"); connection.keyringConnectionId = json.optInt("keyring_connection_ID"); connection.keyringConnectionUserId = json.optInt("keyring_connection_user_ID"); 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 aea1a39dbcac..6a3e66125f3a 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 @@ -121,7 +121,7 @@ public void loadData() { long currentUserId = mAccountStore.getAccount().getUserId(); PublicizeConnectionAdapter adapter = - new PublicizeConnectionAdapter(getActivity(), mSite.getSiteId(), mServiceId, currentUserId); + new PublicizeConnectionAdapter(getActivity(), mSite.getId(), mServiceId, currentUserId); adapter.setOnPublicizeActionListener(getOnPublicizeActionListener()); adapter.setOnAdapterLoadedListener(this); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java index c269578adf8e..486306b79786 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java @@ -26,7 +26,7 @@ public interface OnAdapterLoadedListener { private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); - private final long mSiteId; + private final int mSiteId; private final int mAvatarSz; private final long mCurrentUserId; private final String mServiceId; @@ -34,7 +34,7 @@ public interface OnAdapterLoadedListener { private PublicizeActions.OnPublicizeActionListener mActionListener; private OnAdapterLoadedListener mLoadedListener; - public PublicizeConnectionAdapter(Context context, long siteId, String serviceId, long currentUserId) { + public PublicizeConnectionAdapter(Context context, int siteId, String serviceId, long currentUserId) { super(); mSiteId = siteId; mAvatarSz = context.getResources().getDimensionPixelSize(R.dimen.avatar_sz_extra_small); From 8aa7524b64a3b22512bfd8df4aece08f2715b9cc Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 19:32:09 -0400 Subject: [PATCH 32/38] Use correct long siteId for PublicizeTable and PublicizeConnection --- .../org/wordpress/android/datasets/PublicizeTable.java | 10 +++++----- .../wordpress/android/models/PublicizeConnection.java | 4 ++-- 2 files changed, 7 insertions(+), 7 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 8fdfe5d2744c..ea296aa2282b 100644 --- a/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java +++ b/WordPress/src/main/java/org/wordpress/android/datasets/PublicizeTable.java @@ -209,9 +209,9 @@ public static void addOrUpdateConnection(PublicizeConnection connection) { getReadableDb().insertWithOnConflict(CONNECTIONS_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE); } - public static PublicizeConnectionList getConnectionsForSite(int siteId) { + public static PublicizeConnectionList getConnectionsForSite(long siteId) { PublicizeConnectionList connectionList= new PublicizeConnectionList(); - String args[] = {Integer.toString(siteId)}; + String args[] = {Long.toString(siteId)}; Cursor c = getReadableDb().rawQuery("SELECT * FROM " + CONNECTIONS_TABLE + " WHERE site_id=?", args); try { while (c.moveToNext()) { @@ -223,12 +223,12 @@ public static PublicizeConnectionList getConnectionsForSite(int siteId) { } } - public static void setConnectionsForSite(int siteId, PublicizeConnectionList connectionList) { + public static void setConnectionsForSite(long siteId, PublicizeConnectionList connectionList) { SQLiteStatement stmt = null; SQLiteDatabase db = getWritableDb(); db.beginTransaction(); try { - db.delete(CONNECTIONS_TABLE, "site_id=?", new String[] {Integer.toString(siteId)}); + db.delete(CONNECTIONS_TABLE, "site_id=?", new String[] {Long.toString(siteId)}); stmt = db.compileStatement( "INSERT INTO " + CONNECTIONS_TABLE @@ -278,7 +278,7 @@ public static void setConnectionsForSite(int siteId, PublicizeConnectionList con private static PublicizeConnection getConnectionFromCursor(Cursor c) { PublicizeConnection connection = new PublicizeConnection(); - connection.siteId = c.getInt(c.getColumnIndex("site_id")); + connection.siteId = c.getLong(c.getColumnIndex("site_id")); connection.connectionId = c.getInt(c.getColumnIndex("id")); connection.userId = c.getInt(c.getColumnIndex("user_id")); connection.keyringConnectionId = c.getInt(c.getColumnIndex("keyring_connection_id")); 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 2e6992b95e9d..69b33d352739 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java +++ b/WordPress/src/main/java/org/wordpress/android/models/PublicizeConnection.java @@ -25,7 +25,7 @@ public String toString() { } public int connectionId; - public int siteId; + public long siteId; public int keyringConnectionId; public int keyringConnectionUserId; @@ -190,7 +190,7 @@ public static PublicizeConnection fromJson(JSONObject json) { PublicizeConnection connection = new PublicizeConnection(); connection.connectionId = json.optInt("ID"); - connection.siteId = json.optInt("site_ID"); + connection.siteId = json.optLong("site_ID"); connection.userId = json.optInt("user_ID"); connection.keyringConnectionId = json.optInt("keyring_connection_ID"); connection.keyringConnectionUserId = json.optInt("keyring_connection_user_ID"); From c0b20f397ceae890a68fbc667d37de243aed16da Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 19:36:40 -0400 Subject: [PATCH 33/38] Pass the long siteId to PublicizeServiceAdapter --- .../wordpress/android/ui/publicize/PublicizeListFragment.java | 2 +- .../ui/publicize/adapters/PublicizeServiceAdapter.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java index 18a5524a1d7c..ac430d260368 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java @@ -144,7 +144,7 @@ private PublicizeServiceAdapter getAdapter() { if (mAdapter == null) { mAdapter = new PublicizeServiceAdapter( getActivity(), - mSite.getId(), + mSite.getSiteId(), mAccountStore.getAccount().getUserId()); mAdapter.setOnAdapterLoadedListener(mAdapterLoadedListener); if (getActivity() instanceof OnServiceClickListener) { 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 19c24e4bc299..95fa48884fde 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 @@ -34,7 +34,7 @@ public interface OnServiceClickListener { private final PublicizeServiceList mServices = new PublicizeServiceList(); private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); - private final int mSiteId; + private final long mSiteId; private final int mBlavatarSz; private final ColorFilter mGrayScaleFilter; private final int mColorConnected; @@ -44,7 +44,7 @@ public interface OnServiceClickListener { private OnAdapterLoadedListener mAdapterLoadedListener; private OnServiceClickListener mServiceClickListener; - public PublicizeServiceAdapter(Context context, int siteId, long currentUserId) { + public PublicizeServiceAdapter(Context context, long siteId, long currentUserId) { super(); mSiteId = siteId; From e1c774b2dea50ebda4b0a855ce952c833881d787 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 19:45:22 -0400 Subject: [PATCH 34/38] Pass the long siteId to PublicizeUpdateService --- .../android/ui/publicize/PublicizeListActivity.java | 2 +- .../ui/publicize/services/PublicizeUpdateService.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) 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 901f854c81b2..98c0ff41ac5a 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 @@ -52,7 +52,7 @@ public void onCreate(Bundle savedInstanceState) { mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); PublicizeTable.createTables(WordPress.wpDB.getDatabase()); showListFragment(mSite.getId()); - PublicizeUpdateService.updateConnectionsForSite(this, mSite.getId()); + PublicizeUpdateService.updateConnectionsForSite(this, mSite.getSiteId()); } else { mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/services/PublicizeUpdateService.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/services/PublicizeUpdateService.java index 24ff6ad47b54..c778a30679c8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/services/PublicizeUpdateService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/services/PublicizeUpdateService.java @@ -12,6 +12,7 @@ import org.wordpress.android.datasets.PublicizeTable; import org.wordpress.android.models.PublicizeConnectionList; import org.wordpress.android.models.PublicizeServiceList; +import org.wordpress.android.ui.publicize.PublicizeConstants; import org.wordpress.android.ui.publicize.PublicizeEvents; import org.wordpress.android.util.AppLog; @@ -23,15 +24,14 @@ public class PublicizeUpdateService extends IntentService { - private static final String ARG_SITE_ID = "site_id"; private static boolean mHasUpdatedServices; /* * update the publicize connections for the passed site */ - public static void updateConnectionsForSite(Context context, int siteId) { + public static void updateConnectionsForSite(Context context, long siteId) { Intent intent = new Intent(context, PublicizeUpdateService.class); - intent.putExtra(ARG_SITE_ID, siteId); + intent.putExtra(PublicizeConstants.ARG_SITE_ID, siteId); context.startService(intent); } @@ -63,7 +63,7 @@ protected void onHandleIntent(Intent intent) { mHasUpdatedServices = true; } - int siteId = intent.getIntExtra(ARG_SITE_ID, 0); + long siteId = intent.getLongExtra(PublicizeConstants.ARG_SITE_ID, 0); updateConnections(siteId); } @@ -96,7 +96,7 @@ public void onErrorResponse(VolleyError volleyError) { /* * update the connections for the passed blog */ - private void updateConnections(final int siteId) { + private void updateConnections(final long siteId) { RestRequest.Listener listener = new RestRequest.Listener() { @Override public void onResponse(JSONObject jsonObject) { From d1ff83863370a635c25fbead0a2dac7b24504b4f Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 19:47:52 -0400 Subject: [PATCH 35/38] Removed siteId param from showListFragment --- .../android/ui/publicize/PublicizeDetailFragment.java | 4 ++-- .../wordpress/android/ui/publicize/PublicizeListActivity.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 6a3e66125f3a..d4bf76cfad10 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 @@ -120,8 +120,8 @@ public void loadData() { imgIcon.setImageUrl(iconUrl, WPNetworkImageView.ImageType.BLAVATAR); long currentUserId = mAccountStore.getAccount().getUserId(); - PublicizeConnectionAdapter adapter = - new PublicizeConnectionAdapter(getActivity(), mSite.getId(), mServiceId, currentUserId); + PublicizeConnectionAdapter adapter = new PublicizeConnectionAdapter( + getActivity(), mSite.getId(), mServiceId, currentUserId); adapter.setOnPublicizeActionListener(getOnPublicizeActionListener()); adapter.setOnAdapterLoadedListener(this); 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 98c0ff41ac5a..1154b9b952d6 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 @@ -51,7 +51,7 @@ public void onCreate(Bundle savedInstanceState) { if (savedInstanceState == null) { mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); PublicizeTable.createTables(WordPress.wpDB.getDatabase()); - showListFragment(mSite.getId()); + showListFragment(); PublicizeUpdateService.updateConnectionsForSite(this, mSite.getSiteId()); } else { mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); @@ -76,7 +76,7 @@ protected void onResume() { EventBus.getDefault().register(this); } - private void showListFragment(int siteId) { + private void showListFragment() { if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_list); From 016130c79ea9046753a5d67d3597ec2a9ccc5fc1 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 19:50:43 -0400 Subject: [PATCH 36/38] Pass the long siteId to PublicizeConnectionAdapter --- .../android/ui/publicize/PublicizeDetailFragment.java | 2 +- .../ui/publicize/adapters/PublicizeConnectionAdapter.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 d4bf76cfad10..f48954bf14a9 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 @@ -121,7 +121,7 @@ public void loadData() { long currentUserId = mAccountStore.getAccount().getUserId(); PublicizeConnectionAdapter adapter = new PublicizeConnectionAdapter( - getActivity(), mSite.getId(), mServiceId, currentUserId); + getActivity(), mSite.getSiteId(), mServiceId, currentUserId); adapter.setOnPublicizeActionListener(getOnPublicizeActionListener()); adapter.setOnAdapterLoadedListener(this); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java index 486306b79786..c269578adf8e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/adapters/PublicizeConnectionAdapter.java @@ -26,7 +26,7 @@ public interface OnAdapterLoadedListener { private final PublicizeConnectionList mConnections = new PublicizeConnectionList(); - private final int mSiteId; + private final long mSiteId; private final int mAvatarSz; private final long mCurrentUserId; private final String mServiceId; @@ -34,7 +34,7 @@ public interface OnAdapterLoadedListener { private PublicizeActions.OnPublicizeActionListener mActionListener; private OnAdapterLoadedListener mLoadedListener; - public PublicizeConnectionAdapter(Context context, int siteId, String serviceId, long currentUserId) { + public PublicizeConnectionAdapter(Context context, long siteId, String serviceId, long currentUserId) { super(); mSiteId = siteId; mAvatarSz = context.getResources().getDimensionPixelSize(R.dimen.avatar_sz_extra_small); From 872e4c2a38fab6976384f40fe8820febe2b2158e Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Wed, 24 May 2017 20:17:14 -0400 Subject: [PATCH 37/38] Re-enable WebViewUtils.clearCookiesAsync() --- .../android/ui/publicize/PublicizeWebViewFragment.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index c569bc2c0fca..c20e95cb669e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -178,8 +178,7 @@ public void onPageFinished(WebView view, String url) { long currentUserId = mAccountStore.getAccount().getUserId(); // call the endpoint to make the actual connection PublicizeActions.connect(mSite.getSiteId(), mServiceId, currentUserId); - // TODO: uncomment the line below - //WebViewUtils.clearCookiesAsync(); + WebViewUtils.clearCookiesAsync(); } } } From 0ff514ea35f7e11509ad08505a0e6eae575f6af9 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Thu, 25 May 2017 17:33:49 -0400 Subject: [PATCH 38/38] Pass only the siteId --- .../ui/publicize/PublicizeDetailFragment.java | 16 +++++++--------- .../ui/publicize/PublicizeListActivity.java | 6 +++--- .../ui/publicize/PublicizeListFragment.java | 16 +++++++--------- .../ui/publicize/PublicizeWebViewFragment.java | 15 +++++++-------- 4 files changed, 24 insertions(+), 29 deletions(-) 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 f48954bf14a9..812b98e831e9 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 @@ -1,7 +1,6 @@ package org.wordpress.android.ui.publicize; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -11,7 +10,6 @@ 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.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeService; import org.wordpress.android.ui.publicize.PublicizeConstants.ConnectAction; @@ -25,7 +23,7 @@ import javax.inject.Inject; public class PublicizeDetailFragment extends PublicizeBaseFragment implements PublicizeConnectionAdapter.OnAdapterLoadedListener { - private SiteModel mSite; + private long mSiteId; private String mServiceId; private PublicizeService mService; @@ -36,9 +34,9 @@ public class PublicizeDetailFragment extends PublicizeBaseFragment implements Pu @Inject AccountStore mAccountStore; - public static PublicizeDetailFragment newInstance(@NonNull SiteModel site, PublicizeService service) { + public static PublicizeDetailFragment newInstance(long siteId, PublicizeService service) { Bundle args = new Bundle(); - args.putSerializable(WordPress.SITE, site); + args.putLong(PublicizeConstants.ARG_SITE_ID, siteId); args.putString(PublicizeConstants.ARG_SERVICE_ID, service.getId()); PublicizeDetailFragment fragment = new PublicizeDetailFragment(); @@ -52,7 +50,7 @@ public void setArguments(Bundle args) { super.setArguments(args); if (args != null) { - mSite = (SiteModel) args.getSerializable(WordPress.SITE); + mSiteId = args.getLong(PublicizeConstants.ARG_SITE_ID); mServiceId = args.getString(PublicizeConstants.ARG_SERVICE_ID); } } @@ -63,7 +61,7 @@ public void onCreate(Bundle savedInstanceState) { ((WordPress) getActivity().getApplication()).component().inject(this); if (savedInstanceState != null) { - mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); + mSiteId = savedInstanceState.getLong(PublicizeConstants.ARG_SITE_ID); mServiceId = savedInstanceState.getString(PublicizeConstants.ARG_SERVICE_ID); } } @@ -71,7 +69,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putSerializable(WordPress.SITE, mSite); + outState.putLong(PublicizeConstants.ARG_SITE_ID, mSiteId); outState.putString(PublicizeConstants.ARG_SERVICE_ID, mServiceId); } @@ -121,7 +119,7 @@ public void loadData() { long currentUserId = mAccountStore.getAccount().getUserId(); PublicizeConnectionAdapter adapter = new PublicizeConnectionAdapter( - getActivity(), mSite.getSiteId(), mServiceId, currentUserId); + getActivity(), mSiteId, mServiceId, currentUserId); adapter.setOnPublicizeActionListener(getOnPublicizeActionListener()); adapter.setOnAdapterLoadedListener(this); 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 1154b9b952d6..e23cc2c29252 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 @@ -80,7 +80,7 @@ private void showListFragment() { if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_list); - Fragment fragment = PublicizeListFragment.newInstance(mSite); + Fragment fragment = PublicizeListFragment.newInstance(mSite.getSiteId()); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, fragment, tag) @@ -118,7 +118,7 @@ private void showDetailFragment(PublicizeService service) { if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_detail); - Fragment detailFragment = PublicizeDetailFragment.newInstance(mSite, service); + Fragment detailFragment = PublicizeDetailFragment.newInstance(mSite.getSiteId(), service); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, detailFragment, tag) @@ -149,7 +149,7 @@ private void showWebViewFragment(PublicizeService service, if (isFinishing()) return; String tag = getString(R.string.fragment_tag_publicize_webview); - Fragment webViewFragment = PublicizeWebViewFragment.newInstance(mSite, service, publicizeConnection); + Fragment webViewFragment = PublicizeWebViewFragment.newInstance(mSite.getSiteId(), service, publicizeConnection); getFragmentManager() .beginTransaction() .replace(R.id.fragment_container, webViewFragment, tag) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java index ac430d260368..51961561550f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListFragment.java @@ -2,7 +2,6 @@ import android.content.Context; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -12,7 +11,6 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; -import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.store.AccountStore; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter; import org.wordpress.android.ui.publicize.adapters.PublicizeServiceAdapter.OnAdapterLoadedListener; @@ -29,7 +27,7 @@ public interface PublicizeManageConnectionsListener { } private PublicizeManageConnectionsListener mListener; - private SiteModel mSite; + private long mSiteId; private PublicizeServiceAdapter mAdapter; private RecyclerView mRecycler; private TextView mEmptyView; @@ -37,9 +35,9 @@ public interface PublicizeManageConnectionsListener { @Inject AccountStore mAccountStore; - public static PublicizeListFragment newInstance(@NonNull SiteModel site) { + public static PublicizeListFragment newInstance(long siteId) { Bundle args = new Bundle(); - args.putSerializable(WordPress.SITE, site); + args.putLong(PublicizeConstants.ARG_SITE_ID, siteId); PublicizeListFragment fragment = new PublicizeListFragment(); fragment.setArguments(args); @@ -52,7 +50,7 @@ public void setArguments(Bundle args) { super.setArguments(args); if (args != null) { - mSite = (SiteModel) args.getSerializable(WordPress.SITE); + mSiteId = args.getLong(PublicizeConstants.ARG_SITE_ID); } } @@ -62,7 +60,7 @@ public void onCreate(Bundle savedInstanceState) { ((WordPress) getActivity().getApplication()).component().inject(this); if (savedInstanceState != null) { - mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); + mSiteId = savedInstanceState.getLong(PublicizeConstants.ARG_SITE_ID); } } @@ -80,7 +78,7 @@ public void onResume() { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putSerializable(WordPress.SITE, mSite); + outState.putLong(PublicizeConstants.ARG_SITE_ID, mSiteId); } @Override @@ -144,7 +142,7 @@ private PublicizeServiceAdapter getAdapter() { if (mAdapter == null) { mAdapter = new PublicizeServiceAdapter( getActivity(), - mSite.getSiteId(), + mSiteId, mAccountStore.getAccount().getUserId()); mAdapter.setOnAdapterLoadedListener(mAdapterLoadedListener); if (getActivity() instanceof OnServiceClickListener) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java index c20e95cb669e..812d9c93af84 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeWebViewFragment.java @@ -16,7 +16,6 @@ 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.fluxc.store.AccountStore; import org.wordpress.android.models.PublicizeConnection; import org.wordpress.android.models.PublicizeService; @@ -29,7 +28,7 @@ import de.greenrobot.event.EventBus; public class PublicizeWebViewFragment extends PublicizeBaseFragment { - private SiteModel mSite; + private long mSiteId; private String mServiceId; private int mConnectionId; private WebView mWebView; @@ -42,11 +41,11 @@ public class PublicizeWebViewFragment extends PublicizeBaseFragment { * is non-null then we're reconnecting a broken connection, otherwise we're creating a * new connection to the service */ - public static PublicizeWebViewFragment newInstance(@NonNull SiteModel site, + public static PublicizeWebViewFragment newInstance(long siteId, @NonNull PublicizeService service, PublicizeConnection connection) { Bundle args = new Bundle(); - args.putSerializable(WordPress.SITE, site); + args.putSerializable(PublicizeConstants.ARG_SITE_ID, siteId); args.putString(PublicizeConstants.ARG_SERVICE_ID, service.getId()); if (connection != null) { args.putInt(PublicizeConstants.ARG_CONNECTION_ID, connection.connectionId); @@ -63,7 +62,7 @@ public void setArguments(Bundle args) { super.setArguments(args); if (args != null) { - mSite = (SiteModel) args.getSerializable(WordPress.SITE); + mSiteId = args.getLong(PublicizeConstants.ARG_SITE_ID); mServiceId = args.getString(PublicizeConstants.ARG_SERVICE_ID); mConnectionId = args.getInt(PublicizeConstants.ARG_CONNECTION_ID); } @@ -75,7 +74,7 @@ public void onCreate(Bundle savedInstanceState) { ((WordPress) getActivity().getApplication()).component().inject(this); if (savedInstanceState != null) { - mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE); + mSiteId = savedInstanceState.getLong(PublicizeConstants.ARG_SITE_ID); mServiceId = savedInstanceState.getString(PublicizeConstants.ARG_SERVICE_ID); mConnectionId = savedInstanceState.getInt(PublicizeConstants.ARG_CONNECTION_ID); } @@ -84,7 +83,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putSerializable(WordPress.SITE, mSite); + outState.putLong(PublicizeConstants.ARG_SITE_ID, mSiteId); outState.putString(PublicizeConstants.ARG_SERVICE_ID, mServiceId); outState.putInt(PublicizeConstants.ARG_CONNECTION_ID, mConnectionId); mWebView.saveState(outState); @@ -177,7 +176,7 @@ public void onPageFinished(WebView view, String url) { long currentUserId = mAccountStore.getAccount().getUserId(); // call the endpoint to make the actual connection - PublicizeActions.connect(mSite.getSiteId(), mServiceId, currentUserId); + PublicizeActions.connect(mSiteId, mServiceId, currentUserId); WebViewUtils.clearCookiesAsync(); } }