Commit 920eb760 authored by Grigory Fedorov's avatar Grigory Fedorov

FingerprintViewer and QuestionViewer: old contact title removed.

Light refactoring.
parent 3b651f6e
...@@ -31,7 +31,7 @@ public class SMProgress extends BaseEntity implements EntityNotificationItem { ...@@ -31,7 +31,7 @@ public class SMProgress extends BaseEntity implements EntityNotificationItem {
@Override @Override
public Intent getIntent() { public Intent getIntent() {
return QuestionViewer.createCanelIntent( return QuestionViewer.createCancelIntent(
Application.getInstance(), account, user); Application.getInstance(), account, user);
} }
......
...@@ -34,7 +34,6 @@ import com.xabber.android.data.roster.AbstractContact; ...@@ -34,7 +34,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.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;
...@@ -64,14 +63,14 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -64,14 +63,14 @@ public class QuestionViewer extends ManagedActivity implements
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (isFinishing()) if (isFinishing()) {
return; return;
}
Intent intent = getIntent(); Intent intent = getIntent();
account = QuestionViewer.getAccount(intent); account = QuestionViewer.getAccount(intent);
user = QuestionViewer.getUser(intent); user = QuestionViewer.getUser(intent);
if (AccountManager.getInstance().getAccount(account) == null if (AccountManager.getInstance().getAccount(account) == null || user == null) {
|| user == null) {
Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
finish(); finish();
return; return;
...@@ -86,18 +85,19 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -86,18 +85,19 @@ public class QuestionViewer extends ManagedActivity implements
return; return;
} }
showQuestion = intent.getBooleanExtra(EXTRA_FIELD_SHOW_QUESTION, true); showQuestion = intent.getBooleanExtra(EXTRA_FIELD_SHOW_QUESTION, true);
answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, false);
false);
if (showQuestion) { if (showQuestion) {
setContentView(R.layout.question_viewer); setContentView(R.layout.question_viewer);
questionView = (EditText) findViewById(R.id.question); questionView = (EditText) findViewById(R.id.question);
questionView.setEnabled(!answerRequest); questionView.setEnabled(!answerRequest);
if (answerRequest) if (answerRequest) {
questionView.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); questionView.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
else } else {
findViewById(R.id.cancel).setVisibility(View.GONE); findViewById(R.id.cancel).setVisibility(View.GONE);
} else }
} else {
setContentView(R.layout.secret_viewer); setContentView(R.layout.secret_viewer);
}
findViewById(R.id.cancel).setOnClickListener(this); findViewById(R.id.cancel).setOnClickListener(this);
findViewById(R.id.send).setOnClickListener(this); findViewById(R.id.send).setOnClickListener(this);
...@@ -108,53 +108,48 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -108,53 +108,48 @@ public class QuestionViewer extends ManagedActivity implements
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Application.getInstance().addUIListener(OnAccountChangedListener.class, Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
this); Application.getInstance().addUIListener(OnContactChangedListener.class, 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);
} }
@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();
} }
}
@Override @Override
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.send: case R.id.send:
String question = showQuestion ? questionView.getText().toString() String question = showQuestion ? questionView.getText().toString() : null;
: null; String answer = ((TextView) findViewById(R.id.answer)).getText().toString();
String answer = ((TextView) findViewById(R.id.answer)).getText()
.toString();
try { try {
if (answerRequest) if (answerRequest) {
OTRManager.getInstance().respondSmp(account, user, OTRManager.getInstance().respondSmp(account, user, question, answer);
question, answer); } else {
else OTRManager.getInstance().initSmp(account, user, question, answer);
OTRManager.getInstance().initSmp(account, user, question, }
answer);
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
} }
...@@ -173,11 +168,7 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -173,11 +168,7 @@ public class QuestionViewer extends ManagedActivity implements
} }
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);
contactTitleActionBarInflater.update(abstractContact); contactTitleActionBarInflater.update(abstractContact);
} }
...@@ -187,8 +178,7 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -187,8 +178,7 @@ public class QuestionViewer extends ManagedActivity implements
* @param user * @param user
* @return Intent to cancel negotiation. * @return Intent to cancel negotiation.
*/ */
public static Intent createCanelIntent(Context context, String account, public static Intent createCancelIntent(Context context, String account, String user) {
String user) {
Intent intent = new EntityIntentBuilder(context, QuestionViewer.class) Intent intent = new EntityIntentBuilder(context, QuestionViewer.class)
.setAccount(account).setUser(user).build(); .setAccount(account).setUser(user).build();
intent.putExtra(EXTRA_FIELD_CANCEL, true); intent.putExtra(EXTRA_FIELD_CANCEL, true);
...@@ -205,9 +195,8 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -205,9 +195,8 @@ public class QuestionViewer extends ManagedActivity implements
* answerRequest are <code>true</code>. * answerRequest are <code>true</code>.
* @return * @return
*/ */
public static Intent createIntent(Context context, String account, public static Intent createIntent(Context context, String account, String user,
String user, boolean showQuestion, boolean answerRequest, boolean showQuestion, boolean answerRequest, String question) {
String question) {
Intent intent = new EntityIntentBuilder(context, QuestionViewer.class) Intent intent = new EntityIntentBuilder(context, QuestionViewer.class)
.setAccount(account).setUser(user).build(); .setAccount(account).setUser(user).build();
intent.putExtra(EXTRA_FIELD_SHOW_QUESTION, showQuestion); intent.putExtra(EXTRA_FIELD_SHOW_QUESTION, showQuestion);
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
> >
<include layout="@layout/contact_title" />
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
> >
<include layout="@layout/contact_title" />
<ScrollView <ScrollView
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
> >
<include layout="@layout/contact_title" />
<ScrollView <ScrollView
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
......
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