mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-11 20:15:03 -05:00
Handle usernames ( part of email or custom ). Small clean-ups.
This commit is contained in:
parent
6ade89ed54
commit
854c0e51d4
@ -70,13 +70,29 @@
|
|||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<TextView android:id="@+id/server_information"
|
<TextView android:id="@+id/server_information"
|
||||||
android:padding="8dp"
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
android:layout_below="@id/server_information_header"
|
android:layout_below="@id/server_information_header"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<!-- ONLY SHOW WHEN USER HAS TO ENTER A USERNAME HIMSELF -->
|
<!-- ONLY SHOW WHEN USER HAS TO ENTER A USERNAME HIMSELF -->
|
||||||
<!-- TODO -->
|
<LinearLayout android:id="@+id/account_custom_username"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="8dp">
|
||||||
|
<TextView android:id="@+id/account_username_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Please enter your username: "/>
|
||||||
|
<EditText android:id="@+id/account_username_field"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:hint="Username...... " />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- SHOULD ONLY BE MADE VISIBLE WHEN THERE ARE MULTIPLE MATCHING SERVERS
|
<!-- SHOULD ONLY BE MADE VISIBLE WHEN THERE ARE MULTIPLE MATCHING SERVERS
|
||||||
NOTE: see note at beginning of AbstractSetupConfirmActivity class -->
|
NOTE: see note at beginning of AbstractSetupConfirmActivity class -->
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_marginLeft="5dp"
|
|
||||||
android:textSize="14sp" >
|
|
||||||
</TextView>
|
|
@ -15,7 +15,9 @@ package com.fsck.k9.activity.setup;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.text.TextWatcher;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.text.method.MovementMethod;
|
import android.text.method.MovementMethod;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -30,6 +32,8 @@ import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.ServerType;
|
|||||||
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.SocketType;
|
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.SocketType;
|
||||||
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.Server;
|
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.Server;
|
||||||
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.InformationBlock;
|
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.InformationBlock;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class AbstractSetupConfirmActivity extends K9Activity implements View.OnClickListener, OnItemSelectedListener {
|
public abstract class AbstractSetupConfirmActivity extends K9Activity implements View.OnClickListener, OnItemSelectedListener {
|
||||||
@ -39,6 +43,9 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
|
|||||||
private static final String EXTRA_EMAIL = "email";
|
private static final String EXTRA_EMAIL = "email";
|
||||||
private static final String EXTRA_PASSWORD = "password";
|
private static final String EXTRA_PASSWORD = "password";
|
||||||
|
|
||||||
|
private final String LOCALPART_EMAIL = "%EMAILLOCALPART%";
|
||||||
|
private final String WHOLE_EMAIL = "%EMAILADDRESS%";
|
||||||
|
|
||||||
public static void actionConfirmIncoming(Context context, Account account, AutoconfigInfo info) {
|
public static void actionConfirmIncoming(Context context, Account account, AutoconfigInfo info) {
|
||||||
Intent i = new Intent(context, AccountSetupConfirmIncoming.class);
|
Intent i = new Intent(context, AccountSetupConfirmIncoming.class);
|
||||||
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
|
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
|
||||||
@ -57,9 +64,13 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
|
|||||||
// data
|
// data
|
||||||
protected Account mAccount;
|
protected Account mAccount;
|
||||||
protected AutoconfigInfo mConfigInfo;
|
protected AutoconfigInfo mConfigInfo;
|
||||||
|
protected String mEmail;
|
||||||
|
protected String mUsername;
|
||||||
|
private boolean mCustomUsername = false;
|
||||||
|
protected String mPassword;
|
||||||
|
|
||||||
// references to current selections ( easier to code with )
|
// references to current selections ( easier to code with )
|
||||||
private Server mCurrentServer;
|
protected Server mCurrentServer;
|
||||||
private ServerType mCurrentType;
|
private ServerType mCurrentType;
|
||||||
private SocketType mCurrentSocket;
|
private SocketType mCurrentSocket;
|
||||||
private List<? extends Server> mCurrentServerList;
|
private List<? extends Server> mCurrentServerList;
|
||||||
@ -72,6 +83,8 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
|
|||||||
private TextView mServerCountLabel;
|
private TextView mServerCountLabel;
|
||||||
private RelativeLayout mServerBrowseButtons;
|
private RelativeLayout mServerBrowseButtons;
|
||||||
private RelativeLayout mServerDocumentation;
|
private RelativeLayout mServerDocumentation;
|
||||||
|
private LinearLayout mUsernameView;
|
||||||
|
private EditText mUsernameField;
|
||||||
private TextView mDocumentationLinks;
|
private TextView mDocumentationLinks;
|
||||||
|
|
||||||
// difference between incomming & outgoing
|
// difference between incomming & outgoing
|
||||||
@ -91,30 +104,36 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
|
|||||||
mOkButton = (Button) findViewById(R.id.confirm_ok_button);
|
mOkButton = (Button) findViewById(R.id.confirm_ok_button);
|
||||||
mServerCountLabel = (TextView) findViewById(R.id.server_count_label);
|
mServerCountLabel = (TextView) findViewById(R.id.server_count_label);
|
||||||
mDocumentationLinks = (TextView) findViewById(R.id.server_documentation_content);
|
mDocumentationLinks = (TextView) findViewById(R.id.server_documentation_content);
|
||||||
|
mUsernameField = (EditText) findViewById(R.id.account_username_field);
|
||||||
|
|
||||||
|
mUsernameView = (LinearLayout) findViewById(R.id.account_custom_username);
|
||||||
mServerBrowseButtons = (RelativeLayout) findViewById(R.id.confirm_serverbrowse_buttons);
|
mServerBrowseButtons = (RelativeLayout) findViewById(R.id.confirm_serverbrowse_buttons);
|
||||||
mServerDocumentation = (RelativeLayout) findViewById(R.id.confirm_documentation_part);
|
mServerDocumentation = (RelativeLayout) findViewById(R.id.confirm_documentation_part);
|
||||||
|
|
||||||
// get the data out of our intent
|
// get the data out of our intent
|
||||||
// if no blank account passed make one
|
// if no blank account passed make one
|
||||||
|
mEmail = getIntent().getStringExtra(EXTRA_EMAIL);
|
||||||
|
mPassword = getIntent().getStringExtra(EXTRA_PASSWORD);
|
||||||
|
|
||||||
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
|
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
|
||||||
if(accountUuid != null)
|
if(accountUuid != null)
|
||||||
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
||||||
else mAccount = Account.getBlankAccount(this,
|
else mAccount = Account.getBlankAccount(this, mEmail, mPassword);
|
||||||
getIntent().getStringExtra(EXTRA_EMAIL),
|
|
||||||
getIntent().getStringExtra(EXTRA_PASSWORD));
|
|
||||||
mConfigInfo = getIntent().getParcelableExtra(EXTRA_CONFIG_INFO);
|
mConfigInfo = getIntent().getParcelableExtra(EXTRA_CONFIG_INFO);
|
||||||
|
|
||||||
// attach data to gui elements
|
// attach data to gui elements
|
||||||
ArrayAdapter<ServerType> protocolAdapter = new ArrayAdapter<ServerType>(this,
|
ArrayAdapter<ServerType> protocolAdapter = new ArrayAdapter<ServerType>(this,
|
||||||
R.layout.account_setup_confirm_spinners_item, getAvailableServerTypes());
|
android.R.layout.simple_spinner_item, getAvailableServerTypes());
|
||||||
mProtocolSpinner.setAdapter(protocolAdapter);
|
mProtocolSpinner.setAdapter(protocolAdapter);
|
||||||
|
protocolAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
|
||||||
List<SocketType> matchingSocketTypeList = mConfigInfo.getAvailableSocketTypes(
|
List<SocketType> matchingSocketTypeList = mConfigInfo.getAvailableSocketTypes(
|
||||||
mConfigInfo.getFilteredServerList(getServers(),protocolAdapter.getItem(0), null, null));
|
mConfigInfo.getFilteredServerList(getServers(),protocolAdapter.getItem(0), null, null));
|
||||||
ArrayAdapter<SocketType> socketTypeAdapter = new ArrayAdapter<SocketType>(this,
|
ArrayAdapter<SocketType> socketTypeAdapter = new ArrayAdapter<SocketType>(this,
|
||||||
R.layout.account_setup_confirm_spinners_item, matchingSocketTypeList);
|
android.R.layout.simple_spinner_item, matchingSocketTypeList);
|
||||||
mSocketTypeSpinner.setAdapter(socketTypeAdapter);
|
mSocketTypeSpinner.setAdapter(socketTypeAdapter);
|
||||||
|
socketTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
|
||||||
// if there is extra information, display it
|
// if there is extra information, display it
|
||||||
if( mConfigInfo.hasExtraInfo() ){
|
if( mConfigInfo.hasExtraInfo() ){
|
||||||
@ -126,6 +145,18 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
|
|||||||
mProtocolSpinner.setOnItemSelectedListener(this);
|
mProtocolSpinner.setOnItemSelectedListener(this);
|
||||||
mSocketTypeSpinner.setOnItemSelectedListener(this);
|
mSocketTypeSpinner.setOnItemSelectedListener(this);
|
||||||
mOkButton.setOnClickListener(this);
|
mOkButton.setOnClickListener(this);
|
||||||
|
mUsernameField.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||||
|
if( mCustomUsername )
|
||||||
|
if( ! mUsernameField.getText().toString().isEmpty() ) mOkButton.setEnabled(true);
|
||||||
|
else mOkButton.setEnabled(false);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable editable) {}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -152,7 +183,9 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
|
|||||||
// now we have to reset the options in sockettype spinner
|
// now we have to reset the options in sockettype spinner
|
||||||
List<SocketType> newTypes = mConfigInfo.getAvailableSocketTypes(
|
List<SocketType> newTypes = mConfigInfo.getAvailableSocketTypes(
|
||||||
mConfigInfo.getFilteredServerList(getServers(),(ServerType) mProtocolSpinner.getAdapter().getItem(pos), null, null));
|
mConfigInfo.getFilteredServerList(getServers(),(ServerType) mProtocolSpinner.getAdapter().getItem(pos), null, null));
|
||||||
mSocketTypeSpinner.setAdapter(new ArrayAdapter(this, R.layout.account_setup_confirm_spinners_item, newTypes));
|
ArrayAdapter<SocketType> tmpAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, newTypes);
|
||||||
|
tmpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
mSocketTypeSpinner.setAdapter(tmpAdapter);
|
||||||
mSocketTypeSpinner.invalidate();
|
mSocketTypeSpinner.invalidate();
|
||||||
break;
|
break;
|
||||||
case R.id.spinner_sockettype:
|
case R.id.spinner_sockettype:
|
||||||
@ -192,11 +225,39 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
|
|||||||
|
|
||||||
|
|
||||||
private void setServerInfo(Server mCurrentServer) {
|
private void setServerInfo(Server mCurrentServer) {
|
||||||
// TODO: string resources
|
// TODO: use string resources
|
||||||
mServerInfoText.setText("Host: "+mCurrentServer.hostname+"\n"+
|
mServerInfoText.setText("Host: "+mCurrentServer.hostname+"\n"+
|
||||||
"Port: "+mCurrentServer.port+"\n"+
|
"Port: "+mCurrentServer.port+"\n"+
|
||||||
"Authentication: "+mCurrentServer.authentication);
|
"Authentication: "+mCurrentServer.authentication);
|
||||||
|
|
||||||
|
// see if we need a custom username
|
||||||
|
if( mCurrentServer.username != null ){
|
||||||
|
mServerInfoText.setText(mServerInfoText.getText().toString()+"\n"+
|
||||||
|
"Username: "+determineUsername(mCurrentServer));
|
||||||
|
mOkButton.setEnabled(true);
|
||||||
|
mCustomUsername = false;
|
||||||
|
mUsernameView.setVisibility(View.GONE);
|
||||||
|
}else{
|
||||||
|
mOkButton.setEnabled(false);
|
||||||
|
mCustomUsername = true;
|
||||||
|
mUsernameView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private String determineUsername(Server mCurrentServer) {
|
||||||
|
mCustomUsername = false;
|
||||||
|
if( mCurrentServer.username.equals(LOCALPART_EMAIL)){
|
||||||
|
mUsername = mEmail.split("@")[0];
|
||||||
|
}else if( mCurrentServer.username.equals(WHOLE_EMAIL)){
|
||||||
|
mUsername = mEmail;
|
||||||
|
}else{
|
||||||
|
mUsername = mCurrentServer.username;
|
||||||
|
}
|
||||||
|
return mUsername;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setServerCount(int count){
|
private void setServerCount(int count){
|
||||||
mServerCountLabel.setText("( "+count+" / "+mCurrentServerList.size()+" )");
|
mServerCountLabel.setText("( "+count+" / "+mCurrentServerList.size()+" )");
|
||||||
@ -204,4 +265,15 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNothingSelected(AdapterView<?> adapterView) {}
|
public void onNothingSelected(AdapterView<?> adapterView) {}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Assuming the first one is set correctly, no checks are build in
|
||||||
|
*/
|
||||||
|
protected String getScheme(){
|
||||||
|
String scheme = "";
|
||||||
|
scheme = mCurrentType.getSchemeName();
|
||||||
|
if( mCurrentSocket != SocketType.plain && mCurrentSocket != SocketType.UNSET )
|
||||||
|
scheme += "+"+mCurrentSocket.getSchemeName();
|
||||||
|
return scheme;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,19 @@ package com.fsck.k9.activity.setup;
|
|||||||
the final settings.
|
the final settings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo;
|
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo;
|
||||||
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.ServerType;
|
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.ServerType;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity{
|
public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity {
|
||||||
@Override
|
@Override
|
||||||
protected List<? extends AutoconfigInfo.Server> getServers() {
|
protected List<? extends AutoconfigInfo.Server> getServers() {
|
||||||
return mConfigInfo.incomingServer;
|
return mConfigInfo.incomingServer;
|
||||||
@ -23,6 +31,25 @@ public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finishAction() {
|
protected void finishAction() {
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
try {
|
||||||
|
// this should already be set, only the username could be different.. but anyway
|
||||||
|
String usernameEnc = URLEncoder.encode(mUsername, "UTF-8");
|
||||||
|
String passwordEnc = URLEncoder.encode(mPassword, "UTF-8");
|
||||||
|
|
||||||
|
URI uri = new URI(
|
||||||
|
getScheme(),
|
||||||
|
usernameEnc + ":" + passwordEnc,
|
||||||
|
mCurrentServer.hostname,
|
||||||
|
mCurrentServer.port,
|
||||||
|
null,null,null);
|
||||||
|
mAccount.setTransportUri(uri.toString());
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException enc) {}
|
||||||
|
catch (URISyntaxException use) {
|
||||||
|
/*
|
||||||
|
* If we can't set up the URL we just continue. It's only for
|
||||||
|
* convenience.
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,14 +53,28 @@ public class AutoconfigInfo implements Parcelable {
|
|||||||
Define types for some of the data
|
Define types for some of the data
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
public static enum AuthenticationType { plain, secure, NTLM, GSSAPI, clientIPaddress, TLSclientcert, none, UNSET };
|
public static enum AuthenticationType { plain, secure, NTLM, GSSAPI, clientIPaddress, TLSclientcert, none, UNSET };
|
||||||
public static enum SocketType { plain, SSL, STARTTLS, UNSET};
|
public static enum SocketType { plain(""), SSL("ssl"), STARTTLS("tls"), UNSET("");
|
||||||
|
private String schemeName;
|
||||||
|
|
||||||
|
SocketType(String schemeName){ this.schemeName = schemeName; }
|
||||||
|
public String getSchemeName() {
|
||||||
|
return schemeName;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static enum RestrictionType { clientIPAddress };
|
public static enum RestrictionType { clientIPAddress };
|
||||||
public static enum InformationType { ENABLE, INSTRUCTION, DOCUMENTATION }
|
public static enum InformationType { ENABLE, INSTRUCTION, DOCUMENTATION }
|
||||||
|
|
||||||
public static enum ServerType{ IMAP(0), POP3(1), SMTP(2), UNSET(3), NO_VALUE(4), WRONG_TAG(5);
|
public static enum ServerType{ IMAP(0,"imap"), POP3(1,"pop3"), SMTP(2,"smtp"), UNSET(3,""), NO_VALUE(4,""), WRONG_TAG(5,"");
|
||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
ServerType(int type){this.type = type;}
|
private String schemeName;
|
||||||
|
|
||||||
|
ServerType(int type, String schemeName){
|
||||||
|
this.type = type;
|
||||||
|
this.schemeName = schemeName;
|
||||||
|
}
|
||||||
|
|
||||||
public Server getServerObject(Parcel parcel){
|
public Server getServerObject(Parcel parcel){
|
||||||
// ugly here but cleanest solution to mix the parcelable and inheritance in the server classes ( user of super() )
|
// ugly here but cleanest solution to mix the parcelable and inheritance in the server classes ( user of super() )
|
||||||
switch(type){
|
switch(type){
|
||||||
@ -83,6 +97,10 @@ public class AutoconfigInfo implements Parcelable {
|
|||||||
return NO_VALUE;
|
return NO_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSchemeName() {
|
||||||
|
return schemeName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user