From 7aa8aba5c0f89d1b1275b6bd0b2ee84f440a013c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 6 Oct 2018 12:48:39 +0200 Subject: [PATCH] code cleanup / reformat in ShareViaAccount --- .../conversations/ui/EditAccountActivity.java | 4 +- .../ui/ShareViaAccountActivity.java | 141 +++++++++--------- 2 files changed, 70 insertions(+), 75 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index c1ed2e99f..46bfaab44 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -278,8 +278,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat if (mAccount != null && mAccount.getStatus() != Account.State.ONLINE && mFetchingAvatar) { - startActivity(new Intent(getApplicationContext(), - ManageAccountActivity.class)); + //TODO: maybe better redirect to StartConversationActivity + startActivity(new Intent(this, ManageAccountActivity.class)); finish(); } else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) { if (!mFetchingAvatar) { diff --git a/src/main/java/eu/siacs/conversations/ui/ShareViaAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareViaAccountActivity.java index 1035c766e..419cda20e 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareViaAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareViaAccountActivity.java @@ -17,88 +17,83 @@ import eu.siacs.conversations.ui.adapter.AccountAdapter; import rocks.xmpp.addr.Jid; public class ShareViaAccountActivity extends XmppActivity { - public static final String EXTRA_CONTACT = "contact"; - public static final String EXTRA_BODY = "body"; + public static final String EXTRA_CONTACT = "contact"; + public static final String EXTRA_BODY = "body"; - protected final List accountList = new ArrayList<>(); - protected ListView accountListView; - protected AccountAdapter mAccountAdapter; + protected final List 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(); - if (actionBar != null) { - actionBar.setHomeButtonEnabled(this.accountList.size() > 0); - actionBar.setDisplayHomeAsUpEnabled(this.accountList.size() > 0); - } - mAccountAdapter.notifyDataSetChanged(); - } + @Override + protected void refreshUiReal() { + synchronized (this.accountList) { + accountList.clear(); + accountList.addAll(xmppConnectionService.getAccounts()); + } + ActionBar actionBar = getSupportActionBar(); + 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); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - setContentView(R.layout.activity_manage_accounts); - setSupportActionBar(findViewById(R.id.toolbar)); - configureActionBar(getSupportActionBar()); - accountListView = (ListView) findViewById(R.id.account_list); - this.mAccountAdapter = new AccountAdapter(this, accountList, false); - accountListView.setAdapter(this.mAccountAdapter); - accountListView.setOnItemClickListener(new OnItemClickListener() { + setContentView(R.layout.activity_manage_accounts); + setSupportActionBar(findViewById(R.id.toolbar)); + configureActionBar(getSupportActionBar()); + accountListView = findViewById(R.id.account_list); + this.mAccountAdapter = new AccountAdapter(this, accountList, false); + accountListView.setAdapter(this.mAccountAdapter); + accountListView.setOnItemClickListener((arg0, view, position, arg3) -> { + final Account account = accountList.get(position); + final String body = getIntent().getStringExtra(EXTRA_BODY); - @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 { + 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 + } - try { - 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(); + }); + } - finish(); - } - }); - } + @Override + protected void onStart() { + super.onStart(); + final int theme = findTheme(); + if (this.mTheme != theme) { + recreate(); + } + } - @Override - protected void onStart() { - super.onStart(); - final int theme = findTheme(); - if (this.mTheme != theme) { - recreate(); - } - } + @Override + void onBackendConnected() { + final int numAccounts = xmppConnectionService.getAccounts().size(); - @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); - if (numAccounts == 1) { - final String body = getIntent().getStringExtra(EXTRA_BODY); - final Account account = xmppConnectionService.getAccounts().get(0); + try { + 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 + } - try { - 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(); - } else { - refreshUiReal(); - } - } + finish(); + } else { + refreshUiReal(); + } + } }