From 52ff46043c9ad94fe55ddd0b6db323ec951456f2 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 25 Jan 2019 23:16:28 +0100 Subject: provide Set as Profile intent --- .../ui/ChooseAccountForProfilePictureActivity.java | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/main/java/de/pixart/messenger/ui/ChooseAccountForProfilePictureActivity.java (limited to 'src/main/java/de/pixart/messenger/ui/ChooseAccountForProfilePictureActivity.java') diff --git a/src/main/java/de/pixart/messenger/ui/ChooseAccountForProfilePictureActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseAccountForProfilePictureActivity.java new file mode 100644 index 000000000..2d109809e --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/ChooseAccountForProfilePictureActivity.java @@ -0,0 +1,82 @@ +package de.pixart.messenger.ui; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.widget.ListView; + +import java.util.ArrayList; +import java.util.List; + +import de.pixart.messenger.R; +import de.pixart.messenger.entities.Account; +import de.pixart.messenger.ui.adapter.AccountAdapter; + +public class ChooseAccountForProfilePictureActivity extends XmppActivity { + + protected final List accountList = new ArrayList<>(); + protected ListView accountListView; + protected AccountAdapter mAccountAdapter; + + @Override + protected void refreshUiReal() { + loadEnabledAccounts(); + mAccountAdapter.notifyDataSetChanged(); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_manage_accounts); + setSupportActionBar(findViewById(R.id.toolbar)); + configureActionBar(getSupportActionBar(), false); + 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); + goToProfilePictureActivity(account); + }); + } + + @Override + protected void onStart() { + super.onStart(); + final int theme = findTheme(); + if (this.mTheme != theme) { + recreate(); + } + } + + @Override + void onBackendConnected() { + loadEnabledAccounts(); + if (accountList.size() == 1) { + goToProfilePictureActivity(accountList.get(0)); + return; + } + mAccountAdapter.notifyDataSetChanged(); + } + + private void loadEnabledAccounts() { + accountList.clear(); + for (Account account : xmppConnectionService.getAccounts()) { + if (account.isEnabled()) { + accountList.add(account); + } + } + } + + private void goToProfilePictureActivity(Account account) { + final Intent startIntent = getIntent(); + final Uri uri = startIntent == null ? null : startIntent.getData(); + if (uri != null) { + Intent intent = new Intent(this, PublishProfilePictureActivity.class); + intent.putExtra(EXTRA_ACCOUNT, account.getJid().asBareJid().toString()); + intent.setData(uri); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivity(intent); + } + finish(); + } +} \ No newline at end of file -- cgit v1.2.3