mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-10 08:00:02 +00:00
Add proxy option
This commit is contained in:
parent
209984417b
commit
524f220264
10 changed files with 172 additions and 10 deletions
|
@ -93,7 +93,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionFail() {
|
public void onConnectionFail() {
|
||||||
Toast.makeText(this, R.string.connection_failed, Toast.LENGTH_SHORT).show();
|
runOnUiThread(() -> Toast.makeText(getApplication(), R.string.connection_failed, Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -105,6 +105,6 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPasswordFail() {
|
public void onPasswordFail() {
|
||||||
Toast.makeText(this, R.string.bad_password, Toast.LENGTH_SHORT).show();
|
runOnUiThread(() -> Toast.makeText(getApplication(), R.string.bad_password, Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -32,7 +32,8 @@ public enum DefaultNodes {
|
||||||
MONERUJO_ONION("monerujods7mbghwe6cobdr6ujih6c22zu5rl7zshmizz2udf7v7fsad.onion:18081/mainnet/monerujo.onion"),
|
MONERUJO_ONION("monerujods7mbghwe6cobdr6ujih6c22zu5rl7zshmizz2udf7v7fsad.onion:18081/mainnet/monerujo.onion"),
|
||||||
Criminales78("56wl7y2ebhamkkiza4b7il4mrzwtyvpdym7bm2bkg3jrei2je646k3qd.onion:18089/mainnet/Criminales78.onion"),
|
Criminales78("56wl7y2ebhamkkiza4b7il4mrzwtyvpdym7bm2bkg3jrei2je646k3qd.onion:18089/mainnet/Criminales78.onion"),
|
||||||
xmrfail("mxcd4577fldb3ppzy7obmmhnu3tf57gbcbd4qhwr2kxyjj2qi3dnbfqd.onion:18081/mainnet/xmrfail.onion"),
|
xmrfail("mxcd4577fldb3ppzy7obmmhnu3tf57gbcbd4qhwr2kxyjj2qi3dnbfqd.onion:18081/mainnet/xmrfail.onion"),
|
||||||
boldsuck("6dsdenp6vjkvqzy4wzsnzn6wixkdzihx3khiumyzieauxuxslmcaeiad.onion:18081/mainnet/boldsuck.onion");
|
boldsuck("6dsdenp6vjkvqzy4wzsnzn6wixkdzihx3khiumyzieauxuxslmcaeiad.onion:18081/mainnet/boldsuck.onion"),
|
||||||
|
SAMOURAI("446unwib5vc7pfbzflosy6m6vtyuhddnalr3hutyavwe4esfuu5g6ryd.onion:18089/mainnet/samourai.onion");
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String uri;
|
private final String uri;
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class OnboardingFragment extends Fragment {
|
||||||
ImageView moreOptionsChevronImageView = view.findViewById(R.id.advanced_settings_chevron_imageview);
|
ImageView moreOptionsChevronImageView = view.findViewById(R.id.advanced_settings_chevron_imageview);
|
||||||
|
|
||||||
moreOptionsDropdownTextView.setOnClickListener(view12 -> mViewModel.onMoreOptionsClicked());
|
moreOptionsDropdownTextView.setOnClickListener(view12 -> mViewModel.onMoreOptionsClicked());
|
||||||
|
moreOptionsChevronImageView.setOnClickListener(view12 -> mViewModel.onMoreOptionsClicked());
|
||||||
|
|
||||||
createWalletButton.setOnClickListener(view1 -> {
|
createWalletButton.setOnClickListener(view1 -> {
|
||||||
String walletPassword = walletPasswordEditText.getText().toString();
|
String walletPassword = walletPasswordEditText.getText().toString();
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
package com.m2049r.xmrwallet.fragment.settings;
|
package com.m2049r.xmrwallet.fragment.settings;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Patterns;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.SwitchCompat;
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@ -25,6 +30,28 @@ import com.m2049r.xmrwallet.util.NightmodeHelper;
|
||||||
public class SettingsFragment extends Fragment implements PasswordBottomSheetDialog.PasswordListener {
|
public class SettingsFragment extends Fragment implements PasswordBottomSheetDialog.PasswordListener {
|
||||||
|
|
||||||
private SettingsViewModel mViewModel;
|
private SettingsViewModel mViewModel;
|
||||||
|
TextWatcher proxyAddressListener = new TextWatcher() {
|
||||||
|
@Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||||
|
@Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||||
|
@Override public void afterTextChanged(Editable editable) {
|
||||||
|
if(mViewModel != null) {
|
||||||
|
mViewModel.setProxyAddress(editable.toString());
|
||||||
|
mViewModel.updateProxy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TextWatcher proxyPortListener = new TextWatcher() {
|
||||||
|
@Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||||
|
@Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||||
|
@Override public void afterTextChanged(Editable editable) {
|
||||||
|
if(mViewModel != null) {
|
||||||
|
mViewModel.setProxyPort(editable.toString());
|
||||||
|
mViewModel.updateProxy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private EditText walletProxyAddressEditText;
|
||||||
|
private EditText walletProxyPortEditText;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
|
@ -39,6 +66,9 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
|
||||||
Button displaySeedButton = view.findViewById(R.id.display_seed_button);
|
Button displaySeedButton = view.findViewById(R.id.display_seed_button);
|
||||||
SwitchCompat nightModeSwitch = view.findViewById(R.id.day_night_switch);
|
SwitchCompat nightModeSwitch = view.findViewById(R.id.day_night_switch);
|
||||||
SwitchCompat torSwitch = view.findViewById(R.id.tor_switch);
|
SwitchCompat torSwitch = view.findViewById(R.id.tor_switch);
|
||||||
|
ConstraintLayout proxySettingsLayout = view.findViewById(R.id.wallet_proxy_settings_layout);
|
||||||
|
walletProxyAddressEditText = view.findViewById(R.id.wallet_proxy_address_edittext);
|
||||||
|
walletProxyPortEditText = view.findViewById(R.id.wallet_proxy_port_edittext);
|
||||||
|
|
||||||
nightModeSwitch.setChecked(NightmodeHelper.getPreferredNightmode() == DayNightMode.NIGHT);
|
nightModeSwitch.setChecked(NightmodeHelper.getPreferredNightmode() == DayNightMode.NIGHT);
|
||||||
nightModeSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
|
nightModeSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||||
|
@ -49,14 +79,41 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
torSwitch.setChecked(PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false));
|
boolean usesProxy = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
|
||||||
|
String proxy = PrefService.getInstance().getString(Constants.PREF_PROXY, "");
|
||||||
|
if(proxy.contains(":")) {
|
||||||
|
String proxyAddress = proxy.split(":")[0];
|
||||||
|
String proxyPort = proxy.split(":")[1];
|
||||||
|
initProxyStuff(proxyAddress, proxyPort);
|
||||||
|
}
|
||||||
|
torSwitch.setChecked(usesProxy);
|
||||||
|
if(usesProxy) {
|
||||||
|
proxySettingsLayout.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
proxySettingsLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
addProxyTextListeners();
|
||||||
|
|
||||||
torSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
|
torSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||||
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_TOR, b).apply();
|
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_TOR, b).apply();
|
||||||
|
if(b) {
|
||||||
|
String proxyString = PrefService.getInstance().getString(Constants.PREF_PROXY, "");
|
||||||
|
if(proxyString.contains(":")) {
|
||||||
|
removeProxyTextListeners();
|
||||||
|
|
||||||
// TODO display "Advanced" settings mode when enabled to configure specific proxy address and port
|
String proxyAddress = proxyString.split(":")[0];
|
||||||
String proxy = b ? "127.0.0.1:9050" : "";
|
String proxyPort = proxyString.split(":")[1];
|
||||||
WalletManager.getInstance().setProxy(proxy);
|
initProxyStuff(proxyAddress, proxyPort);
|
||||||
WalletManager.getInstance().getWallet().setProxy(proxy);
|
|
||||||
|
addProxyTextListeners();
|
||||||
|
}
|
||||||
|
proxySettingsLayout.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
proxySettingsLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mViewModel.updateProxy();
|
||||||
});
|
});
|
||||||
|
|
||||||
displaySeedButton.setOnClickListener(view1 -> {
|
displaySeedButton.setOnClickListener(view1 -> {
|
||||||
|
@ -87,4 +144,24 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
|
||||||
public void onPasswordFail() {
|
public void onPasswordFail() {
|
||||||
Toast.makeText(getContext(), R.string.bad_password, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), R.string.bad_password, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initProxyStuff(String proxyAddress, String proxyPort) {
|
||||||
|
boolean validIpAddress = Patterns.IP_ADDRESS.matcher(proxyAddress).matches();
|
||||||
|
if(validIpAddress) {
|
||||||
|
mViewModel.setProxyAddress(proxyAddress);
|
||||||
|
mViewModel.setProxyPort(proxyPort);
|
||||||
|
walletProxyAddressEditText.setText(proxyAddress);
|
||||||
|
walletProxyPortEditText.setText(proxyPort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeProxyTextListeners() {
|
||||||
|
walletProxyAddressEditText.removeTextChangedListener(proxyAddressListener);
|
||||||
|
walletProxyPortEditText.removeTextChangedListener(proxyPortListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addProxyTextListeners() {
|
||||||
|
walletProxyAddressEditText.addTextChangedListener(proxyAddressListener);
|
||||||
|
walletProxyPortEditText.addTextChangedListener(proxyPortListener);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,48 @@
|
||||||
package com.m2049r.xmrwallet.fragment.settings;
|
package com.m2049r.xmrwallet.fragment.settings;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.util.Patterns;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.R;
|
||||||
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
|
import com.m2049r.xmrwallet.service.PrefService;
|
||||||
|
import com.m2049r.xmrwallet.service.TxService;
|
||||||
|
import com.m2049r.xmrwallet.util.Constants;
|
||||||
|
|
||||||
public class SettingsViewModel extends ViewModel {
|
public class SettingsViewModel extends ViewModel {
|
||||||
|
|
||||||
|
private String proxyAddress = "";
|
||||||
|
private String proxyPort = "";
|
||||||
|
public void updateProxy() {
|
||||||
|
AsyncTask.execute(() -> {
|
||||||
|
boolean usesProxy = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
|
||||||
|
if(!usesProxy) {
|
||||||
|
WalletManager.getInstance().setProxy("");
|
||||||
|
WalletManager.getInstance().getWallet().setProxy("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(proxyAddress.isEmpty()) proxyAddress = "127.0.0.1";
|
||||||
|
if(proxyPort.isEmpty()) proxyPort = "9050";
|
||||||
|
boolean validIpAddress = Patterns.IP_ADDRESS.matcher(proxyAddress).matches();
|
||||||
|
if(validIpAddress) {
|
||||||
|
String proxy = proxyAddress + ":" + proxyPort;
|
||||||
|
PrefService.getInstance().edit().putString(Constants.PREF_PROXY, proxy).apply();
|
||||||
|
WalletManager.getInstance().setProxy(proxy);
|
||||||
|
WalletManager.getInstance().getWallet().setProxy(proxy);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyAddress(String address) {
|
||||||
|
this.proxyAddress = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyPort(String port) {
|
||||||
|
this.proxyPort = port;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -57,9 +57,9 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean usesTor = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
|
boolean usesTor = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
|
||||||
if (usesTor) {
|
if (usesTor) {
|
||||||
String proxy = "127.0.0.1:9050";
|
String proxy = PrefService.getInstance().getString(Constants.PREF_PROXY, "");
|
||||||
WalletManager.getInstance().setProxy(proxy);
|
WalletManager.getInstance().setProxy(proxy);
|
||||||
WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.boldsuck.getUri()));
|
WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.SAMOURAI.getUri()));
|
||||||
wallet.setProxy(proxy);
|
wallet.setProxy(proxy);
|
||||||
} else {
|
} else {
|
||||||
WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.XMRTW.getUri()));
|
WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.XMRTW.getUri()));
|
||||||
|
|
|
@ -6,4 +6,5 @@ public class Constants {
|
||||||
public static final String PREF_USES_PASSWORD = "pref_uses_password";
|
public static final String PREF_USES_PASSWORD = "pref_uses_password";
|
||||||
public static final String PREF_USES_TOR = "pref_uses_tor";
|
public static final String PREF_USES_TOR = "pref_uses_tor";
|
||||||
public static final String PREF_NIGHT_MODE = "pref_night_mode";
|
public static final String PREF_NIGHT_MODE = "pref_night_mode";
|
||||||
|
public static final String PREF_PROXY = "pref_proxy";
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:text="@string/more_options"
|
android:text="@string/more_options"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
|
android:padding="4dp"
|
||||||
app:layout_constraintBottom_toTopOf="@id/wallet_seed_edittext"
|
app:layout_constraintBottom_toTopOf="@id/wallet_seed_edittext"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.0"
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
|
@ -51,6 +52,8 @@
|
||||||
android:id="@+id/advanced_settings_chevron_imageview"
|
android:id="@+id/advanced_settings_chevron_imageview"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:minWidth="24dp"
|
||||||
|
android:minHeight="24dp"
|
||||||
android:src="@drawable/ic_keyboard_arrow_down"
|
android:src="@drawable/ic_keyboard_arrow_down"
|
||||||
app:layout_constraintBottom_toBottomOf="@id/advanced_settings_dropdown_textview"
|
app:layout_constraintBottom_toBottomOf="@id/advanced_settings_dropdown_textview"
|
||||||
app:layout_constraintStart_toEndOf="@id/advanced_settings_dropdown_textview"
|
app:layout_constraintStart_toEndOf="@id/advanced_settings_dropdown_textview"
|
||||||
|
|
|
@ -109,4 +109,38 @@
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/network_settings_textview" />
|
app:layout_constraintTop_toBottomOf="@id/network_settings_textview" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:id="@+id/wallet_proxy_settings_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tor_switch"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent">
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/wallet_proxy_address_edittext"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="32dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:background="@drawable/edittext_bg"
|
||||||
|
android:hint="@string/wallet_proxy_address_hint"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/wallet_proxy_port_edittext"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/wallet_proxy_port_edittext"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/edittext_bg"
|
||||||
|
android:hint="@string/wallet_proxy_port_hint"
|
||||||
|
android:inputType="number"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/wallet_proxy_address_edittext" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -76,4 +76,8 @@
|
||||||
<string name="wallet">Wallet</string>
|
<string name="wallet">Wallet</string>
|
||||||
<string name="appearance">Appearance</string>
|
<string name="appearance">Appearance</string>
|
||||||
<string name="network">Network</string>
|
<string name="network">Network</string>
|
||||||
|
|
||||||
|
<string name="wallet_proxy_address_hint">127.0.0.1</string>
|
||||||
|
<string name="wallet_proxy_port_hint">9050</string>
|
||||||
|
<string name="invalid_ip">Invalid IP address</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue