-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Site creation rework: theme loading retry when connection resumes #7247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1c2b1ac
ea6437b
a3301d7
fc7351a
035160e
adaa5fe
3d61f5a
71f4c2d
12a8e0f
cb4f8cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,11 @@ | |
| import org.wordpress.android.R; | ||
| import org.wordpress.android.analytics.AnalyticsTracker; | ||
| import org.wordpress.android.ui.accounts.signup.SiteCreationService.SiteCreationState; | ||
| import org.wordpress.android.ui.accounts.signup.SiteCreationService.SiteCreationStep; | ||
| import org.wordpress.android.util.AppLog; | ||
| import org.wordpress.android.util.AppLog.T; | ||
| import org.wordpress.android.util.AutoForeground.ServiceEventConnection; | ||
| import org.wordpress.android.util.NetworkUtils; | ||
| import org.wordpress.android.util.URLFilteredWebViewClient; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
@@ -31,8 +33,6 @@ public class SiteCreationCreatingFragment extends SiteCreationBaseFormFragment<S | |
| private static final String ARG_SITE_SLUG = "ARG_SITE_SLUG"; | ||
| private static final String ARG_SITE_THEME_ID = "ARG_SITE_THEME_ID"; | ||
|
|
||
| private static final String KEY_IN_MODAL_MODE = "KEY_IN_MODAL_MODE"; | ||
| private static final String KEY_CREATION_FINISHED = "KEY_CREATION_FINISHED"; | ||
| private static final String KEY_WEBVIEW_LOADED_IN_TIME = "KEY_WEBVIEW_LOADED_IN_TIME"; | ||
| private static final String KEY_TRACKED_SUCCESS = "KEY_TRACKED_SUCCESS"; | ||
|
|
||
|
|
@@ -48,19 +48,32 @@ public class SiteCreationCreatingFragment extends SiteCreationBaseFormFragment<S | |
| private TextView[] mLabels; | ||
|
|
||
| private boolean mTrackedSuccess; | ||
| private boolean mInModalMode; | ||
| private boolean mCreationSucceeded; | ||
| private boolean mWebViewLoadedInTime; | ||
| private int mNewSiteLocalId; | ||
| int mNewSiteLocalId; | ||
|
|
||
| private PreviewWebViewClient mPreviewWebViewClient; | ||
|
|
||
| public boolean isInModalMode() { | ||
| return mInModalMode; | ||
| SiteCreationState state = SiteCreationService.getState(); | ||
| return state != null && state.isInProgress(); | ||
| } | ||
|
|
||
| public boolean isCreationSucceeded() { | ||
| return mCreationSucceeded; | ||
| SiteCreationState state = SiteCreationService.getState(); | ||
| return state != null && SiteCreationService.getState().getStep() == SiteCreationStep.SUCCESS; | ||
| } | ||
|
|
||
| public boolean canGoBack() { | ||
| SiteCreationState state = SiteCreationService.getState(); | ||
| if (state == null) { | ||
| return true; | ||
| } | ||
|
|
||
| if (state.getStep() == SiteCreationStep.FAILURE) { | ||
| state = (SiteCreationState) state.getPayload(); | ||
| } | ||
|
|
||
| return !state.isAfterCreation(); | ||
| } | ||
|
|
||
| public static SiteCreationCreatingFragment newInstance(String siteTitle, String siteTagline, String siteSlug, | ||
|
|
@@ -130,11 +143,8 @@ public void onCreate(Bundle savedInstanceState) { | |
|
|
||
| if (savedInstanceState == null) { | ||
| // on first appearance start the Service to perform the site creation | ||
| mInModalMode = true; | ||
| createSite(); | ||
| } else { | ||
| mInModalMode = savedInstanceState.getBoolean(KEY_IN_MODAL_MODE, false); | ||
| mCreationSucceeded = savedInstanceState.getBoolean(KEY_CREATION_FINISHED, false); | ||
| mWebViewLoadedInTime = savedInstanceState.getBoolean(KEY_WEBVIEW_LOADED_IN_TIME, false); | ||
| mTrackedSuccess = savedInstanceState.getBoolean(KEY_TRACKED_SUCCESS, false); | ||
| } | ||
|
|
@@ -144,7 +154,7 @@ public void onCreate(Bundle savedInstanceState) { | |
| public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
| super.onViewCreated(view, savedInstanceState); | ||
|
|
||
| showHomeButton(!mInModalMode); | ||
| showHomeButton(!isInModalMode(), false); | ||
|
|
||
| if (savedInstanceState == null) { | ||
| AnalyticsTracker.track(AnalyticsTracker.Stat.SITE_CREATION_CREATING_VIEWED); | ||
|
|
@@ -171,21 +181,19 @@ public void onPause() { | |
| public void onSaveInstanceState(Bundle outState) { | ||
| super.onSaveInstanceState(outState); | ||
|
|
||
| outState.putBoolean(KEY_IN_MODAL_MODE, mInModalMode); | ||
| outState.putBoolean(KEY_CREATION_FINISHED, mCreationSucceeded); | ||
| outState.putBoolean(KEY_WEBVIEW_LOADED_IN_TIME, mWebViewLoadedInTime); | ||
| outState.putBoolean(KEY_TRACKED_SUCCESS, mTrackedSuccess); | ||
| } | ||
|
|
||
| private void createSite() { | ||
| void createSite() { | ||
| String siteTitle = getArguments().getString(ARG_SITE_TITLE); | ||
| String siteTagline = getArguments().getString(ARG_SITE_TAGLINE); | ||
| String siteSlug = getArguments().getString(ARG_SITE_SLUG); | ||
| String themeId = getArguments().getString(ARG_SITE_THEME_ID); | ||
| SiteCreationService.createSite(getContext(), siteTitle, siteTagline, siteSlug, themeId); | ||
| } | ||
|
|
||
| private void retryFromState(SiteCreationState retryFromState, long newSiteRemoteId) { | ||
| void retryFromState(SiteCreationState retryFromState, long newSiteRemoteId) { | ||
| String siteTagline = getArguments().getString(ARG_SITE_TAGLINE); | ||
| String themeId = getArguments().getString(ARG_SITE_THEME_ID); | ||
| SiteCreationService.retryFromState(getContext(), retryFromState, newSiteRemoteId, siteTagline, themeId); | ||
|
|
@@ -217,7 +225,7 @@ private PreviewWebViewClient loadWebview() { | |
| } | ||
|
|
||
| private static class PreviewWebViewClient extends URLFilteredWebViewClient { | ||
| private boolean mIsPageFinished; | ||
| boolean mIsPageFinished; | ||
|
|
||
| PreviewWebViewClient(String siteAddress) { | ||
| super(siteAddress); | ||
|
|
@@ -245,9 +253,17 @@ private void disableUntil(@IdRes int textViewId) { | |
| } | ||
| } | ||
|
|
||
| private void setModalMode(boolean inModalMode) { | ||
| mInModalMode = inModalMode; | ||
| showHomeButton(!mInModalMode); | ||
| private void configureBackButton() { | ||
| SiteCreationState currentState = SiteCreationService.getState(); | ||
|
|
||
| SiteCreationState failedOnState = null; | ||
| if (currentState != null && currentState.getStep() == SiteCreationStep.FAILURE) { | ||
| failedOnState = (SiteCreationState) currentState.getPayload(); | ||
| } | ||
|
|
||
| boolean isInModal = currentState != null && currentState.isInProgress(); | ||
| boolean failedAfterCreation = failedOnState != null && failedOnState.isAfterCreation(); | ||
| showHomeButton(!isInModal, failedAfterCreation); | ||
| } | ||
|
|
||
| private void configureImage(boolean hasFailure) { | ||
|
|
@@ -269,8 +285,8 @@ public void onClick(View view) { | |
| if (failedState.isTerminal()) { | ||
| throw new RuntimeException("Internal inconsistency: Cannot resume site creation from " | ||
| + failedState.getStepName()); | ||
| } else if (failedState.getStep() == SiteCreationService.SiteCreationStep.IDLE | ||
| || failedState.getStep() == SiteCreationService.SiteCreationStep.NEW_SITE) { | ||
| } else if (failedState.getStep() == SiteCreationStep.IDLE | ||
| || failedState.getStep() == SiteCreationStep.NEW_SITE) { | ||
| createSite(); | ||
| } else { | ||
| retryFromState(failedState, (long) failedState.getPayload()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with 71f4c2d. |
||
|
|
@@ -287,6 +303,8 @@ public void onSiteCreationStateUpdated(SiteCreationState event) { | |
| mProgressContainer.setVisibility(View.VISIBLE); | ||
| mErrorContainer.setVisibility(View.GONE); | ||
|
|
||
| configureBackButton(); | ||
|
|
||
| switch (event.getStep()) { | ||
| case IDLE: | ||
| disableUntil(0); | ||
|
|
@@ -309,21 +327,19 @@ public void onSiteCreationStateUpdated(SiteCreationState event) { | |
| configureImage(false); | ||
| break; | ||
| case FAILURE: | ||
| setModalMode(false); | ||
| configureImage(true); | ||
| mProgressContainer.setVisibility(View.GONE); | ||
| mErrorContainer.setVisibility(View.VISIBLE); | ||
| handleFailure((SiteCreationState) event.getPayload()); | ||
| NetworkUtils.checkConnection(getContext()); | ||
| break; | ||
| case PRELOAD: | ||
| disableUntil(R.id.site_creation_creating_preparing_frontend); | ||
| configureImage(false); | ||
| mPreviewWebViewClient = loadWebview(); | ||
| break; | ||
| case SUCCESS: | ||
| mCreationSucceeded = true; | ||
| mNewSiteLocalId = (Integer) event.getPayload(); | ||
| setModalMode(false); | ||
|
|
||
| if (mPreviewWebViewClient == null) { | ||
| // Apparently view got rotated while at the final so, just reconfigure the WebView. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
stateis created in the line above, can't we simplifySiteCreationService.getState().getStep()tostate.getStep()to minimize theSiteCreationService.getState()calls? Otherwise, creatingstatedoesn't reduce the number ofSiteCreationService.getState()calls.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good find! I was going to reuse the variable but that fell between the cracks! Done with 12a8e0f.