Fix: Crash on account creation

Wizard crashed if no account were found from NIP

Change-Id: I1e6d8f77a54baf3b6e02a702167042fe1fb087df
diff --git a/ring-android/app/src/main/AndroidManifest.xml b/ring-android/app/src/main/AndroidManifest.xml
index 52bd97d..64a5a25 100644
--- a/ring-android/app/src/main/AndroidManifest.xml
+++ b/ring-android/app/src/main/AndroidManifest.xml
@@ -128,7 +128,7 @@
             </intent-filter>
         </activity>
         <activity
-            android:name=".account.AccountWizard"
+            android:name=".account.AccountWizardActivity"
             android:configChanges="screenSize|screenLayout|smallestScreenSize"
             android:screenOrientation="fullUser"
             android:theme="@style/AppThemeBase" />
diff --git a/ring-android/app/src/main/java/cx/ring/account/AccountEditionActivity.java b/ring-android/app/src/main/java/cx/ring/account/AccountEditionActivity.java
index d74d84d..60e67aa 100644
--- a/ring-android/app/src/main/java/cx/ring/account/AccountEditionActivity.java
+++ b/ring-android/app/src/main/java/cx/ring/account/AccountEditionActivity.java
@@ -221,7 +221,7 @@
 
     @Override
     public void goToWizardActivity() {
-        Intent intent = new Intent(this, AccountWizard.class);
+        Intent intent = new Intent(this, AccountWizardActivity.class);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
         startActivity(intent);
diff --git a/ring-android/app/src/main/java/cx/ring/account/AccountWizard.java b/ring-android/app/src/main/java/cx/ring/account/AccountWizardActivity.java
similarity index 94%
rename from ring-android/app/src/main/java/cx/ring/account/AccountWizard.java
rename to ring-android/app/src/main/java/cx/ring/account/AccountWizardActivity.java
index 4b32803..120b133 100644
--- a/ring-android/app/src/main/java/cx/ring/account/AccountWizard.java
+++ b/ring-android/app/src/main/java/cx/ring/account/AccountWizardActivity.java
@@ -53,8 +53,8 @@
 import ezvcard.property.RawProperty;
 import ezvcard.property.Uid;
 
-public class AccountWizard extends BaseActivity<AccountWizardPresenter> implements AccountWizardView {
-    static final String TAG = AccountWizard.class.getName();
+public class AccountWizardActivity extends BaseActivity<AccountWizardPresenter> implements AccountWizardView {
+    static final String TAG = AccountWizardActivity.class.getName();
 
     private ProgressDialog mProgress = null;
     private String mAccountType;
@@ -170,7 +170,7 @@
     public void displayProgress(final boolean display) {
         runOnUiThread(() -> {
             if (display) {
-                mProgress = new ProgressDialog(AccountWizard.this);
+                mProgress = new ProgressDialog(AccountWizardActivity.this);
                 mProgress.setTitle(R.string.dialog_wait_create);
                 mProgress.setMessage(getString(R.string.dialog_wait_create_details));
                 mProgress.setCancelable(false);
@@ -189,7 +189,7 @@
 
     @Override
     public void displayCreationError() {
-        runOnUiThread(() -> Toast.makeText(AccountWizard.this, "Error creating account", Toast.LENGTH_SHORT).show());
+        runOnUiThread(() -> Toast.makeText(AccountWizardActivity.this, "Error creating account", Toast.LENGTH_SHORT).show());
     }
 
     @Override
@@ -202,7 +202,7 @@
     public void finish(final boolean affinity) {
         runOnUiThread(() -> {
             if (affinity) {
-                startActivity(new Intent(AccountWizard.this, HomeActivity.class));
+                startActivity(new Intent(AccountWizardActivity.this, HomeActivity.class));
                 finish();
             } else {
                 finishAffinity();
@@ -216,7 +216,7 @@
             if (mAlertDialog != null && mAlertDialog.isShowing()) {
                 return;
             }
-            mAlertDialog = new AlertDialog.Builder(AccountWizard.this)
+            mAlertDialog = new AlertDialog.Builder(AccountWizardActivity.this)
                     .setPositiveButton(android.R.string.ok, null)
                     .setTitle(R.string.account_cannot_be_found_title)
                     .setMessage(R.string.account_cannot_be_found_message)
@@ -230,7 +230,7 @@
             if (mAlertDialog != null && mAlertDialog.isShowing()) {
                 return;
             }
-            mAlertDialog = new AlertDialog.Builder(AccountWizard.this)
+            mAlertDialog = new AlertDialog.Builder(AccountWizardActivity.this)
                     .setPositiveButton(android.R.string.ok, null)
                     .setTitle(R.string.account_no_network_title)
                     .setMessage(R.string.account_no_network_message)
@@ -244,7 +244,7 @@
             if (mAlertDialog != null && mAlertDialog.isShowing()) {
                 return;
             }
-            mAlertDialog = new AlertDialog.Builder(AccountWizard.this)
+            mAlertDialog = new AlertDialog.Builder(AccountWizardActivity.this)
                     .setPositiveButton(android.R.string.ok, null)
                     .setTitle(R.string.account_cannot_be_found_title)
                     .setMessage(R.string.account_cannot_be_found_message)
@@ -258,7 +258,7 @@
             if (mAlertDialog != null && mAlertDialog.isShowing()) {
                 return;
             }
-            mAlertDialog = new AlertDialog.Builder(AccountWizard.this)
+            mAlertDialog = new AlertDialog.Builder(AccountWizardActivity.this)
                     .setPositiveButton(android.R.string.ok, null)
                     .setTitle(R.string.account_device_added_title)
                     .setMessage(R.string.account_device_added_message)
diff --git a/ring-android/app/src/main/java/cx/ring/account/RingAccountCreationFragment.java b/ring-android/app/src/main/java/cx/ring/account/RingAccountCreationFragment.java
index 7ab0df9..13c1e7f 100644
--- a/ring-android/app/src/main/java/cx/ring/account/RingAccountCreationFragment.java
+++ b/ring-android/app/src/main/java/cx/ring/account/RingAccountCreationFragment.java
@@ -114,7 +114,7 @@
     @Override
     public void onAttach(Context context) {
         super.onAttach(context);
-        ActionBar ab = ((AccountWizard) getActivity()).getSupportActionBar();
+        ActionBar ab = ((AccountWizardActivity) getActivity()).getSupportActionBar();
         if (ab != null) {
             ab.setTitle(R.string.account_create_title);
         }
@@ -216,8 +216,8 @@
     @Override
     public void goToAccountCreation(RingAccountViewModel ringAccountViewModel) {
         Activity wizardActivity = getActivity();
-        if (wizardActivity != null && wizardActivity instanceof AccountWizard) {
-            AccountWizard wizard = (AccountWizard) wizardActivity;
+        if (wizardActivity != null && wizardActivity instanceof AccountWizardActivity) {
+            AccountWizardActivity wizard = (AccountWizardActivity) wizardActivity;
             wizard.createAccount(ringAccountViewModel);
         }
     }
diff --git a/ring-android/app/src/main/java/cx/ring/account/RingLinkAccountFragment.java b/ring-android/app/src/main/java/cx/ring/account/RingLinkAccountFragment.java
index 90601aa..a84723c 100644
--- a/ring-android/app/src/main/java/cx/ring/account/RingLinkAccountFragment.java
+++ b/ring-android/app/src/main/java/cx/ring/account/RingLinkAccountFragment.java
@@ -103,6 +103,6 @@
 
     @Override
     public void createAccount(RingAccountViewModel ringAccountViewModel) {
-        ((AccountWizard) getActivity()).createAccount(ringAccountViewModel);
+        ((AccountWizardActivity) getActivity()).createAccount(ringAccountViewModel);
     }
 }
\ No newline at end of file
diff --git a/ring-android/app/src/main/java/cx/ring/client/HomeActivity.java b/ring-android/app/src/main/java/cx/ring/client/HomeActivity.java
index 8e12373..ad80e04 100644
--- a/ring-android/app/src/main/java/cx/ring/client/HomeActivity.java
+++ b/ring-android/app/src/main/java/cx/ring/client/HomeActivity.java
@@ -54,7 +54,7 @@
 import cx.ring.BuildConfig;
 import cx.ring.R;
 import cx.ring.about.AboutFragment;
-import cx.ring.account.AccountWizard;
+import cx.ring.account.AccountWizardActivity;
 import cx.ring.application.RingApplication;
 import cx.ring.contactrequests.ContactRequestsFragment;
 import cx.ring.fragments.AccountsManagementFragment;
@@ -535,7 +535,7 @@
         if (!isDrawerLocked) {
             mNavigationDrawer.closeDrawers();
         }
-        Intent intent = new Intent(HomeActivity.this, AccountWizard.class);
+        Intent intent = new Intent(HomeActivity.this, AccountWizardActivity.class);
         intent.setAction(AccountConfig.ACCOUNT_TYPE_SIP);
         startActivityForResult(intent, AccountsManagementFragment.ACCOUNT_CREATE_REQUEST);
     }
@@ -545,7 +545,7 @@
         if (!isDrawerLocked) {
             mNavigationDrawer.closeDrawers();
         }
-        Intent intent = new Intent(HomeActivity.this, AccountWizard.class);
+        Intent intent = new Intent(HomeActivity.this, AccountWizardActivity.class);
         intent.setAction(AccountConfig.ACCOUNT_TYPE_RING);
         startActivityForResult(intent, AccountsManagementFragment.ACCOUNT_CREATE_REQUEST);
     }
diff --git a/ring-android/app/src/main/java/cx/ring/dependencyinjection/RingInjectionComponent.java b/ring-android/app/src/main/java/cx/ring/dependencyinjection/RingInjectionComponent.java
index db2d384..377ec0a 100755
--- a/ring-android/app/src/main/java/cx/ring/dependencyinjection/RingInjectionComponent.java
+++ b/ring-android/app/src/main/java/cx/ring/dependencyinjection/RingInjectionComponent.java
@@ -23,7 +23,7 @@
 
 import cx.ring.about.AboutFragment;
 import cx.ring.account.AccountEditionActivity;
-import cx.ring.account.AccountWizard;
+import cx.ring.account.AccountWizardActivity;
 import cx.ring.account.HomeAccountCreationFragment;
 import cx.ring.account.ProfileCreationFragment;
 import cx.ring.account.RegisterNameDialog;
@@ -87,7 +87,7 @@
 
     void inject(HomeActivity activity);
 
-    void inject(AccountWizard activity);
+    void inject(AccountWizardActivity activity);
 
     void inject(AccountEditionActivity activity);
 
diff --git a/ring-android/app/src/main/java/cx/ring/fragments/AccountsManagementFragment.java b/ring-android/app/src/main/java/cx/ring/fragments/AccountsManagementFragment.java
index 48976e8..e66d6f3 100644
--- a/ring-android/app/src/main/java/cx/ring/fragments/AccountsManagementFragment.java
+++ b/ring-android/app/src/main/java/cx/ring/fragments/AccountsManagementFragment.java
@@ -38,7 +38,7 @@
 import butterknife.OnItemClick;
 import cx.ring.R;
 import cx.ring.account.AccountEditionActivity;
-import cx.ring.account.AccountWizard;
+import cx.ring.account.AccountWizardActivity;
 import cx.ring.account.AccountsAdapter;
 import cx.ring.account.AccountsManagementPresenter;
 import cx.ring.account.AccountsManagementView;
@@ -128,14 +128,14 @@
         Log.d(TAG, "Launch account migration activity");
 
         Intent intent = new Intent()
-                .setClass(getActivity(), AccountWizard.class)
+                .setClass(getActivity(), AccountWizardActivity.class)
                 .setData(Uri.withAppendedPath(ContentUriHandler.ACCOUNTS_CONTENT_URI, account.getAccountID()));
         startActivityForResult(intent, ACCOUNT_EDIT_REQUEST);
     }
 
     @Override
     public void launchWizardActivity() {
-        Intent intent = new Intent(getActivity(), AccountWizard.class);
+        Intent intent = new Intent(getActivity(), AccountWizardActivity.class);
         startActivityForResult(intent, ACCOUNT_CREATE_REQUEST);
     }
 
diff --git a/ring-android/app/src/main/java/cx/ring/launch/LaunchActivity.java b/ring-android/app/src/main/java/cx/ring/launch/LaunchActivity.java
index e6fb779..6841385 100644
--- a/ring-android/app/src/main/java/cx/ring/launch/LaunchActivity.java
+++ b/ring-android/app/src/main/java/cx/ring/launch/LaunchActivity.java
@@ -31,7 +31,7 @@
 import java.util.ArrayList;
 
 import cx.ring.R;
-import cx.ring.account.AccountWizard;
+import cx.ring.account.AccountWizardActivity;
 import cx.ring.application.RingApplication;
 import cx.ring.client.HomeActivity;
 import cx.ring.mvp.BaseActivity;
@@ -63,7 +63,7 @@
 
     @Override
     public void goToAccountCreation() {
-        startActivity(new Intent(LaunchActivity.this, AccountWizard.class));
+        startActivity(new Intent(LaunchActivity.this, AccountWizardActivity.class));
         finish();
     }
 
diff --git a/ring-android/app/src/main/java/cx/ring/navigation/RingNavigationFragment.java b/ring-android/app/src/main/java/cx/ring/navigation/RingNavigationFragment.java
index cab96fb..492ce61 100644
--- a/ring-android/app/src/main/java/cx/ring/navigation/RingNavigationFragment.java
+++ b/ring-android/app/src/main/java/cx/ring/navigation/RingNavigationFragment.java
@@ -51,7 +51,7 @@
 import butterknife.BindView;
 import butterknife.OnClick;
 import cx.ring.R;
-import cx.ring.account.AccountWizard;
+import cx.ring.account.AccountWizardActivity;
 import cx.ring.adapters.ContactDetailsTask;
 import cx.ring.application.RingApplication;
 import cx.ring.client.HomeActivity;
@@ -271,7 +271,7 @@
 
     @OnClick(R.id.addaccount_btn)
     public void addNewAccount() {
-        getActivity().startActivity(new Intent(getActivity(), AccountWizard.class));
+        getActivity().startActivity(new Intent(getActivity(), AccountWizardActivity.class));
     }
 
     private void setupNavigationMenu() {
diff --git a/ring-android/app/src/main/res/drawable/icon_focused.xml b/ring-android/app/src/main/res/drawable/icon_focused.xml
index bab1cc6..62eabed 100644
--- a/ring-android/app/src/main/res/drawable/icon_focused.xml
+++ b/ring-android/app/src/main/res/drawable/icon_focused.xml
@@ -1,19 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2015 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
     <solid android:color="#4DEEEEEE"></solid>
diff --git a/ring-android/app/src/main/res/layout/frag_acc_home_create.xml b/ring-android/app/src/main/res/layout/frag_acc_home_create.xml
index a7ba42c..a044ebc 100644
--- a/ring-android/app/src/main/res/layout/frag_acc_home_create.xml
+++ b/ring-android/app/src/main/res/layout/frag_acc_home_create.xml
@@ -4,7 +4,7 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="@color/color_primary_light"
-    tools:context=".account.AccountWizard">
+    tools:context=".account.AccountWizardActivity">
 
     <LinearLayout
         android:layout_width="match_parent"
diff --git a/ring-android/app/src/main/res/layout/frag_acc_ring_create.xml b/ring-android/app/src/main/res/layout/frag_acc_ring_create.xml
index a9cf16e..784f320 100644
--- a/ring-android/app/src/main/res/layout/frag_acc_ring_create.xml
+++ b/ring-android/app/src/main/res/layout/frag_acc_ring_create.xml
@@ -6,7 +6,7 @@
     android:layout_height="match_parent"
     android:theme="@style/Wizard"
     tools:background="@color/color_primary_dark"
-    tools:context="cx.ring.account.AccountWizard">
+    tools:context="cx.ring.account.AccountWizardActivity">
 
     <cx.ring.views.BoundedScrollView
         android:layout_width="match_parent"
diff --git a/ring-android/app/src/main/res/layout/frag_account_migration.xml b/ring-android/app/src/main/res/layout/frag_account_migration.xml
index 3cae936..96364ee 100644
--- a/ring-android/app/src/main/res/layout/frag_account_migration.xml
+++ b/ring-android/app/src/main/res/layout/frag_account_migration.xml
@@ -23,7 +23,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    tools:context=".account.AccountWizard">
+    tools:context=".account.AccountWizardActivity">
 
     <cx.ring.views.BoundedLinearLayout
         style="@style/AccountFormContainer"
diff --git a/ring-android/libringclient/src/main/java/cx/ring/account/AccountWizardPresenter.java b/ring-android/libringclient/src/main/java/cx/ring/account/AccountWizardPresenter.java
index 4841db9..d763fba 100644
--- a/ring-android/libringclient/src/main/java/cx/ring/account/AccountWizardPresenter.java
+++ b/ring-android/libringclient/src/main/java/cx/ring/account/AccountWizardPresenter.java
@@ -178,16 +178,20 @@
 
         String stateAccountId = event.getEventInput(ServiceEvent.EventInput.ACCOUNT_ID, String.class);
 
+        getView().displayProgress(false);
+
         if (!stateAccountId.isEmpty() && stateAccountId.equals(mCreatedAccountId)) {
             String newState = event.getEventInput(ServiceEvent.EventInput.STATE, String.class);
 
             mAccount = mAccountService.getAccount(mCreatedAccountId);
-
-            if (mAccount != null && mAccount.isRing() && (newState.isEmpty() || newState.contentEquals(AccountConfig.STATE_INITIALIZING))) {
+            if (mAccount == null) {
+                getView().displayCannotBeFoundError();
                 return;
             }
 
-            getView().displayProgress(false);
+            if (mAccount.isRing() && (newState.isEmpty() || newState.contentEquals(AccountConfig.STATE_INITIALIZING))) {
+                return;
+            }
 
             if (!mCreationError) {
                 switch (newState) {