Commit e0a538f7 authored by Grigory Fedorov's avatar Grigory Fedorov

Add conference screen changed: "X" up button, action menu, button removed.

parent e1a93d40
...@@ -14,18 +14,16 @@ ...@@ -14,18 +14,16 @@
*/ */
package com.xabber.android.ui; package com.xabber.android.ui;
import java.util.Collection;
import org.jivesoftware.smack.util.StringUtils;
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.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener; import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
...@@ -43,8 +41,11 @@ import com.xabber.android.ui.helper.ActionBarPainter; ...@@ -43,8 +41,11 @@ import com.xabber.android.ui.helper.ActionBarPainter;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class MUCEditor extends ManagedActivity implements View.OnClickListener, import org.jivesoftware.smack.util.StringUtils;
OnItemSelectedListener {
import java.util.Collection;
public class MUCEditor extends ManagedActivity implements OnItemSelectedListener {
private static final String SAVED_ACCOUNT = "com.xabber.android.ui.MUCEditor.SAVED_ACCOUNT"; private static final String SAVED_ACCOUNT = "com.xabber.android.ui.MUCEditor.SAVED_ACCOUNT";
private static final String SAVED_ROOM = "com.xabber.android.ui.MUCEditor.SAVED_ROOM"; private static final String SAVED_ROOM = "com.xabber.android.ui.MUCEditor.SAVED_ROOM";
...@@ -71,13 +72,16 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -71,13 +72,16 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (isFinishing()) if (isFinishing()) {
return; return;
}
setContentView(R.layout.muc_editor); setContentView(R.layout.muc_editor);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null);
accountView = (Spinner) findViewById(R.id.contact_account); accountView = (Spinner) findViewById(R.id.contact_account);
serverView = (EditText) findViewById(R.id.muc_server); serverView = (EditText) findViewById(R.id.muc_server);
...@@ -85,7 +89,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -85,7 +89,6 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
nickView = (EditText) findViewById(R.id.muc_nick); nickView = (EditText) findViewById(R.id.muc_nick);
passwordView = (EditText) findViewById(R.id.muc_password); passwordView = (EditText) findViewById(R.id.muc_password);
((Button) findViewById(R.id.ok)).setOnClickListener(this);
accountView.setAdapter(new AccountChooseAdapter(this)); accountView.setAdapter(new AccountChooseAdapter(this));
accountView.setOnItemSelectedListener(this); accountView.setOnItemSelectedListener(this);
...@@ -108,35 +111,36 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -108,35 +111,36 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
String password; String password;
RoomInvite roomInvite = MUCManager.getInstance().getInvite( RoomInvite roomInvite = MUCManager.getInstance().getInvite(
account, room); account, room);
if (roomInvite != null) if (roomInvite != null) {
password = roomInvite.getPassword(); password = roomInvite.getPassword();
else } else {
password = MUCManager.getInstance().getPassword(account, password = MUCManager.getInstance().getPassword(account, room);
room); }
passwordView.setText(password); passwordView.setText(password);
} }
} }
if (account == null) { if (account == null) {
Collection<String> accounts = AccountManager.getInstance() Collection<String> accounts = AccountManager.getInstance().getAccounts();
.getAccounts(); if (accounts.size() == 1) {
if (accounts.size() == 1)
account = accounts.iterator().next(); account = accounts.iterator().next();
} }
}
actionBarPainter = new ActionBarPainter(this); actionBarPainter = new ActionBarPainter(this);
if (account != null) { if (account != null) {
actionBarPainter.updateWithAccountName(account); actionBarPainter.updateWithAccountName(account);
for (int position = 0; position < accountView.getCount(); position++) for (int position = 0; position < accountView.getCount(); position++) {
if (account.equals(accountView.getItemAtPosition(position))) { if (account.equals(accountView.getItemAtPosition(position))) {
accountView.setSelection(position); accountView.setSelection(position);
break; break;
} }
} }
if ("".equals(nickView.getText().toString())) }
nickView.setText(getNickname(((String) accountView if ("".equals(nickView.getText().toString())) {
.getSelectedItem()))); nickView.setText(getNickname(((String) accountView.getSelectedItem())));
}
} }
...@@ -155,80 +159,89 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -155,80 +159,89 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
} }
@Override @Override
public void onClick(View view) { public boolean onCreateOptionsMenu(Menu menu) {
switch (view.getId()) { MenuInflater inflater=getMenuInflater();
case R.id.ok: inflater.inflate(R.menu.add_conference, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_conference:
addConference();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void addConference() {
String account = (String) accountView.getSelectedItem(); String account = (String) accountView.getSelectedItem();
if (account == null) { if (account == null) {
Toast.makeText(this, getString(R.string.EMPTY_ACCOUNT), Toast.makeText(this, getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG).show();
return; return;
} }
String server = serverView.getText().toString(); String server = serverView.getText().toString();
if ("".equals(server)) { if ("".equals(server)) {
Toast.makeText(this, getString(R.string.EMPTY_SERVER_NAME), Toast.makeText(this, getString(R.string.EMPTY_SERVER_NAME), Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG).show();
return; return;
} }
String room = roomView.getText().toString(); String room = roomView.getText().toString();
if ("".equals(room)) { if ("".equals(room)) {
Toast.makeText(this, getString(R.string.EMPTY_ROOM_NAME), Toast.makeText(this, getString(R.string.EMPTY_ROOM_NAME), Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG).show();
return; return;
} }
String nick = nickView.getText().toString(); String nick = nickView.getText().toString();
if ("".equals(nick)) { if ("".equals(nick)) {
Toast.makeText(this, getString(R.string.EMPTY_NICK_NAME), Toast.makeText(this, getString(R.string.EMPTY_NICK_NAME), Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG).show();
return; return;
} }
String password = passwordView.getText().toString(); String password = passwordView.getText().toString();
boolean join = ((CheckBox) findViewById(R.id.muc_join)).isChecked(); boolean join = ((CheckBox) findViewById(R.id.muc_join)).isChecked();
room = room + "@" + server; room = room + "@" + server;
if (this.account != null && this.room != null) if (this.account != null && this.room != null) {
if (!account.equals(this.account) || !room.equals(this.room)) { if (!account.equals(this.account) || !room.equals(this.room)) {
MUCManager.getInstance() MUCManager.getInstance().removeRoom(this.account, this.room);
.removeRoom(this.account, this.room); MessageManager.getInstance().closeChat(this.account, this.room);
MessageManager.getInstance().closeChat(this.account, NotificationManager.getInstance().removeMessageNotification(this.account, this.room);
this.room);
NotificationManager.getInstance()
.removeMessageNotification(this.account, this.room);
}
MUCManager.getInstance().createRoom(account, room, nick, password,
join);
finish();
break;
default:
break;
} }
} }
MUCManager.getInstance().createRoom(account, room, nick, password, join);
finish();
}
/** /**
* @param account * @param account
* @return Suggested nickname in the room. * @return Suggested nickname in the room.
*/ */
private String getNickname(String account) { private String getNickname(String account) {
if (account == null) if (account == null) {
return ""; return "";
}
String nickname = AccountManager.getInstance().getNickName(account); String nickname = AccountManager.getInstance().getNickName(account);
String name = StringUtils.parseName(nickname); String name = StringUtils.parseName(nickname);
if ("".equals(name)) if ("".equals(name)) {
return nickname; return nickname;
else } else {
return name; return name;
} }
}
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
long id) {
String current = nickView.getText().toString(); String current = nickView.getText().toString();
String previous; String previous;
if (selectedAccount == AdapterView.INVALID_POSITION) if (selectedAccount == AdapterView.INVALID_POSITION) {
previous = ""; previous = "";
else } else {
previous = getNickname((String) accountView.getAdapter().getItem(selectedAccount)); previous = getNickname((String) accountView.getAdapter().getItem(selectedAccount));
if (current.equals(previous)) }
if (current.equals(previous)) {
nickView.setText(getNickname((String) accountView.getSelectedItem())); nickView.setText(getNickname((String) accountView.getSelectedItem()));
}
selectedAccount = accountView.getSelectedItemPosition(); selectedAccount = accountView.getSelectedItemPosition();
actionBarPainter.updateWithAccountName((String) accountView.getSelectedItem()); actionBarPainter.updateWithAccountName((String) accountView.getSelectedItem());
...@@ -245,8 +258,7 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener, ...@@ -245,8 +258,7 @@ public class MUCEditor extends ManagedActivity implements View.OnClickListener,
public static Intent createIntent(Context context, String account, public static Intent createIntent(Context context, String account,
String room) { String room) {
return new EntityIntentBuilder(context, MUCEditor.class) return new EntityIntentBuilder(context, MUCEditor.class).setAccount(account).setUser(room).build();
.setAccount(account).setUser(room).build();
} }
private static String getAccount(Intent intent) { private static String getAccount(Intent intent) {
......
...@@ -101,22 +101,5 @@ ...@@ -101,22 +101,5 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
/> />
<LinearLayout
android:orientation="horizontal"
android:gravity="center_horizontal|bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:text="@string/muc_save"
android:id="@+id/ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_add_conference"
android:title="@string/muc_add"
app:showAsAction="always"
/>
</menu>
\ No newline at end of file
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/conference_editor_error.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/conference_editor_error.png -->
<string name="ALREADY_JOINED">Уже подключена</string> <string name="ALREADY_JOINED">Уже подключена</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/conference_editor.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/conference_editor.png -->
<string name="muc_add">Присоединиться к конференции</string> <string name="muc_add">Добавить конференцию</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_conference_context_menu.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_conference_context_menu.png -->
<string name="muc_delete">Удалить конференцию</string> <string name="muc_delete">Удалить конференцию</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_conference_confirm.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_conference_confirm.png -->
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/conference_editor_error.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/conference_editor_error.png -->
<string name="ALREADY_JOINED">Already joined</string> <string name="ALREADY_JOINED">Already joined</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/conference_editor.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/conference_editor.png -->
<string name="muc_add">Join conference</string> <string name="muc_add">Add conference</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_conference_context_menu.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_conference_context_menu.png -->
<string name="muc_delete">Remove conference</string> <string name="muc_delete">Remove conference</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_conference_confirm.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_conference_confirm.png -->
......
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