mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-29 09:03:14 +00:00
Add support for launching app from Monero URI
This commit is contained in:
parent
f17bd07d67
commit
822128c4c6
5 changed files with 102 additions and 21 deletions
|
@ -24,6 +24,14 @@
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data android:scheme="monero" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.m2049r.xmrwallet;
|
package com.m2049r.xmrwallet;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -11,6 +13,7 @@ import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.fragment.dialog.PasswordBottomSheetDialog;
|
import com.m2049r.xmrwallet.fragment.dialog.PasswordBottomSheetDialog;
|
||||||
|
import com.m2049r.xmrwallet.fragment.dialog.SendBottomSheetDialog;
|
||||||
import com.m2049r.xmrwallet.livedata.SingleLiveEvent;
|
import com.m2049r.xmrwallet.livedata.SingleLiveEvent;
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
|
@ -22,6 +25,7 @@ import com.m2049r.xmrwallet.service.MoneroHandlerThread;
|
||||||
import com.m2049r.xmrwallet.service.PrefService;
|
import com.m2049r.xmrwallet.service.PrefService;
|
||||||
import com.m2049r.xmrwallet.service.TxService;
|
import com.m2049r.xmrwallet.service.TxService;
|
||||||
import com.m2049r.xmrwallet.util.Constants;
|
import com.m2049r.xmrwallet.util.Constants;
|
||||||
|
import com.m2049r.xmrwallet.util.UriData;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@ -33,6 +37,9 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
private HistoryService historyService = null;
|
private HistoryService historyService = null;
|
||||||
private BlockchainService blockchainService = null;
|
private BlockchainService blockchainService = null;
|
||||||
|
|
||||||
|
private boolean proceedToSend = false;
|
||||||
|
private UriData uriData = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -48,6 +55,15 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
passwordDialog.listener = this;
|
passwordDialog.listener = this;
|
||||||
passwordDialog.show(getSupportFragmentManager(), "password_dialog");
|
passwordDialog.show(getSupportFragmentManager(), "password_dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
Uri uri = intent.getData();
|
||||||
|
if(uri != null) {
|
||||||
|
uriData = UriData.parse(uri.toString());
|
||||||
|
if (uriData != null) {
|
||||||
|
proceedToSend = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
navigate(R.id.onboarding_fragment);
|
navigate(R.id.onboarding_fragment);
|
||||||
}
|
}
|
||||||
|
@ -101,6 +117,12 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
||||||
File walletFile = new File(getApplicationInfo().dataDir, Constants.WALLET_NAME);
|
File walletFile = new File(getApplicationInfo().dataDir, Constants.WALLET_NAME);
|
||||||
init(walletFile, password);
|
init(walletFile, password);
|
||||||
restartEvents.call();
|
restartEvents.call();
|
||||||
|
|
||||||
|
if(proceedToSend) {
|
||||||
|
SendBottomSheetDialog sendDialog = new SendBottomSheetDialog();
|
||||||
|
sendDialog.uriData = uriData;
|
||||||
|
sendDialog.show(getSupportFragmentManager(), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,6 +31,7 @@ import com.m2049r.xmrwallet.service.BalanceService;
|
||||||
import com.m2049r.xmrwallet.service.TxService;
|
import com.m2049r.xmrwallet.service.TxService;
|
||||||
import com.m2049r.xmrwallet.util.Constants;
|
import com.m2049r.xmrwallet.util.Constants;
|
||||||
import com.m2049r.xmrwallet.util.Helper;
|
import com.m2049r.xmrwallet.util.Helper;
|
||||||
|
import com.m2049r.xmrwallet.util.UriData;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -65,6 +66,8 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
private ImageButton pasteAddressImageButton;
|
private ImageButton pasteAddressImageButton;
|
||||||
private ImageButton scanAddressImageButton;
|
private ImageButton scanAddressImageButton;
|
||||||
|
|
||||||
|
public UriData uriData = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
return inflater.inflate(R.layout.send_bottom_sheet_dialog, null);
|
return inflater.inflate(R.layout.send_bottom_sheet_dialog, null);
|
||||||
|
@ -85,6 +88,13 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
addressTextView = view.findViewById(R.id.address_pending_textview);
|
addressTextView = view.findViewById(R.id.address_pending_textview);
|
||||||
amountTextView = view.findViewById(R.id.amount_pending_textview);
|
amountTextView = view.findViewById(R.id.amount_pending_textview);
|
||||||
|
|
||||||
|
if (uriData != null) {
|
||||||
|
addressEditText.setText(uriData.getAddress());
|
||||||
|
if(uriData.hasAmount()) {
|
||||||
|
amountEditText.setText(uriData.getAmount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pasteAddressImageButton.setOnClickListener(view1 -> {
|
pasteAddressImageButton.setOnClickListener(view1 -> {
|
||||||
Context ctx = getContext();
|
Context ctx = getContext();
|
||||||
if (ctx != null) {
|
if (ctx != null) {
|
||||||
|
@ -236,27 +246,11 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pasteAddress(String address) {
|
private void pasteAddress(String address) {
|
||||||
HashMap<String, String> params = new HashMap<>();
|
UriData uriData = UriData.parse(address);
|
||||||
String[] uriParts = address.replace(Constants.URI_PREFIX, "").split("\\?");
|
if (uriData != null) {
|
||||||
String finalAddress = uriParts[0];
|
addressEditText.setText(uriData.getAddress());
|
||||||
String queryParams = "";
|
if(uriData.hasAmount()) {
|
||||||
if(uriParts.length > 1) {
|
amountEditText.setText(uriData.getAmount());
|
||||||
queryParams = uriParts[1];
|
|
||||||
String[] queryParts = queryParams.split("&");
|
|
||||||
for (String param : queryParts) {
|
|
||||||
String[] paramParts = param.split("=");
|
|
||||||
String variable = paramParts[0];
|
|
||||||
String value = paramParts[1];
|
|
||||||
params.put(variable, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean isValid = Wallet.isAddressValid(finalAddress);
|
|
||||||
if (isValid) {
|
|
||||||
addressEditText.setText(finalAddress);
|
|
||||||
if(!params.isEmpty()) {
|
|
||||||
if(params.containsKey(Constants.URI_ARG_AMOUNT)) {
|
|
||||||
amountEditText.setText(params.get(Constants.URI_ARG_AMOUNT));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.m2049r.xmrwallet.fragment.home;
|
package com.m2049r.xmrwallet.fragment.home;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -30,6 +32,7 @@ import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
import com.m2049r.xmrwallet.service.BalanceService;
|
import com.m2049r.xmrwallet.service.BalanceService;
|
||||||
import com.m2049r.xmrwallet.service.BlockchainService;
|
import com.m2049r.xmrwallet.service.BlockchainService;
|
||||||
import com.m2049r.xmrwallet.service.HistoryService;
|
import com.m2049r.xmrwallet.service.HistoryService;
|
||||||
|
import com.m2049r.xmrwallet.util.UriData;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
|
54
app/src/main/java/com/m2049r/xmrwallet/util/UriData.java
Normal file
54
app/src/main/java/com/m2049r/xmrwallet/util/UriData.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package com.m2049r.xmrwallet.util;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class UriData {
|
||||||
|
private final String address;
|
||||||
|
private final HashMap<String, String> params;
|
||||||
|
|
||||||
|
public UriData(String address, HashMap<String, String> params) {
|
||||||
|
this.address = address;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, String> getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAmount() {
|
||||||
|
return params.get(Constants.URI_ARG_AMOUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAmount() {
|
||||||
|
return params.containsKey(Constants.URI_ARG_AMOUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UriData parse(String uri) {
|
||||||
|
HashMap<String, String> params = new HashMap<>();
|
||||||
|
String[] uriParts = uri.replace(Constants.URI_PREFIX, "").split("\\?");
|
||||||
|
String finalAddress = uriParts[0];
|
||||||
|
String queryParams = "";
|
||||||
|
if(uriParts.length > 1) {
|
||||||
|
queryParams = uriParts[1];
|
||||||
|
String[] queryParts = queryParams.split("&");
|
||||||
|
for (String param : queryParts) {
|
||||||
|
String[] paramParts = param.split("=");
|
||||||
|
String variable = paramParts[0];
|
||||||
|
String value = paramParts[1];
|
||||||
|
params.put(variable, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean valid = Wallet.isAddressValid(finalAddress);
|
||||||
|
if(valid) {
|
||||||
|
return new UriData(finalAddress, params);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue