Skip to content
This repository has been archived by the owner on Dec 20, 2017. It is now read-only.

Commit

Permalink
Changing the send form verification procedure for more CPU-friendly one
Browse files Browse the repository at this point in the history
  • Loading branch information
bilthon committed Feb 23, 2017
1 parent 00ddf4e commit 77b849f
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 156 deletions.
223 changes: 106 additions & 117 deletions app/src/main/java/de/bitshares_munich/smartcoinswallet/SendScreen.java
Expand Up @@ -63,7 +63,6 @@
import butterknife.OnTextChanged;
import de.bitshares_munich.database.HistoricalTransferEntry;
import de.bitshares_munich.database.SCWallDatabase;
import de.bitshares_munich.interfaces.IAccount;
import de.bitshares_munich.interfaces.IExchangeRate;
import de.bitshares_munich.interfaces.IRelativeHistory;
import de.bitshares_munich.interfaces.ContactSelectionListener;
Expand All @@ -89,7 +88,6 @@
import de.bitsharesmunich.graphenej.TransferTransactionBuilder;
import de.bitsharesmunich.graphenej.UserAccount;
import de.bitsharesmunich.graphenej.api.GetAccountByName;
import de.bitsharesmunich.graphenej.api.GetRelativeAccountHistory;
import de.bitsharesmunich.graphenej.api.TransactionBroadcastSequence;
import de.bitsharesmunich.graphenej.crypto.SecureRandomGenerator;
import de.bitsharesmunich.graphenej.errors.MalformedTransactionException;
Expand All @@ -106,7 +104,7 @@
/**
* Created by Syed Muhammad Muzzammil on 5/6/16.
*/
public class SendScreen extends BaseActivity implements IExchangeRate, IAccount, IRelativeHistory, ContactSelectionListener {
public class SendScreen extends BaseActivity implements IExchangeRate, IRelativeHistory, ContactSelectionListener {
private static final String TAG = "SendScreen";

TinyDB tinyDB;
Expand Down Expand Up @@ -184,10 +182,7 @@ public class SendScreen extends BaseActivity implements IExchangeRate, IAccount,
Spinner spinnerFrom;

@Bind(R.id.btnSend)
LinearLayout btnSend;

@Bind(R.id.sendicon)
ImageView sendicon;
Button btnSend;

@Bind(R.id.etLoyalty)
EditText etLoyalty;
Expand All @@ -210,7 +205,6 @@ public class SendScreen extends BaseActivity implements IExchangeRate, IAccount,
* Handler and delay
*/
private int REQUEST_TRANSFER_HISTORY_DELAY = 1800;
private Handler mHandler;

/**
* Instance of the database interface
Expand Down Expand Up @@ -269,25 +263,6 @@ public void onError(BaseResponse.Error error) {
}
};

/**
* Callback that obtains the response from the get_account_by_name API call.
* Here we're just interested in get one of the public keys from the recipient account
* in order to use it for memo encryption.
*/
private WitnessResponseListener accountByNameListener = new WitnessResponseListener() {
@Override
public void onSuccess(WitnessResponse response) {
Log.d(TAG,"accountByNameListener. onSuccess");
AccountProperties accountProperties = ((WitnessResponse<AccountProperties>) response).result;
destination = accountProperties.active.getKeyAuths().keySet().iterator().next();
}

@Override
public void onError(BaseResponse.Error error) {
Log.d(TAG,"accountByNameListener.onError. Msg: "+error.message);
}
};

/**
* Callback fired when we get a response from the transaction broadcast
* sequence for the donation button.
Expand Down Expand Up @@ -360,7 +335,7 @@ protected void onCreate(Bundle savedInstanceState) {

ButterKnife.bind(this);
Application.registerExchangeRateCallback(this);
Application.registerCallback(this);
// Application.registerCallback(this);
Application.registerRelativeHistoryCallback(this);

tvAppVersion.setText("v" + BuildConfig.VERSION_NAME + getString(R.string.beta));
Expand All @@ -372,33 +347,6 @@ protected void onCreate(Bundle savedInstanceState) {

cbAlwaysDonate.setText(getString(R.string.checkbox_donate) + " BitShares Munich");

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (!validReceiver && !validating) {
if (etReceiverAccount.getText().length() > 0) {
myLowerCaseTimer.cancel();
myAccountNameValidationTimer.cancel();
myLowerCaseTimer.start();
myAccountNameValidationTimer.start();
}
}
//Do something after 100ms
if (validateSend() && validReceiver) {
btnSend.setEnabled(true);
btnSend.setBackgroundColor(getColorWrapper(getApplicationContext(), R.color.redcolor));
sendicon.setImageDrawable(getDrawable(getApplicationContext(), R.mipmap.icon_send));

} else {
// btnSend.setEnabled(false);
btnSend.setBackgroundColor(getColorWrapper(getApplicationContext(), R.color.gray));
sendicon.setImageDrawable(getDrawable(getApplicationContext(), R.drawable.sendicon2));
}
handler.postDelayed(this, 200);
}
}, 100);

database = new SCWallDatabase(this);
}

Expand Down Expand Up @@ -453,8 +401,6 @@ void onTextChangedTo(CharSequence text) {
}
tvErrorRecieverAccount.setVisibility(View.GONE);
loadWebView(webviewTo, 34, Helper.hash(etReceiverAccount.getText().toString(), Helper.SHA256));

mHandler = new Handler();
}

@OnFocusChange(R.id.etReceiverAccount)
Expand All @@ -472,7 +418,7 @@ public void onFocusChange(boolean hasFocus) {
}
@OnTextChanged(R.id.etAmount)
void onAmountChanged(CharSequence text) {
updateAmountStatus();
onTransferAmountUpdated();
}

Boolean runningSpinerForFirstTime = true;
Expand Down Expand Up @@ -502,7 +448,7 @@ void onItemSelected(int position) {
@OnItemSelected(R.id.spAssets)
void onAssetsSelected(int position) {
if (loyaltyAsset == null) {
updateAmountStatus();
onTransferAmountUpdated();
}
if (backupAsset != null && !backupAsset.isEmpty()) {
getExchangeRate(200);
Expand Down Expand Up @@ -710,7 +656,8 @@ private void selectedAccountAsset() {
}
}

public void updateAmountStatus() {
public void onTransferAmountUpdated() {
Log.d(TAG,"onTransferAmountUpdated");
try {
tvAmountStatus.setTextColor(tvTotalStatus.getTextColors());
String selectedAsset;
Expand Down Expand Up @@ -762,8 +709,17 @@ public void updateAmountStatus() {
tvAmountStatus.setTextColor(Color.RED); //shayan
updateTotalStatus();
} catch (Exception e) {
Log.e(TAG,"Exception. Msg: "+e.getMessage());
}

// Enabling or disabling the send button depending on
// the result of the validation.
if(validateSend()){
btnSend.setEnabled(true);
}else{
btnSend.setEnabled(false);
}

}

private void loadWebView(WebView webView, int size, String encryptText) {
Expand Down Expand Up @@ -795,15 +751,56 @@ public void onFinish() {
};

private void lookupAccounts() {
String socketText = getString(R.string.lookup_account_a);
String scketText2 = getString(R.string.lookup_account_b) + "\"" + etReceiverAccount.getText().toString() + "\"" + ",50]],\"id\": 6}";
myWebSocketHelper.make_websocket_call(socketText, scketText2, webSocketCallHelper.api_identifier.database);
// String socketText = getString(R.string.lookup_account_a);
// String scketText2 = getString(R.string.lookup_account_b) + "\"" + etReceiverAccount.getText().toString() + "\"" + ",50]],\"id\": 6}";
// myWebSocketHelper.make_websocket_call(socketText, scketText2, webSocketCallHelper.api_identifier.database);

this.getAccountByName = new WebsocketWorkerThread(new GetAccountByName(etReceiverAccount.getText().toString(), accountByNameListener), 0);
this.getAccountByName = new WebsocketWorkerThread(new GetAccountByName(etReceiverAccount.getText().toString(), mAccountByNameListener));
this.getAccountByName.start();
validating = true;
}

Handler reloadToAccountValidation = new Handler();
/**
* Callback that obtains the response from the get_account_by_name API call.
* Here we're just interested in get one of the public keys from the recipient account
* in order to use it for memo encryption.
*/
private WitnessResponseListener mAccountByNameListener = new WitnessResponseListener() {

@Override
public void onSuccess(final WitnessResponse response) {
Log.d(TAG,"mAccountByNameListener. onSuccess");

runOnUiThread(new Runnable() {
@Override
public void run() {
AccountProperties accountProperties = ((WitnessResponse<AccountProperties>) response).result;
if(accountProperties != null){
Log.d(TAG,"Found account with name");
Log.d(TAG,accountProperties.name);
destination = accountProperties.active.getKeyAuths().keySet().iterator().next();
}else{
Log.i(TAG, "No account with that name");
destination = null;
}

validating = false;

// Check whether we can enable the "send" button or not
if(validateSend()){
btnSend.setEnabled(true);
}else{
btnSend.setEnabled(false);
}
}
});
}

@Override
public void onError(BaseResponse.Error error) {
Log.d(TAG,"mAccountByNameListener.onError. Msg: "+error.message);
}
};

public void createBitShareAN(boolean focused) {
if (!focused) {
Expand Down Expand Up @@ -1101,6 +1098,8 @@ public boolean validateSend() {
return false;
} else if (checkIfZero()) {
return false;
} else if(destination == null){
return false;
}
return true;
}
Expand Down Expand Up @@ -1229,58 +1228,48 @@ public void run() {

}

@Override
public void checkAccount(JSONObject jsonObject) {
myWebSocketHelper.cleanUpTransactionsHandler();
try {
JSONArray jsonArray = jsonObject.getJSONArray("result");
boolean found = false;
for (int i = 0; i < jsonArray.length(); i++) {
final String accountName = jsonArray.getJSONArray(i).getString(0);
String accountId = jsonArray.getJSONArray(i).getString(1);
if (accountName.equals(etReceiverAccount.getText().toString())) {
Log.d(TAG, "valid account name: "+accountName+", account id: "+accountId);
found = true;
validReceiver = true;
receiverID = jsonArray.getJSONArray(i).getString(1);
runOnUiThread(new Runnable() {
@Override
public void run() {
// if (sendBtnPressed) {
//// validatingComplete();
// }
}
});
sendBtnPressed = false;
validating = false;
// destination = new UserAccount(accountId, accountName);
break;
}
}
if (!found) {
runOnUiThread(new Runnable() {
@Override
public void run() {
validReceiver = false;
sendBtnPressed = false;
validating = false;
// This code works correct, donot edit if it shows red underline
try {
String format = String.format(getResources().getString(R.string.account_name_not_exist), etReceiverAccount.getText());
format = format.replaceAll("\\s+", " ").trim();
tvErrorRecieverAccount.setText(format);
} catch (Exception e) {
tvErrorRecieverAccount.setText("");
}

tvErrorRecieverAccount.setVisibility(View.VISIBLE);
}
});
}
} catch (Exception e) {
sendBtnPressed = false;
}
}
// @Override
// public void checkAccount(JSONObject jsonObject) {
// myWebSocketHelper.cleanUpTransactionsHandler();
// try {
// JSONArray jsonArray = jsonObject.getJSONArray("result");
// boolean found = false;
// for (int i = 0; i < jsonArray.length(); i++) {
// final String accountName = jsonArray.getJSONArray(i).getString(0);
// String accountId = jsonArray.getJSONArray(i).getString(1);
// if (accountName.equals(etReceiverAccount.getText().toString())) {
// found = true;
// validReceiver = true;
// receiverID = jsonArray.getJSONArray(i).getString(1);
// sendBtnPressed = false;
// validating = false;
// break;
// }
// }
// if (!found) {
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// validReceiver = false;
// sendBtnPressed = false;
// validating = false;
// // This code works correct, donot edit if it shows red underline
// try {
// String format = String.format(getResources().getString(R.string.account_name_not_exist), etReceiverAccount.getText());
// format = format.replaceAll("\\s+", " ").trim();
// tvErrorRecieverAccount.setText(format);
// } catch (Exception e) {
// tvErrorRecieverAccount.setText("");
// }
//
// tvErrorRecieverAccount.setVisibility(View.VISIBLE);
// }
// });
// }
// } catch (Exception e) {
// sendBtnPressed = false;
// }
// }

private void showDialog(String title, String msg)
{
Expand Down
Expand Up @@ -469,7 +469,6 @@ private static String headBlockNumber(String json) {
}
}
if (rawBlockId.equals("")) {
Log.w(TAG, "Could not process data");
return blockHead;
}
// Setting block number
Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_send_button.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_send_button.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_send_button.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/send_button.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/send_button_background.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:drawable="@color/redcolor"/>
<item android:state_enabled="false" android:drawable="@color/gray"/>
</selector>
8 changes: 4 additions & 4 deletions app/src/main/res/layout/fragment_balances.xml
Expand Up @@ -80,7 +80,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@mipmap/icon_receive"
android:src="@drawable/icon_receive"
android:visibility="visible"/>

</LinearLayout>
Expand All @@ -89,7 +89,7 @@
android:layout_height="100dp"
android:layout_gravity="center"
android:gravity="center"
android:src="@mipmap/icon_receive"
android:src="@drawable/icon_receive"
android:visibility="gone"/>
<TextView
android:layout_width="100dp"
Expand All @@ -106,7 +106,7 @@
android:layout_height="75dp"
android:layout_gravity="center"
android:layout_weight="0.6"
android:src="@mipmap/icon_camera"
android:src="@drawable/icon_camera"
android:visibility="invisible"/>

<View android:id="@+id/backLine"
Expand All @@ -133,7 +133,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@mipmap/icon_send"/>
android:src="@drawable/icon_send"/>
</LinearLayout>

<TextView
Expand Down

0 comments on commit 77b849f

Please sign in to comment.