conversations-classic/src/main/java/eu/siacs/conversations/ui/ShareViaAccountActivity.java

104 lines
3 KiB
Java
Raw Normal View History

2017-12-07 15:45:20 +00:00
package eu.siacs.conversations.ui;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
2017-12-07 15:45:20 +00:00
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.ui.adapter.AccountAdapter;
2018-03-05 17:30:40 +00:00
import rocks.xmpp.addr.Jid;
2017-12-07 15:45:20 +00:00
public class ShareViaAccountActivity extends XmppActivity {
public static final String EXTRA_CONTACT = "contact";
public static final String EXTRA_BODY = "body";
protected final List<Account> accountList = new ArrayList<>();
protected ListView accountListView;
protected AccountAdapter mAccountAdapter;
@Override
protected void refreshUiReal() {
synchronized (this.accountList) {
accountList.clear();
accountList.addAll(xmppConnectionService.getAccounts());
}
ActionBar actionBar = getSupportActionBar();
2017-12-07 15:45:20 +00:00
if (actionBar != null) {
actionBar.setHomeButtonEnabled(this.accountList.size() > 0);
actionBar.setDisplayHomeAsUpEnabled(this.accountList.size() > 0);
}
mAccountAdapter.notifyDataSetChanged();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage_accounts);
2017-12-07 15:45:20 +00:00
accountListView = (ListView) findViewById(R.id.account_list);
this.mAccountAdapter = new AccountAdapter(this, accountList, false);
accountListView.setAdapter(this.mAccountAdapter);
accountListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long arg3) {
final Account account = accountList.get(position);
final String body = getIntent().getStringExtra(EXTRA_BODY);
try {
2018-03-05 17:30:40 +00:00
final Jid contact = Jid.of(getIntent().getStringExtra(EXTRA_CONTACT));
2017-12-07 15:45:20 +00:00
final Conversation conversation = xmppConnectionService.findOrCreateConversation(
account, contact, false, false);
switchToConversation(conversation, body, false);
2018-03-05 17:30:40 +00:00
} catch (IllegalArgumentException e) {
2017-12-07 15:45:20 +00:00
// ignore error
}
finish();
}
});
}
@Override
protected void onStart() {
super.onStart();
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
}
}
@Override
void onBackendConnected() {
final int numAccounts = xmppConnectionService.getAccounts().size();
if (numAccounts == 1) {
final String body = getIntent().getStringExtra(EXTRA_BODY);
final Account account = xmppConnectionService.getAccounts().get(0);
try {
2018-03-05 17:30:40 +00:00
final Jid contact = Jid.of(getIntent().getStringExtra(EXTRA_CONTACT));
2017-12-07 15:45:20 +00:00
final Conversation conversation = xmppConnectionService.findOrCreateConversation(
account, contact, false, false);
switchToConversation(conversation, body, false);
2018-03-05 17:30:40 +00:00
} catch (IllegalArgumentException e) {
2017-12-07 15:45:20 +00:00
// ignore error
}
finish();
} else {
refreshUiReal();
}
}
}