Change custom implementations of classes to kotlin

*AccountSeedViewModel
*CreateSeedActivity
*UIValidator
*UIValidatorListener
*FieldsValidator
*CustomValidationField
*PinDoubleConfirmationValidationField
*BitsharesAccountNameValidation
-In the Send Assets window in the field Memo set it to max length to 255
This commit is contained in:
dtvv 2018-08-14 16:15:45 -05:00
parent f57305312b
commit da8eda93b5
8 changed files with 21 additions and 393 deletions

View file

@ -1,4 +1,13 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
kapt {
generateStubs = true
javacOptions {
option("-Xmaxerrs", 500)
}
}
android {
compileSdkVersion 27
@ -43,6 +52,7 @@ dependencies {
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
//testCompile 'com.android.support.test:runner:1.0.1'
implementation 'com.afollestad.material-dialogs:core:0.9.6.0' //DTVV Thrusday 31 July 2018
implementation 'com.android.support:appcompat-v7:27.1.1'
@ -52,7 +62,6 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'android.arch.lifecycle:runtime:1.1.1'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'android.arch.persistence.room:runtime:1.1.0'
implementation 'android.arch.paging:runtime:1.0.0'
implementation 'com.idescout.sql:sqlscout-server:2.0'
implementation 'com.google.code.gson:gson:2.8.0'
@ -72,8 +81,15 @@ dependencies {
//testCompile 'junit:junit: 4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
implementation 'android.arch.persistence.room:runtime:1.1.0'
kapt 'android.arch.persistence.room:runtime:1.1.0'
annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'
kapt 'android.arch.lifecycle:compiler:1.1.1'
annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'
kapt 'android.arch.persistence.room:compiler:1.1.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.0'
kapt 'com.jakewharton:butterknife-compiler:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.squareup.picasso:picasso:2.5.2'

View file

@ -31,13 +31,12 @@
<activity android:name=".activities.BoardActivity"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity android:name=".activities.CreateSeedActivity" >
</activity>
<activity android:name=".activities.AccountSeedsManagementActivity" >
</activity>
<activity android:name=".activities.ImportSeedActivity" >
</activity>
<activity android:name=".activities.CreateSeedActivity"
android:noHistory="true">
</activity>
<activity android:name=".activities.SendTransactionActivity" >
</activity>
<activity android:name=".activities.GeneralSettingsActivity" >

View file

@ -7,13 +7,10 @@ import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@ -23,6 +20,7 @@ import butterknife.OnClick;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel;
//tvBrainKey
public class BackupSeedActivity extends AppCompatActivity {

View file

@ -1,337 +0,0 @@
package cy.agorise.crystalwallet.activities;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.text.Editable;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTextChanged;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.dialogs.material.LoadingDialog;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
import cy.agorise.crystalwallet.requestmanagers.ValidateCreateBitsharesAccountRequest;
import cy.agorise.crystalwallet.models.GrapheneAccount;
import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel;
import cy.agorise.crystalwallet.viewmodels.validators.customImpl.interfaces.UIValidatorListener;
import cy.agorise.crystalwallet.viewmodels.validators.customImpl.validationFields.BitsharesAccountNameValidation;
import cy.agorise.crystalwallet.viewmodels.validators.customImpl.validationFields.CustomValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.customImpl.validationFields.PinDoubleConfirmationValidationField;
import cy.agorise.crystalwallet.views.natives.CustomTextInputEditText;
/*
* Commented code backup
*
*
* alertBuilder.setTitle("Processing");
alertBuilder.setMessage("Creating Bitshares Account");
------
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(CreateSeedActivity.this,R.style.AppTheme);
alertBuilder.setView(R.layout.progress_creating_account);
final AlertDialog processDialog = alertBuilder.create();
CreateSeedActivity.this.runOnUiThread(new Runnable() { //Run on UI Thread
@Override
public void run() {
processDialog.setCancelable(false);
processDialog.show();
processDialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
});
*/
public class CreateSeedActivity extends CustomActivity {
AccountSeedViewModel accountSeedViewModel;
@BindView(R.id.tilPin)
TextInputLayout tilPin;
@BindView(R.id.tietPin)
CustomTextInputEditText tietPin;
@BindView(R.id.tilPinConfirmation)
TextInputLayout tilPinConfirmation;
@BindView(R.id.tietPinConfirmation)
CustomTextInputEditText tietPinConfirmation;
@BindView(R.id.tilAccountName)
TextInputLayout tilAccountName;
@BindView (R.id.tietAccountName)
CustomTextInputEditText tietAccountName;
@BindView(R.id.btnCreate)
Button btnCreate;
@BindView(R.id.btnCancel)
Button btnCancel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_seed);
/*
* Initialice butterknife MVC
* */
ButterKnife.bind(this);
/*This button should not be enabled till all the fields be correctly filled*/
disableCreate();
/*
* Add the controls to the validator
* */
this.fieldsValidator.add(tietPin);
this.fieldsValidator.add(tietPinConfirmation);
this.fieldsValidator.add(tietAccountName);
/*
* Validations listener
* */
final UIValidatorListener uiValidatorListener = new UIValidatorListener() {
@Override
public void onValidationSucceeded(final CustomValidationField customValidationField) {
try{
/*
* Remove error
* */
runOnUiThread(new Runnable() {
@Override
public void run() {
final CustomTextInputEditText customTextInputEditText = (CustomTextInputEditText) customValidationField.getCurrentView();
customTextInputEditText.setError(null);
}
});
}catch (Exception e){
e.printStackTrace();
}
/*
* Validate if can continue
* */
validateFieldsToContinue();
}
@Override
public void onValidationFailed(final CustomValidationField customValidationField) {
/*
* Set error label
* */
runOnUiThread(new Runnable() {
@Override
public void run() {
final CustomTextInputEditText customTextInputEditText = (CustomTextInputEditText) customValidationField.getCurrentView();
customTextInputEditText.setError(customTextInputEditText.getFieldValidatorModel().getMessage());
}
});
}
};
/*
* Create the pin double validation
* */
final PinDoubleConfirmationValidationField pinDoubleConfirmationValidationField = new PinDoubleConfirmationValidationField(this,tietPin,tietPinConfirmation,uiValidatorListener);
/*
* Listener for the validation for success or fail
* */
tietPin.setUiValidator(pinDoubleConfirmationValidationField); //Validator for the field
tietPinConfirmation.setUiValidator(pinDoubleConfirmationValidationField); //Validator for the field
/*
* Account name validator
* */
final BitsharesAccountNameValidation bitsharesAccountNameValidation = new BitsharesAccountNameValidation(this,tietAccountName,uiValidatorListener);
bitsharesAccountNameValidation.setOnAccountExist(new BitsharesAccountNameValidation.OnAccountExist() {
@Override
public void onAccountExists() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(globalActivity,getResources().getString(R.string.account_name_already_exist), Toast.LENGTH_LONG).show();
}
});
}
});
tietAccountName.setUiValidator(bitsharesAccountNameValidation);
/*
* This button initially is not enabled til all the field validation be ok
* */
disableCreate();
accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class);
/*
* Set the focus on the fisrt field and show keyboard
* */
tilPin.requestFocus();
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(tilPin, InputMethodManager.SHOW_IMPLICIT);
}
@OnTextChanged(value = R.id.tietPin,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterPinChanged(Editable editable) {
this.fieldsValidator.validate();
/*
* Validate continue to create account
* */
validateFieldsToContinue();
}
@OnTextChanged(value = R.id.tietPinConfirmation,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterPinConfirmationChanged(Editable editable) {
this.fieldsValidator.validate();
/*
* Validate continue to create account
* */
validateFieldsToContinue();
}
@OnTextChanged(value = R.id.tietAccountName,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterAccountNameChanged(Editable editable) {
this.fieldsValidator.validate();
/*
* Always disable till the server response comes
* */
disableCreate();
}
@OnClick(R.id.btnCancel)
public void cancel(){
/*
* Exit of the activity
* */
this.finish();
}
@OnClick(R.id.btnCreate)
public void createSeed(){
// Make request to create a bitshare account
final ValidateCreateBitsharesAccountRequest request =
new ValidateCreateBitsharesAccountRequest(tietAccountName.getText().toString(), getApplicationContext());
//DTVV: Friday 27 July 2018
//Makes dialog to tell the user that the account is been created
final LoadingDialog creatingAccountMaterialDialog = new LoadingDialog(this);
creatingAccountMaterialDialog.setMessage(this.getResources().getString(R.string.window_create_seed_DialogMessage));
creatingAccountMaterialDialog.build();
CreateSeedActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
creatingAccountMaterialDialog.show();
}
});
request.setListener(new CryptoNetInfoRequestListener() {
@Override
public void onCarryOut() {
creatingAccountMaterialDialog.dismiss();
if (request.getStatus().equals(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED)) {
GrapheneAccount accountSeed = request.getAccount();
Intent intent = new Intent(getApplicationContext(), BackupSeedActivity.class);
intent.putExtra("SEED_ID", accountSeed.getId());
startActivity(intent);
} else {
fieldsValidator.validate();
}
}
});
Thread thread = new Thread() {
@Override
public void run() {
CryptoNetInfoRequests.getInstance().addRequest(request);
}
};
thread.start();
}
/*
* Validate that all is complete to continue to create
* */
private void validateFieldsToContinue(){
boolean result = false; //Contains the final result
boolean pinValid = this.tietPin.getFieldValidatorModel().isValid();
boolean pinConfirmationValid = this.tietPinConfirmation.getFieldValidatorModel().isValid();
boolean pinAccountNameValid = this.tietAccountName.getFieldValidatorModel().isValid();
if(pinValid &&
pinConfirmationValid &&
pinAccountNameValid){
result = true; //Validation is correct
}
/*
* If the result is true so the user can continue to the creation of the account
* */
if(result){
enableCreate();
}
else{
disableCreate();
}
}
/*
* Enable create button
* */
private void enableCreate(){
btnCreate.setEnabled(true);
btnCreate.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
}
/*
* Disable create button
* */
private void disableCreate(){
btnCreate.setEnabled(false);
btnCreate.setBackground(getResources().getDrawable(R.drawable.disable_style));
}
}

