Commit 673647ed authored by Grigory Fedorov's avatar Grigory Fedorov

ContactEditor: old contact title removed. Light refactoring.

parent 920eb760
...@@ -17,6 +17,7 @@ package com.xabber.android.ui; ...@@ -17,6 +17,7 @@ package com.xabber.android.ui;
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.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
...@@ -31,7 +32,6 @@ import com.xabber.android.data.roster.AbstractContact; ...@@ -31,7 +32,6 @@ 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.ContactTitleInflater;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid; import com.xabber.xmpp.address.Jid;
...@@ -61,11 +61,10 @@ public class ContactEditor extends GroupListActivity implements ...@@ -61,11 +61,10 @@ public class ContactEditor extends GroupListActivity implements
Intent intent = getIntent(); Intent intent = getIntent();
account = ContactEditor.getAccount(intent); account = ContactEditor.getAccount(intent);
user = ContactEditor.getUser(intent); user = ContactEditor.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();
return;
} }
} }
...@@ -82,62 +81,55 @@ public class ContactEditor extends GroupListActivity implements ...@@ -82,62 +81,55 @@ public class ContactEditor extends GroupListActivity implements
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
((EditText) findViewById(R.id.contact_name)).setText(RosterManager ((EditText) findViewById(R.id.contact_name)).setText(RosterManager.getInstance().getName(account, user));
.getInstance().getName(account, user)); Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
Application.getInstance().addUIListener(OnAccountChangedListener.class, Application.getInstance().addUIListener(OnContactChangedListener.class, this);
this);
Application.getInstance().addUIListener(OnContactChangedListener.class,
this);
update(); update();
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
Application.getInstance().removeUIListener( Application.getInstance().removeUIListener(OnAccountChangedListener.class, this);
OnAccountChangedListener.class, this); Application.getInstance().removeUIListener(OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(
OnContactChangedListener.class, this);
try { try {
String name = ((EditText) findViewById(R.id.contact_name)) String name = ((EditText) findViewById(R.id.contact_name)).getText().toString();
.getText().toString(); RosterManager.getInstance().setNameAndGroup(account, user, name, getSelected());
RosterManager.getInstance().setNameAndGroup(account, user, name,
getSelected());
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
} }
} }
private void update() { private void update() {
AbstractContact abstractContact = RosterManager.getInstance() AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
.getBestContact(account, user);
ContactTitleInflater.updateTitle(findViewById(R.id.title), this,
abstractContact);
((TextView) findViewById(R.id.name)).setText(getString(
R.string.contact_editor_title, abstractContact.getName()));
((TextView) findViewById(R.id.status_text)).setText(user);
contactTitleActionBarInflater.update(abstractContact); contactTitleActionBarInflater.update(abstractContact);
View actionBarView = contactTitleActionBarInflater.getActionBarView();
((TextView) actionBarView.findViewById(R.id.name))
.setText(getString(R.string.contact_editor_title, abstractContact.getName()));
((TextView) actionBarView.findViewById(R.id.status_text)).setText(user);
} }
@Override @Override
public void onContactsChanged(Collection<BaseEntity> entities) { public void onContactsChanged(Collection<BaseEntity> entities) {
String thisBareAddress = Jid.getBareAddress(user); String thisBareAddress = Jid.getBareAddress(user);
for (BaseEntity entity : entities) for (BaseEntity entity : entities) {
if (entity.equals(account, thisBareAddress)) { if (entity.equals(account, thisBareAddress)) {
update(); update();
break; break;
} }
}
} }
@Override @Override
public void onAccountsChanged(Collection<String> accounts) { public void onAccountsChanged(Collection<String> accounts) {
if (accounts.contains(account)) if (accounts.contains(account)) {
update(); update();
}
} }
public static Intent createIntent(Context context, String account, public static Intent createIntent(Context context, String account, String user) {
String user) {
Intent intent = new EntityIntentBuilder(context, ContactEditor.class) Intent intent = new EntityIntentBuilder(context, ContactEditor.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);
......
...@@ -55,4 +55,8 @@ public class ContactTitleActionBarInflater { ...@@ -55,4 +55,8 @@ public class ContactTitleActionBarInflater {
} }
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel])); activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
} }
public View getActionBarView() {
return actionBarView;
}
} }
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
> >
<include layout="@layout/contact_title" />
<TextView <TextView
android:text="@string/contact_name" android:text="@string/contact_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
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