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