View file

@ -7,21 +7,16 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTextChanged;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.GeneralSetting;
import cy.agorise.crystalwallet.util.PasswordManager;
import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel;
import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel;
public class PinRequestActivity extends AppCompatActivity {

View file

@ -1,16 +1,13 @@
package cy.agorise.crystalwallet.fragments;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@ -21,9 +18,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnTextChanged;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.activities.CreateSeedActivity;
import cy.agorise.crystalwallet.application.CrystalSecurityMonitor;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.GeneralSetting;
import cy.agorise.crystalwallet.util.PasswordManager;
import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel;

View file

@ -1,39 +0,0 @@
package cy.agorise.crystalwallet.viewmodels;
import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.LiveData;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.AccountSeed;
/**
* Created by Henry Varona on 27/9/2017.
*/
public class AccountSeedViewModel extends AndroidViewModel {
private LiveData<AccountSeed> accountSeed;
private CrystalDatabase db;
private Application app;
public AccountSeedViewModel(Application application) {
super(application);
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
this.app = application;
}
public void loadSeed(long seedId){
this.accountSeed = this.db.accountSeedDao().findByIdLiveData(seedId);
}
public void addSeed(AccountSeed seed){
long newId = this.db.accountSeedDao().insertAccountSeed(seed);
seed.setId(newId);
}
public LiveData<AccountSeed> getAccountSeed(){
return this.accountSeed;
}
}

View file

@ -74,6 +74,7 @@
android:inputType="text"
android:textSize="20sp"
android:hint="@string/to_capital"
android:maxLength="255"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/gravatar" />