Commit dbc5f830 authored by Grigory Fedorov's avatar Grigory Fedorov

Merge branch 'feature/expanding_toolbar' into develop

parents 9a7822f5 e3c90c3d
...@@ -2,14 +2,14 @@ apply plugin: 'com.android.application' ...@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
android { android {
compileSdkVersion 22 compileSdkVersion 22
buildToolsVersion "22.0.0" buildToolsVersion "22.0.1"
defaultConfig { defaultConfig {
applicationId "com.xabber.androiddev" applicationId "com.xabber.androiddev"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 22 targetSdkVersion 22
versionCode 136 versionCode 144
versionName '0.10.36' versionName '0.10.44'
} }
compileOptions { compileOptions {
...@@ -18,8 +18,13 @@ android { ...@@ -18,8 +18,13 @@ android {
} }
} }
repositories {
mavenCentral()
}
dependencies { 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 project('otr4j') compile project('otr4j')
} }
...@@ -141,13 +141,13 @@ ...@@ -141,13 +141,13 @@
</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.ContactList" 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 -->
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.ContactList" /> android:value="com.xabber.android.ui.ContactViewer" />
</activity> </activity>
<activity <activity
android:label="@string/contact_add" android:label="@string/contact_add"
...@@ -219,13 +219,13 @@ ...@@ -219,13 +219,13 @@
<activity <activity
android:label="@string/contact_viewer" android:label="@string/contact_viewer"
android:name="com.xabber.android.ui.preferences.ContactViewer" android:name="com.xabber.android.ui.ContactViewer"
android:parentActivityName="com.xabber.android.ui.ContactList" android:parentActivityName="com.xabber.android.ui.ChatViewer"
> >
<!-- Parent activity meta-data to support 4.0 and lower --> <!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value="com.xabber.android.ui.ContactList" /> android:value="com.xabber.android.ui.ChatViewer" />
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
...@@ -235,6 +235,7 @@ ...@@ -235,6 +235,7 @@
<data android:host="com.android.contacts" /> <data android:host="com.android.contacts" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name="com.xabber.android.ui.FingerprintViewer" android:name="com.xabber.android.ui.FingerprintViewer"
android:label="@string/otr_verify_fingerprint" android:label="@string/otr_verify_fingerprint"
......
...@@ -326,33 +326,40 @@ public class RosterManager implements OnDisconnectListener, OnPacketListener, ...@@ -326,33 +326,40 @@ public class RosterManager implements OnDisconnectListener, OnPacketListener,
ConnectionManager.getInstance().sendPacket(account, packet); ConnectionManager.getInstance().sendPacket(account, packet);
} }
/** public void setGroups(String account, String bareAddress, Collection<String> groups) throws NetworkException {
* Requests to change contact's name and groups. RosterContact contact = getRosterContact(account, bareAddress);
* if (contact == null) {
* @param account throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
* @param bareAddress }
* @param name
* @param groups HashSet<String> check = new HashSet<>(contact.getGroupNames());
* @throws NetworkException if (check.size() == groups.size()) {
*/ check.removeAll(groups);
public void setNameAndGroup(String account, String bareAddress, if (check.isEmpty())
String name, Collection<String> groups) throws NetworkException { return;
}
updateRosterContact(account, bareAddress, contact.getRealName(), groups);
}
public void setName(String account, String bareAddress, String name) throws NetworkException {
RosterContact contact = getRosterContact(account, bareAddress); RosterContact contact = getRosterContact(account, bareAddress);
if (contact == null) if (contact == null)
throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND); throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
if (contact.getRealName().equals(name)) { if (contact.getRealName().equals(name)) {
HashSet<String> check = new HashSet<String>(contact.getGroupNames()); return;
if (check.size() == groups.size()) {
check.removeAll(groups);
if (check.isEmpty())
return;
}
} }
updateRosterContact(account, bareAddress, name, contact.getGroupNames());
}
private void updateRosterContact(String account, String bareAddress, String name, Collection<String> groups) throws NetworkException {
RosterPacket packet = new RosterPacket(); RosterPacket packet = new RosterPacket();
packet.setType(IQ.Type.SET); packet.setType(IQ.Type.SET);
RosterPacket.Item item = new RosterPacket.Item(bareAddress, name); RosterPacket.Item item = new RosterPacket.Item(bareAddress, name);
for (String group : groups) for (String group : groups) {
item.addGroupName(group); item.addGroupName(group);
}
packet.addRosterItem(item); packet.addRosterItem(item);
ConnectionManager.getInstance().sendPacket(account, packet); ConnectionManager.getInstance().sendPacket(account, packet);
} }
......
...@@ -27,13 +27,11 @@ import android.view.Menu; ...@@ -27,13 +27,11 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager;
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;
import com.xabber.android.data.extension.archive.MessageArchiveManager; import com.xabber.android.data.extension.archive.MessageArchiveManager;
...@@ -41,8 +39,6 @@ import com.xabber.android.data.extension.attention.AttentionManager; ...@@ -41,8 +39,6 @@ import com.xabber.android.data.extension.attention.AttentionManager;
import com.xabber.android.data.extension.muc.MUCManager; import com.xabber.android.data.extension.muc.MUCManager;
import com.xabber.android.data.extension.muc.RoomChat; import com.xabber.android.data.extension.muc.RoomChat;
import com.xabber.android.data.extension.muc.RoomState; import com.xabber.android.data.extension.muc.RoomState;
import com.xabber.android.data.extension.otr.OTRManager;
import com.xabber.android.data.extension.otr.SecurityLevel;
import com.xabber.android.data.intent.EntityIntentBuilder; import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.AbstractChat; import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
...@@ -58,7 +54,6 @@ import com.xabber.android.ui.dialog.ChatExportDialogFragment; ...@@ -58,7 +54,6 @@ import com.xabber.android.ui.dialog.ChatExportDialogFragment;
import com.xabber.android.ui.helper.ContactTitleActionBarInflater; import com.xabber.android.ui.helper.ContactTitleActionBarInflater;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.preferences.ChatEditor; import com.xabber.android.ui.preferences.ChatEditor;
import com.xabber.android.ui.preferences.ContactViewer;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.Collection; import java.util.Collection;
...@@ -222,24 +217,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -222,24 +217,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
} }
if (abstractChat instanceof RegularChat) { if (abstractChat instanceof RegularChat) {
menu.findItem(R.id.action_edit_contact).setVisible(true); menu.findItem(R.id.action_view_contact).setVisible(true);
menu.findItem(R.id.action_close_chat).setVisible(true); menu.findItem(R.id.action_close_chat).setVisible(true);
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
if (securityLevel == SecurityLevel.plain) {
menu.findItem(R.id.action_start_encryption).setVisible(true)
.setEnabled(SettingsManager.securityOtrMode() != SettingsManager.SecurityOtrMode.disabled);
} else {
menu.findItem(R.id.action_restart_encryption).setVisible(true);
}
boolean isEncrypted = securityLevel != SecurityLevel.plain;
menu.findItem(R.id.action_stop_encryption).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_fingerprint).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_question).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_shared_secret).setEnabled(isEncrypted);
} }
} }
...@@ -314,8 +293,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -314,8 +293,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
final String user = actionWithUser; final String user = actionWithUser;
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_edit_contact: case R.id.action_view_contact:
startActivity(ContactEditor.createIntent(this, account, user)); startActivity(ContactViewer.createIntent(this, account, user));
return true; return true;
case R.id.action_chat_list: case R.id.action_chat_list:
...@@ -372,32 +351,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -372,32 +351,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
startActivity(OccupantList.createIntent(this, account, user)); startActivity(OccupantList.createIntent(this, account, user));
return true; return true;
/* encryption */
case R.id.action_start_encryption:
startEncryption(account, user);
return true;
case R.id.action_restart_encryption:
restartEncryption(account, user);
return true;
case R.id.action_stop_encryption:
stopEncryption(account, user);
return true;
case R.id.action_verify_with_fingerprint:
startActivity(FingerprintViewer.createIntent(this, account, user));
return true;
case R.id.action_verify_with_question:
startActivity(QuestionViewer.createIntent(this, account, user, true, false, null));
return true;
case R.id.action_verify_with_shared_secret:
startActivity(QuestionViewer.createIntent(this, account, user, false, false, null));
return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
...@@ -411,30 +364,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -411,30 +364,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
} }
} }
private void stopEncryption(String account, String user) {
try {
OTRManager.getInstance().endSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void restartEncryption(String account, String user) {
try {
OTRManager.getInstance().refreshSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void startEncryption(String account, String user) {
try {
OTRManager.getInstance().startSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void callAttention(String account, String user) { private void callAttention(String account, String user) {
try { try {
AttentionManager.getInstance().sendAttention(account, user); AttentionManager.getInstance().sendAttention(account, user);
...@@ -656,21 +585,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -656,21 +585,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
final AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user); final AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
contactTitleActionBarInflater.update(abstractContact); contactTitleActionBarInflater.update(abstractContact);
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
SettingsManager.SecurityOtrMode securityOtrMode = SettingsManager.securityOtrMode();
ImageView securityView = contactTitleActionBarInflater.getSecurityView();
if (securityLevel == SecurityLevel.plain
&& (securityOtrMode == SettingsManager.SecurityOtrMode.disabled
|| securityOtrMode == SettingsManager.SecurityOtrMode.manual)) {
securityView.setVisibility(View.GONE);
} else {
securityView.setVisibility(View.VISIBLE);
securityView.setImageLevel(securityLevel.getImageLevel());
}
} }
private void updateRegisteredChats() { private void updateRegisteredChats() {
......
...@@ -10,6 +10,7 @@ import android.text.TextWatcher; ...@@ -10,6 +10,7 @@ import android.text.TextWatcher;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
...@@ -18,18 +19,25 @@ import android.widget.AdapterView; ...@@ -18,18 +19,25 @@ import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ListView; import android.widget.ListView;
import android.widget.PopupMenu;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager; import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.cs.ChatStateManager; import com.xabber.android.data.extension.cs.ChatStateManager;
import com.xabber.android.data.extension.otr.OTRManager;
import com.xabber.android.data.extension.otr.SecurityLevel;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageItem; import com.xabber.android.data.message.MessageItem;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.message.RegularChat;
import com.xabber.android.data.message.chat.ChatManager; import com.xabber.android.data.message.chat.ChatManager;
import com.xabber.android.ui.adapter.ChatMessageAdapter; import com.xabber.android.ui.adapter.ChatMessageAdapter;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ChatViewerFragment extends Fragment implements AdapterView.OnItemClickListener { public class ChatViewerFragment extends Fragment implements AdapterView.OnItemClickListener, PopupMenu.OnMenuItemClickListener {
public static final String ARGUMENT_ACCOUNT = "ARGUMENT_ACCOUNT"; public static final String ARGUMENT_ACCOUNT = "ARGUMENT_ACCOUNT";
public static final String ARGUMENT_USER = "ARGUMENT_USER"; public static final String ARGUMENT_USER = "ARGUMENT_USER";
...@@ -45,6 +53,7 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -45,6 +53,7 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
boolean isInputEmpty = true; boolean isInputEmpty = true;
private ImageButton sendButton; private ImageButton sendButton;
private ImageButton securityButton;
public static ChatViewerFragment newInstance(String account, String user) { public static ChatViewerFragment newInstance(String account, String user) {
ChatViewerFragment fragment = new ChatViewerFragment(); ChatViewerFragment fragment = new ChatViewerFragment();
...@@ -74,6 +83,20 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -74,6 +83,20 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
sendButton = (ImageButton) view.findViewById(R.id.button_send_message); sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp); sendButton.setImageResource(R.drawable.ic_button_send_inactive_24dp);
AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
securityButton = (ImageButton) view.findViewById(R.id.button_security);
if (abstractChat instanceof RegularChat) {
securityButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showSecurityMenu();
}
});
} else {
securityButton.setVisibility(View.GONE);
}
chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user); chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user);
listView = (ListView) view.findViewById(android.R.id.list); listView = (ListView) view.findViewById(android.R.id.list);
...@@ -143,6 +166,32 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -143,6 +166,32 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
} }
private void showSecurityMenu() {
PopupMenu popup = new PopupMenu(getActivity(), securityButton);
popup.inflate(R.menu.security);
popup.setOnMenuItemClickListener(this);
Menu menu = popup.getMenu();
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
if (securityLevel == SecurityLevel.plain) {
menu.findItem(R.id.action_start_encryption).setVisible(true)
.setEnabled(SettingsManager.securityOtrMode() != SettingsManager.SecurityOtrMode.disabled);
} else {
menu.findItem(R.id.action_restart_encryption).setVisible(true);
}
boolean isEncrypted = securityLevel != SecurityLevel.plain;
menu.findItem(R.id.action_stop_encryption).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_fingerprint).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_question).setEnabled(isEncrypted);
menu.findItem(R.id.action_verify_with_shared_secret).setEnabled(isEncrypted);
popup.show();
}
private void setSendButtonColor() { private void setSendButtonColor() {
boolean empty = inputView.getText().toString().isEmpty(); boolean empty = inputView.getText().toString().isEmpty();
...@@ -274,6 +323,13 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -274,6 +323,13 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
public void updateChat() { public void updateChat() {
chatMessageAdapter.onChange(); chatMessageAdapter.onChange();
updateSecurityButton();
}
private void updateSecurityButton() {
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
securityButton.setImageLevel(securityLevel.getImageLevel());
} }
public boolean isEqual(String account, String user) { public boolean isEqual(String account, String user) {
...@@ -314,4 +370,60 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl ...@@ -314,4 +370,60 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
listView.showContextMenuForChild(view); listView.showContextMenuForChild(view);
unregisterForContextMenu(listView); unregisterForContextMenu(listView);
} }
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_start_encryption:
startEncryption(account, user);
return true;
case R.id.action_restart_encryption:
restartEncryption(account, user);
return true;
case R.id.action_stop_encryption:
stopEncryption(account, user);
return true;
case R.id.action_verify_with_fingerprint:
startActivity(FingerprintViewer.createIntent(getActivity(), account, user));
return true;
case R.id.action_verify_with_question:
startActivity(QuestionViewer.createIntent(getActivity(), account, user, true, false, null));
return true;
case R.id.action_verify_with_shared_secret:
startActivity(QuestionViewer.createIntent(getActivity(), account, user, false, false, null));
return true;
default:
return false;
}
}
private void stopEncryption(String account, String user) {
try {
OTRManager.getInstance().endSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void restartEncryption(String account, String user) {
try {
OTRManager.getInstance().refreshSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
private void startEncryption(String account, String user) {
try {
OTRManager.getInstance().startSession(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
} }
...@@ -14,187 +14,68 @@ ...@@ -14,187 +14,68 @@
*/ */
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.Menu;
import android.view.View; import android.view.MenuInflater;
import android.widget.AdapterView; import android.view.MenuItem;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.EntityIntentBuilder; import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.message.MessageManager; import com.xabber.android.ui.helper.ActionBarPainter;
import com.xabber.android.data.roster.PresenceManager; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ContactAdd extends GroupListActivity implements public class ContactAdd extends ManagedActivity implements ContactAddFragment.Listener {
View.OnClickListener, OnItemSelectedListener {
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_NAME = "com.xabber.android.ui.ContactAdd.SAVED_NAME";
private String account;
private String user;
/** ActionBarPainter actionBarPainter;
* Views
*/
private Spinner accountView;
private EditText userView;
private EditText nameView;
@Override @Override
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);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setTitle(null);
ListView listView = getListView(); actionBarPainter = new ActionBarPainter(this);
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.setOnItemSelectedListener(this);
userView = (EditText) view.findViewById(R.id.contact_user);
nameView = (EditText) view.findViewById(R.id.contact_name);
((Button) view.findViewById(R.id.ok)).setOnClickListener(this);
String name;
Intent intent = getIntent(); Intent intent = getIntent();
if (savedInstanceState != null) {
account = savedInstanceState.getString(SAVED_ACCOUNT); if (savedInstanceState == null) {
user = savedInstanceState.getString(SAVED_USER); getSupportFragmentManager()
name = savedInstanceState.getString(SAVED_NAME); .beginTransaction()
} else { .add(R.id.container, ContactAddFragment.newInstance(getAccount(intent), getUser(intent)))
account = getAccount(intent); .commit();
user = getUser(intent);
if (account == null || user == null)
name = null;
else {
name = RosterManager.getInstance().getName(account, user);
if (user.equals(name))
name = null;
}
}
if (account == null) {
Collection<String> accounts = AccountManager.getInstance()
.getAccounts();
if (accounts.size() == 1)
account = accounts.iterator().next();
}
if (account != null) {
for (int position = 0; position < accountView.getCount(); position++)
if (account.equals(accountView.getItemAtPosition(position))) {
accountView.setSelection(position);
break;
}
} }
if (user != null)
userView.setText(user);
if (name != null)
nameView.setText(name);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SAVED_ACCOUNT,
(String) accountView.getSelectedItem());
outState.putString(SAVED_USER, userView.getText().toString());
outState.putString(SAVED_NAME, nameView.getText().toString());
} }
@Override private void addContact() {
public void onClick(View view) { ((ContactAddFragment)getSupportFragmentManager().findFragmentById(R.id.container)).addContact();
switch (view.getId()) {
case R.id.ok:
String user = userView.getText().toString();
if ("".equals(user)) {
Toast.makeText(this, getString(R.string.EMPTY_USER_NAME),
Toast.LENGTH_LONG).show();
return;
}
String account = (String) accountView.getSelectedItem();
if (account == null) {
Toast.makeText(this, getString(R.string.EMPTY_ACCOUNT),
Toast.LENGTH_LONG).show();
return;
}
try {
RosterManager.getInstance().createContact(account, user,
nameView.getText().toString(), getSelected());
PresenceManager.getInstance()
.requestSubscription(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
finish();
return;
}
MessageManager.getInstance().openChat(account, user);
finish();
break;
default:
break;
}
} }
@Override @Override
Collection<String> getInitialGroups() { public boolean onCreateOptionsMenu(Menu menu) {
String account = (String) accountView.getSelectedItem(); MenuInflater inflater=getMenuInflater();
if (account == null) inflater.inflate(R.menu.add_contact, menu);
return Collections.emptyList();
return RosterManager.getInstance().getGroups(account);
}
@Override return true;
Collection<String> getInitialSelected() {
return Collections.emptyList();
} }
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, public boolean onOptionsItemSelected(MenuItem item) {
long id) { switch (item.getItemId()) {
String account = (String) accountView.getSelectedItem(); case R.id.action_add_contact:
if (account == null) { addContact();
onNothingSelected(parent); return true;
} else {
HashSet<String> groups = new HashSet<String>(RosterManager
.getInstance().getGroups(account));
groups.addAll(getSelected());
setGroups(groups, getSelected());
}
}
@Override default:
public void onNothingSelected(AdapterView<?> parent) { return super.onOptionsItemSelected(item);
setGroups(getSelected(), getSelected()); }
} }
public static Intent createIntent(Context context) { public static Intent createIntent(Context context) {
...@@ -205,10 +86,8 @@ public class ContactAdd extends GroupListActivity implements ...@@ -205,10 +86,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) {
...@@ -219,4 +98,8 @@ public class ContactAdd extends GroupListActivity implements ...@@ -219,4 +98,8 @@ public class ContactAdd extends GroupListActivity implements
return EntityIntentBuilder.getUser(intent); return EntityIntentBuilder.getUser(intent);
} }
@Override
public void onAccountSelected(String account) {
actionBarPainter.updateWithAccountName(account);
}
} }
package com.xabber.android.ui;
import android.app.Activity;
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;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter;
import com.xabber.androiddev.R;
import java.util.Collection;
public class ContactAddFragment extends GroupEditorFragment implements AdapterView.OnItemSelectedListener {
private static final String SAVED_NAME = "com.xabber.android.ui.ContactAdd.SAVED_NAME";
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 Spinner accountView;
private EditText userView;
private EditText nameView;
Listener listenerActivity;
private String name;
private View accountSelectorPanel;
public static ContactAddFragment newInstance(String account, String user) {
ContactAddFragment fragment = new ContactAddFragment();
Bundle args = new Bundle();
args.putString(ARG_ACCOUNT, account);
args.putString(ARG_USER, user);
fragment.setArguments(args);
return fragment;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
listenerActivity = (Listener)activity;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.contact_add_fragment, container, false);
if (savedInstanceState != null) {
name = savedInstanceState.getString(SAVED_NAME);
setAccount(savedInstanceState.getString(SAVED_ACCOUNT));
setUser(savedInstanceState.getString(SAVED_USER));
} else {
if (getAccount() == null || getUser() == null) {
name = null;
} else {
name = RosterManager.getInstance().getName(getAccount(), getUser());
if (getUser().equals(name)) {
name = null;
}
}
}
if (getAccount() == null) {
Collection<String> accounts = AccountManager.getInstance().getAccounts();
if (accounts.size() == 1) {
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))) {
accountView.setSelection(position);
break;
}
}
}
}
@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);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SAVED_ACCOUNT, getAccount());
outState.putString(SAVED_USER, userView.getText().toString());
outState.putString(SAVED_NAME, nameView.getText().toString());
}
@Override
public void onDetach() {
super.onDetach();
listenerActivity = null;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selectedAccount = (String) accountView.getSelectedItem();
if (selectedAccount == null) {
onNothingSelected(parent);
setAccount(selectedAccount);
} else {
listenerActivity.onAccountSelected(selectedAccount);
if (!selectedAccount.equals(getAccount())) {
setAccount(selectedAccount);
setAccountGroups();
updateGroups();
}
if (getListView().getVisibility() == View.GONE) {
setUpListView();
getListView().setVisibility(View.VISIBLE);
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
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),
Toast.LENGTH_LONG).show();
return;
}
String account = (String) accountView.getSelectedItem();
if (account == null) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT),
Toast.LENGTH_LONG).show();
return;
}
try {
RosterManager.getInstance().createContact(account, user,
nameView.getText().toString(), getSelected());
PresenceManager.getInstance().requestSubscription(account, user);
} catch (NetworkException e) {
Application.getInstance().onError(e);
getActivity().finish();
return;
}
MessageManager.getInstance().openChat(account, user);
getActivity().finish();
}
public interface Listener {
void onAccountSelected(String account);
}
}
...@@ -12,26 +12,36 @@ ...@@ -12,26 +12,36 @@
* 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/.
*/ */
package com.xabber.android.ui.preferences; package com.xabber.android.ui;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.text.InputType;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager; import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException;
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;
import com.xabber.android.data.extension.vcard.OnVCardListener; import com.xabber.android.data.extension.vcard.OnVCardListener;
import com.xabber.android.data.extension.vcard.VCardManager; import com.xabber.android.data.extension.vcard.VCardManager;
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.data.roster.AbstractContact;
import com.xabber.android.data.roster.OnContactChangedListener; import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.RosterContact; import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.helper.ContactTitleActionBarInflater; import com.xabber.android.ui.dialog.ContactDeleteDialogFragment;
import com.xabber.android.ui.helper.ContactTitleExpandableToolbarInflater;
import com.xabber.android.ui.helper.ManagedActivity; 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;
...@@ -54,8 +64,8 @@ import java.util.Map; ...@@ -54,8 +64,8 @@ import java.util.Map;
public class ContactViewer extends ManagedActivity implements public class ContactViewer extends ManagedActivity implements
OnVCardListener, OnContactChangedListener, OnAccountChangedListener { OnVCardListener, OnContactChangedListener, OnAccountChangedListener {
private static final String SAVED_VCARD = "com.xabber.android.ui.preferences.ContactViewer.SAVED_VCARD"; private static final String SAVED_VCARD = "com.xabber.android.ui.ContactViewer.SAVED_VCARD";
private static final String SAVED_VCARD_ERROR = "com.xabber.android.ui.preferences.ContactViewer.SAVED_VCARD_ERROR"; private static final String SAVED_VCARD_ERROR = "com.xabber.android.ui.ContactViewer.SAVED_VCARD_ERROR";
private String account; private String account;
private String bareAddress; private String bareAddress;
...@@ -68,6 +78,8 @@ public class ContactViewer extends ManagedActivity implements ...@@ -68,6 +78,8 @@ public class ContactViewer extends ManagedActivity implements
private static final Map<TelephoneType, Integer> TELEPHONE_TYPE_MAP = new HashMap<>(); private static final Map<TelephoneType, Integer> TELEPHONE_TYPE_MAP = new HashMap<>();
private static final Map<EmailType, Integer> EMAIL_TYPE_MAP = new HashMap<>(); private static final Map<EmailType, Integer> EMAIL_TYPE_MAP = new HashMap<>();
private ContactTitleExpandableToolbarInflater contactTitleExpandableToolbarInflater;
static { static {
ADDRESS_TYPE_MAP.put(AddressType.DOM, R.string.vcard_type_dom); ADDRESS_TYPE_MAP.put(AddressType.DOM, R.string.vcard_type_dom);
ADDRESS_TYPE_MAP.put(AddressType.HOME, R.string.vcard_type_home); ADDRESS_TYPE_MAP.put(AddressType.HOME, R.string.vcard_type_home);
...@@ -184,22 +196,16 @@ public class ContactViewer extends ManagedActivity implements ...@@ -184,22 +196,16 @@ public class ContactViewer extends ManagedActivity implements
LogManager.exception(this, e); LogManager.exception(this, e);
} }
} }
setTitle(getString(R.string.contact_viewer));
setContentView(R.layout.contact_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.contact_viewer_toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ContactTitleActionBarInflater contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
contactTitleActionBarInflater.setUpActionBarView();
contactTitleActionBarInflater.update(RosterManager.getInstance().getBestContact(account, bareAddress));
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ContactViewerFragment()).commit(); .add(R.id.scrollable_container, new ContactViewerFragment()).commit();
} }
contactTitleExpandableToolbarInflater = new ContactTitleExpandableToolbarInflater(this);
AbstractContact bestContact = RosterManager.getInstance().getBestContact(account, bareAddress);
contactTitleExpandableToolbarInflater.onCreate(bestContact);
} }
@Override @Override
...@@ -213,15 +219,78 @@ public class ContactViewer extends ManagedActivity implements ...@@ -213,15 +219,78 @@ public class ContactViewer extends ManagedActivity implements
if (vCard == null && !vCardError) if (vCard == null && !vCardError)
VCardManager.getInstance().request(account, bareAddress, null); VCardManager.getInstance().request(account, bareAddress, null);
contactTitleExpandableToolbarInflater.onResume();
ContactViewerFragment contactViewerFragment = getFragment(); ContactViewerFragment contactViewerFragment = getFragment();
contactViewerFragment.updateContact(account, bareAddress); contactViewerFragment.updateContact(account, bareAddress);
contactViewerFragment.updateVCard(vCard); contactViewerFragment.updateVCard(vCard);
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.contact_viewer, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_edit_alias:
editAlias();
return true;
case R.id.action_edit_groups:
startActivity(GroupEditor.createIntent(this, account, bareAddress));
return true;
case R.id.action_remove_contact:
ContactDeleteDialogFragment.newInstance(account, bareAddress)
.show(getFragmentManager(), "CONTACT_DELETE");
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void editAlias() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.edit_alias);
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress);
input.setText(rosterContact.getName());
builder.setView(input);
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
RosterManager.getInstance().setName(account, bareAddress, input.getText().toString());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
private ContactViewerFragment getFragment() { private ContactViewerFragment getFragment() {
return (ContactViewerFragment) getFragmentManager() return (ContactViewerFragment) getFragmentManager()
.findFragmentById(R.id.preferences_activity_container); .findFragmentById(R.id.scrollable_container);
} }
@Override @Override
...@@ -308,4 +377,10 @@ public class ContactViewer extends ManagedActivity implements ...@@ -308,4 +377,10 @@ public class ContactViewer extends ManagedActivity implements
public static Map<EmailType, Integer> getEmailTypeMap() { public static Map<EmailType, Integer> getEmailTypeMap() {
return EMAIL_TYPE_MAP; return EMAIL_TYPE_MAP;
} }
public View getContactTitleView() {
return findViewById(R.id.expandable_contact_title);
}
} }
...@@ -18,11 +18,8 @@ import android.content.Context; ...@@ -18,11 +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.widget.AdapterView;
import android.widget.EditText;
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;
...@@ -31,13 +28,13 @@ import com.xabber.android.data.roster.AbstractContact; ...@@ -31,13 +28,13 @@ 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.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, AdapterView.OnItemClickListener,
OnAccountChangedListener { OnAccountChangedListener {
private String account; private String account;
...@@ -45,38 +42,34 @@ public class ContactEditor extends GroupListActivity implements ...@@ -45,38 +42,34 @@ public class ContactEditor extends GroupListActivity implements
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.group_editor);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this); contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
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();
} }
}
@Override if (savedInstanceState == null) {
Collection<String> getInitialGroups() { getSupportFragmentManager().beginTransaction()
return RosterManager.getInstance().getGroups(account); .add(R.id.container, GroupEditorFragment.newInstance(account, user)).commit();
} }
@Override
Collection<String> getInitialSelected() {
return RosterManager.getInstance().getGroups(account, user);
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
((EditText) findViewById(R.id.contact_name)).setText(RosterManager.getInstance().getName(account, user));
Application.getInstance().addUIListener(OnAccountChangedListener.class, this); Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
Application.getInstance().addUIListener(OnContactChangedListener.class, this); Application.getInstance().addUIListener(OnContactChangedListener.class, this);
update(); update();
...@@ -87,19 +80,13 @@ public class ContactEditor extends GroupListActivity implements ...@@ -87,19 +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 {
String name = ((EditText) findViewById(R.id.contact_name)).getText().toString();
RosterManager.getInstance().setNameAndGroup(account, user, name, 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.setName(getString(R.string.contact_editor_title, abstractContact.getName()));
contactTitleActionBarInflater.setStatusText(user); contactTitleActionBarInflater.setStatusText(user);
contactTitleActionBarInflater.hideStatusIcon();
} }
@Override @Override
...@@ -121,7 +108,7 @@ public class ContactEditor extends GroupListActivity implements ...@@ -121,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;
......
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;
import java.util.HashSet;
public class GroupEditorFragment extends ListFragment implements TextWatcher, View.OnClickListener {
protected static final String ARG_ACCOUNT = "com.xabber.android.ui.GroupEditorFragment.ARG_ACCOUNT";
protected 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 static final String SAVED_ADD_GROUP_NAME = "com.xabber.android.ui.GroupEditorFragment.SAVED_ADD_GROUP_NAME";
private String account;
private String user;
private GroupEditorAdapter groupEditorAdapter;
private Collection<String> groups;
private Collection<String> selected = new HashSet<>();
private EditText groupAddInput;
private CheckBox groupAddCheckBox;
private View footerView;
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);
groupAddInput.setText(savedInstanceState.getString(SAVED_ADD_GROUP_NAME));
} else {
setAccountGroups();
if (user != null) {
selected = RosterManager.getInstance().getGroups(account, user);
}
}
}
protected void setAccountGroups() {
groups = RosterManager.getInstance().getGroups(account);
}
private void setUpFooter() {
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();
updateGroups();
}
protected void updateGroups() {
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);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
selected = getSelected();
outState.putStringArrayList(SAVED_GROUPS, getGroups());
outState.putStringArrayList(SAVED_SELECTED, new ArrayList<>(selected));
outState.putString(SAVED_ADD_GROUP_NAME, groupAddInput.getText().toString());
}
@Override
public void onPause() {
super.onPause();
selected = getSelected();
if (account != null && !"".equals(user)) {
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_item_selected_checkbox);
checkBox.toggle();
GroupEditorAdapter.Group group = groupEditorAdapter.getItem(position - getListView().getHeaderViewsCount());
group.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) {
}
protected String getAccount() {
return account;
}
protected String getUser() {
return user;
}
protected void setAccount(String account) {
this.account = account;
}
protected void setUser(String user) {
this.user = user;
}
protected View getFooterView() {
return footerView;
}
}
/**
* 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
OnItemClickListener, 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);
listView.setOnItemClickListener(this);
arrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_multiple_choice,
new ArrayList<String>());
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.add_item, listView, false);
((TextView) view.findViewById(android.R.id.message))
.setText(R.string.group_add);
listView.addFooterView(view, null, true);
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;
}
private void showGroupAddDialog() {
GroupAddDialogFragment.newInstance(getGroups()).show(getFragmentManager(), "GROUP-ADD");
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if (listView.getItemAtPosition(position) == null) // Footer
showGroupAddDialog();
}
/**
* 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);
}
}
...@@ -92,7 +92,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -92,7 +92,7 @@ public class StatusEditor extends ManagedListActivity implements
setListAdapter(adapter); setListAdapter(adapter);
statusTextView = (EditText) header.findViewById(R.id.status_text); statusTextView = (EditText) header.findViewById(R.id.status_text);
statusModeView = (Spinner) header.findViewById(R.id.status_mode); statusModeView = (Spinner) header.findViewById(R.id.status_icon);
statusModeView.setAdapter(new StatusModeAdapter(this)); statusModeView.setAdapter(new StatusModeAdapter(this));
findViewById(R.id.ok).setOnClickListener(this); findViewById(R.id.ok).setOnClickListener(this);
......
...@@ -129,7 +129,7 @@ public class AccountToggleAdapter implements UpdatableAdapter { ...@@ -129,7 +129,7 @@ public class AccountToggleAdapter implements UpdatableAdapter {
* @return The data for the specified view. * @return The data for the specified view.
*/ */
public String getItemForView(View view) { public String getItemForView(View view) {
if (view.getId() == R.id.status_mode) { if (view.getId() == R.id.status_icon) {
view = (View) view.getParent(); view = (View) view.getParent();
} }
for (int index = 0; index < linearLayout.getChildCount(); index++) { for (int index = 0; index < linearLayout.getChildCount(); index++) {
...@@ -146,7 +146,7 @@ public class AccountToggleAdapter implements UpdatableAdapter { ...@@ -146,7 +146,7 @@ public class AccountToggleAdapter implements UpdatableAdapter {
final ImageView disabled; final ImageView disabled;
public AccountViewHolder(View view) { public AccountViewHolder(View view) {
statusMode = (ImageView) view.findViewById(R.id.status_mode); statusMode = (ImageView) view.findViewById(R.id.status_icon);
avatar = (ImageView) view.findViewById(R.id.avatar); avatar = (ImageView) view.findViewById(R.id.avatar);
disabled = (ImageView) view.findViewById(R.id.disabled); disabled = (ImageView) view.findViewById(R.id.disabled);
} }
......
...@@ -61,7 +61,7 @@ public abstract class BaseContactInflater { ...@@ -61,7 +61,7 @@ public abstract class BaseContactInflater {
this.activity = activity; this.activity = activity;
layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.shadow); Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.contact_shadow);
shadowDrawable = new BitmapDrawable(activity.getResources(), bitmap); shadowDrawable = new BitmapDrawable(activity.getResources(), bitmap);
shadowDrawable.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); shadowDrawable.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
......
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_item_selected_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;
}
}
}
...@@ -92,7 +92,7 @@ public class OccupantListAdapter extends BaseAdapter implements ...@@ -92,7 +92,7 @@ public class OccupantListAdapter extends BaseAdapter implements
final TextView statusTextView = (TextView) view final TextView statusTextView = (TextView) view
.findViewById(R.id.status); .findViewById(R.id.status);
final ImageView statusModeView = (ImageView) view final ImageView statusModeView = (ImageView) view
.findViewById(R.id.status_mode); .findViewById(R.id.status_icon);
if (MUCManager.getInstance().getNickname(account, room) if (MUCManager.getInstance().getNickname(account, room)
.equalsIgnoreCase(occupant.getNickname())) .equalsIgnoreCase(occupant.getNickname()))
avatarView.setImageDrawable(AvatarManager.getInstance() avatarView.setImageDrawable(AvatarManager.getInstance()
......
...@@ -58,7 +58,7 @@ public class StatusContactInflater extends BaseContactInflater { ...@@ -58,7 +58,7 @@ public class StatusContactInflater extends BaseContactInflater {
public ViewHolder(View view) { public ViewHolder(View view) {
super(view); super(view);
statusMode = (ImageView) view.findViewById(R.id.status_mode); statusMode = (ImageView) view.findViewById(R.id.status_icon);
} }
} }
......
...@@ -7,6 +7,8 @@ import com.xabber.android.data.Application; ...@@ -7,6 +7,8 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException; 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.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.ContactList;
import com.xabber.android.ui.ContactViewer;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ContactDeleteDialogFragment extends ConfirmDialogFragment { public class ContactDeleteDialogFragment extends ConfirmDialogFragment {
...@@ -44,6 +46,10 @@ public class ContactDeleteDialogFragment extends ConfirmDialogFragment { ...@@ -44,6 +46,10 @@ public class ContactDeleteDialogFragment extends ConfirmDialogFragment {
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
} }
if (getActivity() instanceof ContactViewer) {
startActivity(ContactList.createIntent(getActivity()));
}
return true; return true;
} }
......
package com.xabber.android.ui.helper;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.view.Window;
import android.view.WindowManager;
import com.xabber.android.data.account.AccountManager;
import com.xabber.androiddev.R;
public class ActionBarPainter {
private int[] accountActionBarColors;
private int[] accountStatusBarColors;
private String[] accountColorNames;
private Window window;
private int defaultStatusBarColor;
private ColorDrawable defaultActionBarBackground;
private final ActionBarActivity activity;
public ActionBarPainter(ActionBarActivity activity) {
this.activity = activity;
accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar);
accountStatusBarColors = activity.getResources().getIntArray(R.array.account_status_bar);
accountColorNames = activity.getResources().getStringArray(R.array.account_color_names);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window = this.activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
defaultStatusBarColor = window.getStatusBarColor();
}
TypedArray a = activity.getTheme().obtainStyledAttributes(R.style.Theme, new int[] {R.attr.colorPrimary});
int attributeResourceId = a.getResourceId(0, 0);
defaultActionBarBackground = new ColorDrawable(activity.getResources().getColor(attributeResourceId));
}
public void updateWithAccountName(String account) {
updateWithColorLevel(AccountManager.getInstance().getColorLevel(account));
}
public void updateWithColorLevel(int colorLevel) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(accountStatusBarColors[colorLevel]);
}
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
}
public void restore() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(defaultStatusBarColor);
}
activity.getSupportActionBar().setBackgroundDrawable(defaultActionBarBackground);
}
public void updateWithColorName(String targetColorName) {
for (int i = 0; i < accountColorNames.length; i++) {
String accountColorName = accountColorNames[i];
if (accountColorName.equals(targetColorName)) {
updateWithColorLevel(i);
}
}
}
}
package com.xabber.android.ui.helper; package com.xabber.android.ui.helper;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -23,78 +16,47 @@ public class ContactTitleActionBarInflater { ...@@ -23,78 +16,47 @@ public class ContactTitleActionBarInflater {
private final ActionBarActivity activity; private final ActionBarActivity activity;
private View actionBarView; private View actionBarView;
private int[] accountActionBarColors;
private int[] accountStatusBarColors;
private Window window;
private int defaultStatusBarColor;
private Animation shakeAnimation = null; private Animation shakeAnimation = null;
private ColorDrawable defaultActionBarBackground; private ActionBarPainter actionBarPainter;
public ContactTitleActionBarInflater(ActionBarActivity activity) { public ContactTitleActionBarInflater(ActionBarActivity activity) {
this.activity = activity; this.activity = activity;
} }
public void setUpActionBarView() { public void setUpActionBarView() {
accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar);
accountStatusBarColors = activity.getResources().getIntArray(R.array.account_status_bar); actionBarPainter = new ActionBarPainter(activity);
ActionBar actionBar = activity.getSupportActionBar(); ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
actionBarView = LayoutInflater.from(activity).inflate(R.layout.contact_title, null); actionBarView = LayoutInflater.from(activity).inflate(R.layout.contact_title, null);
actionBar.setCustomView(actionBarView, new ActionBar.LayoutParams( actionBar.setCustomView(actionBarView, new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT)); ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window = this.activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
defaultStatusBarColor = window.getStatusBarColor();
}
TypedArray a = activity.getTheme().obtainStyledAttributes(R.style.Theme, new int[] {R.attr.colorPrimary});
int attributeResourceId = a.getResourceId(0, 0);
defaultActionBarBackground = new ColorDrawable(activity.getResources().getColor(attributeResourceId));
} }
public void update(AbstractContact abstractContact) { public void update(AbstractContact abstractContact) {
actionBarPainter.updateWithAccountName(abstractContact.getAccount());
activity.getSupportActionBar().setDisplayShowCustomEnabled(true); activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setDisplayShowTitleEnabled(false); activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
actionBarView.setVisibility(View.VISIBLE); actionBarView.setVisibility(View.VISIBLE);
ContactTitleInflater.updateTitle(actionBarView, activity, abstractContact); ContactTitleInflater.updateTitle(actionBarView, activity, abstractContact);
int colorLevel = AccountManager.getInstance().getColorLevel(abstractContact.getAccount());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(accountStatusBarColors[colorLevel]);
}
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
} }
public void restoreDefaultTitleView(String title) { public void restoreDefaultTitleView(String title) {
actionBarPainter.restore();
activity.getSupportActionBar().setDisplayShowCustomEnabled(false); activity.getSupportActionBar().setDisplayShowCustomEnabled(false);
activity.getSupportActionBar().setDisplayShowTitleEnabled(true); activity.getSupportActionBar().setDisplayShowTitleEnabled(true);
actionBarView.setVisibility(View.GONE); actionBarView.setVisibility(View.GONE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(defaultStatusBarColor);
}
activity.getSupportActionBar().setBackgroundDrawable(defaultActionBarBackground);
activity.setTitle(title); activity.setTitle(title);
} }
public ImageView getSecurityView() {
return (ImageView)actionBarView.findViewById(R.id.security);
}
public void playIncomingAnimation() { public void playIncomingAnimation() {
if (shakeAnimation == null) { if (shakeAnimation == null) {
shakeAnimation = AnimationUtils.loadAnimation(activity, R.anim.shake); shakeAnimation = AnimationUtils.loadAnimation(activity, R.anim.shake);
...@@ -117,4 +79,8 @@ public class ContactTitleActionBarInflater { ...@@ -117,4 +79,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);
}
} }
package com.xabber.android.ui.helper;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.github.ksoichiro.android.observablescrollview.ObservableListView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;
import com.github.ksoichiro.android.observablescrollview.ScrollUtils;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.roster.AbstractContact;
import com.xabber.androiddev.R;
import static java.lang.Math.pow;
import static java.lang.Math.round;
import static java.lang.Math.sqrt;
public class ContactTitleExpandableToolbarInflater implements ObservableScrollViewCallbacks {
private final ActionBarActivity activity;
private View avatarView;
private View titleView;
private View contactNamePanel;
private int toolbarHeight;
private int paddingLeftMin;
private int paddingRight;
private int actionBarSize;
private int toolbarHeightDelta;
private int avatarLargeSize;
private int avatarNormalSize;
private int avatarRadius;
private int contactTitlePaddingBottomBig;
private int contactTitlePaddingBottomSmall;
public ContactTitleExpandableToolbarInflater(ActionBarActivity activity) {
this.activity = activity;
}
public void onCreate(AbstractContact abstractContact) {
activity.setContentView(R.layout.expandable_contact_title_activity);
activity.setSupportActionBar((Toolbar) activity.findViewById(R.id.toolbar_overlay));
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
avatarView = activity.findViewById(R.id.avatar);
contactNamePanel = activity.findViewById(R.id.contact_name_panel);
titleView = activity.findViewById(R.id.expandable_contact_title);
ContactTitleInflater.updateTitle(titleView, activity, abstractContact);
int[] accountStatusBarColors = activity.getResources().getIntArray(R.array.account_status_bar);
int colorLevel = AccountManager.getInstance().getColorLevel(abstractContact.getAccount());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(accountStatusBarColors[colorLevel]);
}
}
public void onResume() {
Resources resources = activity.getResources();
paddingLeftMin = resources.getDimensionPixelSize(R.dimen.contact_title_padding_left);
paddingRight = resources.getDimensionPixelSize(R.dimen.contact_title_padding_right);
avatarLargeSize = resources.getDimensionPixelSize(R.dimen.avatar_large_size);
avatarNormalSize = resources.getDimensionPixelSize(R.dimen.avatar_normal_size);
avatarRadius = resources.getDimensionPixelSize(R.dimen.avatar_radius);
contactTitlePaddingBottomBig = resources.getDimensionPixelSize(R.dimen.contact_title_padding_bottom_big);
contactTitlePaddingBottomSmall = resources.getDimensionPixelSize(R.dimen.contact_title_padding_bottom_small);
toolbarHeight = resources.getDimensionPixelSize(R.dimen.toolbar_height);
actionBarSize = getActionBarSize();
toolbarHeightDelta = toolbarHeight - actionBarSize;
final ObservableScrollView scrollView = (ObservableScrollView) activity.findViewById(R.id.scroll);
scrollView.setScrollViewCallbacks(this);
ScrollUtils.addOnGlobalLayoutListener(activity.findViewById(R.id.expandable_contact_title), new Runnable() {
@Override
public void run() {
updateFlexibleSpaceText(scrollView.getCurrentScrollY());
}
});
}
protected int getActionBarSize() {
TypedValue typedValue = new TypedValue();
int[] textSizeAttr = new int[]{R.attr.actionBarSize};
int indexOfAttrTextSize = 0;
TypedArray a = activity.obtainStyledAttributes(typedValue.data, textSizeAttr);
int actionBarSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1);
a.recycle();
return actionBarSize;
}
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
updateFlexibleSpaceText(scrollY);
}
@Override
public void onDownMotionEvent() {
}
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
}
private void updateFlexibleSpaceText(final int scrollY) {
setLeftPadding(scrollY);
setTopPadding(scrollY);
setAvatarSize(scrollY);
setHeight(scrollY);
}
private void setTopPadding(int scrollY) {
int paddingDelta = contactTitlePaddingBottomBig - contactTitlePaddingBottomSmall;
int paddingBottom = contactTitlePaddingBottomBig - scrollY * paddingDelta / toolbarHeightDelta;
if (scrollY <= 0) {
paddingBottom = contactTitlePaddingBottomBig;
}
if (scrollY >= toolbarHeightDelta) {
paddingBottom = contactTitlePaddingBottomSmall;
}
contactNamePanel.setPadding(0, 0, 0, paddingBottom);
}
private void setAvatarSize(int scrollY) {
int newAvatarSize = avatarLargeSize - (scrollY / 2);
if (newAvatarSize < avatarNormalSize) {
newAvatarSize = avatarNormalSize;
}
if (avatarView.getWidth() != newAvatarSize) {
avatarView.getLayoutParams().width = newAvatarSize;
avatarView.getLayoutParams().height = newAvatarSize;
}
}
private void setHeight(int scrollY) {
int newHeight = toolbarHeight - scrollY;
if (newHeight < actionBarSize) {
newHeight = actionBarSize;
}
titleView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, newHeight));
}
private void setLeftPadding(int scrollY) {
int paddingLeft = (int) round(sqrt(pow(avatarRadius, 2) - pow(scrollY - avatarRadius, 2)));
if (scrollY < 0) {
paddingLeft = paddingLeftMin;
}
if (scrollY > avatarRadius) {
paddingLeft = avatarRadius;
}
if (paddingLeft < paddingLeftMin) {
paddingLeft = paddingLeftMin;
}
titleView.setPadding(paddingLeft, 0, paddingLeft, 0);
}
}
...@@ -62,7 +62,7 @@ public class ContactTitleInflater { ...@@ -62,7 +62,7 @@ public class ContactTitleInflater {
} }
private static void setStatus(Activity activity, View titleView, AbstractContact abstractContact) { private static void setStatus(Activity activity, View titleView, AbstractContact abstractContact) {
final ImageView statusModeView = (ImageView) titleView.findViewById(R.id.status_mode); final ImageView statusModeView = (ImageView) titleView.findViewById(R.id.status_icon);
int statusLevel = abstractContact.getStatusMode().getStatusLevel(); int statusLevel = abstractContact.getStatusMode().getStatusLevel();
if (isContactOffline(statusLevel)) { if (isContactOffline(statusLevel)) {
......
...@@ -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;
...@@ -44,7 +43,7 @@ import com.xabber.android.ui.dialog.GroupDeleteDialogFragment; ...@@ -44,7 +43,7 @@ import com.xabber.android.ui.dialog.GroupDeleteDialogFragment;
import com.xabber.android.ui.dialog.GroupRenameDialogFragment; import com.xabber.android.ui.dialog.GroupRenameDialogFragment;
import com.xabber.android.ui.dialog.MUCDeleteDialogFragment; import com.xabber.android.ui.dialog.MUCDeleteDialogFragment;
import com.xabber.android.ui.preferences.AccountEditor; import com.xabber.android.ui.preferences.AccountEditor;
import com.xabber.android.ui.preferences.ContactViewer; import com.xabber.android.ui.ContactViewer;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
/** /**
...@@ -63,17 +62,6 @@ public class ContextMenuHelper { ...@@ -63,17 +62,6 @@ public class ContextMenuHelper {
final String account = abstractContact.getAccount(); final String account = abstractContact.getAccount();
final String user = abstractContact.getUser(); final String user = abstractContact.getUser();
menu.setHeaderTitle(abstractContact.getName()); menu.setHeaderTitle(abstractContact.getName());
menu.add(R.string.chat_viewer).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
MessageManager.getInstance().openChat(account, user);
activity.startActivity(ChatViewer.createIntent(
activity, account, user));
return true;
}
});
if (MUCManager.getInstance().hasRoom(account, user)) { if (MUCManager.getInstance().hasRoom(account, user)) {
if (!MUCManager.getInstance().inUse(account, user)) if (!MUCManager.getInstance().inUse(account, user))
menu.add(R.string.muc_edit).setIntent( menu.add(R.string.muc_edit).setIntent(
...@@ -121,10 +109,6 @@ public class ContextMenuHelper { ...@@ -121,10 +109,6 @@ public class ContextMenuHelper {
}); });
} else { } else {
menu.add(R.string.contact_viewer).setIntent(
ContactViewer.createIntent(activity, account, user));
menu.add(R.string.contact_editor).setIntent(
ContactEditor.createIntent(activity, account, user));
menu.add(R.string.contact_delete).setOnMenuItemClickListener( menu.add(R.string.contact_delete).setOnMenuItemClickListener(
new MenuItem.OnMenuItemClickListener() { new MenuItem.OnMenuItemClickListener() {
...@@ -185,7 +169,7 @@ public class ContextMenuHelper { ...@@ -185,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;
} }
...@@ -290,7 +274,6 @@ public class ContextMenuHelper { ...@@ -290,7 +274,6 @@ public class ContextMenuHelper {
} }
return true; return true;
} }
}); });
menu.add(R.string.contact_add).setIntent( menu.add(R.string.contact_add).setIntent(
ContactAdd.createIntent(activity, account)); ContactAdd.createIntent(activity, account));
......
...@@ -28,6 +28,7 @@ import com.xabber.android.data.account.AccountManager; ...@@ -28,6 +28,7 @@ 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.ui.OAuthActivity; import com.xabber.android.ui.OAuthActivity;
import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder; import com.xabber.android.ui.dialog.OrbotInstallerDialogBuilder;
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;
...@@ -46,6 +47,7 @@ public class AccountEditor extends ManagedActivity implements ...@@ -46,6 +47,7 @@ public class AccountEditor extends ManagedActivity implements
private AccountItem accountItem; private AccountItem accountItem;
private String token; private String token;
private ActionBarPainter actionBarPainter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -76,6 +78,9 @@ public class AccountEditor extends ManagedActivity implements ...@@ -76,6 +78,9 @@ public class AccountEditor extends ManagedActivity implements
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(AccountManager.getInstance().getVerboseName(account)); setTitle(AccountManager.getInstance().getVerboseName(account));
actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
} }
@Override @Override
...@@ -158,4 +163,9 @@ public class AccountEditor extends ManagedActivity implements ...@@ -158,4 +163,9 @@ public class AccountEditor extends ManagedActivity implements
public void showOrbotDialog() { public void showOrbotDialog() {
showDialog(ORBOT_DIALOG_ID); showDialog(ORBOT_DIALOG_ID);
} }
@Override
public void onColorChange(String colorName) {
actionBarPainter.updateWithColorName(colorName);
}
} }
...@@ -92,6 +92,11 @@ public class AccountEditorFragment extends BaseSettingsFragment ...@@ -92,6 +92,11 @@ public class AccountEditorFragment extends BaseSettingsFragment
} }
} }
} }
if (getString(R.string.account_color_key).equals(key)) {
mListener.onColorChange((String)newValue);
}
return true; return true;
} }
...@@ -210,10 +215,11 @@ public class AccountEditorFragment extends BaseSettingsFragment ...@@ -210,10 +215,11 @@ public class AccountEditorFragment extends BaseSettingsFragment
} }
public interface AccountEditorFragmentInteractionListener { public interface AccountEditorFragmentInteractionListener {
public String getAccount(); String getAccount();
public AccountItem getAccountItem(); AccountItem getAccountItem();
public String getToken(); String getToken();
public void onOAuthClick(); void onOAuthClick();
public void showOrbotDialog(); void showOrbotDialog();
void onColorChange(String colorName);
} }
} }
...@@ -23,6 +23,7 @@ import com.xabber.android.data.Application; ...@@ -23,6 +23,7 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.account.AccountItem; import com.xabber.android.data.account.AccountItem;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.EntityIntentBuilder; import com.xabber.android.data.intent.EntityIntentBuilder;
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;
...@@ -51,6 +52,9 @@ public class ChatEditor extends ManagedActivity ...@@ -51,6 +52,9 @@ public class ChatEditor extends ManagedActivity
setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default)); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_default));
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ActionBarPainter actionBarPainter = new ActionBarPainter(this);
actionBarPainter.updateWithAccountName(account);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.add(R.id.preferences_activity_container, new ChatEditorFragment()).commit(); .add(R.id.preferences_activity_container, new ChatEditorFragment()).commit();
......
package com.xabber.android.ui.preferences;
import android.os.Bundle;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import com.xabber.android.data.extension.capability.CapabilitiesManager;
import com.xabber.android.data.extension.capability.ClientInfo;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.ResourceItem;
import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.helper.PreferenceSummaryHelper;
import com.xabber.android.ui.widget.StatusPreference;
import com.xabber.androiddev.R;
import com.xabber.xmpp.vcard.Address;
import com.xabber.xmpp.vcard.AddressProperty;
import com.xabber.xmpp.vcard.AddressType;
import com.xabber.xmpp.vcard.Email;
import com.xabber.xmpp.vcard.EmailType;
import com.xabber.xmpp.vcard.NameProperty;
import com.xabber.xmpp.vcard.Organization;
import com.xabber.xmpp.vcard.Telephone;
import com.xabber.xmpp.vcard.TelephoneType;
import com.xabber.xmpp.vcard.VCard;
import com.xabber.xmpp.vcard.VCardProperty;
import java.util.ArrayList;
import java.util.List;
public class ContactViewerFragment extends android.preference.PreferenceFragment {
private List<PreferenceCategory> addresses;
private List<PreferenceCategory> telephones;
private List<PreferenceCategory> emails;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addresses = new ArrayList<>();
telephones = new ArrayList<>();
emails = new ArrayList<>();
addPreferencesFromResource(R.xml.contact_viewer);
PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
}
/**
* Sets value for the preference by its id.
*
* @param resourceId
* @param value
*/
private void setValue(int resourceId, String value) {
if (value == null)
value = "";
findPreference(getString(resourceId)).setSummary(value);
}
/**
* @param source
* @param value
* @param splitter
* @return Concatenated source and value with splitter if necessary.
*/
private String addString(String source, String value, String splitter) {
if (value == null || "".equals(value))
return source;
if (source == null || "".equals(source))
return value;
return source + splitter + value;
}
public void updateContact(String account, String bareAddress) {
setValue(R.string.contact_viewer_jid, bareAddress);
RosterContact rosterContact = RosterManager.getInstance()
.getRosterContact(account, bareAddress);
setValue(R.string.contact_viewer_name, rosterContact == null ? null
: rosterContact.getRealName());
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference(getString(R.string.contact_viewer_resources));
preferenceCategory.removeAll();
if (rosterContact != null && rosterContact.isConnected())
for (ResourceItem resourceItem : PresenceManager.getInstance()
.getResourceItems(account, bareAddress)) {
StatusPreference preference = new StatusPreference(getActivity());
preference.setLayoutResource(R.layout.info_preference);
preference.setStatusMode(resourceItem.getStatusMode());
String user = resourceItem.getUser(bareAddress);
ClientInfo clientInfo = CapabilitiesManager.getInstance()
.getClientInfo(account, user);
String client;
if (clientInfo == null) {
CapabilitiesManager.getInstance().request(account, user);
client = getString(R.string.please_wait);
} else if (clientInfo == CapabilitiesManager.INVALID_CLIENT_INFO) {
client = getString(R.string.unknown);
} else {
String name = clientInfo.getName();
if (name == null)
name = getString(R.string.unknown);
String type = clientInfo.getType();
if (type == null)
type = getString(R.string.unknown);
client = getString(R.string.contact_viewer_client_info,
name, type);
}
preference.setTitle(getString(
R.string.contact_viewer_resource_summary,
resourceItem.getVerbose(), resourceItem.getPriority(),
client));
preference.setSummary(resourceItem.getStatusText());
preferenceCategory.addPreference(preference);
}
}
public void updateVCard(VCard vCard) {
if (vCard == null)
return;
setValue(R.string.vcard_nick_name,
vCard.getField(VCardProperty.NICKNAME));
setValue(R.string.vcard_formatted_name, vCard.getFormattedName());
setValue(R.string.vcard_prefix_name,
vCard.getField(NameProperty.PREFIX));
setValue(R.string.vcard_given_name, vCard.getField(NameProperty.GIVEN));
setValue(R.string.vcard_middle_name,
vCard.getField(NameProperty.MIDDLE));
setValue(R.string.vcard_family_name,
vCard.getField(NameProperty.FAMILY));
setValue(R.string.vcard_suffix_name,
vCard.getField(NameProperty.SUFFIX));
setValue(R.string.vcard_birth_date, vCard.getField(VCardProperty.BDAY));
setValue(R.string.vcard_title, vCard.getField(VCardProperty.TITLE));
setValue(R.string.vcard_role, vCard.getField(VCardProperty.ROLE));
List<Organization> organizations = vCard.getOrganizations();
String organization;
if (organizations.isEmpty())
organization = null;
else {
organization = organizations.get(0).getName();
for (String unit : organizations.get(0).getUnits())
organization = addString(organization, unit, "\n");
}
setValue(R.string.vcard_organization, organization);
setValue(R.string.vcard_url, vCard.getField(VCardProperty.URL));
String categories = null;
for (String category : vCard.getCategories())
categories = addString(categories, category, "\n");
setValue(R.string.vcard_categories, categories);
setValue(R.string.vcard_note, vCard.getField(VCardProperty.NOTE));
setValue(R.string.vcard_decsription, vCard.getField(VCardProperty.DESC));
PreferenceScreen screen = getPreferenceScreen();
for (PreferenceCategory category : addresses)
screen.removePreference(category);
for (PreferenceCategory category : telephones)
screen.removePreference(category);
for (PreferenceCategory category : emails)
screen.removePreference(category);
for (Address address : vCard.getAddresses()) {
String types = null;
for (AddressType type : address.getTypes())
types = addString(types, getString(ContactViewer.getAddressTypeMap().get(type)),
", ");
String value = null;
for (AddressProperty property : AddressProperty.values())
value = addString(value, address.getProperties().get(property),
"\n");
PreferenceScreen addressScreen = createTypedCategory(
R.string.vcard_address, types, value);
for (AddressProperty property : AddressProperty.values())
addPreferenceScreen(addressScreen,
ContactViewer.getAddressPropertyMap().get(property), address
.getProperties().get(property));
}
for (Telephone telephone : vCard.getTelephones()) {
String types = null;
for (TelephoneType type : telephone.getTypes())
types = addString(types,
getString(ContactViewer.getTelephoneTypeMap().get(type)), ", ");
createTypedCategory(R.string.vcard_telephone, types,
telephone.getValue());
}
for (Email email : vCard.getEmails()) {
String types = null;
for (EmailType type : email.getTypes())
types = addString(types, getString(ContactViewer.getEmailTypeMap().get(type)),
", ");
createTypedCategory(R.string.vcard_email, types, email.getValue());
}
}
private PreferenceScreen createTypedCategory(int title, String types,
String value) {
PreferenceCategory preferenceCategory = new PreferenceCategory(getActivity());
preferenceCategory.setTitle(title);
getPreferenceScreen().addPreference(preferenceCategory);
addPreferenceScreen(preferenceCategory, R.string.vcard_type, types);
return addPreferenceScreen(preferenceCategory, title, value);
}
private PreferenceScreen addPreferenceScreen(PreferenceGroup container,
int title, String summary) {
PreferenceScreen preference = getPreferenceManager().createPreferenceScreen(getActivity());
preference.setLayoutResource(R.layout.info_preference);
preference.setTitle(title);
preference.setSummary(summary == null ? "" : summary);
container.addPreference(preference);
return preference;
}
}
...@@ -58,7 +58,7 @@ public class StatusPreference extends Preference { ...@@ -58,7 +58,7 @@ public class StatusPreference extends Preference {
@Override @Override
protected void onBindView(View view) { protected void onBindView(View view) {
super.onBindView(view); super.onBindView(view);
((ImageView) view.findViewById(R.id.status_mode)) ((ImageView) view.findViewById(R.id.status_icon))
.setImageLevel(statusMode.getStatusLevel()); .setImageLevel(statusMode.getStatusLevel());
} }
......
...@@ -16,7 +16,7 @@ package com.xabber.xmpp.vcard; ...@@ -16,7 +16,7 @@ package com.xabber.xmpp.vcard;
public class Email extends AbstractTypedDataWithValue<EmailType> { public class Email extends AbstractTypedDataWithValue<EmailType> {
public static final String ELEMENT_NAME = "TEL"; public static final String ELEMENT_NAME = "EMAIL";
public static final String USERID_NAME = "USERID"; public static final String USERID_NAME = "USERID";
public Email() { public Email() {
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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