mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +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
|
<activity
|
||||||
android:name=".android.contact.add.remote.AddContactActivity"
|
android:name=".android.contact.add.remote.AddContactActivity"
|
||||||
android:theme="@style/BriarTheme"
|
|
||||||
android:label="@string/add_contact_remotely_title_case"
|
android:label="@string/add_contact_remotely_title_case"
|
||||||
|
android:launchMode="singleTask"
|
||||||
|
android:theme="@style/BriarTheme"
|
||||||
android:windowSoftInputMode="stateHidden|adjustResize">
|
android:windowSoftInputMode="stateHidden|adjustResize">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.BROWSABLE" />
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<category android:name="android.intent.category.BROWSABLE"/>
|
||||||
|
|
||||||
<data android:scheme="briar"/>
|
<data android:scheme="briar"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class AddContactActivity extends BriarActivity implements
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
private AddContactViewModel viewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectActivity(ActivityComponent component) {
|
public void injectActivity(ActivityComponent component) {
|
||||||
@@ -46,9 +47,8 @@ public class AddContactActivity extends BriarActivity implements
|
|||||||
ab.setDisplayHomeAsUpEnabled(true);
|
ab.setDisplayHomeAsUpEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddContactViewModel viewModel =
|
viewModel = ViewModelProviders.of(this, viewModelFactory)
|
||||||
ViewModelProviders.of(this, viewModelFactory)
|
.get(AddContactViewModel.class);
|
||||||
.get(AddContactViewModel.class);
|
|
||||||
viewModel.getRemoteLinkEntered().observe(this, entered -> {
|
viewModel.getRemoteLinkEntered().observe(this, entered -> {
|
||||||
if (entered != null && entered) {
|
if (entered != null && entered) {
|
||||||
NicknameFragment f = new NicknameFragment();
|
NicknameFragment f = new NicknameFragment();
|
||||||
@@ -58,33 +58,39 @@ public class AddContactActivity extends BriarActivity implements
|
|||||||
|
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
if (i != null) {
|
if (i != null) {
|
||||||
String action = i.getAction();
|
onNewIntent(i);
|
||||||
if (ACTION_SEND.equals(action) || ACTION_VIEW.equals(action)) {
|
setIntent(null); // don't keep the intent for configuration changes
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
showInitialFragment(new LinkExchangeFragment());
|
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
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
|||||||
@@ -200,6 +200,7 @@
|
|||||||
<string name="own_link_error">Enter your contact\'s link, not your own</string>
|
<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="nickname_missing">Please enter a nickname</string>
|
||||||
<string name="invalid_link">Invalid link</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>
|
<string name="missing_link">Please enter a link</string>
|
||||||
<!-- This is a numeral indicating the first step in a series of screens -->
|
<!-- This is a numeral indicating the first step in a series of screens -->
|
||||||
<string name="step_1">1</string>
|
<string name="step_1">1</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user