Commit bfa625b4 authored by Grigory Fedorov's avatar Grigory Fedorov

ConferenceAdd activity and fragment changed to let choose only nick and password. #503

parent 0ad59543
......@@ -20,29 +20,20 @@ import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import com.xabber.android.R;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.ui.helper.BarPainter;
import com.xabber.android.ui.helper.ManagedActivity;
import java.util.Collection;
public class ConferenceAdd extends ManagedActivity implements ConferenceAddFragment.Listener {
public class ConferenceAdd extends ManagedActivity {
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 BarPainter barPainter;
private String account;
private String room;
public static Intent createIntent(Context context) {
return ConferenceAdd.createIntent(context, null, null);
}
public static Intent createIntent(Context context, String account,
String room) {
public static Intent createIntent(Context context, String account, String room) {
return new EntityIntentBuilder(context, ConferenceAdd.class).setAccount(account).setUser(room).build();
}
......@@ -69,14 +60,11 @@ public class ConferenceAdd extends ManagedActivity implements ConferenceAddFragm
setSupportActionBar(toolbar);
barPainter = new BarPainter(this, toolbar);
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.setDefaultColor();
Intent intent = getIntent();
account = null;
room = null;
if (savedInstanceState != null) {
account = savedInstanceState.getString(SAVED_ACCOUNT);
room = savedInstanceState.getString(SAVED_ROOM);
......@@ -85,16 +73,7 @@ public class ConferenceAdd extends ManagedActivity implements ConferenceAddFragm
room = getUser(intent);
}
if (account == null) {
Collection<String> accounts = AccountManager.getInstance().getAccounts();
if (accounts.size() == 1) {
account = accounts.iterator().next();
}
}
if (account != null) {
barPainter.updateWithAccountName(account);
}
barPainter.updateWithAccountName(account);
if (savedInstanceState == null) {
getFragmentManager()
......@@ -110,10 +89,4 @@ public class ConferenceAdd extends ManagedActivity implements ConferenceAddFragm
outState.putString(SAVED_ACCOUNT, account);
outState.putString(SAVED_ROOM, room);
}
@Override
public void onAccountSelected(String account) {
barPainter.updateWithAccountName(account);
this.account = account;
}
}
package com.xabber.android.ui;
import android.app.Activity;
import android.app.Fragment;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
......@@ -10,41 +10,29 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.xabber.android.R;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomInvite;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter;
import org.jivesoftware.smack.util.StringUtils;
public class ConferenceAddFragment extends Fragment implements AdapterView.OnItemSelectedListener {
public class ConferenceAddFragment extends Fragment {
protected static final String ARG_ACCOUNT = "com.xabber.android.ui.ConferenceAddFragment.ARG_ACCOUNT";
protected static final String ARG_ROOM = "com.xabber.android.ui.ConferenceAddFragment.ARG_ROOM";
private Spinner accountView;
private EditText serverView;
private EditText roomView;
private EditText nickView;
private EditText passwordView;
private CheckBox joinCheckBox;
private int selectedAccount;
private String account = null;
private String room = null;
private Listener listener;
public static ConferenceAddFragment newInstance(String account, String room) {
ConferenceAddFragment fragment = new ConferenceAddFragment();
Bundle args = new Bundle();
......@@ -54,13 +42,6 @@ public class ConferenceAddFragment extends Fragment implements AdapterView.OnIte
return fragment;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listener = (Listener) activity;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -71,93 +52,45 @@ public class ConferenceAddFragment extends Fragment implements AdapterView.OnIte
}
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.conference_add_fragment, container, false);
accountView = (Spinner) view.findViewById(R.id.contact_account);
serverView = (EditText) view.findViewById(R.id.muc_server);
roomView = (EditText) view.findViewById(R.id.muc_room);
nickView = (EditText) view.findViewById(R.id.muc_nick);
passwordView = (EditText) view.findViewById(R.id.muc_password);
joinCheckBox = (CheckBox) view.findViewById(R.id.muc_join);
((TextView) view.findViewById(R.id.muc_conference_jid)).setText(room);
((TextView) view.findViewById(R.id.muc_account_jid)).setText(StringUtils.parseBareAddress(account));
accountView.setAdapter(new AccountChooseAdapter(getActivity()));
accountView.setOnItemSelectedListener(this);
Drawable accountAvatar = AvatarManager.getInstance().getAccountAvatar(account);
int h = accountAvatar.getIntrinsicHeight();
int w = accountAvatar.getIntrinsicWidth();
accountAvatar.setBounds( 0, 0, w, h );
((TextView) view.findViewById(R.id.muc_account_jid)).setCompoundDrawables(accountAvatar, null, null, null);
if (room != null) {
serverView.setText(StringUtils.parseServer(room));
roomView.setText(StringUtils.parseName(room));
nickView = (EditText) view.findViewById(R.id.muc_nick);
nickView.setText(MUCManager.getInstance().getNickname(account, room));
if ("".equals(nickView.getText().toString())) {
nickView.setText(getNickname(account));
}
if (account != null && room != null) {
MUCManager.getInstance().removeAuthorizationError(account, room);
nickView.setText(MUCManager.getInstance().getNickname(account, room));
String password;
RoomInvite roomInvite = MUCManager.getInstance().getInvite(account, room);
if (roomInvite != null) {
password = roomInvite.getPassword();
} else {
password = MUCManager.getInstance().getPassword(account, room);
}
passwordView.setText(password);
passwordView = (EditText) view.findViewById(R.id.muc_password);
String password;
RoomInvite roomInvite = MUCManager.getInstance().getInvite(account, room);
if (roomInvite != null) {
password = roomInvite.getPassword();
} else {
password = MUCManager.getInstance().getPassword(account, room);
}
passwordView.setText(password);
if (account != null) {
for (int position = 0; position < accountView.getCount(); position++) {
if (account.equals(accountView.getItemAtPosition(position))) {
accountView.setSelection(position);
break;
}
}
}
if ("".equals(nickView.getText().toString())) {
nickView.setText(getNickname(((String) accountView.getSelectedItem())));
}
MUCManager.getInstance().removeAuthorizationError(account, room);
setHasOptionsMenu(true);
return view;
}
@Override
public void onResume() {
super.onResume();
selectedAccount = accountView.getSelectedItemPosition();
}
@Override
public void onDetach() {
super.onDetach();
listener = null;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String current = nickView.getText().toString();
String previous;
if (selectedAccount == AdapterView.INVALID_POSITION) {
previous = "";
} else {
previous = getNickname((String) accountView.getAdapter().getItem(selectedAccount));
}
if (current.equals(previous)) {
nickView.setText(getNickname((String) accountView.getSelectedItem()));
}
selectedAccount = accountView.getSelectedItemPosition();
listener.onAccountSelected((String) accountView.getSelectedItem());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
selectedAccount = accountView.getSelectedItemPosition();
}
/**
* @param account
* @return Suggested nickname in the room.
*/
private String getNickname(String account) {
......@@ -174,36 +107,13 @@ public class ConferenceAddFragment extends Fragment implements AdapterView.OnIte
}
private void addConference() {
String account = (String) accountView.getSelectedItem();
if (account == null) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_LONG).show();
return;
}
String server = serverView.getText().toString();
if ("".equals(server)) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_SERVER_NAME), Toast.LENGTH_LONG).show();
return;
}
String room = roomView.getText().toString();
if ("".equals(room)) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ROOM_NAME), Toast.LENGTH_LONG).show();
return;
}
String nick = nickView.getText().toString();
if ("".equals(nick)) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_NICK_NAME), Toast.LENGTH_LONG).show();
return;
}
String password = passwordView.getText().toString();
boolean join = joinCheckBox.isChecked();
room = room + "@" + server;
if (this.account != null && this.room != null) {
if (!account.equals(this.account) || !room.equals(this.room)) {
MUCManager.getInstance().removeRoom(this.account, this.room);
MessageManager.getInstance().closeChat(this.account, this.room);
NotificationManager.getInstance().removeMessageNotification(this.account, this.room);
}
}
final boolean join = true;
MUCManager.getInstance().createRoom(account, room, nick, password, join);
getActivity().finish();
}
......@@ -225,7 +135,4 @@ public class ConferenceAddFragment extends Fragment implements AdapterView.OnIte
}
}
interface Listener {
void onAccountSelected(String account);
}
}
......@@ -7,7 +7,6 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_default"
android:orientation="vertical"
android:padding="16dp">
......@@ -16,34 +15,31 @@
android:layout_height="wrap_content"
android:text="@string/contact_account" />
<com.xabber.android.ui.widget.NoDefaultSpinner
android:id="@+id/contact_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="@string/choose_account" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/muc_server" />
<EditText
android:id="@+id/muc_server"
android:id="@+id/muc_account_jid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/conference_jabber_org"
android:inputType="textEmailAddress"
android:singleLine="true" />
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="account@jabber.org"
android:padding="8dp"
android:singleLine="true"
android:gravity="center_vertical"
android:drawablePadding="8dp"
android:drawableLeft="@drawable/ic_avatar_1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/muc_room" />
<EditText
android:id="@+id/muc_room"
<TextView
android:id="@+id/muc_conference_jid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="room@conference.jabber.org"
android:padding="8dp"
android:singleLine="true" />
<TextView
......@@ -56,6 +52,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/muc_nick_hint"
android:paddingLeft="8dp"
android:imeOptions="flagNoExtractUi"
android:singleLine="true" />
<TextView
......@@ -69,14 +67,10 @@
android:layout_height="wrap_content"
android:hint="@string/muc_password_hint"
android:inputType="textPassword"
android:paddingLeft="8dp"
android:imeOptions="flagNoExtractUi"
android:singleLine="true" />
<CheckBox
android:id="@+id/muc_join"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/muc_join" />
</LinearLayout>
</ScrollView>
\ No newline at end of file
......@@ -2,7 +2,7 @@
<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"
android:title="@string/muc_join"
app:showAsAction="always"
/>
</menu>
\ No newline at end of file
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