From 5965528abefffa2942a03d3d5e66954a4db7cb9b Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 31 Oct 2018 22:19:15 -0400 Subject: [PATCH] - Once again, the list of accounts in the profiles settings are really account seeds - When an account seed is pressed, the seeds settings show the mnemonic words and a new tab for the coin settings - The coin settings allow the user to activate a coin account like bitcoin --- app/src/main/AndroidManifest.xml | 4 + .../AccountSeedSettingsActivity.java | 134 ++++++++++++++++++ .../activities/AccountsActivity.java | 22 +-- .../CryptoNetAccountSettingsActivity.java | 1 + ...oNetAccountActivationSettingsFragment.java | 127 +++++++++++++++++ ...eneralAccountSeedCoinSettingsFragment.java | 116 +++++++++++++++ .../fragments/GeneralAccountSeedFragment.java | 122 ++++++++++++++++ .../models/CryptoNetSelection.java | 45 ++++++ .../views/AccountSeedViewHolder.java | 3 +- .../views/CryptoNetSelectionListAdapter.java | 91 ++++++++++++ .../views/CryptoNetSelectionViewHolder.java | 64 +++++++++ .../layout/account_seed_activity_settings.xml | 124 ++++++++++++++++ app/src/main/res/layout/activity_accounts.xml | 22 ++- .../res/layout/crypto_net_selection_item.xml | 31 ++++ ...ent_general_account_seed_coin_settings.xml | 23 +++ 15 files changed, 913 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/activities/AccountSeedSettingsActivity.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/fragments/CryptoNetAccountActivationSettingsFragment.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralAccountSeedCoinSettingsFragment.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralAccountSeedFragment.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetSelection.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetSelectionListAdapter.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetSelectionViewHolder.java create mode 100644 app/src/main/res/layout/account_seed_activity_settings.xml create mode 100644 app/src/main/res/layout/crypto_net_selection_item.xml create mode 100644 app/src/main/res/layout/fragment_general_account_seed_coin_settings.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8739183..b3b545f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -40,6 +40,10 @@ + + diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/AccountSeedSettingsActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/AccountSeedSettingsActivity.java new file mode 100644 index 0000000..8d7b736 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/AccountSeedSettingsActivity.java @@ -0,0 +1,134 @@ +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.design.widget.TabLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.view.ViewPager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.fragments.BitsharesSettingsFragment; +import cy.agorise.crystalwallet.fragments.GeneralAccountSeedCoinSettingsFragment; +import cy.agorise.crystalwallet.fragments.GeneralAccountSeedFragment; +import cy.agorise.crystalwallet.fragments.GeneralCryptoNetAccountSettingsFragment; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel; +import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; + +/** + * Created by henry varona on 10/29/18. + * + */ + +public class AccountSeedSettingsActivity extends AppCompatActivity{ + + @BindView(R.id.ivGoBack) + public ImageView ivGoBack; + + @BindView(R.id.pager) + public ViewPager mPager; + + public SettingsPagerAdapter settingsPagerAdapter; + + + @BindView(R.id.tvBuildVersion) + public TextView tvBuildVersion; + + @BindView(R.id.tabs) + public TabLayout tabs; + + private AccountSeed accountSeed; + + @BindView(R.id.ivAppBarAnimation) + ImageView ivAppBarAnimation; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.account_seed_activity_settings); + ButterKnife.bind(this); + final AccountSeedSettingsActivity thisActivity = this; + + long accountSeedId = getIntent().getLongExtra("SEED_ID",-1); + + if (accountSeedId > -1) { + AccountSeedViewModel accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); + accountSeedViewModel.loadSeed(accountSeedId); + LiveData accountSeedLiveData = accountSeedViewModel.getAccountSeed(); + + accountSeedLiveData.observe(this, new Observer() { + @Override + public void onChanged(@Nullable AccountSeed accountSeed) { + thisActivity.accountSeed = accountSeed; + + settingsPagerAdapter = new SettingsPagerAdapter(getSupportFragmentManager()); + mPager.setAdapter(settingsPagerAdapter); + + TabLayout tabLayout = findViewById(R.id.tabs); + + mPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); + tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mPager)); + } + }); + + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + // Sets AppBar animation + Glide.with(this) + .load(R.drawable.appbar_background) + .apply(new RequestOptions().centerCrop()) + .into(ivAppBarAnimation); + + + } else { + this.finish(); + } + } + + private class SettingsPagerAdapter extends FragmentStatePagerAdapter { + SettingsPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int position) { + switch (position){ + case 0: + return GeneralAccountSeedFragment.newInstance(accountSeed.getId()); + case 1: + return GeneralAccountSeedCoinSettingsFragment.newInstance(accountSeed.getId()); + } + + return null; + } + + @Override + public int getCount() { + int tabCount = 2; + + return tabCount; + } + } + + @OnClick(R.id.ivGoBack) + public void goBack(){ + onBackPressed(); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java index 0196bba..a7c68d6 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/AccountsActivity.java @@ -57,8 +57,11 @@ public class AccountsActivity extends AppCompatActivity { @BindView(R.id.tvClose) TextView tvClose; - @BindView(R.id.vAccountList) - CryptoNetAccountListView vAccountList; + //@BindView(R.id.vAccountList) + //CryptoNetAccountListView vAccountList; + + @BindView(R.id.vAccountSeedList) + AccountSeedListView vAccountSeedList; @BindView(R.id.user_img) CircleImageView userImg; @@ -88,14 +91,17 @@ public class AccountsActivity extends AppCompatActivity { } ); - CryptoNetAccountListViewModel crytpoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class); - LiveData> accountData = crytpoNetAccountListViewModel.getCryptoNetAccounts(); - vAccountList.setData(null); + AccountSeedListViewModel accountSeedListViewModel = ViewModelProviders.of(this).get(AccountSeedListViewModel.class); + LiveData> accountSeedLD = accountSeedListViewModel.getAccountSeedList(); - accountData.observe(this, new Observer>() { + //CryptoNetAccountListViewModel crytpoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class); + //LiveData> accountData = crytpoNetAccountListViewModel.getCryptoNetAccounts(); + vAccountSeedList.setData(null); + + accountSeedLD.observe(this, new Observer>() { @Override - public void onChanged(List cryptoNetAccounts) { - vAccountList.setData(cryptoNetAccounts); + public void onChanged(List accountsSeeds) { + vAccountSeedList.setData(accountsSeeds); } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CryptoNetAccountSettingsActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/CryptoNetAccountSettingsActivity.java index 9406ff0..a791019 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CryptoNetAccountSettingsActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CryptoNetAccountSettingsActivity.java @@ -27,6 +27,7 @@ import butterknife.OnClick; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.fragments.BackupsSettingsFragment; import cy.agorise.crystalwallet.fragments.BitsharesSettingsFragment; +import cy.agorise.crystalwallet.fragments.CryptoNetAccountActivationSettingsFragment; import cy.agorise.crystalwallet.fragments.GeneralCryptoNetAccountSettingsFragment; import cy.agorise.crystalwallet.fragments.GeneralSettingsFragment; import cy.agorise.crystalwallet.fragments.SecuritySettingsFragment; diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/CryptoNetAccountActivationSettingsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/CryptoNetAccountActivationSettingsFragment.java new file mode 100644 index 0000000..9ac3dcf --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/CryptoNetAccountActivationSettingsFragment.java @@ -0,0 +1,127 @@ +package cy.agorise.crystalwallet.fragments; + +import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.thekhaeng.pushdownanim.PushDownAnim; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + + +/** + * Created by xd on 12/28/17. + */ + +public class CryptoNetAccountActivationSettingsFragment extends Fragment { + + @BindView(R.id.tvMnemonic) + TextView tvMnemonic; + + @BindView(R.id.btnCopy) + Button btnCopy; + + CryptoNetAccount cryptoNetAccount; + AccountSeed accountSeed; + + + + + public CryptoNetAccountActivationSettingsFragment() { + + if (getArguments() != null) { + long cryptoNetAcountId = getArguments().getLong("CRYPTO_NET_ACCOUNT_ID", -1); + + if (cryptoNetAcountId > -1) { + this.cryptoNetAccount = CrystalDatabase.getAppDatabase(getContext()).cryptoNetAccountDao().getById(cryptoNetAcountId); + this.accountSeed = CrystalDatabase.getAppDatabase(getContext()).accountSeedDao().findById(this.cryptoNetAccount.getSeedId()); + } + } + // Required empty public constructor + } + + public static CryptoNetAccountActivationSettingsFragment newInstance(long cryptoNetAccountId) { + CryptoNetAccountActivationSettingsFragment fragment = new CryptoNetAccountActivationSettingsFragment(); + Bundle args = new Bundle(); + args.putLong("CRYPTO_NET_ACCOUNT_ID", cryptoNetAccountId); + fragment.setArguments(args); + + + if (cryptoNetAccountId > -1){ + fragment.cryptoNetAccount = CrystalDatabase.getAppDatabase(fragment.getContext()).cryptoNetAccountDao().getById(cryptoNetAccountId); + fragment.accountSeed = CrystalDatabase.getAppDatabase(fragment.getContext()).accountSeedDao().findById(fragment.cryptoNetAccount.getSeedId()); + } + + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View v = inflater.inflate(R.layout.fragment_general_crypto_net_account_settings, container, false); + ButterKnife.bind(this, v); + + /* + * Integration of library with button efects + * */ + PushDownAnim.setPushDownAnimTo(btnCopy) + .setOnClickListener( new View.OnClickListener(){ + @Override + public void onClick( View view ){ + btnCopyClick(); + } + + } ); + + initAlreadyLtm(); + + return v; + } + + public void initAlreadyLtm(){ + if (this.cryptoNetAccount != null) { + tvMnemonic.setText(this.accountSeed.getMasterSeed()); + } + } + + /* + * Clic on button copy to clipboard + * */ + @OnClick(R.id.btnCopy) + public void btnCopyClick(){ + + /* + * Save to clipboard the brainkey chain + * */ + final Activity activity = getActivity(); + ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText(tvMnemonic.getText(), tvMnemonic.getText().toString()); + clipboard.setPrimaryClip(clip); + + /* + * Success message + * */ + Toast.makeText(activity,getResources().getString(R.string.window_seed_toast_clipboard), Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralAccountSeedCoinSettingsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralAccountSeedCoinSettingsFragment.java new file mode 100644 index 0000000..45917d1 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralAccountSeedCoinSettingsFragment.java @@ -0,0 +1,116 @@ +package cy.agorise.crystalwallet.fragments; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Toast; + +import java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.enums.CryptoNet; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetSelection; +import cy.agorise.crystalwallet.requestmanagers.CreateBitcoinAccountRequest; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.views.CryptoNetSelectionListAdapter; + + +/** + * Created by xd on 12/28/17. + */ + +public class GeneralAccountSeedCoinSettingsFragment extends Fragment implements CryptoNetSelectionListAdapter.CryptoNetSelectionListener { + + @BindView(R.id.rvCoinSelection) + RecyclerView rvCoinSelection; + + AccountSeed accountSeed; + + ArrayList cryptoNetSelectionList; + + public GeneralAccountSeedCoinSettingsFragment() { + + if (getArguments() != null) { + long accountSeedId = getArguments().getLong("SEED_ID", -1); + + if (accountSeedId > -1) { + this.accountSeed = CrystalDatabase.getAppDatabase(getContext()).accountSeedDao().findById(accountSeedId); + } + } + + cryptoNetSelectionList = new ArrayList(); + CryptoNetSelection nextCryptoNetSelection; + for (CryptoNet nextCryptoNet : CryptoNet.values()){ + + if ((nextCryptoNet != CryptoNet.UNKNOWN) && (nextCryptoNet != CryptoNet.BITCOIN_TEST)) { + nextCryptoNetSelection = new CryptoNetSelection(nextCryptoNet, false); + cryptoNetSelectionList.add(nextCryptoNetSelection); + } + } + // Required empty public constructor + } + + public static GeneralAccountSeedCoinSettingsFragment newInstance(long accountSeedId) { + GeneralAccountSeedCoinSettingsFragment fragment = new GeneralAccountSeedCoinSettingsFragment(); + Bundle args = new Bundle(); + args.putLong("SEED_ID", accountSeedId); + fragment.setArguments(args); + + + if (accountSeedId > -1){ + fragment.accountSeed = CrystalDatabase.getAppDatabase(fragment.getContext()).accountSeedDao().findById(accountSeedId); + } + + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View v = inflater.inflate(R.layout.fragment_general_account_seed_coin_settings, container, false); + ButterKnife.bind(this, v); + + CryptoNetSelectionListAdapter cryptoNetSelectionListAdapter = new CryptoNetSelectionListAdapter(this.cryptoNetSelectionList); + cryptoNetSelectionListAdapter.addListener(this); + rvCoinSelection.setAdapter(cryptoNetSelectionListAdapter); + LinearLayoutManager llm = new LinearLayoutManager(this.getContext()); + llm.setOrientation(LinearLayoutManager.VERTICAL); + rvCoinSelection.setLayoutManager(llm); + + return v; + } + + @Override + public void onCryptoNetSelectionChecked(CryptoNetSelection source) { + //Toast.makeText(this.getContext(),"the coin "+source.getCryptoNet().name()+" was "+(source.getSelected()?"selected":"unselected"),Toast.LENGTH_LONG).show(); + final CreateBitcoinAccountRequest request = new CreateBitcoinAccountRequest(this.accountSeed,this.getContext(),source.getCryptoNet()); + + request.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (request.getStatus() == CreateBitcoinAccountRequest.StatusCode.SUCCEEDED){ + Toast.makeText(getContext(),"The account was successfully created",Toast.LENGTH_LONG); + } else { + Toast.makeText(getContext(),"There was an error enabling the account",Toast.LENGTH_LONG); + } + } + }); + + CryptoNetInfoRequests.getInstance().addRequest(request); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralAccountSeedFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralAccountSeedFragment.java new file mode 100644 index 0000000..12cfa66 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralAccountSeedFragment.java @@ -0,0 +1,122 @@ +package cy.agorise.crystalwallet.fragments; + +import android.app.Activity; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.thekhaeng.pushdownanim.PushDownAnim; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + + +/** + * Created by xd on 12/28/17. + */ + +public class GeneralAccountSeedFragment extends Fragment { + + @BindView(R.id.tvMnemonic) + TextView tvMnemonic; + + @BindView(R.id.btnCopy) + Button btnCopy; + + AccountSeed accountSeed; + + + + + public GeneralAccountSeedFragment() { + + if (getArguments() != null) { + long accountSeedId = getArguments().getLong("SEED_ID", -1); + + if (accountSeedId > -1) { + this.accountSeed = CrystalDatabase.getAppDatabase(getContext()).accountSeedDao().findById(accountSeedId); + } + } + // Required empty public constructor + } + + public static GeneralAccountSeedFragment newInstance(long accountSeedId) { + GeneralAccountSeedFragment fragment = new GeneralAccountSeedFragment(); + Bundle args = new Bundle(); + args.putLong("SEED_ID", accountSeedId); + fragment.setArguments(args); + + + if (accountSeedId > -1){ + fragment.accountSeed = CrystalDatabase.getAppDatabase(fragment.getContext()).accountSeedDao().findById(accountSeedId); + } + + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View v = inflater.inflate(R.layout.fragment_general_crypto_net_account_settings, container, false); + ButterKnife.bind(this, v); + + /* + * Integration of library with button efects + * */ + PushDownAnim.setPushDownAnimTo(btnCopy) + .setOnClickListener( new View.OnClickListener(){ + @Override + public void onClick( View view ){ + btnCopyClick(); + } + + } ); + + initAlreadyLtm(); + + return v; + } + + public void initAlreadyLtm(){ + tvMnemonic.setText(this.accountSeed.getMasterSeed()); + } + + /* + * Clic on button copy to clipboard + * */ + @OnClick(R.id.btnCopy) + public void btnCopyClick(){ + + /* + * Save to clipboard the brainkey chain + * */ + final Activity activity = getActivity(); + ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText(tvMnemonic.getText(), tvMnemonic.getText().toString()); + clipboard.setPrimaryClip(clip); + + /* + * Success message + * */ + Toast.makeText(activity,getResources().getString(R.string.window_seed_toast_clipboard), Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetSelection.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetSelection.java new file mode 100644 index 0000000..515c20d --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetSelection.java @@ -0,0 +1,45 @@ +package cy.agorise.crystalwallet.models; + +import android.support.annotation.NonNull; +import android.support.v7.util.DiffUtil; + +import cy.agorise.crystalwallet.enums.CryptoNet; + +public class CryptoNetSelection { + CryptoNet cryptoNet; + Boolean selected; + + public CryptoNetSelection(CryptoNet cryptoNet, Boolean selected) { + this.cryptoNet = cryptoNet; + this.selected = selected; + } + + public CryptoNet getCryptoNet() { + return cryptoNet; + } + + public void setCryptoNet(CryptoNet cryptoNet) { + this.cryptoNet = cryptoNet; + } + + public Boolean getSelected() { + return selected; + } + + public void setSelected(Boolean selected) { + this.selected = selected; + } + + public static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { + @Override + public boolean areItemsTheSame( + @NonNull CryptoNetSelection oldCryptoNetSelection, @NonNull CryptoNetSelection newCryptoNetSelection) { + return oldCryptoNetSelection.getCryptoNet() == newCryptoNetSelection.getCryptoNet(); + } + @Override + public boolean areContentsTheSame( + @NonNull CryptoNetSelection oldCryptoNetSelection, @NonNull CryptoNetSelection newCryptoNetSelection) { + return oldCryptoNetSelection.equals(newCryptoNetSelection); + } + }; +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/AccountSeedViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/AccountSeedViewHolder.java index 47e1325..f25d932 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/AccountSeedViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/AccountSeedViewHolder.java @@ -7,6 +7,7 @@ import android.view.View; import android.widget.TextView; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.activities.AccountSeedSettingsActivity; import cy.agorise.crystalwallet.activities.BackupSeedActivity; import cy.agorise.crystalwallet.activities.SettingsActivity; import cy.agorise.crystalwallet.models.AccountSeed; @@ -39,7 +40,7 @@ public class AccountSeedViewHolder extends RecyclerView.ViewHolder { tvAccountSeedName.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Intent intent = new Intent(context, BackupSeedActivity.class); + Intent intent = new Intent(context, AccountSeedSettingsActivity.class); intent.putExtra("SEED_ID", accountSeed.getId()); context.startActivity(intent); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetSelectionListAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetSelectionListAdapter.java new file mode 100644 index 0000000..efed1ae --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetSelectionListAdapter.java @@ -0,0 +1,91 @@ +package cy.agorise.crystalwallet.views; + + +import android.support.annotation.NonNull; +import android.support.v7.recyclerview.extensions.ListAdapter; +import android.support.v7.util.DiffUtil; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.TextView; +import android.widget.Toast; + +import org.tukaani.xz.check.Check; + +import java.util.ArrayList; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; +import cy.agorise.crystalwallet.models.CryptoNetSelection; + +/** + * Created by Henry Varona on 10/30/2018. + * + */ + +public class CryptoNetSelectionListAdapter extends ListAdapter { + + private ArrayList cryptoNetSelections = new ArrayList(); + private ArrayList listeners = new ArrayList<>(); + + public CryptoNetSelectionListAdapter(ArrayList cryptoNetSelections) { + super(CryptoNetSelection.DIFF_CALLBACK); + this.cryptoNetSelections = cryptoNetSelections; + } + + public CryptoNetSelection findCryptoNetSelectionByName(String name){ + for(CryptoNetSelection nextCryptoNetSelection : this.cryptoNetSelections){ + if (nextCryptoNetSelection.getCryptoNet().getLabel().equals(name)){ + return nextCryptoNetSelection; + } + } + + return null; + } + + @NonNull + @Override + public CryptoNetSelectionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.crypto_net_selection_item,parent,false); + final CheckBox cbCryptoNetSelected = v.findViewById(R.id.cbCryptoNetSelected); + final TextView tvCryptoNetName = v.findViewById(R.id.tvCryptoNetName); + + cbCryptoNetSelected.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + CryptoNetSelection cryptoNetSelection = findCryptoNetSelectionByName(tvCryptoNetName.getText().toString()); + cryptoNetSelection.setSelected(b); + _fireOnChecked(cryptoNetSelection); + } + }); + + + return new CryptoNetSelectionViewHolder(v); + } + + @Override + public int getItemCount() { + return cryptoNetSelections.size(); + } + + @Override + public void onBindViewHolder(@NonNull CryptoNetSelectionViewHolder holder, int position) { + holder.bindTo(cryptoNetSelections.get(position)); + } + + public void addListener(CryptoNetSelectionListener listener){ + this.listeners.add(listener); + } + + public void _fireOnChecked(CryptoNetSelection selection){ + for(CryptoNetSelectionListener listener:this.listeners){ + listener.onCryptoNetSelectionChecked(selection); + } + } + + public interface CryptoNetSelectionListener{ + public void onCryptoNetSelectionChecked(CryptoNetSelection source); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetSelectionViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetSelectionViewHolder.java new file mode 100644 index 0000000..e079993 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetSelectionViewHolder.java @@ -0,0 +1,64 @@ +package cy.agorise.crystalwallet.views; + +import android.arch.lifecycle.LifecycleOwner; +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.Observer; +import android.content.Context; +import android.support.annotation.Nullable; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.CheckBox; +import android.widget.TextView; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; +import cy.agorise.crystalwallet.models.CryptoCurrency; +import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; +import cy.agorise.crystalwallet.models.CryptoNetSelection; +import cy.agorise.crystalwallet.models.GeneralSetting; + +/** + * Created by Henry Varona on 10/30/2018. + * + */ + +public class CryptoNetSelectionViewHolder extends RecyclerView.ViewHolder { + /* + * the view holding the crypto coin name + */ + private TextView cryptoNetName; + + private CheckBox cryptoNetCheckBox; + + private Context context; + + public CryptoNetSelectionViewHolder(View itemView) { + super(itemView); + //TODO: use ButterKnife to load this + cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName); + cryptoNetCheckBox = (CheckBox) itemView.findViewById(R.id.cbCryptoNetSelected); + this.context = itemView.getContext(); + + } + + /* + * Clears the information in this element view + */ + public void clear(){ + cryptoNetName.setText(""); + cryptoNetCheckBox.setSelected(false); + } + + /* + * Binds this view with the data of an element of the list + */ + public void bindTo(final CryptoNetSelection cryptoNetSelection) { + if (cryptoNetSelection == null){ + this.clear(); + } else { + cryptoNetName.setText(cryptoNetSelection.getCryptoNet().getLabel()); + cryptoNetCheckBox.setSelected(cryptoNetSelection.getSelected()); + } + } +} diff --git a/app/src/main/res/layout/account_seed_activity_settings.xml b/app/src/main/res/layout/account_seed_activity_settings.xml new file mode 100644 index 0000000..f6a268d --- /dev/null +++ b/app/src/main/res/layout/account_seed_activity_settings.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_accounts.xml b/app/src/main/res/layout/activity_accounts.xml index 71948a8..b7d75e9 100644 --- a/app/src/main/res/layout/activity_accounts.xml +++ b/app/src/main/res/layout/activity_accounts.xml @@ -101,7 +101,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/secondView" /> --> - + + app:layout_constraintBottom_toBottomOf="@id/vAccountSeedList" + app:layout_constraintEnd_toEndOf="@id/vAccountSeedList" + app:layout_constraintStart_toStartOf="@id/vAccountSeedList" + app:layout_constraintTop_toTopOf="@id/vAccountSeedList" /> + app:layout_constraintTop_toBottomOf="@id/vAccountSeedList" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_general_account_seed_coin_settings.xml b/app/src/main/res/layout/fragment_general_account_seed_coin_settings.xml new file mode 100644 index 0000000..b0d8329 --- /dev/null +++ b/app/src/main/res/layout/fragment_general_account_seed_coin_settings.xml @@ -0,0 +1,23 @@ + + + + + + + +