mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Move link input into fragment
This commit is contained in:
@@ -16,6 +16,7 @@ import org.briarproject.briar.android.blog.RssFeedImportActivity;
|
||||
import org.briarproject.briar.android.blog.RssFeedManageActivity;
|
||||
import org.briarproject.briar.android.blog.WriteBlogPostActivity;
|
||||
import org.briarproject.briar.android.contact.ContactLinkInputActivity;
|
||||
import org.briarproject.briar.android.contact.ContactLinkInputFragment;
|
||||
import org.briarproject.briar.android.contact.ContactLinkOutputActivity;
|
||||
import org.briarproject.briar.android.contact.ContactLinkOutputFragment;
|
||||
import org.briarproject.briar.android.contact.ContactListFragment;
|
||||
@@ -177,6 +178,7 @@ public interface ActivityComponent {
|
||||
void inject(PendingRequestsActivity activity);
|
||||
void inject(ContactLinkOutputFragment activity);
|
||||
void inject(ContactQrCodeOutputFragment activity);
|
||||
void inject(ContactLinkInputFragment activity);
|
||||
|
||||
// Fragments
|
||||
void inject(AuthorNameFragment fragment);
|
||||
|
||||
@@ -2,17 +2,11 @@ package org.briarproject.briar.android.contact;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog.Builder;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||
@@ -20,7 +14,7 @@ import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -29,7 +23,6 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.app.AlarmManager.ELAPSED_REALTIME;
|
||||
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
|
||||
import static android.content.Intent.ACTION_SEND;
|
||||
import static android.content.Intent.ACTION_VIEW;
|
||||
import static android.content.Intent.EXTRA_TEXT;
|
||||
@@ -39,8 +32,8 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
|
||||
|
||||
public class ContactLinkInputActivity extends BriarActivity
|
||||
implements TextWatcher {
|
||||
public class ContactLinkInputActivity extends BriarActivity implements
|
||||
BaseFragmentListener {
|
||||
|
||||
@Inject
|
||||
LifecycleManager lifecycleManager;
|
||||
@@ -49,12 +42,6 @@ public class ContactLinkInputActivity extends BriarActivity
|
||||
@Inject
|
||||
Clock clock;
|
||||
|
||||
private ClipboardManager clipboard;
|
||||
private EditText linkInput;
|
||||
private Button pasteButton;
|
||||
private EditText contactNameInput;
|
||||
private Button addButton;
|
||||
|
||||
@Override
|
||||
public void injectActivity(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
@@ -63,72 +50,38 @@ public class ContactLinkInputActivity extends BriarActivity
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle state) {
|
||||
super.onCreate(state);
|
||||
setContentView(R.layout.activity_contact_link_input);
|
||||
setContentView(R.layout.activity_fragment_container);
|
||||
|
||||
ActionBar ab = getSupportActionBar();
|
||||
if (ab != null) {
|
||||
ab.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
clipboard = (ClipboardManager) requireNonNull(
|
||||
getSystemService(CLIPBOARD_SERVICE));
|
||||
|
||||
linkInput = findViewById(R.id.linkInput);
|
||||
linkInput.addTextChangedListener(this);
|
||||
|
||||
pasteButton = findViewById(R.id.pasteButton);
|
||||
pasteButton.setOnClickListener(v -> linkInput
|
||||
.setText(clipboard.getPrimaryClip().getItemAt(0).getText()));
|
||||
|
||||
contactNameInput = findViewById(R.id.contactNameInput);
|
||||
contactNameInput.addTextChangedListener(this);
|
||||
|
||||
addButton = findViewById(R.id.addButton);
|
||||
addButton.setOnClickListener(v -> onAddButtonClicked());
|
||||
|
||||
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) linkInput.setText(text);
|
||||
if (text != null) {
|
||||
showInitialFragment(
|
||||
ContactLinkInputFragment.newInstance(text));
|
||||
return;
|
||||
}
|
||||
String uri = i.getDataString();
|
||||
if (uri != null) linkInput.setText(uri);
|
||||
if (uri != null) {
|
||||
showInitialFragment(
|
||||
ContactLinkInputFragment.newInstance(uri));
|
||||
return;
|
||||
}
|
||||
} else if ("addContact".equals(action)) {
|
||||
removeFakeRequest(i.getStringExtra("name"),
|
||||
i.getLongExtra("timestamp", 0));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (hasLinkInClipboard()) pasteButton.setEnabled(true);
|
||||
else pasteButton.setEnabled(false);
|
||||
}
|
||||
|
||||
private boolean hasLinkInClipboard() {
|
||||
return clipboard.hasPrimaryClip() &&
|
||||
clipboard.getPrimaryClip().getDescription()
|
||||
.hasMimeType(MIMETYPE_TEXT_PLAIN) &&
|
||||
clipboard.getPrimaryClip().getItemCount() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before,
|
||||
int count) {
|
||||
updateAddButtonState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (state == null) {
|
||||
showInitialFragment(ContactLinkInputFragment.newInstance(null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,36 +95,7 @@ public class ContactLinkInputActivity extends BriarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBriarLink(CharSequence s) {
|
||||
String link = s.toString().trim();
|
||||
return link.matches("^(briar://)?[A-Z2-7]{64}$");
|
||||
}
|
||||
|
||||
private void updateAddButtonState() {
|
||||
addButton.setEnabled(isBriarLink(linkInput.getText()) &&
|
||||
contactNameInput.getText().length() > 0);
|
||||
}
|
||||
|
||||
private void onAddButtonClicked() {
|
||||
addFakeRequest();
|
||||
|
||||
Builder builder = new Builder(this, R.style.BriarDialogTheme_Neutral);
|
||||
builder.setMessage(getString(R.string.add_contact_link_question));
|
||||
builder.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
startActivity(new Intent(ContactLinkInputActivity.this,
|
||||
NavDrawerActivity.class));
|
||||
finish();
|
||||
});
|
||||
builder.setNegativeButton(R.string.no, (dialog, which) -> {
|
||||
startActivity(new Intent(ContactLinkInputActivity.this,
|
||||
ContactLinkOutputActivity.class));
|
||||
finish();
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void addFakeRequest() {
|
||||
String name = contactNameInput.getText().toString();
|
||||
void addFakeRequest(String name) {
|
||||
long timestamp = clock.currentTimeMillis();
|
||||
try {
|
||||
messagingManager.addNewPendingContact(name, timestamp);
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package org.briarproject.briar.android.contact;
|
||||
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@NotNullByDefault
|
||||
public class ContactLinkInputFragment extends BaseFragment
|
||||
implements TextWatcher {
|
||||
|
||||
private ClipboardManager clipboard;
|
||||
private EditText linkInput;
|
||||
private Button pasteButton;
|
||||
private EditText contactNameInput;
|
||||
private Button addButton;
|
||||
|
||||
static BaseFragment newInstance(@Nullable String link) {
|
||||
BaseFragment f = new ContactLinkInputFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("link", link);
|
||||
f.setArguments(bundle);
|
||||
return f;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
getActivity().setTitle(R.string.open_link_title);
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_contact_link_input,
|
||||
container, false);
|
||||
|
||||
clipboard = (ClipboardManager) requireNonNull(
|
||||
getContext().getSystemService(CLIPBOARD_SERVICE));
|
||||
|
||||
linkInput = v.findViewById(R.id.linkInput);
|
||||
linkInput.addTextChangedListener(this);
|
||||
|
||||
pasteButton = v.findViewById(R.id.pasteButton);
|
||||
pasteButton.setOnClickListener(view -> linkInput
|
||||
.setText(clipboard.getPrimaryClip().getItemAt(0).getText()));
|
||||
|
||||
contactNameInput = v.findViewById(R.id.contactNameInput);
|
||||
contactNameInput.addTextChangedListener(this);
|
||||
|
||||
addButton = v.findViewById(R.id.addButton);
|
||||
addButton.setOnClickListener(view -> onAddButtonClicked());
|
||||
|
||||
linkInput.setText(getArguments().getString("link"));
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public static final String TAG = ContactLinkInputFragment.class.getName();
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (hasLinkInClipboard()) pasteButton.setEnabled(true);
|
||||
else pasteButton.setEnabled(false);
|
||||
}
|
||||
|
||||
private boolean hasLinkInClipboard() {
|
||||
return clipboard.hasPrimaryClip() &&
|
||||
clipboard.getPrimaryClip().getDescription()
|
||||
.hasMimeType(MIMETYPE_TEXT_PLAIN) &&
|
||||
clipboard.getPrimaryClip().getItemCount() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before,
|
||||
int count) {
|
||||
updateAddButtonState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
|
||||
private boolean isBriarLink(CharSequence s) {
|
||||
String link = s.toString().trim();
|
||||
return link.matches("^(briar://)?[A-Z2-7]{64}$");
|
||||
}
|
||||
|
||||
private void updateAddButtonState() {
|
||||
addButton.setEnabled(isBriarLink(linkInput.getText()) &&
|
||||
contactNameInput.getText().length() > 0);
|
||||
}
|
||||
|
||||
private void onAddButtonClicked() {
|
||||
if (getActivity() == null || getContext() == null) return;;
|
||||
|
||||
((ContactLinkInputActivity) getActivity())
|
||||
.addFakeRequest(contactNameInput.getText().toString());
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext(), R.style.BriarDialogTheme_Neutral);
|
||||
builder.setMessage(getString(R.string.add_contact_link_question));
|
||||
builder.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
startActivity(new Intent(getContext(), NavDrawerActivity.class));
|
||||
finish();
|
||||
});
|
||||
builder.setNegativeButton(R.string.no, (dialog, which) -> {
|
||||
startActivity(
|
||||
new Intent(getContext(), ContactLinkOutputActivity.class));
|
||||
finish();
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.android.contact;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
@@ -42,10 +41,10 @@ public class ContactLinkOutputActivity extends BriarActivity implements
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.contact_output_actions, menu);
|
||||
menu.findItem(R.id.action_switch)
|
||||
.setTitle(showQrCode ? R.string.show_link : R.string.show_code);
|
||||
// MenuInflater inflater = getMenuInflater();
|
||||
// inflater.inflate(R.menu.contact_output_actions, menu);
|
||||
// menu.findItem(R.id.action_switch)
|
||||
// .setTitle(showQrCode ? R.string.show_link : R.string.show_code);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
||||
9
briar-android/src/main/res/drawable/ic_add_nearby.xml
Normal file
9
briar-android/src/main/res/drawable/ic_add_nearby.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M12,11c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,13c0,-3.31 -2.69,-6 -6,-6s-6,2.69 -6,6c0,2.22 1.21,4.15 3,5.19l1,-1.74c-1.19,-0.7 -2,-1.97 -2,-3.45 0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,1.48 -0.81,2.75 -2,3.45l1,1.74c1.79,-1.04 3,-2.97 3,-5.19zM12,3C6.48,3 2,7.48 2,13c0,3.7 2.01,6.92 4.99,8.65l1,-1.73C5.61,18.53 4,15.96 4,13c0,-4.42 3.58,-8 8,-8s8,3.58 8,8c0,2.96 -1.61,5.53 -4,6.92l1,1.73c2.99,-1.73 5,-4.95 5,-8.65 0,-5.52 -4.48,-10 -10,-10z"/>
|
||||
</vector>
|
||||
5
briar-android/src/main/res/drawable/ic_person_add.xml
Normal file
5
briar-android/src/main/res/drawable/ic_person_add.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
||||
</vector>
|
||||
9
briar-android/src/main/res/drawable/ic_qr_code_scan.xml
Normal file
9
briar-android/src/main/res/drawable/ic_qr_code_scan.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M4,4H10V10H4V4M20,4V10H14V4H20M14,15H16V13H14V11H16V13H18V11H20V13H18V15H20V18H18V20H16V18H13V20H11V16H14V15M16,15V18H18V15H16M4,20V14H10V20H4M6,6V8H8V6H6M16,6V8H18V6H16M6,16V18H8V16H6M4,11H6V13H4V11M9,11H13V15H11V13H9V11M11,6H13V10H11V6M2,2V6H0V2A2,2 0 0,1 2,0H6V2H2M22,0A2,2 0 0,1 24,2V6H22V2H18V0H22M2,18V22H6V24H2A2,2 0 0,1 0,22V18H2M22,22V18H24V22A2,2 0 0,1 22,24H18V22H22Z"/>
|
||||
</vector>
|
||||
@@ -21,7 +21,8 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
app:sdMainFabClosedSrc="@drawable/ic_add_white"
|
||||
app:sdMainFabClosedSrc="@drawable/ic_person_add"
|
||||
app:sdMainFabOpenedSrc="@drawable/ic_close"
|
||||
app:sdOverlayLayout="@id/overlay"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
@@ -5,22 +5,28 @@
|
||||
|
||||
<item
|
||||
android:id="@+id/action_add_contact"
|
||||
android:icon="@drawable/ic_add_white"
|
||||
android:icon="@drawable/ic_add_nearby"
|
||||
android:title="@string/add_contact_nearby_title"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<!--
|
||||
<item
|
||||
android:id="@+id/action_open_link"
|
||||
android:icon="@drawable/ic_link"
|
||||
android:title="@string/open_link_title"
|
||||
app:showAsAction="never"/>
|
||||
<!--
|
||||
|
||||
<item
|
||||
android:id="@+id/action_send_link"
|
||||
android:icon="@drawable/ic_link"
|
||||
android:title="@string/send_link_title"
|
||||
app:showAsAction="never"/>
|
||||
-->
|
||||
-->
|
||||
<item
|
||||
android:id="@+id/action_open_link"
|
||||
android:icon="@drawable/ic_qr_code_scan"
|
||||
android:title="@string/open_code_title"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_send_link"
|
||||
android:icon="@drawable/ic_qr_code"
|
||||
|
||||
@@ -152,6 +152,7 @@
|
||||
|
||||
<string name="add_contact_nearby_title">Add Contact Nearby</string>
|
||||
<string name="open_link_title">Open Link</string>
|
||||
<string name="open_code_title">Open QR Code</string>
|
||||
<string name="send_link_title">Send My Link</string>
|
||||
<string name="send_code_title">Send My QR Code</string>
|
||||
<string name="show_link">Show Link</string>
|
||||
|
||||
Reference in New Issue
Block a user