Skip to content

Commit

Permalink
Pass only the siteId
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed May 25, 2017
1 parent 872e4c2 commit 0ff514e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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);
}
}
Expand All @@ -63,15 +61,15 @@ 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);
}
}

@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);
}

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -29,17 +27,17 @@ public interface PublicizeManageConnectionsListener {
}

private PublicizeManageConnectionsListener mListener;
private SiteModel mSite;
private long mSiteId;
private PublicizeServiceAdapter mAdapter;
private RecyclerView mRecycler;
private TextView mEmptyView;
private Button mManageButton;

@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);
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 0ff514e

Please sign in to comment.