From 6999ad58a1cce0c09cedee44c17fedc7b40a2436 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 27 Mar 2018 21:44:41 -0400 Subject: [PATCH] Change in the request package Put the File Service logic only for bin files --- .../activities/BackupSeedActivity.java | 11 -- .../activities/CreateContactActivity.java | 11 -- .../activities/CreateSeedActivity.java | 17 +-- .../ReceiveTransactionActivity.java | 12 -- .../activities/SendTransactionActivity.java | 11 +- .../dao/CryptoNetAccountDao.java | 3 + .../fragments/ContactSelectionFragment.java | 34 ----- .../fragments/ReceiveTransactionFragment.java | 3 - .../fragments/SendTransactionFragment.java | 11 +- .../manager/BitsharesAccountManager.java | 14 +- .../manager/FileBackupManager.java | 127 ++++++++++++++++++ .../requestmanagers/CreateBackupRequest.java | 32 +++++ .../CryptoNetEquivalentRequest.java | 2 +- .../CryptoNetInfoRequest.java | 4 +- .../CryptoNetInfoRequestListener.java | 2 +- .../CryptoNetInfoRequests.java | 2 +- .../CryptoNetInfoRequestsListener.java | 2 +- .../requestmanagers/FileServiceRequest.java | 37 +++++ .../FileServiceRequestListener.java | 10 ++ .../requestmanagers/FileServiceRequests.java | 56 ++++++++ .../FileServiceRequestsListener.java | 10 ++ .../requestmanagers/ImportBackupRequest.java | 15 +++ .../ValidateBitsharesSendRequest.java | 2 +- ...ValidateCreateBitsharesAccountRequest.java | 2 +- .../ValidateExistBitsharesAccountRequest.java | 2 +- ...ValidateImportBitsharesAccountRequest.java | 2 +- .../service/CrystalWalletService.java | 5 +- .../service/EquivalencesThread.java | 2 +- .../viewmodels/AccountSeedViewModel.java | 6 - .../AmountValidationField.java | 4 - .../AssetValidationField.java | 5 - ...tsharesAccountMnemonicValidationField.java | 6 +- ...ccountNameDoesntExistsValidationField.java | 6 +- .../BitsharesAccountNameValidationField.java | 6 +- .../ContactNameValidationField.java | 13 -- .../validationfields/FromValidationField.java | 7 +- .../validationfields/MemoValidationField.java | 5 - .../validationfields/ToValidationField.java | 6 +- 38 files changed, 331 insertions(+), 174 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/manager/FileBackupManager.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CreateBackupRequest.java rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/CryptoNetEquivalentRequest.java (96%) rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/CryptoNetInfoRequest.java (86%) rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/CryptoNetInfoRequestListener.java (79%) rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/CryptoNetInfoRequests.java (96%) rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/CryptoNetInfoRequestsListener.java (87%) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequest.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequestListener.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequests.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequestsListener.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ImportBackupRequest.java rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/ValidateBitsharesSendRequest.java (97%) rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/ValidateCreateBitsharesAccountRequest.java (97%) rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/ValidateExistBitsharesAccountRequest.java (95%) rename app/src/main/java/cy/agorise/crystalwallet/{cryptonetinforequests => requestmanagers}/ValidateImportBitsharesAccountRequest.java (96%) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java index 2de4db6..7b3c6e5 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BackupSeedActivity.java @@ -5,27 +5,16 @@ import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProviders; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; -import android.text.Editable; -import android.view.ViewGroup; import android.widget.Button; -import android.widget.EditText; import android.widget.TextView; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAccountRequest; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel; -import cy.agorise.crystalwallet.viewmodels.validators.CreateSeedValidator; -import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; -import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; public class BackupSeedActivity extends AppCompatActivity { diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateContactActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateContactActivity.java index fcb1469..8db5e8d 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateContactActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateContactActivity.java @@ -3,17 +3,13 @@ package cy.agorise.crystalwallet.activities; import android.arch.lifecycle.LiveData; import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProviders; -import android.content.Intent; import android.support.annotation.Nullable; -import android.support.v4.app.FragmentActivity; -import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Editable; import android.view.View; -import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; @@ -26,21 +22,14 @@ import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAccountRequest; import cy.agorise.crystalwallet.models.Contact; import cy.agorise.crystalwallet.models.ContactAddress; -import cy.agorise.crystalwallet.models.GrapheneAccount; -import cy.agorise.crystalwallet.viewmodels.ContactListViewModel; import cy.agorise.crystalwallet.viewmodels.ContactViewModel; import cy.agorise.crystalwallet.viewmodels.validators.CreateContactValidator; -import cy.agorise.crystalwallet.viewmodels.validators.CreateSeedValidator; import cy.agorise.crystalwallet.viewmodels.validators.ModifyContactValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.views.ContactAddressListAdapter; -import cy.agorise.crystalwallet.views.ContactViewHolder; public class CreateContactActivity extends AppCompatActivity implements UIValidatorListener { diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java index 8eca7a1..1718203 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java @@ -10,32 +10,21 @@ import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.view.ViewGroup; import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAccountRequest; -import cy.agorise.crystalwallet.enums.SeedType; -import cy.agorise.crystalwallet.models.AccountSeed; -import cy.agorise.crystalwallet.models.CryptoNetAccount; +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.models.GrapheneAccountInfo; import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel; -import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; -import cy.agorise.crystalwallet.viewmodels.GrapheneAccountInfoViewModel; import cy.agorise.crystalwallet.viewmodels.validators.CreateSeedValidator; -import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; -import static cy.agorise.crystalwallet.enums.SeedType.BIP39; - public class CreateSeedActivity extends AppCompatActivity implements UIValidatorListener { AccountSeedViewModel accountSeedViewModel; diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/ReceiveTransactionActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/ReceiveTransactionActivity.java index 6e4f266..f8bd04b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/ReceiveTransactionActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/ReceiveTransactionActivity.java @@ -5,30 +5,18 @@ import android.arch.lifecycle.Observer; 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.Spinner; import android.widget.TextView; import java.util.ArrayList; import java.util.List; -import butterknife.BindView; import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnItemSelected; -import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.GrapheneAccount; -import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; -import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; -import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; public class ReceiveTransactionActivity extends AppCompatActivity { diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java index 01d26b4..f1783e3 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java @@ -2,15 +2,12 @@ package cy.agorise.crystalwallet.activities; 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.v7.app.AppCompatActivity; import android.text.Editable; -import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; -import android.widget.SimpleAdapter; import android.widget.Spinner; import android.widget.TextView; @@ -23,18 +20,12 @@ import butterknife.OnClick; import butterknife.OnItemSelected; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; +import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.dao.CrystalDatabase; -import cy.agorise.crystalwallet.enums.CryptoNet; -import cy.agorise.crystalwallet.enums.SeedType; -import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.GrapheneAccount; -import cy.agorise.crystalwallet.models.GrapheneAccountInfo; -import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; -import cy.agorise.crystalwallet.viewmodels.GrapheneAccountInfoViewModel; import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java index 8875da5..f987a69 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java @@ -26,6 +26,9 @@ public interface CryptoNetAccountDao { @Query("SELECT cna.* FROM crypto_net_account cna") List getAllCryptoNetAccount(); + @Query("SELECT cna.* FROM crypto_net_account cna WHERE seed_id = :seedId") + List getAllCryptoNetAccountBySeed( long seedId); + @Query("SELECT * FROM crypto_net_account WHERE id = :accountId") LiveData getByIdLiveData( long accountId); diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactSelectionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactSelectionFragment.java index 46576d5..5f6f483 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactSelectionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactSelectionFragment.java @@ -5,59 +5,25 @@ import android.arch.lifecycle.LiveData; import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProviders; import android.arch.paging.PagedList; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.design.widget.FloatingActionButton; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.text.Editable; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.Spinner; -import android.widget.TextView; - -import com.google.zxing.Result; - -import java.util.ArrayList; -import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnItemSelected; -import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.models.Contact; -import cy.agorise.crystalwallet.models.CryptoCoinBalance; -import cy.agorise.crystalwallet.models.CryptoCurrency; -import cy.agorise.crystalwallet.models.CryptoNetAccount; -import cy.agorise.crystalwallet.models.GrapheneAccount; import cy.agorise.crystalwallet.viewmodels.ContactListViewModel; -import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel; -import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; -import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; -import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.views.ContactSelectionListAdapter; -import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; -import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter; -import me.dm7.barcodescanner.zxing.ZXingScannerView; public class ContactSelectionFragment extends DialogFragment implements ContactSelectionListAdapter.ContactSelectionListAdapterListener{ diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java index db94f95..9398816 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java @@ -1,7 +1,6 @@ package cy.agorise.crystalwallet.fragments; import android.app.Dialog; -import android.app.LauncherActivity; import android.arch.lifecycle.LiveData; import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProviders; @@ -43,14 +42,12 @@ import butterknife.ButterKnife; import butterknife.OnItemSelected; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.GrapheneAccount; import cy.agorise.crystalwallet.viewmodels.validators.ReceiveTransactionValidator; -import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java index c73b340..d3bbf8c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -15,20 +15,17 @@ import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; -import android.view.animation.LinearInterpolator; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; -import android.widget.Toast; import com.google.zxing.Result; @@ -45,11 +42,10 @@ import butterknife.OnClick; import butterknife.OnItemSelected; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.dao.CrystalDatabase; -import cy.agorise.crystalwallet.models.Contact; import cy.agorise.crystalwallet.models.ContactAddress; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCurrency; @@ -57,7 +53,6 @@ import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.GrapheneAccount; import cy.agorise.crystalwallet.viewmodels.ContactViewModel; import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel; -import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index abdd5e4..816865c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -18,13 +18,13 @@ import cy.agorise.crystalwallet.apigenerator.ApiRequestListener; import cy.agorise.crystalwallet.apigenerator.BitsharesFaucetApiGenerator; import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator; import cy.agorise.crystalwallet.application.constant.BitsharesConstant; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetEquivalentRequest; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest; -import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAccountRequest; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetEquivalentRequest; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestsListener; +import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest; +import cy.agorise.crystalwallet.requestmanagers.ValidateCreateBitsharesAccountRequest; +import cy.agorise.crystalwallet.requestmanagers.ValidateExistBitsharesAccountRequest; +import cy.agorise.crystalwallet.requestmanagers.ValidateImportBitsharesAccountRequest; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.dao.TransactionDao; import cy.agorise.crystalwallet.enums.CryptoNet; diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/FileBackupManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/FileBackupManager.java new file mode 100644 index 0000000..67ff6d3 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/FileBackupManager.java @@ -0,0 +1,127 @@ +package cy.agorise.crystalwallet.manager; + +import android.app.Activity; +import android.os.Environment; +import android.util.Log; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.List; + +import cy.agorise.crystalwallet.application.CrystalApplication; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.requestmanagers.CreateBackupRequest; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest; +import cy.agorise.crystalwallet.requestmanagers.FileServiceRequest; +import cy.agorise.crystalwallet.requestmanagers.FileServiceRequestsListener; +import cy.agorise.graphenej.BrainKey; +import cy.agorise.graphenej.Chains; +import cy.agorise.graphenej.FileBin; +import cy.agorise.graphenej.models.backup.LinkedAccount; +import cy.agorise.graphenej.models.backup.PrivateKeyBackup; +import cy.agorise.graphenej.models.backup.Wallet; +import cy.agorise.graphenej.models.backup.WalletBackup; + +/** + * Created by henry on 21/3/2018. + */ + +public class FileBackupManager implements FileServiceRequestsListener { + + @Override + public void onNewRequest(FileServiceRequest request) { + if(request instanceof CreateBackupRequest){ + createBackupBinFile((CreateBackupRequest) request); + } + } + + public void createBackupBinFile(CreateBackupRequest request) + { + CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext()); + db.cryptoNetAccountDao().getAllCryptoNetAccountBySeed(request.getSeed().getId()); + + /*TinyDB tinyDB = new TinyDB(myActivity); + ArrayList accountDetails = tinyDB.getListObject(myActivity.getResources().getString(R.string.pref_wallet_accounts), AccountDetails.class); + String _brnKey = getBrainKey(accountDetails); + String _accountName = getAccountName(accountDetails); + String _pinCode = getPin(accountDetails); + + getBinBytesFromBrainkey(_pinCode, _brnKey, _accountName);*/ + } + + public void getBinBytesFromBrainkey(String pin, String brnKey, String accountName, CreateBackupRequest request) { + BrainKey brainKey = new BrainKey(brnKey, 0); + try { + ArrayList wallets = new ArrayList<>(); + ArrayList accounts = new ArrayList<>(); + ArrayList keys = new ArrayList<>(); + + Wallet wallet = new Wallet(accountName, brainKey.getBrainKey(), brainKey.getSequenceNumber(), Chains.BITSHARES.CHAIN_ID, pin); + wallets.add(wallet); + + PrivateKeyBackup keyBackup = new PrivateKeyBackup(brainKey.getPrivateKey().getPrivKeyBytes(), + brainKey.getSequenceNumber(), brainKey.getSequenceNumber(), wallet.getEncryptionKey(pin)); + keys.add(keyBackup); + + LinkedAccount linkedAccount = new LinkedAccount(accountName, Chains.BITSHARES.CHAIN_ID); + accounts.add(linkedAccount); + + WalletBackup backup = new WalletBackup(wallets, keys, accounts); + byte[] results = FileBin.serializeWalletBackup(backup, pin); + List resultFile = new ArrayList<>(); + for(byte result: results){ + resultFile.add(result & 0xff); + } + saveBinContentToFile(resultFile, accountName, request); + } + catch (Exception e) { + + //TODO error exception + + } + } + static void saveBinContentToFile(List content, String _accountName, CreateBackupRequest request ) + { + + String folder = Environment.getExternalStorageDirectory() + File.separator + "Crystal"; //TODO make constant + String path = folder + File.separator + _accountName + ".bin"; + + boolean success = saveBinFile(path,content,request); + //TODO handle sucess + } + + private static boolean saveBinFile (String filePath , List content, CreateBackupRequest request) + { + boolean success = false; + try + { + //TODO permissions + // PermissionManager Manager = new PermissionManager(); + // Manager.verifyStoragePermissions(_activity); + + File file = new File(filePath); + byte[] fileData = new byte[content.size()]; + + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); + + for ( int i = 0 ; i < content.size() ; i++ ) + { + fileData[i] = content.get(i).byteValue(); + } + + bos.write(fileData); + bos.flush(); + bos.close(); + + success = true; + } + catch (Exception e) + { + //TODO handle error + } + + return success; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CreateBackupRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CreateBackupRequest.java new file mode 100644 index 0000000..28942b4 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CreateBackupRequest.java @@ -0,0 +1,32 @@ +package cy.agorise.crystalwallet.requestmanagers; + +import android.app.Activity; +import android.content.Context; + +import cy.agorise.crystalwallet.models.AccountSeed; + +/** + * Created by henry on 26/3/2018. + */ + +public class CreateBackupRequest extends FileServiceRequest { + + private AccountSeed seed; + + enum StatusCode{ + + + + } + + public CreateBackupRequest(Context context, Activity activity, AccountSeed seed) { + super(context, activity); + this.seed = seed; + } + + public AccountSeed getSeed() { + return seed; + } + + +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetEquivalentRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetEquivalentRequest.java similarity index 96% rename from app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetEquivalentRequest.java rename to app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetEquivalentRequest.java index e24f573..660e70f 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetEquivalentRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetEquivalentRequest.java @@ -1,4 +1,4 @@ -package cy.agorise.crystalwallet.cryptonetinforequests; +package cy.agorise.crystalwallet.requestmanagers; import android.content.Context; diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequest.java similarity index 86% rename from app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequest.java rename to app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequest.java index 33c9815..6a207b6 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequest.java @@ -1,4 +1,4 @@ -package cy.agorise.crystalwallet.cryptonetinforequests; +package cy.agorise.crystalwallet.requestmanagers; import cy.agorise.crystalwallet.enums.CryptoCoin; @@ -19,7 +19,7 @@ public abstract class CryptoNetInfoRequest { */ protected CryptoNetInfoRequestListener listener; - public CryptoNetInfoRequest(CryptoCoin coin){ + protected CryptoNetInfoRequest(CryptoCoin coin){ this.coin = coin; } diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestListener.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequestListener.java similarity index 79% rename from app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestListener.java rename to app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequestListener.java index 72f5a65..475ee00 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestListener.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequestListener.java @@ -1,4 +1,4 @@ -package cy.agorise.crystalwallet.cryptonetinforequests; +package cy.agorise.crystalwallet.requestmanagers; /** * Listener for manager request diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequests.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequests.java similarity index 96% rename from app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequests.java rename to app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequests.java index 92e34a1..a0b7040 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequests.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequests.java @@ -1,4 +1,4 @@ -package cy.agorise.crystalwallet.cryptonetinforequests; +package cy.agorise.crystalwallet.requestmanagers; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestsListener.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequestsListener.java similarity index 87% rename from app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestsListener.java rename to app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequestsListener.java index 82c234c..2001503 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/CryptoNetInfoRequestsListener.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/CryptoNetInfoRequestsListener.java @@ -1,4 +1,4 @@ -package cy.agorise.crystalwallet.cryptonetinforequests; +package cy.agorise.crystalwallet.requestmanagers; /** * Listener extends for the manager classes diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequest.java new file mode 100644 index 0000000..b6c0af3 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequest.java @@ -0,0 +1,37 @@ +package cy.agorise.crystalwallet.requestmanagers; + +import android.app.Activity; +import android.content.Context; + +/** + * Created by henry on 26/3/2018. + */ + +public abstract class FileServiceRequest { + + protected Context context; + protected Activity activity; + + protected FileServiceRequest(Context context, Activity activity) { + this.context = context; + this.activity = activity; + } + + protected FileServiceRequestListener listener; + + public void setListener(FileServiceRequestListener listener){ + this.listener = listener; + } + + public Context getContext() { + return context; + } + + public Activity getActivity() { + return activity; + } + + protected void _fireOnCarryOutEvent(){ + listener.onCarryOut(); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequestListener.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequestListener.java new file mode 100644 index 0000000..7a2cc89 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequestListener.java @@ -0,0 +1,10 @@ +package cy.agorise.crystalwallet.requestmanagers; + +/** + * Created by henry on 26/3/2018. + */ + +public interface FileServiceRequestListener { + + public void onCarryOut(); +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequests.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequests.java new file mode 100644 index 0000000..9a56692 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/FileServiceRequests.java @@ -0,0 +1,56 @@ +package cy.agorise.crystalwallet.requestmanagers; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by henry on 26/3/2018. + */ + +public class FileServiceRequests { + + private List requests; + private List listeners; + private static FileServiceRequests instance; + + + /** + * Private constructor for singleton pattern + */ + private FileServiceRequests() { + } + + /** + * Gets an instance of this manager + * @return the instance to manage the cryptonetinforequest + */ + public static FileServiceRequests getInstance(){ + if (FileServiceRequests.instance == null){ + FileServiceRequests.instance = new FileServiceRequests(); + FileServiceRequests.instance.requests = new ArrayList<>(); + FileServiceRequests.instance.listeners = new ArrayList<>(); + } + + return FileServiceRequests.instance; + } + + public void addRequest(FileServiceRequest request){ + this.requests.add(request); + + this._fireNewRequestEvent(request); + } + + public void removeRequest(FileServiceRequest request){ + this.requests.remove(request); + } + + public void addListener(FileServiceRequestsListener listener){ + this.listeners.add(listener); + } + + private void _fireNewRequestEvent(FileServiceRequest request){ + for (int i=0;i