Commit efa782c0 authored by Grigory Fedorov's avatar Grigory Fedorov

ContactEditor renamed to GroupEditor. New GroupEditorFragment and GroupEditorAdapter.

GroupListActivity removed. ContactAdd: groups removed.
parent 23f3846a
...@@ -26,6 +26,5 @@ dependencies { ...@@ -26,6 +26,5 @@ dependencies {
compile 'com.android.support:appcompat-v7:22.0.0' compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:support-v13:22.0.0' compile 'com.android.support:support-v13:22.0.0'
compile 'com.github.ksoichiro:android-observablescrollview:1.5.0' compile 'com.github.ksoichiro:android-observablescrollview:1.5.0'
compile 'com.melnykov:floatingactionbutton:1.2.0'
compile project('otr4j') compile project('otr4j')
} }
...@@ -141,7 +141,7 @@ ...@@ -141,7 +141,7 @@
</activity> </activity>
<activity <activity
android:label="@string/contact_editor" android:label="@string/contact_editor"
android:name="com.xabber.android.ui.ContactEditor" android:name="com.xabber.android.ui.GroupEditor"
android:parentActivityName="com.xabber.android.ui.ContactViewer" android:parentActivityName="com.xabber.android.ui.ContactViewer"
> >
<!-- Parent activity meta-data to support 4.0 and lower --> <!-- Parent activity meta-data to support 4.0 and lower -->
......
...@@ -14,21 +14,12 @@ ...@@ -14,21 +14,12 @@
*/ */
package com.xabber.android.ui; package com.xabber.android.ui;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
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.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast; import android.widget.Toast;
...@@ -40,10 +31,13 @@ import com.xabber.android.data.message.MessageManager; ...@@ -40,10 +31,13 @@ import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.PresenceManager; import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter; import com.xabber.android.ui.adapter.AccountChooseAdapter;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ContactAdd extends GroupListActivity implements import java.util.Collection;
View.OnClickListener, OnItemSelectedListener { import java.util.HashSet;
public class ContactAdd extends ManagedActivity implements View.OnClickListener {
private static final String SAVED_ACCOUNT = "com.xabber.android.ui.ContactAdd.SAVED_ACCOUNT"; private static final String SAVED_ACCOUNT = "com.xabber.android.ui.ContactAdd.SAVED_ACCOUNT";
private static final String SAVED_USER = "com.xabber.android.ui.ContactAdd.SAVED_USER"; private static final String SAVED_USER = "com.xabber.android.ui.ContactAdd.SAVED_USER";
...@@ -63,28 +57,15 @@ public class ContactAdd extends GroupListActivity implements ...@@ -63,28 +57,15 @@ public class ContactAdd extends GroupListActivity implements
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
}
@Override
protected void onInflate(Bundle savedInstanceState) {
setContentView(R.layout.contact_add); setContentView(R.layout.contact_add);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ListView listView = getListView(); accountView = (Spinner) findViewById(R.id.contact_account);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.contact_add_header, listView,
false);
listView.addHeaderView(view, null, false);
accountView = (Spinner) view.findViewById(R.id.contact_account);
accountView.setAdapter(new AccountChooseAdapter(this)); accountView.setAdapter(new AccountChooseAdapter(this));
accountView.setOnItemSelectedListener(this); userView = (EditText) findViewById(R.id.contact_user);
userView = (EditText) view.findViewById(R.id.contact_user); nameView = (EditText) findViewById(R.id.contact_name);
nameView = (EditText) view.findViewById(R.id.contact_name); findViewById(R.id.ok).setOnClickListener(this);
((Button) view.findViewById(R.id.ok)).setOnClickListener(this);
String name; String name;
Intent intent = getIntent(); Intent intent = getIntent();
...@@ -122,11 +103,11 @@ public class ContactAdd extends GroupListActivity implements ...@@ -122,11 +103,11 @@ public class ContactAdd extends GroupListActivity implements
nameView.setText(name); nameView.setText(name);
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putString(SAVED_ACCOUNT, outState.putString(SAVED_ACCOUNT, (String) accountView.getSelectedItem());
(String) accountView.getSelectedItem());
outState.putString(SAVED_USER, userView.getText().toString()); outState.putString(SAVED_USER, userView.getText().toString());
outState.putString(SAVED_NAME, nameView.getText().toString()); outState.putString(SAVED_NAME, nameView.getText().toString());
} }
...@@ -149,9 +130,8 @@ public class ContactAdd extends GroupListActivity implements ...@@ -149,9 +130,8 @@ public class ContactAdd extends GroupListActivity implements
} }
try { try {
RosterManager.getInstance().createContact(account, user, RosterManager.getInstance().createContact(account, user,
nameView.getText().toString(), getSelected()); nameView.getText().toString(), new HashSet<String>());
PresenceManager.getInstance() PresenceManager.getInstance().requestSubscription(account, user);
.requestSubscription(account, user);
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
finish(); finish();
...@@ -165,38 +145,6 @@ public class ContactAdd extends GroupListActivity implements ...@@ -165,38 +145,6 @@ public class ContactAdd extends GroupListActivity implements
} }
} }
@Override
Collection<String> getInitialGroups() {
String account = (String) accountView.getSelectedItem();
if (account == null)
return Collections.emptyList();
return RosterManager.getInstance().getGroups(account);
}
@Override
Collection<String> getInitialSelected() {
return Collections.emptyList();
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
String account = (String) accountView.getSelectedItem();
if (account == null) {
onNothingSelected(parent);
} else {
HashSet<String> groups = new HashSet<String>(RosterManager
.getInstance().getGroups(account));
groups.addAll(getSelected());
setGroups(groups, getSelected());
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
setGroups(getSelected(), getSelected());
}
public static Intent createIntent(Context context) { public static Intent createIntent(Context context) {
return createIntent(context, null); return createIntent(context, null);
} }
...@@ -205,10 +153,8 @@ public class ContactAdd extends GroupListActivity implements ...@@ -205,10 +153,8 @@ public class ContactAdd extends GroupListActivity implements
return createIntent(context, account, null); return createIntent(context, account, null);
} }
public static Intent createIntent(Context context, String account, public static Intent createIntent(Context context, String account, String user) {
String user) { return new EntityIntentBuilder(context, ContactAdd.class).setAccount(account).setUser(user).build();
return new EntityIntentBuilder(context, ContactAdd.class)
.setAccount(account).setUser(user).build();
} }
private static String getAccount(Intent intent) { private static String getAccount(Intent intent) {
......
...@@ -244,7 +244,7 @@ public class ContactViewer extends ManagedActivity implements ...@@ -244,7 +244,7 @@ public class ContactViewer extends ManagedActivity implements
case R.id.action_edit_groups: case R.id.action_edit_groups:
startActivity(ContactEditor.createIntent(this, account, bareAddress)); startActivity(GroupEditor.createIntent(this, account, bareAddress));
return true; return true;
case R.id.action_remove_contact: case R.id.action_remove_contact:
......
...@@ -18,14 +18,8 @@ import android.content.Context; ...@@ -18,14 +18,8 @@ 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.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import com.melnykov.fab.FloatingActionButton;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.OnAccountChangedListener; import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
...@@ -33,23 +27,24 @@ import com.xabber.android.data.intent.EntityIntentBuilder; ...@@ -33,23 +27,24 @@ import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.OnContactChangedListener; import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.dialog.GroupAddDialogFragment;
import com.xabber.android.ui.helper.ContactTitleActionBarInflater; import com.xabber.android.ui.helper.ContactTitleActionBarInflater;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid; import com.xabber.xmpp.address.Jid;
import java.util.Collection; import java.util.Collection;
public class ContactEditor extends GroupListActivity implements public class GroupEditor extends ManagedActivity implements OnContactChangedListener,
OnContactChangedListener, OnAccountChangedListener, View.OnClickListener { OnAccountChangedListener {
private String account; private String account;
private String user; private String user;
ContactTitleActionBarInflater contactTitleActionBarInflater; ContactTitleActionBarInflater contactTitleActionBarInflater;
@Override protected void onCreate(Bundle savedInstanceState) {
protected void onInflate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.contact_editor); setContentView(R.layout.contact_editor);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
...@@ -57,28 +52,19 @@ public class ContactEditor extends GroupListActivity implements ...@@ -57,28 +52,19 @@ public class ContactEditor extends GroupListActivity implements
contactTitleActionBarInflater.setUpActionBarView(); contactTitleActionBarInflater.setUpActionBarView();
Intent intent = getIntent(); Intent intent = getIntent();
account = ContactEditor.getAccount(intent); account = GroupEditor.getAccount(intent);
user = ContactEditor.getUser(intent); user = GroupEditor.getUser(intent);
if (AccountManager.getInstance().getAccount(account) == null || user == null) { if (AccountManager.getInstance().getAccount(account) == null || user == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish(); finish();
} }
ListView listView = (ListView) findViewById(android.R.id.list); if (savedInstanceState == null) {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); getSupportFragmentManager().beginTransaction()
fab.attachToListView(listView); .add(R.id.container, GroupEditorFragment.newInstance(account, user)).commit();
fab.setOnClickListener(this); }
}
@Override
Collection<String> getInitialGroups() {
return RosterManager.getInstance().getGroups(account);
}
@Override
Collection<String> getInitialSelected() {
return RosterManager.getInstance().getGroups(account, user);
} }
@Override @Override
...@@ -94,17 +80,13 @@ public class ContactEditor extends GroupListActivity implements ...@@ -94,17 +80,13 @@ public class ContactEditor extends GroupListActivity implements
super.onPause(); super.onPause();
Application.getInstance().removeUIListener(OnAccountChangedListener.class, this); Application.getInstance().removeUIListener(OnAccountChangedListener.class, this);
Application.getInstance().removeUIListener(OnContactChangedListener.class, this); Application.getInstance().removeUIListener(OnContactChangedListener.class, this);
try {
RosterManager.getInstance().setGroups(account, user, getSelected());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
} }
private void update() { private void update() {
AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user); AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
contactTitleActionBarInflater.update(abstractContact); contactTitleActionBarInflater.update(abstractContact);
contactTitleActionBarInflater.setStatusText(user); contactTitleActionBarInflater.setStatusText(user);
contactTitleActionBarInflater.hideStatusIcon();
} }
@Override @Override
...@@ -126,7 +108,7 @@ public class ContactEditor extends GroupListActivity implements ...@@ -126,7 +108,7 @@ public class ContactEditor extends GroupListActivity implements
} }
public static Intent createIntent(Context context, String account, String user) { public static Intent createIntent(Context context, String account, String user) {
Intent intent = new EntityIntentBuilder(context, ContactEditor.class) Intent intent = new EntityIntentBuilder(context, GroupEditor.class)
.setAccount(account).setUser(user).build(); .setAccount(account).setUser(user).build();
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
return intent; return intent;
...@@ -140,13 +122,4 @@ public class ContactEditor extends GroupListActivity implements ...@@ -140,13 +122,4 @@ public class ContactEditor extends GroupListActivity implements
return EntityIntentBuilder.getUser(intent); return EntityIntentBuilder.getUser(intent);
} }
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.fab:
showGroupAddDialog();
return;
}
}
} }
package com.xabber.android.ui;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.GroupEditorAdapter;
import com.xabber.androiddev.R;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class GroupEditorFragment extends ListFragment implements TextWatcher, View.OnClickListener {
private static final String ARG_ACCOUNT = "com.xabber.android.ui.GroupEditorFragment.ARG_ACCOUNT";
private static final String ARG_USER = "com.xabber.android.ui.GroupEditorFragment.ARG_USER";
private static final String SAVED_GROUPS = "com.xabber.android.ui.GroupEditorFragment.SAVED_GROUPS";
private static final String SAVED_SELECTED = "com.xabber.android.ui.GroupEditorFragment.SAVED_SELECTED";
private String account;
private String user;
private GroupEditorAdapter groupEditorAdapter;
private Collection<String> groups;
private Collection<String> selected;
private EditText groupAddInput;
private CheckBox groupAddCheckBox;
public static GroupEditorFragment newInstance(String account, String user) {
GroupEditorFragment fragment = new GroupEditorFragment();
Bundle args = new Bundle();
args.putString(ARG_ACCOUNT, account);
args.putString(ARG_USER, user);
fragment.setArguments(args);
return fragment;
}
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public GroupEditorFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
account = getArguments().getString(ARG_ACCOUNT);
user = getArguments().getString(ARG_USER);
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setUpFooter();
groupEditorAdapter = new GroupEditorAdapter(getActivity(),
R.layout.group_list_item, new ArrayList<GroupEditorAdapter.Group>());
setListAdapter(groupEditorAdapter);
if (savedInstanceState != null) {
groups = savedInstanceState.getStringArrayList(SAVED_GROUPS);
selected = savedInstanceState.getStringArrayList(SAVED_SELECTED);
} else {
groups = RosterManager.getInstance().getGroups(account);
selected = RosterManager.getInstance().getGroups(account, user);
}
}
private void setUpFooter() {
View footerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.group_add_footer, null, false);
getListView().addFooterView(footerView);
groupAddInput = (EditText) footerView.findViewById(R.id.group_add_input);
groupAddInput.addTextChangedListener(this);
groupAddCheckBox = (CheckBox) footerView.findViewById(R.id.group_add_checkbox);
groupAddCheckBox.setVisibility(View.INVISIBLE);
groupAddCheckBox.setOnClickListener(this);
}
@Override
public void onResume() {
super.onResume();
setGroups(groups, selected);
}
void setGroups(Collection<String> groups, Collection<String> selected) {
ArrayList<String> list = new ArrayList<>(groups);
Collections.sort(list);
groupEditorAdapter.clear();
for (int position = 0; position < list.size(); position++) {
String groupName = list.get(position);
GroupEditorAdapter.Group group = new GroupEditorAdapter.Group(groupName, selected.contains(groupName));
groupEditorAdapter.add(group);
getListView().setItemChecked(position + getListView().getHeaderViewsCount(),
selected.contains(groupName));
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
selected = getSelected();
outState.putStringArrayList(SAVED_GROUPS, getGroups());
outState.putStringArrayList(SAVED_SELECTED, new ArrayList<>(selected));
}
@Override
public void onPause() {
super.onPause();
selected = getSelected();
try {
RosterManager.getInstance().setGroups(account, user, selected);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
CheckBox checkBox = (CheckBox) v.findViewById(R.id.group_add_checkbox);
checkBox.toggle();
groupEditorAdapter.getItem(position).setIsSelected(checkBox.isChecked());
}
protected ArrayList<String> getGroups() {
ArrayList<String> groups = new ArrayList<>();
for (int position = 0; position < groupEditorAdapter.getCount(); position++)
groups.add(groupEditorAdapter.getItem(position).getGroupName());
return groups;
}
public ArrayList<String> getSelected() {
ArrayList<String> selectedGroups = new ArrayList<>();
for (int position = 0; position < groupEditorAdapter.getCount(); position++) {
GroupEditorAdapter.Group item = groupEditorAdapter.getItem(position);
if (item.isSelected()) {
selectedGroups.add(item.getGroupName());
}
}
return selectedGroups;
}
@Override
public void afterTextChanged(Editable s) {
String groupName = groupAddInput.getText().toString().trim();
if (groupName.isEmpty() || getGroups().contains(groupName)) {
groupAddCheckBox.setVisibility(View.INVISIBLE);
} else {
groupAddCheckBox.setVisibility(View.VISIBLE);
}
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.group_add_checkbox) {
String groupName = groupAddInput.getText().toString().trim();
groupEditorAdapter.add(new GroupEditorAdapter.Group(groupName, true));
groupAddInput.getText().clear();
groupAddInput.clearFocus();
hideKeyboard(getActivity());
groupAddCheckBox.setChecked(false);
}
}
public static void hideKeyboard(Activity activity) {
// Check if no view has focus:
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.ui;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.xabber.android.ui.dialog.GroupAddDialogFragment;
import com.xabber.android.ui.dialog.GroupAddDialogFragment.OnGroupAddConfirmed;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* Manage list of selected groups.
*
* @author alexander.ivanov
*/
public abstract class GroupListActivity extends ManagedListActivity implements OnGroupAddConfirmed {
private static final String SAVED_GROUPS = "com.xabber.android.ui.ContactList.SAVED_GROUPS";
private static final String SAVED_SELECTED = "com.xabber.android.ui.ContactList.SAVED_SELECTED";
private ArrayAdapter<String> arrayAdapter;
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isFinishing())
return;
onInflate(savedInstanceState);
if (isFinishing())
return;
Collection<String> groups;
Collection<String> selected;
if (savedInstanceState != null) {
groups = savedInstanceState.getStringArrayList(SAVED_GROUPS);
selected = savedInstanceState.getStringArrayList(SAVED_SELECTED);
} else {
groups = getInitialGroups();
selected = getInitialSelected();
}
listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
arrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_multiple_choice,
new ArrayList<String>());
setListAdapter(arrayAdapter);
setGroups(groups, selected);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putStringArrayList(SAVED_GROUPS, getGroups());
outState.putStringArrayList(SAVED_SELECTED, getSelected());
}
/**
* Inflates layout.
*
* @param savedInstanceState
*/
protected abstract void onInflate(Bundle savedInstanceState);
/**
* @return List of initial allowed groups.
*/
abstract Collection<String> getInitialGroups();
/**
* @return List of initially selected groups.
*/
abstract Collection<String> getInitialSelected();
/**
* @return Actual groups from adapter.
*/
private ArrayList<String> getGroups() {
ArrayList<String> groups = new ArrayList<>();
for (int position = 0; position < arrayAdapter.getCount(); position++)
groups.add(arrayAdapter.getItem(position));
return groups;
}
/**
* @return Actual selected groups from adapter.
*/
public ArrayList<String> getSelected() {
ArrayList<String> groups = new ArrayList<>();
for (int position = 0; position < arrayAdapter.getCount(); position++)
if (listView.isItemChecked(position
+ listView.getHeaderViewsCount())) {
groups.add(arrayAdapter.getItem(position));
}
return groups;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.create_new_group, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_create_new_group:
showGroupAddDialog();
return true;
}
return false;
}
protected void showGroupAddDialog() {
GroupAddDialogFragment.newInstance(getGroups()).show(getFragmentManager(), "GROUP-ADD");
}
/**
* Sets new list of groups and select specified groups.
*
* @param groups
* @param selected
*/
void setGroups(Collection<String> groups, Collection<String> selected) {
ArrayList<String> list = new ArrayList<>(groups);
Collections.sort(list);
arrayAdapter.clear();
for (int position = 0; position < list.size(); position++) {
String group = list.get(position);
arrayAdapter.add(group);
listView.setItemChecked(position + listView.getHeaderViewsCount(),
selected.contains(group));
}
}
@Override
public void onGroupAddConfirmed(String group) {
ArrayList<String> groups = getGroups();
groups.add(group);
ArrayList<String> selected = getSelected();
selected.add(group);
setGroups(groups, selected);
}
}
package com.xabber.android.ui.adapter;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import com.xabber.androiddev.R;
import java.util.List;
public class GroupEditorAdapter extends ArrayAdapter<GroupEditorAdapter.Group> {
private FragmentActivity activity;
private int layoutResourceId;
public GroupEditorAdapter(FragmentActivity activity, int layoutResourceId, List<GroupEditorAdapter.Group> objects) {
super(activity, layoutResourceId, objects);
this.activity = activity;
this.layoutResourceId = layoutResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
GroupHolder holder;
if (row == null) {
LayoutInflater inflater = activity.getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new GroupHolder();
holder.groupCheckbox = (CheckBox) row.findViewById(R.id.group_add_checkbox);
holder.groupName = (TextView) row.findViewById(R.id.group_item_name);
row.setTag(holder);
} else {
holder = (GroupHolder)row.getTag();
}
Group group = getItem(position);
holder.groupName.setText(group.groupName);
holder.groupCheckbox.setChecked(group.isSelected);
return row;
}
static class GroupHolder {
TextView groupName;
CheckBox groupCheckbox;
}
public static class Group {
String groupName;
boolean isSelected;
public Group(String groupName, boolean isSelected) {
this.groupName = groupName;
this.isSelected = isSelected;
}
public String getGroupName() {
return groupName;
}
public boolean isSelected() {
return isSelected;
}
public void setIsSelected(boolean isSelected) {
this.isSelected = isSelected;
}
}
}
...@@ -112,4 +112,8 @@ public class ContactTitleActionBarInflater { ...@@ -112,4 +112,8 @@ public class ContactTitleActionBarInflater {
public void setStatusText(String user) { public void setStatusText(String user) {
((TextView) actionBarView.findViewById(R.id.status_text)).setText(user); ((TextView) actionBarView.findViewById(R.id.status_text)).setText(user);
} }
public void hideStatusIcon() {
actionBarView.findViewById(R.id.status_icon).setVisibility(View.GONE);
}
} }
...@@ -33,9 +33,8 @@ import com.xabber.android.data.roster.AbstractContact; ...@@ -33,9 +33,8 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.GroupManager; import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.PresenceManager; import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.ShowOfflineMode; import com.xabber.android.data.roster.ShowOfflineMode;
import com.xabber.android.ui.ChatViewer;
import com.xabber.android.ui.ContactAdd; import com.xabber.android.ui.ContactAdd;
import com.xabber.android.ui.ContactEditor; import com.xabber.android.ui.GroupEditor;
import com.xabber.android.ui.MUCEditor; import com.xabber.android.ui.MUCEditor;
import com.xabber.android.ui.StatusEditor; import com.xabber.android.ui.StatusEditor;
import com.xabber.android.ui.adapter.UpdatableAdapter; import com.xabber.android.ui.adapter.UpdatableAdapter;
...@@ -170,7 +169,7 @@ public class ContextMenuHelper { ...@@ -170,7 +169,7 @@ public class ContextMenuHelper {
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
} }
activity.startActivity(ContactEditor.createIntent( activity.startActivity(GroupEditor.createIntent(
activity, account, user)); activity, account, user));
return true; return true;
} }
......
...@@ -21,11 +21,6 @@ ...@@ -21,11 +21,6 @@
<include layout="@layout/toolbar_default" /> <include layout="@layout/toolbar_default" />
<ListView <include layout="@layout/contact_add_header" />
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dip" />
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -12,51 +12,21 @@ ...@@ -12,51 +12,21 @@
You should have received a copy of the GNU General Public License, You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/. along with this program. If not, see http://www.gnu.org/licenses/.
--> -->
<RelativeLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
>
<include layout="@layout/toolbar_default" <include layout="@layout/toolbar_default"
android:id="@+id/toolbar_default" android:id="@+id/toolbar_default"
/> />
<TextView <FrameLayout
android:text="@string/contact_group" android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dip"
android:paddingBottom="2dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:id="@+id/edit_groups_title"
android:layout_below="@+id/toolbar_default"
/>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_below="@+id/toolbar_default"
android:paddingLeft="8dp" >
android:paddingStart="8dp"
android:layout_below="@+id/edit_groups_title"
/>
<com.melnykov.fab.FloatingActionButton </FrameLayout>
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_margin="16dp"
android:src="@drawable/ic_add_white_24dp"
fab:fab_colorNormal="@color/red_500"
fab:fab_colorPressed="@color/red_700"
fab:fab_colorRipple="@color/red_300"
/>
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/input_holder"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="12dp"
android:paddingRight="16dp"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/group_add_input"
android:layout_weight="1"
android:hint="Add new group..."
android:singleLine="true" />
<CheckBox
android:id="@+id/group_add_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
\ No newline at end of file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/input_holder"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<TextView
android:id="@+id/group_item_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:layout_weight="1"
android:singleLine="true"
/>
<CheckBox
android:id="@+id/group_add_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"
/>
</LinearLayout>
\ No newline at end of file
<?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_create_new_group"
android:title="@string/group_add"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_group_add_white_24dp"
android:orderInCategory="100"
/>
</menu>
\ No newline at end of file
...@@ -40,4 +40,6 @@ ...@@ -40,4 +40,6 @@
<string name="choose_account">Выберите учетную запись</string> <string name="choose_account">Выберите учетную запись</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_editor_error.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_editor_error.png -->
<string name="EMPTY_ACCOUNT">Пожалуйста, выберите учетную запись</string> <string name="EMPTY_ACCOUNT">Пожалуйста, выберите учетную запись</string>
<string name="add_new_group">Добавить новую группу…</string>
</resources> </resources>
\ No newline at end of file
...@@ -40,4 +40,6 @@ ...@@ -40,4 +40,6 @@
<string name="choose_account">Choose an account</string> <string name="choose_account">Choose an account</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_editor_error.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_editor_error.png -->
<string name="EMPTY_ACCOUNT">Please select an account</string> <string name="EMPTY_ACCOUNT">Please select an account</string>
<string name="add_new_group">Add new group…</string>
</resources> </resources>
\ 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