mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
[android] show Toast when user shares own handshake link
This also limits the AddContactActivity to run within one single task
This commit is contained in:
@@ -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,9 +47,8 @@ public class AddContactActivity extends BriarActivity implements
|
||||
ab.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
AddContactViewModel viewModel =
|
||||
ViewModelProviders.of(this, viewModelFactory)
|
||||
.get(AddContactViewModel.class);
|
||||
viewModel = ViewModelProviders.of(this, viewModelFactory)
|
||||
.get(AddContactViewModel.class);
|
||||
viewModel.getRemoteLinkEntered().observe(this, entered -> {
|
||||
if (entered != null && entered) {
|
||||
NicknameFragment f = new NicknameFragment();
|
||||
@@ -58,33 +58,39 @@ public class AddContactActivity extends BriarActivity implements
|
||||
|
||||
Intent i = getIntent();
|
||||
if (i != null) {
|
||||
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 (uri != null) {
|
||||
if (viewModel.isValidRemoteContactLink(uri)) {
|
||||
viewModel.setRemoteHandshakeLink(uri);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.invalid_link, LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
String uri = i.getDataString();
|
||||
if (text != null) handleIncomingLink(text);
|
||||
else if (uri != null) handleIncomingLink(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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user