From 67f244555c24b55bde4be9ad93c42388f69fd821 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 24 Jan 2020 20:19:40 +0100 Subject: add scan qr button to welcome screen --- .../de/pixart/messenger/ui/WelcomeActivity.java | 40 +++++++++++++++++++--- src/main/res/menu/welcome_menu.xml | 11 ++++++ 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 src/main/res/menu/welcome_menu.xml (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java index d396c8723..0e1b7f604 100644 --- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java +++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java @@ -1,9 +1,13 @@ package de.pixart.messenger.ui; +import android.Manifest; import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; import android.os.Bundle; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.Toast; @@ -12,9 +16,13 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; +import java.util.Arrays; +import java.util.List; + import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.databinding.WelcomeBinding; +import de.pixart.messenger.entities.Account; import de.pixart.messenger.ui.util.IntroHelper; import de.pixart.messenger.utils.InstallReferrerUtils; import de.pixart.messenger.utils.SignupUtils; @@ -112,8 +120,6 @@ public class WelcomeActivity extends XmppActivity { binding.importText.setVisibility(View.VISIBLE); } binding.importDatabase.setOnClickListener(v -> startActivity(new Intent(this, ImportBackupActivity.class))); - - binding.createAccount.setOnClickListener(v -> { final Intent intent = new Intent(WelcomeActivity.this, MagicCreateActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); @@ -124,8 +130,14 @@ public class WelcomeActivity extends XmppActivity { binding.createAccount.setVisibility(View.GONE); } binding.useExistingAccount.setOnClickListener(v -> { + final List accounts = xmppConnectionService.getAccounts(); Intent intent = new Intent(WelcomeActivity.this, EditAccountActivity.class); - intent.putExtra("init", true); + if (accounts.size() == 1) { + intent.putExtra("jid", accounts.get(0).getJid().asBareJid().toString()); + intent.putExtra("init", true); + } else if (accounts.size() >= 1) { + intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class); + } intent.putExtra("existing", true); addInviteUri(intent); startActivity(intent); @@ -133,7 +145,6 @@ public class WelcomeActivity extends XmppActivity { finish(); overridePendingTransition(R.animator.fade_in, R.animator.fade_out); }); - } public void addInviteUri(Intent to) { @@ -154,8 +165,27 @@ public class WelcomeActivity extends XmppActivity { activity.overridePendingTransition(0, 0); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.welcome_menu, menu); + final MenuItem scan = menu.findItem(R.id.action_scan_qr_code); + scan.setVisible(getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_scan_qr_code: + UriHandlerActivity.scan(this); + break; + } + return super.onOptionsItemSelected(item); + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults); if (grantResults.length > 0) { if (allGranted(grantResults)) { switch (requestCode) { @@ -163,7 +193,7 @@ public class WelcomeActivity extends XmppActivity { startActivity(new Intent(this, ImportBackupActivity.class)); break; } - } else { + } else if (Arrays.asList(permissions).contains(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); } } diff --git a/src/main/res/menu/welcome_menu.xml b/src/main/res/menu/welcome_menu.xml new file mode 100644 index 000000000..825af5445 --- /dev/null +++ b/src/main/res/menu/welcome_menu.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file -- cgit v1.2.3