mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Clean up several UX interactions with proxy entry.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user