Commit 19bc73ac authored by Torsten Grote's avatar Torsten Grote

[android] show Toast when user shares own handshake link

This also limits the AddContactActivity to run within one single task
parent d17331b5
Pipeline #3260 passed with stage
in 10 minutes and 54 seconds
......@@ -427,13 +427,16 @@
<activity
android:name=".android.contact.add.remote.AddContactActivity"
android:theme="@style/BriarTheme"
android:label="@string/add_contact_remotely_title_case"
android:launchMode="singleTask"
android:theme="@style/BriarTheme"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="briar"/>
</intent-filter>
<intent-filter>
......
......@@ -30,6 +30,7 @@ public class AddContactActivity extends BriarActivity implements
@Inject
ViewModelProvider.Factory viewModelFactory;
private AddContactViewModel viewModel;
@Override
public void injectActivity(ActivityComponent component) {
......@@ -46,8 +47,7 @@ public class AddContactActivity extends BriarActivity implements
ab.setDisplayHomeAsUpEnabled(true);
}
AddContactViewModel viewModel =
ViewModelProviders.of(this, viewModelFactory)
viewModel = ViewModelProviders.of(this, viewModelFactory)
.get(AddContactViewModel.class);
viewModel.getRemoteLinkEntered().observe(this, entered -> {
if (entered != null && entered) {
......@@ -58,32 +58,38 @@ public class AddContactActivity extends BriarActivity implements
Intent i = getIntent();
if (i != null) {
onNewIntent(i);
setIntent(null); // don't keep the intent for configuration changes
}
if (state == null) {
showInitialFragment(new LinkExchangeFragment());
}
}
@Override
protected void onNewIntent(Intent i) {
super.onNewIntent(i);
String action = i.getAction();
if (ACTION_SEND.equals(action) || ACTION_VIEW.equals(action)) {
String text = i.getStringExtra(EXTRA_TEXT);
if (text != null) {
if (viewModel.isValidRemoteContactLink(text)) {
viewModel.setRemoteHandshakeLink(text);
} else {
Toast.makeText(this, R.string.invalid_link, LENGTH_LONG)
.show();
String uri = i.getDataString();
if (text != null) handleIncomingLink(text);
else if (uri != null) handleIncomingLink(uri);
}
}
String uri = i.getDataString();
if (uri != null) {
if (viewModel.isValidRemoteContactLink(uri)) {
viewModel.setRemoteHandshakeLink(uri);
private void handleIncomingLink(String link) {
if (link.equals(viewModel.getHandshakeLink().getValue())) {
Toast.makeText(this, R.string.intent_own_link, LENGTH_LONG)
.show();
} else if (viewModel.isValidRemoteContactLink(link)) {
viewModel.setRemoteHandshakeLink(link);
} else {
Toast.makeText(this, R.string.invalid_link, LENGTH_LONG)
.show();
}
}
}
}
if (state == null) {
showInitialFragment(new LinkExchangeFragment());
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
......
......@@ -200,6 +200,7 @@
<string name="own_link_error">Enter your contact\'s link, not your own</string>
<string name="nickname_missing">Please enter a nickname</string>
<string name="invalid_link">Invalid link</string>
<string name="intent_own_link">You opened your own link. Use the one of the contact you want to add!</string>
<string name="missing_link">Please enter a link</string>
<!-- This is a numeral indicating the first step in a series of screens -->
<string name="step_1">1</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment