add scan qr button to welcome screen

closes #2920
This commit is contained in:
Daniel Gultsch 2020-01-11 14:06:33 +01:00
parent 8e0c02f3cc
commit f57a28ca32
3 changed files with 36 additions and 18 deletions

View File

@ -1,7 +1,9 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.Manifest;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -12,6 +14,7 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast; import android.widget.Toast;
import java.util.Arrays;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
@ -32,8 +35,15 @@ public class WelcomeActivity extends XmppActivity {
private XmppUri inviteUri; private XmppUri inviteUri;
public static void launch(AppCompatActivity activity) {
Intent intent = new Intent(activity, WelcomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.startActivity(intent);
activity.overridePendingTransition(0, 0);
}
public void onInstallReferrerDiscovered(final String referrer) { public void onInstallReferrerDiscovered(final String referrer) {
Log.d(Config.LOGTAG,"welcome activity: on install referrer discovered "+referrer); Log.d(Config.LOGTAG, "welcome activity: on install referrer discovered " + referrer);
if (referrer != null) { if (referrer != null) {
final XmppUri xmppUri = new XmppUri(referrer); final XmppUri xmppUri = new XmppUri(referrer);
runOnUiThread(() -> processXmppUri(xmppUri)); runOnUiThread(() -> processXmppUri(xmppUri));
@ -110,7 +120,7 @@ public class WelcomeActivity extends XmppActivity {
startActivity(intent); startActivity(intent);
}); });
binding.useExisting.setOnClickListener(v -> { binding.useExisting.setOnClickListener(v -> {
List<Account> accounts = xmppConnectionService.getAccounts(); final List<Account> accounts = xmppConnectionService.getAccounts();
Intent intent = new Intent(WelcomeActivity.this, EditAccountActivity.class); Intent intent = new Intent(WelcomeActivity.this, EditAccountActivity.class);
intent.putExtra(EditAccountActivity.EXTRA_FORCE_REGISTER, false); intent.putExtra(EditAccountActivity.EXTRA_FORCE_REGISTER, false);
if (accounts.size() == 1) { if (accounts.size() == 1) {
@ -128,22 +138,29 @@ public class WelcomeActivity extends XmppActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.welcome_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); return super.onCreateOptionsMenu(menu);
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_import_backup) { switch (item.getItemId()) {
if (hasStoragePermission(REQUEST_IMPORT_BACKUP)) { case R.id.action_import_backup:
startActivity(new Intent(this, ImportBackupActivity.class)); if (hasStoragePermission(REQUEST_IMPORT_BACKUP)) {
} startActivity(new Intent(this, ImportBackupActivity.class));
return true; }
break;
case R.id.action_scan_qr_code:
UriHandlerActivity.scan(this);
break;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults);
if (grantResults.length > 0) { if (grantResults.length > 0) {
if (allGranted(grantResults)) { if (allGranted(grantResults)) {
switch (requestCode) { switch (requestCode) {
@ -151,7 +168,7 @@ public class WelcomeActivity extends XmppActivity {
startActivity(new Intent(this, ImportBackupActivity.class)); startActivity(new Intent(this, ImportBackupActivity.class));
break; 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(); Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
} }
} }
@ -168,16 +185,9 @@ public class WelcomeActivity extends XmppActivity {
final String invite = from.getStringExtra(StartConversationActivity.EXTRA_INVITE_URI); final String invite = from.getStringExtra(StartConversationActivity.EXTRA_INVITE_URI);
to.putExtra(StartConversationActivity.EXTRA_INVITE_URI, invite); to.putExtra(StartConversationActivity.EXTRA_INVITE_URI, invite);
} else if (this.inviteUri != null) { } else if (this.inviteUri != null) {
Log.d(Config.LOGTAG,"injecting referrer uri into on-boarding flow"); Log.d(Config.LOGTAG, "injecting referrer uri into on-boarding flow");
to.putExtra(StartConversationActivity.EXTRA_INVITE_URI, this.inviteUri.toString()); to.putExtra(StartConversationActivity.EXTRA_INVITE_URI, this.inviteUri.toString());
} }
} }
public static void launch(AppCompatActivity activity) {
Intent intent = new Intent(activity, WelcomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.startActivity(intent);
activity.overridePendingTransition(0, 0);
}
} }

View File

@ -1,6 +1,14 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_scan_qr_code"
android:title="@string/scan_qr_code"
app:showAsAction="ifRoom"
android:orderInCategory="10"
android:visible="@bool/show_qr_code_scan"
android:icon="?attr/icon_scan_qr_code"/>
<item <item
android:id="@+id/action_import_backup" android:id="@+id/action_import_backup"
app:showAsAction="never" app:showAsAction="never"

View File

@ -274,7 +274,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults); UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults);
if (grantResults.length > 0) { if (grantResults.length > 0) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {