Skip to content
Merged
6 changes: 5 additions & 1 deletion WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
<activity
android:name=".ui.accounts.NewBlogActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/SignInTheme"
android:theme="@style/LoginTheme"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".ui.accounts.HelpActivity"
Expand Down Expand Up @@ -535,6 +535,10 @@
android:name=".ui.notifications.services.NotificationsUpdateService"
android:exported="false"
android:label="Notifications Update Service" />
<service
android:name=".ui.accounts.signup.SiteCreationService"
android:exported="false"
android:label="Site Creation Service" />

<!-- Samsung multiwindow support -->
<uses-library
Expand Down
20 changes: 20 additions & 0 deletions WordPress/src/main/java/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,26 @@ public static Object getBuildConfigValue(Application application, String fieldNa
}
}

/**
* Gets a field from the project's BuildConfig using reflection. This is useful when flavors
* are used at the project level to set custom fields.
* based on: https://code.google.com/p/android/issues/detail?id=52962#c38
* @param activity Used to get the Application instance
* @param configValueName The name of the field-to-access
* @return The string value of the field, or empty string if the field is not found.
*/
public static String getBuildConfigString(Activity activity, String configValueName) {
if (!BuildConfig.DEBUG) return "";

String value = (String) WordPress.getBuildConfigValue(activity.getApplication(), configValueName);
if (!TextUtils.isEmpty(value)) {
AppLog.d(AppLog.T.NUX, "Auto-filled from build config: " + configValueName);
return value;
}

return "";
}

/**
* Detect when the app goes to the background and come back to the foreground.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.wordpress.android.ui.accounts.login.LoginSiteAddressFragment;
import org.wordpress.android.ui.accounts.login.LoginSiteAddressHelpDialogFragment;
import org.wordpress.android.ui.accounts.login.LoginUsernamePasswordFragment;
import org.wordpress.android.ui.accounts.signup.SiteCreationService;
import org.wordpress.android.ui.comments.CommentAdapter;
import org.wordpress.android.ui.comments.CommentDetailFragment;
import org.wordpress.android.ui.comments.CommentsActivity;
Expand Down Expand Up @@ -129,6 +130,7 @@ public interface AppComponent {
void inject(NewBlogFragment object);
void inject(SignInDialogFragment object);
void inject(NewUserFragment object);
void inject(SiteCreationService object);

void inject(UploadService object);
void inject(MediaUploadHandler object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ public static void viewSSLCerts(Context context, String certificateString) {

public static void newBlogForResult(Activity activity) {
Intent intent = new Intent(activity, NewBlogActivity.class);
intent.putExtra(NewBlogActivity.KEY_START_MODE, NewBlogActivity.CREATE_BLOG);
activity.startActivityForResult(intent, RequestCodes.CREATE_SITE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
package org.wordpress.android.ui.accounts;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import org.wordpress.android.R;
import org.wordpress.android.ui.accounts.signup.SiteCreatingFragment;

public class NewBlogActivity extends AppCompatActivity {
public static final String KEY_START_MODE = "start-mode";
public static final int CREATE_BLOG = 1;
public static final int CREATE_BLOG_LOGOUT_ON_CANCEL = 2;

private NewBlogFragment mNewBlogFragment;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_blog_activity);

FragmentManager fragmentManager = getSupportFragmentManager();
mNewBlogFragment = (NewBlogFragment) fragmentManager.
findFragmentById(R.id.new_blog_fragment);
if (getActionMode() == CREATE_BLOG_LOGOUT_ON_CANCEL) {
mNewBlogFragment.setSignoutOnCancelMode(true);
}
}
if (savedInstanceState == null) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, new SiteCreatingFragment(), SiteCreatingFragment.TAG);
fragmentTransaction.commit();

private int getActionMode() {
Bundle extras = getIntent().getExtras();
if (extras != null) {
return extras.getInt(KEY_START_MODE, CREATE_BLOG);
}
return CREATE_BLOG;
}

@Override
public void onBackPressed() {
if (mNewBlogFragment.isSignoutOnCancelMode()) {
mNewBlogFragment.onBackPressed();
} else {
super.onBackPressed();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.wordpress.android.ui.accounts.signup;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.ui.accounts.signup.SiteCreationService.OnSiteCreationStateUpdated;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.AutoForeground.ServiceEventConnection;

public class SiteCreatingFragment extends Fragment {
public static final String TAG = "site_creating_fragment_tag";

private ServiceEventConnection mServiceEventConnection;

private TextView mLabel;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.site_creating_screen, container, false);

mLabel = (TextView) view.findViewById(R.id.label);

return view;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);

ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
}

if (savedInstanceState == null) {
AnalyticsTracker.track(AnalyticsTracker.Stat.LOGIN_MAGIC_LINK_OPEN_EMAIL_CLIENT_VIEWED);
}
}

@Override
public void onResume() {
super.onResume();

// connect to the Service. We'll receive updates via EventBus.
mServiceEventConnection = new ServiceEventConnection(getContext(), SiteCreationService.class, this);
}

@Override
public void onPause() {
super.onPause();

// disconnect from the Service
mServiceEventConnection.disconnect(getContext(), this);
}

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSiteCreationPhaseUpdated(OnSiteCreationStateUpdated event) {
AppLog.i(T.NUX, "Received state: " + event.state.name());

switch (event.state) {
case IDLE:
SiteCreationService.createSite(getActivity(),
WordPress.getBuildConfigString(getActivity(), "DEBUG_DOTCOM_NEW_SITE_TITLE"),
WordPress.getBuildConfigString(getActivity(), "DEBUG_DOTCOM_NEW_SITE_TAGLINE"),
WordPress.getBuildConfigString(getActivity(), "DEBUG_DOTCOM_NEW_SITE_SLUG"),
WordPress.getBuildConfigString(getActivity(), "DEBUG_DOTCOM_NEW_SITE_THEME"));

mLabel.setText(R.string.site_creating_label);
break;
case NEW_SITE:
// nothing special to do here, just waiting for the site creation result...
break;
case FETCHING_NEW_SITE:
mLabel.setText(R.string.site_creating_fetching_info);
break;
case SET_TAGLINE:
mLabel.setText(R.string.site_creating_set_tagline);
break;
case SET_THEME:
mLabel.setText(R.string.site_creating_set_theme);
break;
case FAILURE:
mLabel.setText(R.string.site_creating_failed);
break;
case SUCCESS:
mLabel.setText(R.string.site_creating_success);
break;
}
}
}
Loading