Clean up several UX interactions with proxy entry.

fork-5.53.8
Greyson Parrelli 2021-02-03 13:45:40 -05:00
rodzic e798f3f276
commit 64fe78ff9a
8 zmienionych plików z 82 dodań i 16 usunięć

Wyświetl plik

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.keyvalue;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
public final class ProxyValues extends SignalStoreValues {
@ -19,8 +20,11 @@ public final class ProxyValues extends SignalStoreValues {
void onFirstEverAppLaunch() {
}
public void enableProxy(@NonNull SignalProxy proxy) {
if (Util.isEmpty(proxy.getHost())) {
throw new IllegalArgumentException("Empty host!");
}
getStore().beginWrite()
.putBoolean(KEY_PROXY_ENABLED, true)
.putString(KEY_HOST, proxy.getHost())
@ -67,4 +71,9 @@ public final class ProxyValues extends SignalStoreValues {
return null;
}
}
public @Nullable String getProxyHost() {
SignalProxy proxy = getProxy();
return proxy != null ? proxy.getHost() : null;
}
}

Wyświetl plik

@ -20,9 +20,12 @@ import androidx.lifecycle.ViewModelProviders;
import com.dd.CircularProgressButton;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.net.PipeConnectivityListener;
import org.thoughtcrime.securesms.util.SignalProxyUtil;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
@ -54,6 +57,13 @@ public class EditProxyFragment extends Fragment {
this.saveButton = view.findViewById(R.id.edit_proxy_save);
this.shareButton = view.findViewById(R.id.edit_proxy_share);
proxyText.addTextChangedListener(new SimpleTextWatcher() {
@Override
public void onTextChanged(String text) {
onProxyTextChanged(text);
}
});
this.proxyText.setText(Optional.fromNullable(SignalStore.proxy().getProxy()).transform(SignalProxy::getHost).or(""));
this.proxySwitch.setChecked(SignalStore.proxy().isProxyEnabled());
@ -87,12 +97,8 @@ public class EditProxyFragment extends Fragment {
case ALL_ENABLED:
proxyText.setEnabled(true);
proxyText.setAlpha(1);
saveButton.setEnabled(true);
saveButton.setAlpha(1);
shareButton.setEnabled(true);
shareButton.setAlpha(1);
proxyTitle.setAlpha(1);
proxyStatus.setVisibility(View.VISIBLE);
onProxyTextChanged(proxyText.getText().toString());
break;
case ALL_DISABLED:
proxyText.setEnabled(false);
@ -137,12 +143,16 @@ public class EditProxyFragment extends Fragment {
new AlertDialog.Builder(requireContext())
.setTitle(R.string.preferences_success)
.setMessage(R.string.preferences_you_are_connected_to_the_proxy)
.setPositiveButton(android.R.string.ok, (d, i) -> d.dismiss())
.setPositiveButton(android.R.string.ok, (d, i) -> {
d.dismiss();
requireActivity().onBackPressed();
})
.show();
break;
case PROXY_FAILURE:
proxyStatus.setVisibility(View.INVISIBLE);
proxyText.setText(Optional.fromNullable(SignalStore.proxy().getProxy()).transform(SignalProxy::getHost).or(""));
ViewUtil.focusAndMoveCursorToEndAndOpenKeyboard(proxyText);
new AlertDialog.Builder(requireContext())
.setTitle(R.string.preferences_failed_to_connect)
.setMessage(R.string.preferences_couldnt_connect_to_the_proxy)
@ -172,10 +182,32 @@ public class EditProxyFragment extends Fragment {
}
private void onShareClicked() {
String host = proxyText.getText().toString();
String link = SignalProxyUtil.generateProxyUrl(proxyText.getText().toString());
ShareCompat.IntentBuilder.from(requireActivity())
.setText(host)
.setText(link)
.setType("text/plain")
.startChooser();
}
private void onProxyTextChanged(@NonNull String text) {
if (Util.isEmpty(text)) {
saveButton.setEnabled(false);
saveButton.setAlpha(0.5f);
shareButton.setEnabled(false);
shareButton.setAlpha(0.5f);
proxyStatus.setVisibility(View.INVISIBLE);
} else {
saveButton.setEnabled(true);
saveButton.setAlpha(1);
shareButton.setEnabled(true);
shareButton.setAlpha(1);
String trueHost = SignalProxyUtil.convertUserEnteredAddressToHost(proxyText.getText().toString());
if (SignalStore.proxy().isProxyEnabled() && trueHost.equals(SignalStore.proxy().getProxyHost())) {
proxyStatus.setVisibility(View.VISIBLE);
} else {
proxyStatus.setVisibility(View.INVISIBLE);
}
}
}
}

Wyświetl plik

@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.net.PipeConnectivityListener;
import org.thoughtcrime.securesms.util.SignalProxyUtil;
import org.thoughtcrime.securesms.util.SingleLiveEvent;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.signalservice.internal.configuration.SignalProxy;
import java.util.concurrent.TimeUnit;
@ -41,7 +42,7 @@ public class EditProxyViewModel extends ViewModel {
if (enabled) {
SignalProxy currentProxy = SignalStore.proxy().getProxy();
if (currentProxy != null) {
if (currentProxy != null && !Util.isEmpty(currentProxy.getHost())) {
SignalProxyUtil.enableProxy(currentProxy);
}
uiState.postValue(UiState.ALL_ENABLED);
@ -52,8 +53,7 @@ public class EditProxyViewModel extends ViewModel {
}
public void onSaveClicked(@NonNull String host) {
String parsedHost = SignalProxyUtil.parseHostFromProxyLink(host);
String trueHost = parsedHost != null ? parsedHost : host;
String trueHost = SignalProxyUtil.convertUserEnteredAddressToHost(host);
saveState.postValue(SaveState.IN_PROGRESS);

Wyświetl plik

@ -243,7 +243,9 @@ public class SignalServiceNetworkAccess {
}
public SignalServiceConfiguration getConfiguration(@Nullable String localNumber) {
if (localNumber == null) return this.uncensoredConfiguration;
if (localNumber == null || SignalStore.proxy().isProxyEnabled()) {
return this.uncensoredConfiguration;
}
if (SignalStore.internalValues().forcedCensorship()) {
return this.censorshipConfiguration.get(COUNTRY_CODE_QATAR);

Wyświetl plik

@ -213,7 +213,7 @@ public class CommunicationActions {
* Otherwise returns false, indicating was not a proxy link.
*/
public static boolean handlePotentialProxyLinkUrl(@NonNull FragmentActivity activity, @NonNull String potentialProxyLinkUrl) {
String proxy = SignalProxyUtil.parseHostFromProxyLink(potentialProxyLinkUrl);
String proxy = SignalProxyUtil.parseHostFromProxyDeepLink(potentialProxyLinkUrl);
if (proxy != null) {
ProxyBottomSheetFragment.showForProxy(activity.getSupportFragmentManager(), proxy);

Wyświetl plik

@ -100,10 +100,10 @@ public final class SignalProxyUtil {
}
/**
* If this is a valid proxy link, this will return the embedded host. If not, it will return
* If this is a valid proxy deep link, this will return the embedded host. If not, it will return
* null.
*/
public static @Nullable String parseHostFromProxyLink(@NonNull String proxyLink) {
public static @Nullable String parseHostFromProxyDeepLink(@NonNull String proxyLink) {
try {
URI uri = new URI(proxyLink);
@ -130,4 +130,24 @@ public final class SignalProxyUtil {
return null;
}
}
/**
* Takes in an address that could be in various formats, and converts it to the format we should
* be storing and connecting to.
*/
public static @NonNull String convertUserEnteredAddressToHost(@NonNull String host) {
String parsedHost = SignalProxyUtil.parseHostFromProxyDeepLink(host);
return parsedHost != null ? parsedHost : host;
}
public static @NonNull String generateProxyUrl(@NonNull String link) {
String host = link;
String parsed = parseHostFromProxyDeepLink(link);
if (parsed != null) {
host = parsed;
}
return "https://" + PROXY_LINK_HOST + "/#" + host;
}
}

Wyświetl plik

@ -40,6 +40,8 @@
android:id="@+id/edit_proxy_host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-2dp"
android:hint="@string/preferences_enter_proxy_address"
app:layout_constraintTop_toBottomOf="@id/edit_proxy_address_title"
tools:hint="https://proxy.parker.org"/>

Wyświetl plik

@ -2325,6 +2325,7 @@
<string name="preferences_you_are_connected_to_the_proxy">You are connected to the proxy. You can turn the proxy off at any time from Settings.</string>
<string name="preferences_success">Success</string>
<string name="preferences_failed_to_connect">Failed to connect</string>
<string name="preferences_enter_proxy_address">Enter proxy address</string>
<string name="configurable_single_select__customize_option">Customize option</string>