From 0ff514ea35f7e11509ad08505a0e6eae575f6af9 Mon Sep 17 00:00:00 2001 From: Nick Bradbury Date: Thu, 25 May 2017 17:33:49 -0400 Subject: [PATCH] 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(); } }