Only allow new introductions in START state

When the user attempts an introduction, instead of the introduction
message input field, an explanatory text will be shown and the
introduction can not be made until the last one has been finished.
This commit is contained in:
Torsten Grote
2018-04-25 12:05:15 -03:00
parent 94a6137a42
commit b291fcd2cd
6 changed files with 88 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ package org.briarproject.briar.android.introduction;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.MenuItem;
@@ -32,6 +33,7 @@ import im.delight.android.identicons.IdenticonDrawable;
import static android.app.Activity.RESULT_OK;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.WARNING;
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_REQUEST_MESSAGE_LENGTH;
@@ -124,14 +126,15 @@ public class IntroductionMessageFragment extends BaseFragment
new ContactId(contactId1));
Contact c2 = contactManager.getContact(
new ContactId(contactId2));
setUpViews(c1, c2);
boolean possible = introductionManager.canIntroduce(c1, c2);
setUpViews(c1, c2, possible);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
}
});
}
private void setUpViews(Contact c1, Contact c2) {
private void setUpViews(Contact c1, Contact c2, boolean possible) {
introductionActivity.runOnUiThreadUnlessDestroyed(() -> {
contact1 = c1;
contact2 = c2;
@@ -146,13 +149,22 @@ public class IntroductionMessageFragment extends BaseFragment
ui.contactName1.setText(c1.getAuthor().getName());
ui.contactName2.setText(c2.getAuthor().getName());
// set button action
ui.message.setListener(IntroductionMessageFragment.this);
// hide progress bar and show views
// hide progress bar
ui.progressBar.setVisibility(GONE);
ui.message.setSendButtonEnabled(true);
ui.message.showSoftKeyboard();
if (possible) {
// set button action
ui.message.setListener(IntroductionMessageFragment.this);
// show views
ui.notPossible.setVisibility(GONE);
ui.message.setVisibility(VISIBLE);
ui.message.setSendButtonEnabled(true);
ui.message.showSoftKeyboard();
} else {
ui.notPossible.setVisibility(VISIBLE);
ui.message.setVisibility(GONE);
}
});
}
@@ -174,7 +186,8 @@ public class IntroductionMessageFragment extends BaseFragment
ui.message.setSendButtonEnabled(false);
String msg = ui.message.getText().toString();
msg = StringUtils.truncateUtf8(msg, MAX_REQUEST_MESSAGE_LENGTH);
if (msg.equals("")) msg = null;
else msg = StringUtils.truncateUtf8(msg, MAX_REQUEST_MESSAGE_LENGTH);
makeIntroduction(contact1, contact2, msg);
// don't wait for the introduction to be made before finishing activity
@@ -183,7 +196,8 @@ public class IntroductionMessageFragment extends BaseFragment
introductionActivity.supportFinishAfterTransition();
}
private void makeIntroduction(Contact c1, Contact c2, String msg) {
private void makeIntroduction(Contact c1, Contact c2,
@Nullable String msg) {
introductionActivity.runOnDbThread(() -> {
// actually make the introduction
try {
@@ -207,6 +221,7 @@ public class IntroductionMessageFragment extends BaseFragment
private final ProgressBar progressBar;
private final CircleImageView avatar1, avatar2;
private final TextView contactName1, contactName2;
private final TextView notPossible;
private final TextInputView message;
private ViewHolder(View v) {
@@ -215,6 +230,7 @@ public class IntroductionMessageFragment extends BaseFragment
avatar2 = v.findViewById(R.id.avatarContact2);
contactName1 = v.findViewById(R.id.nameContact1);
contactName2 = v.findViewById(R.id.nameContact2);
notPossible = v.findViewById(R.id.introductionNotPossibleView);
message = v.findViewById(R.id.introductionMessageView);
}
}

View File

@@ -94,13 +94,25 @@
android:layout_gravity="center"
tools:visibility="gone"/>
<TextView
android:id="@+id/introductionNotPossibleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_activity_horizontal"
android:text="@string/introduction_not_possible"
android:textSize="@dimen/text_size_large"
android:visibility="gone"
tools:visibility="visible"/>
<org.briarproject.briar.android.view.LargeTextInputView
android:id="@+id/introductionMessageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:buttonText="@string/introduction_button"
app:hint="@string/introduction_message_hint"
app:maxLines="5"/>
app:maxLines="5"
tools:visibility="visible"/>
</LinearLayout>
</ScrollView>

View File

@@ -144,6 +144,7 @@
<string name="introduction_onboarding_title">Introduce your contacts</string>
<string name="introduction_onboarding_text">You can introduce your contacts to each other, so they don\'t need to meet in person to connect on Briar.</string>
<string name="introduction_activity_title">Select Contact</string>
<string name="introduction_not_possible">You already have one introduction in progress with these contacts. Please allow for this to finish first. If you or your contacts are rarely online, this can take some time.</string>
<string name="introduction_message_title">Introduce Contacts</string>
<string name="introduction_message_hint">Add a message (optional)</string>
<string name="introduction_button">Make Introduction</string>