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;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.TextView;
......@@ -31,7 +32,6 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.helper.ContactTitleActionBarInflater;
import com.xabber.android.ui.helper.ContactTitleInflater;
import com.xabber.androiddev.R;
import com.xabber.xmpp.address.Jid;
......@@ -61,11 +61,10 @@ public class ContactEditor extends GroupListActivity implements
Intent intent = getIntent();
account = ContactEditor.getAccount(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);
finish();
return;
}
}
......@@ -82,62 +81,55 @@ public class ContactEditor extends GroupListActivity implements
@Override
protected void onResume() {
super.onResume();
((EditText) findViewById(R.id.contact_name)).setText(RosterManager
.getInstance().getName(account, user));
Application.getInstance().addUIListener(OnAccountChangedListener.class,
this);
Application.getInstance().addUIListener(OnContactChangedListener.class,
this);
((EditText) findViewById(R.id.contact_name)).setText(RosterManager.getInstance().getName(account, user));
Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
Application.getInstance().addUIListener(OnContactChangedListener.class, this);
update();
}
@Override
protected void onPause() {
super.onPause();
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
Application.getInstance().removeUIListener(
OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(OnAccountChangedListener.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());
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() {
AbstractContact abstractContact = RosterManager.getInstance()
.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);
AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
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
public void onContactsChanged(Collection<BaseEntity> entities) {
String thisBareAddress = Jid.getBareAddress(user);
for (BaseEntity entity : entities)
for (BaseEntity entity : entities) {
if (entity.equals(account, thisBareAddress)) {
update();
break;
}
}
}
@Override
public void onAccountsChanged(Collection<String> accounts) {
if (accounts.contains(account))
if (accounts.contains(account)) {
update();
}
}
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)
.setAccount(account).setUser(user).build();
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
......
......@@ -55,4 +55,8 @@ public class ContactTitleActionBarInflater {
}
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
}
public View getActionBarView() {
return actionBarView;
}
}
......@@ -19,8 +19,6 @@
android:layout_height="match_parent"
>
<include layout="@layout/contact_title" />
<TextView
android:text="@string/contact_name"
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