commit
58c8f1896c
|
@ -89,6 +89,7 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/cmake" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/cmake" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||||
|
@ -100,7 +101,6 @@
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
|
||||||
|
|
|
@ -7,8 +7,8 @@ android {
|
||||||
applicationId "com.m2049r.xmrwallet"
|
applicationId "com.m2049r.xmrwallet"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 3
|
versionCode 4
|
||||||
versionName "0.3.0"
|
versionName "0.4.0"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
|
|
|
@ -18,14 +18,13 @@ package com.m2049r.xmrwallet;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.StrictMode;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
@ -33,131 +32,37 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.ToggleButton;
|
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.model.WalletManager;
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
import com.m2049r.xmrwallet.util.Helper;
|
import com.m2049r.xmrwallet.util.Helper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class LoginActivity extends Activity {
|
public class LoginActivity extends Activity implements LoginFragment.LoginFragmentListener {
|
||||||
static final String TAG = "LoginActivity";
|
static final String TAG = "LoginActivity";
|
||||||
|
|
||||||
static final int MIN_DAEMON_VERSION = 65544;
|
|
||||||
static final int DAEMON_TIMEOUT = 500; // deamon must respond in 500ms
|
static final int DAEMON_TIMEOUT = 500; // deamon must respond in 500ms
|
||||||
|
|
||||||
ListView listView;
|
|
||||||
List<String> walletList = new ArrayList<>();
|
|
||||||
List<String> displayedList = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_login);
|
setContentView(R.layout.login_activity);
|
||||||
|
if (savedInstanceState != null) {
|
||||||
final EditText etDaemonAddress = (EditText) findViewById(R.id.etDaemonAddress);
|
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
|
||||||
|
|
||||||
etDaemonAddress.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
imm.showSoftInput(etDaemonAddress, InputMethodManager.SHOW_IMPLICIT);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
etDaemonAddress.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
||||||
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
|
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ToggleButton tbMainNet = (ToggleButton) findViewById(R.id.tbMainNet);
|
|
||||||
tbMainNet.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
boolean mainnet = ((ToggleButton) v).isChecked(); // current state
|
|
||||||
savePrefs(true); // use previous state as we just clicked it
|
|
||||||
if (mainnet) {
|
|
||||||
setDaemon(daemonMainNet);
|
|
||||||
} else {
|
|
||||||
setDaemon(daemonTestNet);
|
|
||||||
}
|
|
||||||
filterList();
|
|
||||||
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
loadPrefs();
|
|
||||||
|
|
||||||
filterList();
|
|
||||||
|
|
||||||
listView = (ListView) findViewById(R.id.list);
|
|
||||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
|
|
||||||
android.R.layout.simple_list_item_1, android.R.id.text1, this.displayedList);
|
|
||||||
|
|
||||||
listView.setAdapter(adapter);
|
|
||||||
|
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
EditText tvDaemonAddress = (EditText) findViewById(R.id.etDaemonAddress);
|
|
||||||
if (tvDaemonAddress.getText().toString().length() == 0) {
|
|
||||||
Toast.makeText(LoginActivity.this, getString(R.string.prompt_daemon_missing), Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String itemValue = (String) listView.getItemAtPosition(position);
|
|
||||||
if ((isMainNet() && itemValue.charAt(1) != '4')
|
|
||||||
|| (!isMainNet() && itemValue.charAt(1) != '9')) {
|
|
||||||
Toast.makeText(LoginActivity.this, getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int preambleLength = "[123456] ".length();
|
|
||||||
if (itemValue.length() <= (preambleLength)) {
|
|
||||||
Toast.makeText(LoginActivity.this, getString(R.string.panic), Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setWalletDaemon();
|
|
||||||
if (!checkWalletDaemon()) {
|
|
||||||
Toast.makeText(LoginActivity.this, getString(R.string.warn_daemon_unavailable), Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// looking good
|
|
||||||
savePrefs(false);
|
|
||||||
|
|
||||||
String wallet = itemValue.substring(preambleLength);
|
|
||||||
promptPassword(wallet);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (Helper.getWritePermission(this)) {
|
if (Helper.getWritePermission(this)) {
|
||||||
new LoadListTask().execute();
|
startLoginFragment();
|
||||||
} else {
|
} else {
|
||||||
Log.i(TAG, "Waiting for permissions");
|
Log.i(TAG, "Waiting for permissions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// adapted from http://www.mkyong.com/android/android-prompt-user-input-dialog-example/
|
// adapted from http://www.mkyong.com/android/android-prompt-user-input-dialog-example/
|
||||||
void promptPassword(final String wallet) {
|
@Override
|
||||||
|
public void promptPassword(final String wallet) {
|
||||||
Context context = LoginActivity.this;
|
Context context = LoginActivity.this;
|
||||||
LayoutInflater li = LayoutInflater.from(context);
|
LayoutInflater li = LayoutInflater.from(context);
|
||||||
View promptsView = li.inflate(R.layout.prompt_password, null);
|
View promptsView = li.inflate(R.layout.prompt_password, null);
|
||||||
|
@ -209,6 +114,13 @@ public class LoginActivity extends Activity {
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkWalletPassword(String walletName, String password) {
|
||||||
|
String walletPath = new File(Helper.getStorageRoot(getApplicationContext()),
|
||||||
|
walletName + ".keys").getAbsolutePath();
|
||||||
|
// only test view key
|
||||||
|
return WalletManager.getInstance().verifyWalletPassword(walletPath, password, true);
|
||||||
|
}
|
||||||
|
|
||||||
private void processPasswordEntry(String walletName, String pass) {
|
private void processPasswordEntry(String walletName, String pass) {
|
||||||
if (checkWalletPassword(walletName, pass)) {
|
if (checkWalletPassword(walletName, pass)) {
|
||||||
startWallet(walletName, pass);
|
startWallet(walletName, pass);
|
||||||
|
@ -217,43 +129,25 @@ public class LoginActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkWalletDaemon() {
|
////////////////////////////////////////
|
||||||
// if (android.os.Build.VERSION.SDK_INT > 9) {
|
// LoginFragment.LoginFragmentListener
|
||||||
StrictMode.ThreadPolicy prevPolicy = StrictMode.getThreadPolicy();
|
////////////////////////////////////////
|
||||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder(prevPolicy).permitNetwork().build();
|
@Override
|
||||||
StrictMode.setThreadPolicy(policy);
|
public SharedPreferences getPrefs() {
|
||||||
String d[] = WalletManager.getInstance().getDaemonAddress().split(":");
|
return getPreferences(Context.MODE_PRIVATE);
|
||||||
String host = d[0];
|
|
||||||
int port = Integer.parseInt(d[1]);
|
|
||||||
Socket socket = new Socket();
|
|
||||||
long a = new Date().getTime();
|
|
||||||
try {
|
|
||||||
socket.connect(new InetSocketAddress(host, port), DAEMON_TIMEOUT);
|
|
||||||
socket.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Log.d(TAG, "Cannot reach daemon " + host + ":" + port + " because " + ex.getLocalizedMessage());
|
|
||||||
return false;
|
|
||||||
} finally {
|
|
||||||
StrictMode.setThreadPolicy(prevPolicy);
|
|
||||||
}
|
|
||||||
long b = new Date().getTime();
|
|
||||||
Log.d(TAG, "Daemon is " + (b - a) + "ms away.");
|
|
||||||
int version = WalletManager.getInstance().getDaemonVersion();
|
|
||||||
Log.d(TAG, "Daemon is v" + version);
|
|
||||||
return (version >= MIN_DAEMON_VERSION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkWalletPassword(String walletName, String password) {
|
@Override
|
||||||
String walletPath = new File(Helper.getStorageRoot(getApplicationContext()),
|
public File getStorageRoot() {
|
||||||
walletName + ".keys").getAbsolutePath();
|
return Helper.getStorageRoot(getApplicationContext());
|
||||||
// only test view key
|
|
||||||
return WalletManager.getInstance().verifyWalletPassword(walletPath, password, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.d(TAG, "onPause()");
|
Log.d(TAG, "onPause()");
|
||||||
savePrefs(false);
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,76 +157,6 @@ public class LoginActivity extends Activity {
|
||||||
Log.d(TAG, "onResume()");
|
Log.d(TAG, "onResume()");
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isMainNet() {
|
|
||||||
ToggleButton tbMainNet = (ToggleButton) findViewById(R.id.tbMainNet);
|
|
||||||
return tbMainNet.isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMainNet(boolean mainnet) {
|
|
||||||
ToggleButton tbMainNet = (ToggleButton) findViewById(R.id.tbMainNet);
|
|
||||||
tbMainNet.setChecked(mainnet);
|
|
||||||
}
|
|
||||||
|
|
||||||
String getDaemon() {
|
|
||||||
EditText tvDaemonAddress = (EditText) findViewById(R.id.etDaemonAddress);
|
|
||||||
return tvDaemonAddress.getText().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDaemon(String address) {
|
|
||||||
EditText tvDaemonAddress = (EditText) findViewById(R.id.etDaemonAddress);
|
|
||||||
tvDaemonAddress.setText(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String PREF_DAEMON_TESTNET = "daemon_testnet";
|
|
||||||
private static final String PREF_DAEMON_MAINNET = "daemon_mainnet";
|
|
||||||
private static final String PREF_MAINNET = "mainnet";
|
|
||||||
|
|
||||||
private String daemonTestNet;
|
|
||||||
private String daemonMainNet;
|
|
||||||
|
|
||||||
void loadPrefs() {
|
|
||||||
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
|
||||||
|
|
||||||
boolean mainnet = sharedPref.getBoolean(PREF_MAINNET, false);
|
|
||||||
daemonMainNet = sharedPref.getString(PREF_DAEMON_MAINNET, "localhost:18081");
|
|
||||||
daemonTestNet = sharedPref.getString(PREF_DAEMON_TESTNET, "localhost:28081");
|
|
||||||
|
|
||||||
setMainNet(mainnet);
|
|
||||||
if (mainnet) {
|
|
||||||
setDaemon(daemonMainNet);
|
|
||||||
} else {
|
|
||||||
setDaemon(daemonTestNet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void savePrefs(boolean usePreviousState) {
|
|
||||||
// save the daemon address for the net
|
|
||||||
boolean mainnet = isMainNet() ^ usePreviousState;
|
|
||||||
String daemon = getDaemon();
|
|
||||||
if (mainnet) {
|
|
||||||
daemonMainNet = daemon;
|
|
||||||
} else {
|
|
||||||
daemonTestNet = daemon;
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
|
||||||
SharedPreferences.Editor editor = sharedPref.edit();
|
|
||||||
editor.putBoolean(PREF_MAINNET, mainnet);
|
|
||||||
editor.putString(PREF_DAEMON_MAINNET, daemonMainNet);
|
|
||||||
editor.putString(PREF_DAEMON_TESTNET, daemonTestNet);
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setWalletDaemon() {
|
|
||||||
boolean testnet = !isMainNet();
|
|
||||||
String daemon = getDaemon();
|
|
||||||
|
|
||||||
if (!daemon.contains(":")) {
|
|
||||||
daemon = daemon + (testnet ? ":28081" : ":18081");
|
|
||||||
}
|
|
||||||
|
|
||||||
WalletManager.getInstance().setDaemon(daemon, testnet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void startWallet(String walletName, String walletPassword) {
|
void startWallet(String walletName, String walletPassword) {
|
||||||
Log.d(TAG, "startWallet()");
|
Log.d(TAG, "startWallet()");
|
||||||
|
@ -342,44 +166,6 @@ public class LoginActivity extends Activity {
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterList() {
|
|
||||||
displayedList.clear();
|
|
||||||
char x = isMainNet() ? '4' : '9';
|
|
||||||
for (String s : walletList) {
|
|
||||||
if (s.charAt(1) == x) displayedList.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LoadListTask extends AsyncTask<String, Void, Integer> {
|
|
||||||
protected void onPreExecute() {
|
|
||||||
//Toast.makeText(LoginActivity.this, getString(R.string.status_walletlist_loading), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Integer doInBackground(String... params) {
|
|
||||||
WalletManager mgr = WalletManager.getInstance();
|
|
||||||
List<WalletManager.WalletInfo> walletInfos =
|
|
||||||
mgr.findWallets(Helper.getStorageRoot(getApplicationContext()));
|
|
||||||
|
|
||||||
walletList.clear();
|
|
||||||
for (WalletManager.WalletInfo walletInfo : walletInfos) {
|
|
||||||
Log.d(TAG, walletInfo.address);
|
|
||||||
String displayAddress = walletInfo.address;
|
|
||||||
if (displayAddress.length() == 95) {
|
|
||||||
displayAddress = walletInfo.address.substring(0, 6);
|
|
||||||
}
|
|
||||||
walletList.add("[" + displayAddress + "] " + walletInfo.name);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onPostExecute(Integer result) {
|
|
||||||
if (result == 0) {
|
|
||||||
filterList();
|
|
||||||
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
||||||
Log.d(TAG, "onRequestPermissionsResult()");
|
Log.d(TAG, "onRequestPermissionsResult()");
|
||||||
|
@ -388,15 +174,22 @@ public class LoginActivity extends Activity {
|
||||||
// If request is cancelled, the result arrays are empty.
|
// If request is cancelled, the result arrays are empty.
|
||||||
if (grantResults.length > 0
|
if (grantResults.length > 0
|
||||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
new LoadListTask().execute();
|
startLoginFragment();
|
||||||
} else {
|
} else {
|
||||||
String msg = getString(R.string.message_strorage_not_permitted);
|
String msg = getString(R.string.message_strorage_not_permitted);
|
||||||
Log.e(TAG, msg);
|
Log.e(TAG, msg);
|
||||||
throw new IllegalStateException(msg);
|
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||||||
|
//throw new IllegalStateException(msg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
void startLoginFragment() {
|
||||||
|
Fragment fragment = new LoginFragment();
|
||||||
|
getFragmentManager().beginTransaction()
|
||||||
|
.add(R.id.fragment_container, fragment).commit();
|
||||||
|
Log.d(TAG, "fragment added");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,301 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017 m2049r
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.m2049r.xmrwallet;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.StrictMode;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.model.WalletManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LoginFragment extends Fragment {
|
||||||
|
private static final String TAG = "LoginFragment";
|
||||||
|
|
||||||
|
ListView listView;
|
||||||
|
List<String> walletList = new ArrayList<>();
|
||||||
|
List<String> displayedList = new ArrayList<>();
|
||||||
|
|
||||||
|
ToggleButton tbMainNet;
|
||||||
|
EditText etDaemonAddress;
|
||||||
|
|
||||||
|
LoginFragment.LoginFragmentListener activityCallback;
|
||||||
|
|
||||||
|
// Container Activity must implement this interface
|
||||||
|
public interface LoginFragmentListener {
|
||||||
|
SharedPreferences getPrefs();
|
||||||
|
|
||||||
|
File getStorageRoot();
|
||||||
|
|
||||||
|
void promptPassword(final String wallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
if (context instanceof LoginFragment.LoginFragmentListener) {
|
||||||
|
this.activityCallback = (LoginFragment.LoginFragmentListener) context;
|
||||||
|
} else {
|
||||||
|
throw new ClassCastException(context.toString()
|
||||||
|
+ " must implement WalletFragmentListener");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
Log.d(TAG, "onPause()");
|
||||||
|
savePrefs(false);
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
View view = inflater.inflate(R.layout.login_fragment, container, false);
|
||||||
|
|
||||||
|
tbMainNet = (ToggleButton) view.findViewById(R.id.tbMainNet);
|
||||||
|
etDaemonAddress = (EditText) view.findViewById(R.id.etDaemonAddress);
|
||||||
|
|
||||||
|
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||||
|
|
||||||
|
etDaemonAddress.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
imm.showSoftInput(etDaemonAddress, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
etDaemonAddress.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
|
||||||
|
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tbMainNet.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean mainnet = ((ToggleButton) v).isChecked(); // current state
|
||||||
|
savePrefs(true); // use previous state as we just clicked it
|
||||||
|
if (mainnet) {
|
||||||
|
setDaemon(daemonMainNet);
|
||||||
|
} else {
|
||||||
|
setDaemon(daemonTestNet);
|
||||||
|
}
|
||||||
|
filterList();
|
||||||
|
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
loadPrefs();
|
||||||
|
|
||||||
|
listView = (ListView) view.findViewById(R.id.list);
|
||||||
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
|
||||||
|
android.R.layout.simple_list_item_1, android.R.id.text1, this.displayedList);
|
||||||
|
|
||||||
|
listView.setAdapter(adapter);
|
||||||
|
|
||||||
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
EditText tvDaemonAddress = (EditText) getView().findViewById(R.id.etDaemonAddress);
|
||||||
|
if (tvDaemonAddress.getText().toString().length() == 0) {
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.prompt_daemon_missing), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String itemValue = (String) listView.getItemAtPosition(position);
|
||||||
|
if ((isMainNet() && itemValue.charAt(1) != '4')
|
||||||
|
|| (!isMainNet() && itemValue.charAt(1) != '9')) {
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.prompt_wrong_net), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int preambleLength = "[123456] ".length();
|
||||||
|
if (itemValue.length() <= (preambleLength)) {
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.panic), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!checkAndSetWalletDaemon(getDaemon(), !isMainNet())) {
|
||||||
|
Toast.makeText(getActivity(), getString(R.string.warn_daemon_unavailable), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// looking good
|
||||||
|
savePrefs(false);
|
||||||
|
|
||||||
|
String wallet = itemValue.substring(preambleLength);
|
||||||
|
activityCallback.promptPassword(wallet);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
loadList();
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void filterList() {
|
||||||
|
displayedList.clear();
|
||||||
|
char x = isMainNet() ? '4' : '9';
|
||||||
|
for (String s : walletList) {
|
||||||
|
if (s.charAt(1) == x) displayedList.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadList() {
|
||||||
|
WalletManager mgr = WalletManager.getInstance();
|
||||||
|
List<WalletManager.WalletInfo> walletInfos =
|
||||||
|
mgr.findWallets(activityCallback.getStorageRoot());
|
||||||
|
|
||||||
|
walletList.clear();
|
||||||
|
for (WalletManager.WalletInfo walletInfo : walletInfos) {
|
||||||
|
Log.d(TAG, walletInfo.address);
|
||||||
|
String displayAddress = walletInfo.address;
|
||||||
|
if (displayAddress.length() == 95) {
|
||||||
|
displayAddress = walletInfo.address.substring(0, 6);
|
||||||
|
}
|
||||||
|
walletList.add("[" + displayAddress + "] " + walletInfo.name);
|
||||||
|
}
|
||||||
|
filterList();
|
||||||
|
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
boolean isMainNet() {
|
||||||
|
return tbMainNet.isChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMainNet(boolean mainnet) {
|
||||||
|
tbMainNet.setChecked(mainnet);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getDaemon() {
|
||||||
|
return etDaemonAddress.getText().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDaemon(String address) {
|
||||||
|
etDaemonAddress.setText(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String PREF_DAEMON_TESTNET = "daemon_testnet";
|
||||||
|
private static final String PREF_DAEMON_MAINNET = "daemon_mainnet";
|
||||||
|
private static final String PREF_MAINNET = "mainnet";
|
||||||
|
|
||||||
|
private String daemonTestNet;
|
||||||
|
private String daemonMainNet;
|
||||||
|
|
||||||
|
void loadPrefs() {
|
||||||
|
SharedPreferences sharedPref = activityCallback.getPrefs();
|
||||||
|
|
||||||
|
boolean mainnet = sharedPref.getBoolean(PREF_MAINNET, false);
|
||||||
|
daemonMainNet = sharedPref.getString(PREF_DAEMON_MAINNET, "localhost:18081");
|
||||||
|
daemonTestNet = sharedPref.getString(PREF_DAEMON_TESTNET, "localhost:28081");
|
||||||
|
|
||||||
|
setMainNet(mainnet);
|
||||||
|
if (mainnet) {
|
||||||
|
setDaemon(daemonMainNet);
|
||||||
|
} else {
|
||||||
|
setDaemon(daemonTestNet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void savePrefs(boolean usePreviousState) {
|
||||||
|
// save the daemon address for the net
|
||||||
|
boolean mainnet = isMainNet() ^ usePreviousState;
|
||||||
|
String daemon = getDaemon();
|
||||||
|
if (mainnet) {
|
||||||
|
daemonMainNet = daemon;
|
||||||
|
} else {
|
||||||
|
daemonTestNet = daemon;
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedPreferences sharedPref = activityCallback.getPrefs();
|
||||||
|
SharedPreferences.Editor editor = sharedPref.edit();
|
||||||
|
editor.putBoolean(PREF_MAINNET, mainnet);
|
||||||
|
editor.putString(PREF_DAEMON_MAINNET, daemonMainNet);
|
||||||
|
editor.putString(PREF_DAEMON_TESTNET, daemonTestNet);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkAndSetWalletDaemon(String daemonAddress, boolean testnet) {
|
||||||
|
String d[] = daemonAddress.split(":");
|
||||||
|
if (d.length > 2) return false;
|
||||||
|
if (d.length < 1) return false;
|
||||||
|
String host = d[0];
|
||||||
|
int port;
|
||||||
|
if (d.length == 2) {
|
||||||
|
try {
|
||||||
|
port = Integer.parseInt(d[1]);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
port = (testnet ? 28081 : 18081);
|
||||||
|
}
|
||||||
|
// if (android.os.Build.VERSION.SDK_INT > 9) {
|
||||||
|
StrictMode.ThreadPolicy prevPolicy = StrictMode.getThreadPolicy();
|
||||||
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder(prevPolicy).permitNetwork().build();
|
||||||
|
StrictMode.setThreadPolicy(policy);
|
||||||
|
Socket socket = new Socket();
|
||||||
|
long a = new Date().getTime();
|
||||||
|
try {
|
||||||
|
socket.connect(new InetSocketAddress(host, port), LoginActivity.DAEMON_TIMEOUT);
|
||||||
|
socket.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Log.d(TAG, "Cannot reach daemon " + host + ":" + port + " because " + ex.getLocalizedMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
StrictMode.setThreadPolicy(prevPolicy);
|
||||||
|
}
|
||||||
|
long b = new Date().getTime();
|
||||||
|
Log.d(TAG, "Daemon is " + (b - a) + "ms away.");
|
||||||
|
|
||||||
|
WalletManager mgr = WalletManager.getInstance();
|
||||||
|
mgr.setDaemon(daemonAddress, testnet);
|
||||||
|
int version = mgr.getDaemonVersion();
|
||||||
|
Log.d(TAG, "Daemon is v" + version);
|
||||||
|
return (version >= WalletActivity.MIN_DAEMON_VERSION);
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,43 +16,31 @@
|
||||||
|
|
||||||
package com.m2049r.xmrwallet;
|
package com.m2049r.xmrwallet;
|
||||||
|
|
||||||
import android.content.ClipData;
|
import android.app.Activity;
|
||||||
import android.content.ClipboardManager;
|
import android.app.Fragment;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.support.v7.app.AlertDialog;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.support.v7.widget.DividerItemDecoration;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.ProgressBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.layout.TransactionInfoAdapter;
|
|
||||||
import com.m2049r.xmrwallet.model.TransactionInfo;
|
|
||||||
import com.m2049r.xmrwallet.model.Wallet;
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
import com.m2049r.xmrwallet.service.WalletService;
|
import com.m2049r.xmrwallet.service.WalletService;
|
||||||
|
|
||||||
import java.util.List;
|
public class WalletActivity extends Activity implements WalletFragment.WalletFragmentListener,
|
||||||
|
WalletService.Observer {
|
||||||
public class WalletActivity extends AppCompatActivity
|
|
||||||
implements TransactionInfoAdapter.OnInteractionListener, WalletService.Observer {
|
|
||||||
private static final String TAG = "WalletActivity";
|
private static final String TAG = "WalletActivity";
|
||||||
|
|
||||||
|
static final int MIN_DAEMON_VERSION = 65544;
|
||||||
|
|
||||||
public static final String REQUEST_ID = "id";
|
public static final String REQUEST_ID = "id";
|
||||||
public static final String REQUEST_PW = "pw";
|
public static final String REQUEST_PW = "pw";
|
||||||
|
|
||||||
TransactionInfoAdapter adapter;
|
private boolean synced = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
|
@ -71,16 +59,6 @@ public class WalletActivity extends AppCompatActivity
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("No extras passed! Panic!");
|
throw new IllegalStateException("No extras passed! Panic!");
|
||||||
}
|
}
|
||||||
|
|
||||||
onProgress(getString(R.string.status_wallet_loading));
|
|
||||||
showProgress();
|
|
||||||
final Handler handler = new Handler();
|
|
||||||
handler.postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
onProgress(10); // look like we are working!
|
|
||||||
}
|
|
||||||
}, 250);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopWalletService() {
|
private void stopWalletService() {
|
||||||
|
@ -88,20 +66,6 @@ public class WalletActivity extends AppCompatActivity
|
||||||
disconnectWalletService();
|
disconnectWalletService();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String title = null;
|
|
||||||
|
|
||||||
void setActivityTitle(Wallet wallet) {
|
|
||||||
if ((wallet == null) || (title != null)) return;
|
|
||||||
String shortName = wallet.getName();
|
|
||||||
if (shortName.length() > 16) {
|
|
||||||
shortName = shortName.substring(0, 14) + "...";
|
|
||||||
}
|
|
||||||
this.title = "[" + wallet.getAddress().substring(0, 6) + "] " + shortName;
|
|
||||||
setTitle(this.title);
|
|
||||||
onProgress(100);
|
|
||||||
Log.d(TAG, "wallet title is " + this.title);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
Log.d(TAG, "onStop()");
|
Log.d(TAG, "onStop()");
|
||||||
|
@ -121,89 +85,20 @@ public class WalletActivity extends AppCompatActivity
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.wallet_activity);
|
setContentView(R.layout.wallet_activity);
|
||||||
|
|
||||||
// TODO do stuff with savedInstanceState
|
Fragment walletFragment = new WalletFragment();
|
||||||
|
getFragmentManager().beginTransaction()
|
||||||
|
.add(R.id.fragment_container, walletFragment).commit();
|
||||||
|
Log.d(TAG, "fragment added");
|
||||||
|
|
||||||
|
// TODO do stuff with savedInstanceState ?
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Log.d(TAG, "no savedInstanceState");
|
|
||||||
|
|
||||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
|
|
||||||
|
|
||||||
RecyclerView.ItemDecoration itemDecoration = new
|
|
||||||
DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
|
||||||
recyclerView.addItemDecoration(itemDecoration);
|
|
||||||
|
|
||||||
this.adapter = new TransactionInfoAdapter(this);
|
|
||||||
recyclerView.setAdapter(adapter);
|
|
||||||
|
|
||||||
setTitle(getString(R.string.status_wallet_loading));
|
|
||||||
startWalletService();
|
startWalletService();
|
||||||
//Log.d(TAG, "onCreate() done.");
|
Log.d(TAG, "onCreate() done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private long firstBlock = 0;
|
|
||||||
private boolean synced = false;
|
|
||||||
|
|
||||||
private void updateStatus(Wallet wallet) {
|
|
||||||
Log.d(TAG, "updateStatus()");
|
|
||||||
setActivityTitle(wallet);
|
|
||||||
final TextView balanceView = (TextView) findViewById(R.id.tvBalance);
|
|
||||||
final TextView unlockedView = (TextView) findViewById(R.id.tvUnlockedBalance);
|
|
||||||
final TextView syncProgressView = (TextView) findViewById(R.id.tvBlockHeightProgress);
|
|
||||||
final TextView connectionStatusView = (TextView) findViewById(R.id.tvConnectionStatus);
|
|
||||||
balanceView.setText(Wallet.getDisplayAmount(wallet.getBalance()));
|
|
||||||
unlockedView.setText(Wallet.getDisplayAmount(wallet.getUnlockedBalance()));
|
|
||||||
String sync = "";
|
|
||||||
if (mBoundService == null) throw new IllegalStateException("WalletService not bound.");
|
|
||||||
Wallet.ConnectionStatus daemonConnected = mBoundService.getConnectionStatus();
|
|
||||||
if (daemonConnected == Wallet.ConnectionStatus.ConnectionStatus_Connected) {
|
|
||||||
long daemonHeight = mBoundService.getDaemonHeight();
|
|
||||||
if (!wallet.isSynchronized()) {
|
|
||||||
long n = daemonHeight - wallet.getBlockChainHeight();
|
|
||||||
sync = n + " " + getString(R.string.status_remaining);
|
|
||||||
if (firstBlock == 0) {
|
|
||||||
firstBlock = wallet.getBlockChainHeight();
|
|
||||||
}
|
|
||||||
int x = 100 - Math.round(100f * n / (1f * daemonHeight - firstBlock));
|
|
||||||
onProgress(getString(R.string.status_syncing) + " " + sync);
|
|
||||||
if (x == 0) x = -1;
|
|
||||||
onProgress(x);
|
|
||||||
} else {
|
|
||||||
sync = getString(R.string.status_synced) + ": " + wallet.getBlockChainHeight();
|
|
||||||
if (!synced) {
|
|
||||||
hideProgress();
|
|
||||||
saveWallet(); // save on first sync
|
|
||||||
// the usual use case is:
|
|
||||||
// open the wallet, wait for sync, check balance, close app
|
|
||||||
// even if we wait for new transactions, they will be synced and saved next time
|
|
||||||
// the advantage here is that we are storing the state while the app is open
|
|
||||||
// and don't get into timing issues
|
|
||||||
synced = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String net = (wallet.isTestNet() ? getString(R.string.connect_testnet) : getString(R.string.connect_mainnet));
|
|
||||||
syncProgressView.setText(sync);
|
|
||||||
connectionStatusView.setText(net + " " + daemonConnected.toString().substring(17));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRefreshed(final Wallet wallet, final boolean full) {
|
|
||||||
Log.d(TAG, "onRefreshed()");
|
|
||||||
if (wallet.isSynchronized()) {
|
|
||||||
releaseWakeLock(); // the idea is to stay awake until synced
|
|
||||||
}
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (full) {
|
|
||||||
List<TransactionInfo> list = wallet.getHistory().getAll();
|
|
||||||
adapter.setInfos(list);
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
updateStatus(wallet);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Wallet getWallet() {
|
Wallet getWallet() {
|
||||||
if (mBoundService == null) throw new IllegalStateException("WalletService not bound.");
|
if (mBoundService == null) throw new IllegalStateException("WalletService not bound.");
|
||||||
|
@ -223,6 +118,7 @@ public class WalletActivity extends AppCompatActivity
|
||||||
mBoundService = ((WalletService.WalletServiceBinder) service).getService();
|
mBoundService = ((WalletService.WalletServiceBinder) service).getService();
|
||||||
//Log.d(TAG, "setting observer of " + mBoundService);
|
//Log.d(TAG, "setting observer of " + mBoundService);
|
||||||
mBoundService.setObserver(WalletActivity.this);
|
mBoundService.setObserver(WalletActivity.this);
|
||||||
|
updateProgress();
|
||||||
//TODO show current progress (eg. if the service is already busy saving last wallet)
|
//TODO show current progress (eg. if the service is already busy saving last wallet)
|
||||||
Log.d(TAG, "CONNECTED");
|
Log.d(TAG, "CONNECTED");
|
||||||
}
|
}
|
||||||
|
@ -263,48 +159,6 @@ public class WalletActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveWallet() {
|
|
||||||
if (mIsBound) { // no point in talking to unbound service
|
|
||||||
Intent intent = new Intent(getApplicationContext(), WalletService.class);
|
|
||||||
intent.putExtra(WalletService.REQUEST, WalletService.REQUEST_CMD_STORE);
|
|
||||||
startService(intent);
|
|
||||||
Toast.makeText(getApplicationContext(), getString(R.string.status_wallet_unloading), Toast.LENGTH_LONG).show();
|
|
||||||
Log.d(TAG, "STORE request sent");
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Service not bound");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callbacks from TransactionInfoAdapter
|
|
||||||
@Override
|
|
||||||
public void onInteraction(final View view, final TransactionInfo infoItem) {
|
|
||||||
final Context ctx = view.getContext();
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
|
||||||
builder.setTitle("Transaction details");
|
|
||||||
|
|
||||||
builder.setNegativeButton("Copy TX ID", new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
ClipboardManager clipboardManager = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
ClipData clip = ClipData.newPlainText("TX", infoItem.getHash());
|
|
||||||
clipboardManager.setPrimaryClip(clip);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setMessage("TX ID: " + infoItem.getHash() +
|
|
||||||
"\nPayment ID: " + infoItem.getPaymentId() +
|
|
||||||
"\nBlockHeight: " + infoItem.getBlockHeight() +
|
|
||||||
"\nAmount: " + Wallet.getDisplayAmount(infoItem.getAmount()) +
|
|
||||||
"\nFee: " + Wallet.getDisplayAmount(infoItem.getFee()));
|
|
||||||
AlertDialog alert1 = builder.create();
|
|
||||||
alert1.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
Log.d(TAG, "onPause()");
|
Log.d(TAG, "onPause()");
|
||||||
|
@ -334,53 +188,107 @@ public class WalletActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void releaseWakeLock() {
|
public void releaseWakeLock() {
|
||||||
if ((wl == null) || !wl.isHeld()) return;
|
if ((wl == null) || !wl.isHeld()) return;
|
||||||
wl.release();
|
wl.release();
|
||||||
wl = null;
|
wl = null;
|
||||||
Log.d(TAG, "WakeLock released");
|
Log.d(TAG, "WakeLock released");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showProgress() {
|
public void saveWallet() {
|
||||||
|
if (mIsBound) { // no point in talking to unbound service
|
||||||
|
Intent intent = new Intent(getApplicationContext(), WalletService.class);
|
||||||
|
intent.putExtra(WalletService.REQUEST, WalletService.REQUEST_CMD_STORE);
|
||||||
|
startService(intent);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
LinearLayout llProgress = (LinearLayout) findViewById(R.id.llProgress);
|
Toast.makeText(getApplicationContext(), getString(R.string.status_wallet_unloading), Toast.LENGTH_LONG).show();
|
||||||
llProgress.setVisibility(View.VISIBLE);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Log.d(TAG, "STORE request sent");
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Service not bound");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideProgress() {
|
//////////////////////////////////////////
|
||||||
|
// WalletFragment.WalletFragmentListener
|
||||||
|
//////////////////////////////////////////
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasBoundService() {
|
||||||
|
return mBoundService != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Wallet.ConnectionStatus getConnectionStatus() {
|
||||||
|
return mBoundService.getConnectionStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getDaemonHeight() {
|
||||||
|
return mBoundService.getDaemonHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTitle(String title) {
|
||||||
|
super.setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////
|
||||||
|
// WalletService.Observer
|
||||||
|
///////////////////////////
|
||||||
|
@Override
|
||||||
|
public void onRefreshed(final Wallet wallet, final boolean full) {
|
||||||
|
Log.d(TAG, "onRefreshed()");
|
||||||
|
if (wallet.isSynchronized()) {
|
||||||
|
releaseWakeLock(); // the idea is to stay awake until synced
|
||||||
|
if (!synced) {
|
||||||
|
onProgress(null);
|
||||||
|
saveWallet(); // save on first sync
|
||||||
|
synced = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO check which fragment is loaded
|
||||||
|
final WalletFragment walletFragment = (WalletFragment)
|
||||||
|
getFragmentManager().findFragmentById(R.id.fragment_container);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
LinearLayout llProgress = (LinearLayout) findViewById(R.id.llProgress);
|
walletFragment.onRefreshed(wallet, full);
|
||||||
llProgress.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(final String text) {
|
public void onProgress(final String text) {
|
||||||
|
//Log.d(TAG, "PROGRESS: " + text);
|
||||||
|
// TODO check which fragment is loaded
|
||||||
|
final WalletFragment walletFragment = (WalletFragment)
|
||||||
|
getFragmentManager().findFragmentById(R.id.fragment_container);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
TextView progressText = (TextView) findViewById(R.id.tvProgress);
|
walletFragment.onProgress(text);
|
||||||
progressText.setText(text);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgress(final int n) {
|
public void onProgress(final int n) {
|
||||||
|
// TODO check which fragment is loaded
|
||||||
|
final WalletFragment walletFragment = (WalletFragment)
|
||||||
|
getFragmentManager().findFragmentById(R.id.fragment_container);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
ProgressBar progress = (ProgressBar) findViewById(R.id.pbProgress);
|
walletFragment.onProgress(n);
|
||||||
if (n >= 0) {
|
|
||||||
progress.setIndeterminate(false);
|
|
||||||
progress.setProgress(n);
|
|
||||||
} else {
|
|
||||||
progress.setIndeterminate(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateProgress() {
|
||||||
|
// TODO maybe show real state of WalletService (like "still closing previous wallet")
|
||||||
|
if (hasBoundService()) {
|
||||||
|
onProgress(mBoundService.getProgressText());
|
||||||
|
onProgress(mBoundService.getProgressValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,219 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017 m2049r
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.m2049r.xmrwallet;
|
||||||
|
|
||||||
|
import android.app.Fragment;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.support.v7.widget.DividerItemDecoration;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.m2049r.xmrwallet.layout.TransactionInfoAdapter;
|
||||||
|
import com.m2049r.xmrwallet.model.TransactionInfo;
|
||||||
|
import com.m2049r.xmrwallet.model.Wallet;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WalletFragment extends Fragment implements TransactionInfoAdapter.OnInteractionListener {
|
||||||
|
private static final String TAG = "WalletFragment";
|
||||||
|
private TransactionInfoAdapter adapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
View view = inflater.inflate(R.layout.wallet_fragment, container, false);
|
||||||
|
|
||||||
|
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
|
||||||
|
RecyclerView.ItemDecoration itemDecoration = new
|
||||||
|
DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
||||||
|
recyclerView.addItemDecoration(itemDecoration);
|
||||||
|
|
||||||
|
this.adapter = new TransactionInfoAdapter(this);
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
activityCallback.setTitle(getString(R.string.status_wallet_loading));
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callbacks from TransactionInfoAdapter
|
||||||
|
@Override
|
||||||
|
public void onInteraction(final View view, final TransactionInfo infoItem) {
|
||||||
|
final Context ctx = view.getContext();
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
||||||
|
builder.setTitle("Transaction details");
|
||||||
|
|
||||||
|
builder.setNegativeButton("Copy TX ID", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
ClipboardManager clipboardManager = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip = ClipData.newPlainText("TX", infoItem.getHash());
|
||||||
|
clipboardManager.setPrimaryClip(clip);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setMessage("TX ID: " + infoItem.getHash() +
|
||||||
|
"\nPayment ID: " + infoItem.getPaymentId() +
|
||||||
|
"\nBlockHeight: " + infoItem.getBlockHeight() +
|
||||||
|
"\nAmount: " + Wallet.getDisplayAmount(infoItem.getAmount()) +
|
||||||
|
"\nFee: " + Wallet.getDisplayAmount(infoItem.getFee()));
|
||||||
|
AlertDialog alert1 = builder.create();
|
||||||
|
alert1.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// called from activity
|
||||||
|
public void onRefreshed(final Wallet wallet, final boolean full) {
|
||||||
|
Log.d(TAG, "onRefreshed()");
|
||||||
|
if (full) {
|
||||||
|
List<TransactionInfo> list = wallet.getHistory().getAll();
|
||||||
|
adapter.setInfos(list);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
updateStatus(wallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onProgress(final String text) {
|
||||||
|
TextView progressText = (TextView) getView().findViewById(R.id.tvProgress);
|
||||||
|
if (text != null) {
|
||||||
|
progressText.setText(text);
|
||||||
|
showProgress(); //TODO optimize this
|
||||||
|
} else {
|
||||||
|
hideProgress();
|
||||||
|
progressText.setText(getString(R.string.status_working));
|
||||||
|
onProgress(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onProgress(final int n) {
|
||||||
|
ProgressBar progress = (ProgressBar) getView().findViewById(R.id.pbProgress);
|
||||||
|
if (n >= 0) {
|
||||||
|
progress.setIndeterminate(false);
|
||||||
|
progress.setProgress(n);
|
||||||
|
} else {
|
||||||
|
progress.setIndeterminate(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showProgress() {
|
||||||
|
LinearLayout llProgress = (LinearLayout) getView().findViewById(R.id.llProgress);
|
||||||
|
llProgress.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideProgress() {
|
||||||
|
LinearLayout llProgress = (LinearLayout) getView().findViewById(R.id.llProgress);
|
||||||
|
llProgress.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
String setActivityTitle(Wallet wallet) {
|
||||||
|
if (wallet == null) return null;
|
||||||
|
String shortName = wallet.getName();
|
||||||
|
if (shortName.length() > 16) {
|
||||||
|
shortName = shortName.substring(0, 14) + "...";
|
||||||
|
}
|
||||||
|
String title = "[" + wallet.getAddress().substring(0, 6) + "] " + shortName;
|
||||||
|
activityCallback.setTitle(title);
|
||||||
|
Log.d(TAG, "wallet title is " + title);
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private long firstBlock = 0;
|
||||||
|
private String walletTitle = null;
|
||||||
|
|
||||||
|
private void updateStatus(Wallet wallet) {
|
||||||
|
Log.d(TAG, "updateStatus()");
|
||||||
|
if (walletTitle == null) {
|
||||||
|
walletTitle = setActivityTitle(wallet);
|
||||||
|
onProgress(100); // of loading
|
||||||
|
}
|
||||||
|
final TextView balanceView = (TextView) getView().findViewById(R.id.tvBalance);
|
||||||
|
final TextView unlockedView = (TextView) getView().findViewById(R.id.tvUnlockedBalance);
|
||||||
|
final TextView syncProgressView = (TextView) getView().findViewById(R.id.tvBlockHeightProgress);
|
||||||
|
final TextView connectionStatusView = (TextView) getView().findViewById(R.id.tvConnectionStatus);
|
||||||
|
balanceView.setText(Wallet.getDisplayAmount(wallet.getBalance()));
|
||||||
|
unlockedView.setText(Wallet.getDisplayAmount(wallet.getUnlockedBalance()));
|
||||||
|
String sync = "";
|
||||||
|
if (!activityCallback.hasBoundService())
|
||||||
|
throw new IllegalStateException("WalletService not bound.");
|
||||||
|
Wallet.ConnectionStatus daemonConnected = activityCallback.getConnectionStatus();
|
||||||
|
if (daemonConnected == Wallet.ConnectionStatus.ConnectionStatus_Connected) {
|
||||||
|
long daemonHeight = activityCallback.getDaemonHeight();
|
||||||
|
if (!wallet.isSynchronized()) {
|
||||||
|
long n = daemonHeight - wallet.getBlockChainHeight();
|
||||||
|
sync = n + " " + getString(R.string.status_remaining);
|
||||||
|
if (firstBlock == 0) {
|
||||||
|
firstBlock = wallet.getBlockChainHeight();
|
||||||
|
}
|
||||||
|
int x = 100 - Math.round(100f * n / (1f * daemonHeight - firstBlock));
|
||||||
|
onProgress(getString(R.string.status_syncing) + " " + sync);
|
||||||
|
if (x == 0) x = -1;
|
||||||
|
onProgress(x);
|
||||||
|
} else {
|
||||||
|
sync = getString(R.string.status_synced) + ": " + wallet.getBlockChainHeight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String net = (wallet.isTestNet() ? getString(R.string.connect_testnet) : getString(R.string.connect_mainnet));
|
||||||
|
syncProgressView.setText(sync);
|
||||||
|
connectionStatusView.setText(net + " " + daemonConnected.toString().substring(17));
|
||||||
|
}
|
||||||
|
|
||||||
|
WalletFragmentListener activityCallback;
|
||||||
|
|
||||||
|
// Container Activity must implement this interface
|
||||||
|
public interface WalletFragmentListener {
|
||||||
|
boolean hasBoundService();
|
||||||
|
|
||||||
|
Wallet.ConnectionStatus getConnectionStatus();
|
||||||
|
|
||||||
|
long getDaemonHeight(); //mBoundService.getDaemonHeight();
|
||||||
|
|
||||||
|
void setTitle(String title);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
if (context instanceof WalletFragmentListener) {
|
||||||
|
this.activityCallback = (WalletFragmentListener) context;
|
||||||
|
} else {
|
||||||
|
throw new ClassCastException(context.toString()
|
||||||
|
+ " must implement WalletFragmentListener");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runOnUiThread(Runnable runnable) {
|
||||||
|
if (isAdded()) getActivity().runOnUiThread(runnable);
|
||||||
|
}
|
||||||
|
}
|
|
@ -193,18 +193,31 @@ public class WalletService extends Service {
|
||||||
void onProgress(int n);
|
void onProgress(int n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String progressText = null;
|
||||||
|
int progressValue = -1;
|
||||||
|
|
||||||
private void showProgress(String text) {
|
private void showProgress(String text) {
|
||||||
|
progressText = text;
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
observer.onProgress(text);
|
observer.onProgress(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showProgress(int n) {
|
private void showProgress(int n) {
|
||||||
|
progressValue = n;
|
||||||
if (observer != null) {
|
if (observer != null) {
|
||||||
observer.onProgress(n);
|
observer.onProgress(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProgressText() {
|
||||||
|
return progressText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProgressValue() {
|
||||||
|
return progressValue;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
public Wallet getWallet() {
|
public Wallet getWallet() {
|
||||||
if (listener == null) throw new IllegalStateException("no listener");
|
if (listener == null) throw new IllegalStateException("no listener");
|
||||||
|
@ -235,6 +248,8 @@ public class WalletService extends Service {
|
||||||
String walletPw = extras.getString(REQUEST_CMD_LOAD_PW, null);
|
String walletPw = extras.getString(REQUEST_CMD_LOAD_PW, null);
|
||||||
Log.d(TAG, "LOAD wallet " + walletId);// + ":" + walletPw);
|
Log.d(TAG, "LOAD wallet " + walletId);// + ":" + walletPw);
|
||||||
if (walletId != null) {
|
if (walletId != null) {
|
||||||
|
showProgress(getString(R.string.status_wallet_loading));
|
||||||
|
showProgress(10);
|
||||||
start(walletId, walletPw); // TODO What if this fails?
|
start(walletId, walletPw); // TODO What if this fails?
|
||||||
}
|
}
|
||||||
} else if (cmd.equals(REQUEST_CMD_STORE)) {
|
} else if (cmd.equals(REQUEST_CMD_STORE)) {
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/fragment_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
|
@ -1,119 +1,4 @@
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
android:id="@+id/fragment_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" />
|
||||||
android:background="@android:color/white"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
|
||||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
|
||||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
|
||||||
android:paddingTop="@dimen/activity_vertical_margin"
|
|
||||||
>
|
|
||||||
|
|
||||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvBalanceLabel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="10sp"
|
|
||||||
android:layout_marginRight="4dp"
|
|
||||||
android:text="@string/label_balance"
|
|
||||||
app:layout_constraintBaseline_toBaselineOf="@+id/tvBalance"
|
|
||||||
app:layout_constraintRight_toLeftOf="@+id/tvBalance" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvBalance"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:text="00000000.000000000000"
|
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvUnlockedBalanceLabel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="10sp"
|
|
||||||
android:layout_marginRight="4dp"
|
|
||||||
android:text="@string/label_unlockedBalance"
|
|
||||||
app:layout_constraintBaseline_toBaselineOf="@+id/tvUnlockedBalance"
|
|
||||||
app:layout_constraintRight_toLeftOf="@+id/tvUnlockedBalance" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvUnlockedBalance"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
android:text="00000000.000000000000"
|
|
||||||
app:layout_constraintRight_toRightOf="@+id/tvBalance"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/tvBalance" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvConnectionStatus"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="10sp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:text="Loading..."
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvBlockHeightProgress"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="10sp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:text="Loading..."
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/tvConnectionStatus" />
|
|
||||||
|
|
||||||
</android.support.constraint.ConstraintLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/llProgress"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:visibility="gone" >
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvProgress"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:text="Loading..." />
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/pbProgress"
|
|
||||||
style="@android:style/Widget.ProgressBar.Horizontal"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:progress="0"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginLeft="0dp"
|
|
||||||
android:layout_marginRight="0dp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
app:layoutManager="LinearLayoutManager"
|
|
||||||
tools:listitem="@layout/transaction_item" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/white"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
>
|
||||||
|
|
||||||
|
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBalanceLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:layout_marginRight="4dp"
|
||||||
|
android:text="@string/label_balance"
|
||||||
|
app:layout_constraintBaseline_toBaselineOf="@+id/tvBalance"
|
||||||
|
app:layout_constraintRight_toLeftOf="@+id/tvBalance" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBalance"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="00000000.000000000000"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvUnlockedBalanceLabel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:layout_marginRight="4dp"
|
||||||
|
android:text="@string/label_unlockedBalance"
|
||||||
|
app:layout_constraintBaseline_toBaselineOf="@+id/tvUnlockedBalance"
|
||||||
|
app:layout_constraintRight_toLeftOf="@+id/tvUnlockedBalance" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvUnlockedBalance"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:text="00000000.000000000000"
|
||||||
|
app:layout_constraintRight_toRightOf="@+id/tvBalance"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/tvBalance" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvConnectionStatus"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:text="Loading..."
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvBlockHeightProgress"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:text="Loading..."
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/tvConnectionStatus" />
|
||||||
|
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llProgress"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvProgress"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:text="Loading..." />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/pbProgress"
|
||||||
|
style="@android:style/Widget.ProgressBar.Horizontal"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:progress="0"/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginLeft="0dp"
|
||||||
|
android:layout_marginRight="0dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
app:layoutManager="LinearLayoutManager"
|
||||||
|
tools:listitem="@layout/transaction_item" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -12,6 +12,8 @@
|
||||||
<string name="status_wallet_loading">Loading Wallet …</string>
|
<string name="status_wallet_loading">Loading Wallet …</string>
|
||||||
<string name="status_wallet_unloading">Saving Wallet</string>
|
<string name="status_wallet_unloading">Saving Wallet</string>
|
||||||
<string name="status_wallet_connecting">Connecting …</string>
|
<string name="status_wallet_connecting">Connecting …</string>
|
||||||
|
<string name="status_working">Working on it …</string>
|
||||||
|
|
||||||
<string name="prompt_password">Password for</string>
|
<string name="prompt_password">Password for</string>
|
||||||
<string name="bad_password">Bad password!</string>
|
<string name="bad_password">Bad password!</string>
|
||||||
<string name="prompt_daemon_missing">Daemon address must be set!</string>
|
<string name="prompt_daemon_missing">Daemon address must be set!</string>
|
||||||
|
@ -39,6 +41,6 @@
|
||||||
|
|
||||||
<string name="prompt_problems">Problems</string>
|
<string name="prompt_problems">Problems</string>
|
||||||
<string name="message_strorage_not_writable">External Storage is not writable! Panic!</string>
|
<string name="message_strorage_not_writable">External Storage is not writable! Panic!</string>
|
||||||
<string name="message_strorage_not_permitted">External Storage permission not granted! Panic!</string>
|
<string name="message_strorage_not_permitted">We really need those External Storage permissions!</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue