Commit 67104b96 authored by Ricki Hirner's avatar Ricki Hirner

Accept intent extras for LoginActivity

parent e2c8fc96
......@@ -10,6 +10,7 @@ package at.bitfire.davdroid.ui.setup;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
......@@ -92,9 +93,10 @@ public class AccountDetailsFragment extends Fragment {
if (name.isEmpty())
editName.setError(getString(R.string.login_account_name_required));
else {
if (createAccount(name, (DavResourceFinder.Configuration)getArguments().getSerializable(KEY_CONFIG)))
if (createAccount(name, (DavResourceFinder.Configuration)getArguments().getSerializable(KEY_CONFIG))) {
getActivity().setResult(Activity.RESULT_OK);
getActivity().finish();
else
} else
Snackbar.make(v, R.string.login_account_not_created, Snackbar.LENGTH_LONG).show();
}
}
......
......@@ -17,8 +17,30 @@ import android.view.MenuItem;
import at.bitfire.davdroid.Constants;
import at.bitfire.davdroid.R;
/**
* Activity to initially connect to a server and create an account.
* Fields for server/user data can be pre-filled with extras in the Intent.
*/
public class LoginActivity extends AppCompatActivity {
/**
* When set, "login by URL" will be activated by default, and the URL field will be set to this value.
* When not set, "login by email" will be activated by default.
*/
public static final String EXTRA_URL = "url";
/**
* When set, and {@link #EXTRA_PASSWORD} is set too, the user name field will be set to this value.
* When set, and {@link #EXTRA_URL} is not set, the email address field will be set to this value.
*/
public static final String EXTRA_USERNAME = "username";
/**
* When set, the password field will be set to this value.
*/
public static final String EXTRA_PASSWORD = "password";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......
......@@ -8,6 +8,8 @@
package at.bitfire.davdroid.ui.setup;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
......@@ -63,8 +65,31 @@ public class LoginCredentialsFragment extends Fragment implements CompoundButton
radioUseEmail.setOnCheckedChangeListener(this);
radioUseURL.setOnCheckedChangeListener(this);
if (savedInstanceState == null)
if (savedInstanceState == null) {
// first call
Activity activity = getActivity();
Intent intent = (activity != null) ? activity.getIntent() : null;
if (intent != null) {
// we've got initial login data
String url = intent.getStringExtra(LoginActivity.EXTRA_URL),
username = intent.getStringExtra(LoginActivity.EXTRA_USERNAME),
password = intent.getStringExtra(LoginActivity.EXTRA_PASSWORD);
if (url != null) {
radioUseURL.setChecked(true);
editBaseURL.setText(url);
editUserName.setText(username);
editUrlPassword.setText(password);
} else {
radioUseEmail.setChecked(true);
editEmailAddress.setText(username);
editEmailPassword.setText(password);
}
} else
radioUseEmail.setChecked(true);
}
final Button login = (Button)v.findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment