Set charset on server add/edit

This commit is contained in:
Sebastian Kaspari 2010-04-05 22:36:04 +02:00
parent a809ad5245
commit e78a53cae9
3 changed files with 50 additions and 2 deletions

View File

@ -128,6 +128,24 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:layout_height="wrap_content"
android:text=""
android:singleLine="true" />
<TextView
android:text="Preferences"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff333333"
android:textSize="14px"
android:gravity="center_horizontal"
android:padding="3px"
android:layout_margin="2px" />
<TextView
android:text="Charset"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/charset"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/select_charset" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"

View File

@ -19,6 +19,7 @@
<string name="server_autoconnect">Auto connect on startup</string>
<string name="server_channels">Channels</string>
<string name="add_server">Add server</string>
<string name="select_charset">Select a charset</string>
<string name="cancel">Cancel</string>

View File

@ -20,6 +20,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
*/
package org.yaaic.activity;
import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;
import android.app.Activity;
@ -27,8 +28,10 @@ import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import org.yaaic.R;
@ -61,6 +64,12 @@ public class AddServerActivity extends Activity implements OnClickListener
((Button) findViewById(R.id.add)).setOnClickListener(this);
((Button) findViewById(R.id.cancel)).setOnClickListener(this);
Spinner spinner = (Spinner) findViewById(R.id.charset);
String[] charsets = getResources().getStringArray(R.array.charsets);
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, charsets);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey(Extra.SERVER)) {
@ -80,6 +89,16 @@ public class AddServerActivity extends Activity implements OnClickListener
((EditText) findViewById(R.id.realname)).setText(server.getIdentity().getRealName());
((Button) findViewById(R.id.add)).setText("Save");
// Select charset
if (server.getCharset() != null) {
for (int i = 0; i < charsets.length; i++) {
if (server.getCharset().equals(charsets[i])) {
spinner.setSelection(i);
break;
}
}
}
}
Uri uri = getIntent().getData();
@ -144,7 +163,7 @@ public class AddServerActivity extends Activity implements OnClickListener
false, // auto connect
false, // use ssl
identityId,
null // XXX: Soft migration until view has a charset component
server.getCharset()
);
db.close();
@ -175,7 +194,7 @@ public class AddServerActivity extends Activity implements OnClickListener
false, // auto connect
false, // use ssl
identityId,
null // XXX: Softmigration until the view has a charset component
server.getCharset()
);
Identity identity = getIdentityFromView();
@ -205,6 +224,7 @@ public class AddServerActivity extends Activity implements OnClickListener
String host = ((EditText) findViewById(R.id.host)).getText().toString();
int port = Integer.parseInt(((EditText) findViewById(R.id.port)).getText().toString());
String password = ((EditText) findViewById(R.id.password)).getText().toString();
String charset = ((Spinner) findViewById(R.id.charset)).getSelectedItem().toString();
// not in use yet
//boolean autoConnect = ((CheckBox) findViewById(R.id.autoconnect)).isChecked();
@ -215,6 +235,7 @@ public class AddServerActivity extends Activity implements OnClickListener
server.setPort(port);
server.setPassword(password);
server.setTitle(title);
server.setCharset(charset);
server.setStatus(Status.DISCONNECTED);
return server;
@ -249,6 +270,7 @@ public class AddServerActivity extends Activity implements OnClickListener
String title = ((EditText) findViewById(R.id.title)).getText().toString();
String host = ((EditText) findViewById(R.id.host)).getText().toString();
String port = ((EditText) findViewById(R.id.port)).getText().toString();
String charset = ((Spinner) findViewById(R.id.charset)).getSelectedItem().toString();
if (title.trim().equals("")) {
throw new ValidationException("Title cannot be blank");
@ -265,6 +287,13 @@ public class AddServerActivity extends Activity implements OnClickListener
throw new ValidationException("Enter a numeric port");
}
try {
"".getBytes(charset);
}
catch (UnsupportedEncodingException e) {
throw new ValidationException("Charset is not supported by your device");
}
Database db = new Database(this);
if (db.isTitleUsed(title) && (server == null || !server.getTitle().equals(title))) {
db.close();