Commit 49d92809 authored by Grigory Fedorov's avatar Grigory Fedorov

ContactAddFragment: account selector used both in list header and as separate view.

parent cf537c65
......@@ -5,6 +5,7 @@ import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Spinner;
......@@ -31,9 +32,10 @@ public class ContactAddFragment extends GroupEditorFragment implements AdapterVi
private Spinner accountView;
private EditText userView;
private EditText nameView;
private View accountSpecificPanel;
Listener listenerActivity;
private String name;
private View accountSelectorPanel;
public static ContactAddFragment newInstance(String account, String user) {
ContactAddFragment fragment = new ContactAddFragment();
......@@ -51,26 +53,9 @@ public class ContactAddFragment extends GroupEditorFragment implements AdapterVi
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
View headerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.contact_add_header, null, false);
getListView().addHeaderView(headerView);
accountView = (Spinner) headerView.findViewById(R.id.contact_account);
accountView.setAdapter(new AccountChooseAdapter(getActivity()));
accountView.setOnItemSelectedListener(this);
userView = (EditText) headerView.findViewById(R.id.contact_user);
nameView = (EditText) headerView.findViewById(R.id.contact_name);
accountSpecificPanel = headerView.findViewById(R.id.account_specific_panel);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.contact_add_fragment, container, false);
hideAdditionalInputs();
String name;
if (savedInstanceState != null) {
name = savedInstanceState.getString(SAVED_NAME);
......@@ -92,6 +77,19 @@ public class ContactAddFragment extends GroupEditorFragment implements AdapterVi
setAccount(accounts.iterator().next());
}
}
accountSelectorPanel = view.findViewById(R.id.account_selector);
setUpAccountView((Spinner) view.findViewById(R.id.contact_account));
return view;
}
private void setUpAccountView(Spinner view) {
accountView = view;
accountView.setAdapter(new AccountChooseAdapter(getActivity()));
accountView.setOnItemSelectedListener(this);
if (getAccount() != null) {
for (int position = 0; position < accountView.getCount(); position++) {
if (getAccount().equals(accountView.getItemAtPosition(position))) {
......@@ -100,18 +98,33 @@ public class ContactAddFragment extends GroupEditorFragment implements AdapterVi
}
}
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getListView().setVisibility(View.GONE);
}
private void setUpListView() {
View headerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.contact_add_header, null, false);
getListView().addHeaderView(headerView);
accountSelectorPanel.setVisibility(View.GONE);
setUpAccountView((Spinner) headerView.findViewById(R.id.contact_account));
userView = (EditText) headerView.findViewById(R.id.contact_user);
nameView = (EditText) headerView.findViewById(R.id.contact_name);
if (getUser() != null) {
userView.setText(getUser());
}
if (name != null) {
nameView.setText(name);
}
}
private void hideAdditionalInputs() {
accountSpecificPanel.setVisibility(View.GONE);
getFooterView().setVisibility(View.GONE);
}
@Override
......@@ -144,21 +157,25 @@ public class ContactAddFragment extends GroupEditorFragment implements AdapterVi
setAccountGroups();
updateGroups();
}
setAdditionalPanelVisibility(View.VISIBLE);
}
}
private void setAdditionalPanelVisibility(int visible) {
getFooterView().setVisibility(visible);
accountSpecificPanel.setVisibility(visible);
if (getListView().getVisibility() == View.GONE) {
setUpListView();
getListView().setVisibility(View.VISIBLE);
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
setAdditionalPanelVisibility(View.GONE);
}
public void addContact() {
if (getAccount() == null) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT),
Toast.LENGTH_LONG).show();
return;
}
String user = userView.getText().toString();
if ("".equals(user)) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_USER_NAME),
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:text="@string/contact_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<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" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:id="@+id/account_selector"
>
<include layout="@layout/account_select_spinner"/>
</FrameLayout>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" >
</ListView>
</LinearLayout>
\ No newline at end of file
......@@ -22,59 +22,41 @@
android:paddingTop="16dp"
>
<include layout="@layout/account_select_spinner" />
<TextView
android:text="@string/contact_account"
android:text="@string/contact_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<com.xabber.android.ui.widget.NoDefaultSpinner
android:id="@+id/contact_account"
<EditText
android:text=""
android:id="@+id/contact_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="@string/choose_account"
android:hint="user@domain.name"
android:singleLine="true"
android:inputType="textEmailAddress"
/>
<LinearLayout
android:id="@+id/account_specific_panel"
<TextView
android:text="@string/contact_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:text=""
android:id="@+id/contact_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:text="@string/contact_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:text=""
android:id="@+id/contact_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="user@domain.name"
android:singleLine="true"
android:inputType="textEmailAddress"
/>
<TextView
android:text="@string/contact_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:text=""
android:id="@+id/contact_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/>
android:singleLine="true"
/>
<TextView
android:id="@+id/select_groups_text_view"
android:text="@string/contact_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView
android:id="@+id/select_groups_text_view"
android:text="@string/contact_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
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