code cleanup / reformat in ShareViaAccount

This commit is contained in:
Daniel Gultsch 2018-10-06 12:48:39 +02:00
parent b27fa6d206
commit 7aa8aba5c0
2 changed files with 70 additions and 75 deletions

View file

@ -278,8 +278,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
if (mAccount != null if (mAccount != null
&& mAccount.getStatus() != Account.State.ONLINE && mAccount.getStatus() != Account.State.ONLINE
&& mFetchingAvatar) { && mFetchingAvatar) {
startActivity(new Intent(getApplicationContext(), //TODO: maybe better redirect to StartConversationActivity
ManageAccountActivity.class)); startActivity(new Intent(this, ManageAccountActivity.class));
finish(); finish();
} else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) { } else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) {
if (!mFetchingAvatar) { if (!mFetchingAvatar) {

View file

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