Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,23 @@ private void launchHelpshift(HelpshiftHelper.Tag origin) {
private enum SiteCreationBackStackMode {
NORMAL,
MODAL,
FINISH_OK
FINISH_OK,
FINISH_DISMISS
}

private SiteCreationBackStackMode getSiteCreationBackStackMode() {
SiteCreationCreatingFragment siteCreationCreatingFragment =
(SiteCreationCreatingFragment) getSupportFragmentManager()
.findFragmentByTag(SiteCreationCreatingFragment.TAG);

if (siteCreationCreatingFragment == null) {
if (siteCreationCreatingFragment == null || siteCreationCreatingFragment.canGoBack()) {
return SiteCreationBackStackMode.NORMAL;
} else if (siteCreationCreatingFragment.isInModalMode()) {
return SiteCreationBackStackMode.MODAL;
} else if (siteCreationCreatingFragment.isCreationSucceeded()) {
return SiteCreationBackStackMode.FINISH_OK;
} else {
return SiteCreationBackStackMode.NORMAL;
return SiteCreationBackStackMode.FINISH_DISMISS;
}
}

Expand All @@ -144,6 +145,9 @@ public void onBackPressed() {
setResult(RESULT_OK);
finish();
break;
case FINISH_DISMISS:
finish();
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
}
}

protected void showHomeButton(boolean visible) {
protected void showHomeButton(boolean visible, boolean isCloseButton) {
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(visible);
if (isCloseButton) {
actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand All @@ -29,8 +30,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 ServiceEventConnection mServiceEventConnection;
Expand All @@ -44,18 +43,31 @@ public class SiteCreationCreatingFragment extends SiteCreationBaseFormFragment<S
private View mTadaContainer;
private TextView[] mLabels;

private boolean mInModalMode;
private boolean mCreationSucceeded;
private boolean mWebViewLoadedInTime;

private PreviewWebViewClient mPreviewWebViewClient;

public boolean isInModalMode() {
return mInModalMode;
SiteCreationState state = SiteCreationService.getState();
return state != null && SiteCreationService.getState().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,
Expand Down Expand Up @@ -125,11 +137,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);
}
}
Expand All @@ -138,7 +147,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);
Expand All @@ -165,8 +174,6 @@ 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);
}

Expand Down Expand Up @@ -231,9 +238,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) {
Expand All @@ -255,8 +270,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());
Expand All @@ -273,6 +288,8 @@ public void onSiteCreationStateUpdated(SiteCreationState event) {
mProgressContainer.setVisibility(View.VISIBLE);
mErrorContainer.setVisibility(View.GONE);

configureBackButton();

switch (event.getStep()) {
case IDLE:
disableUntil(0);
Expand All @@ -295,7 +312,6 @@ public void onSiteCreationStateUpdated(SiteCreationState event) {
configureImage(false);
break;
case FAILURE:
setModalMode(false);
configureImage(true);
mProgressContainer.setVisibility(View.GONE);
mErrorContainer.setVisibility(View.VISIBLE);
Expand All @@ -307,9 +323,6 @@ public void onSiteCreationStateUpdated(SiteCreationState event) {
mPreviewWebViewClient = loadWebview();
break;
case SUCCESS:
mCreationSucceeded = true;
setModalMode(false);

if (mPreviewWebViewClient == null) {
// Apparently view got rotated while at the final so, just reconfigure the WebView.
loadWebview();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ public enum SiteCreationStep {
}

public static class SiteCreationState implements AutoForeground.ServiceState {
private final SiteCreationStep mStep;
private @NonNull final SiteCreationStep mStep;
private final Object payload;

SiteCreationState(@NonNull SiteCreationStep step, @Nullable Object payload) {
this.mStep = step;
this.payload = payload;
}

@NonNull
SiteCreationStep getStep() {
return mStep;
}
Expand Down Expand Up @@ -109,6 +110,10 @@ public boolean isTerminal() {
public String getStepName() {
return mStep.name();
}

boolean isAfterCreation() {
return mStep.ordinal() > SiteCreationStep.NEW_SITE.ordinal();
}
}

private static class SiteCreationNotification {
Expand Down Expand Up @@ -183,6 +188,10 @@ public static void clearSiteCreationServiceState() {
clearServiceState(SiteCreationState.class);
}

public static SiteCreationState getState() {
return getState(SiteCreationState.class);
}

public SiteCreationService() {
super(new SiteCreationState(SiteCreationStep.IDLE, null));
}
Expand Down
2 changes: 1 addition & 1 deletion libs/login/WordPressLoginFlow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
}

dependencies {
compile ('org.wordpress:utils:1.20.0-beta5') {
compile ('org.wordpress:utils:1.20.0-beta6') {
exclude group: "com.mcxiaoke.volley"
}

Expand Down
2 changes: 1 addition & 1 deletion libs/utils/WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
buildToolsVersion "25.0.3"

defaultConfig {
versionName "1.20.0-beta5"
versionName "1.20.0-beta6"
minSdkVersion 15
targetSdkVersion 25
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ public boolean isForeground() {
return mIsForeground;
}

protected StateClass getState() {
return EventBus.getDefault().getStickyEvent(mStateClass);
@Nullable
private StateClass getState() {
return getState(mStateClass);
}

@Nullable
protected static <StateClass> StateClass getState(Class<StateClass> stateClass) {
return EventBus.getDefault().getStickyEvent(stateClass);
}

@Nullable
Expand Down