From 42e8637d114b291f1bef76f933d616d10f57e244 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 30 May 2018 21:19:46 -0400 Subject: [PATCH] - Change account seed list in profile settings to crypto net account list - Added settings for crypto net accounts. General settings for any crypto net account and Bitshares settings for bitshares accounts - Added new field in db for bitshares accounts: upgraded_to_ltm - Added button to upgrade to ltm (still in progress...) --- .../2.json | 12 +- app/src/main/AndroidManifest.xml | 4 + .../activities/AccountSettingsActivity.java | 118 ++++++++++++ .../activities/AccountsActivity.java | 19 +- .../CryptoNetAccountSettingsActivity.java | 171 ++++++++++++++++++ .../crystalwallet/dao/CrystalDatabase.java | 12 +- .../fragments/BitsharesSettingsFragment.java | 152 ++++++++++++++++ ...neralCryptoNetAccountSettingsFragment.java | 86 +++++++++ .../models/CryptoNetAccount.java | 29 +++ .../crystalwallet/models/GrapheneAccount.java | 10 + .../models/GrapheneAccountInfo.java | 14 ++ .../CryptoNetAccountListViewModel.java | 4 + .../views/CryptoNetAccountListAdapter.java | 39 ++++ .../views/CryptoNetAccountListView.java | 72 ++++++++ .../views/CryptoNetAccountViewHolder.java | 49 +++++ app/src/main/res/layout/activity_accounts.xml | 14 +- .../crypto_net_account_activity_settings.xml | 119 ++++++++++++ .../res/layout/crypto_net_account_list.xml | 13 ++ .../layout/crypto_net_account_list_item.xml | 24 +++ .../layout/fragment_bitshares_settings.xml | 48 +++++ ...nt_general_crypto_net_account_settings.xml | 32 ++++ 21 files changed, 1022 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/activities/AccountSettingsActivity.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/activities/CryptoNetAccountSettingsActivity.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/fragments/BitsharesSettingsFragment.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralCryptoNetAccountSettingsFragment.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountListAdapter.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountListView.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountViewHolder.java create mode 100644 app/src/main/res/layout/crypto_net_account_activity_settings.xml create mode 100644 app/src/main/res/layout/crypto_net_account_list.xml create mode 100644 app/src/main/res/layout/crypto_net_account_list_item.xml create mode 100644 app/src/main/res/layout/fragment_bitshares_settings.xml create mode 100644 app/src/main/res/layout/fragment_general_crypto_net_account_settings.xml diff --git a/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json b/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json index 22f45c4..a31d90d 100644 --- a/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json +++ b/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 2, - "identityHash": "22cb2a56b28a9f7088ec98d6a72f9f67", + "identityHash": "14fe802949d125dda3e3c476a34481d7", "entities": [ { "tableName": "account_seed", @@ -478,7 +478,7 @@ }, { "tableName": "graphene_account", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`crypto_net_account_id` INTEGER NOT NULL, `account_name` TEXT, `account_id` TEXT, PRIMARY KEY(`crypto_net_account_id`), FOREIGN KEY(`crypto_net_account_id`) REFERENCES `crypto_net_account`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`crypto_net_account_id` INTEGER NOT NULL, `account_name` TEXT, `account_id` TEXT, `upgraded_to_ltm` INTEGER NOT NULL, PRIMARY KEY(`crypto_net_account_id`), FOREIGN KEY(`crypto_net_account_id`) REFERENCES `crypto_net_account`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )", "fields": [ { "fieldPath": "cryptoNetAccountId", @@ -497,6 +497,12 @@ "columnName": "account_id", "affinity": "TEXT", "notNull": false + }, + { + "fieldPath": "upgradedToLtm", + "columnName": "upgraded_to_ltm", + "affinity": "INTEGER", + "notNull": true } ], "primaryKey": { @@ -692,7 +698,7 @@ ], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"22cb2a56b28a9f7088ec98d6a72f9f67\")" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"14fe802949d125dda3e3c476a34481d7\")" ] } } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 850e19e..6aed77d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -52,6 +52,10 @@ + + > accountSeedData = accountSeedListViewModel.getAccountSeedList(); - vAccountSeedList.setData(null); + CryptoNetAccountListViewModel crytpoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class); + LiveData> accountData = crytpoNetAccountListViewModel.getCryptoNetAccounts(); + vAccountList.setData(null); - accountSeedData.observe(this, new Observer>() { + accountData.observe(this, new Observer>() { @Override - public void onChanged(List accountSeeds) { - vAccountSeedList.setData(accountSeeds); + public void onChanged(List cryptoNetAccounts) { + vAccountList.setData(cryptoNetAccounts); } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CryptoNetAccountSettingsActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/CryptoNetAccountSettingsActivity.java new file mode 100644 index 0000000..460cfdc --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CryptoNetAccountSettingsActivity.java @@ -0,0 +1,171 @@ +package cy.agorise.crystalwallet.activities; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; +import android.media.MediaPlayer; +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.view.SurfaceHolder; +import android.view.SurfaceView; +import android.widget.ImageView; +import android.widget.TextView; + +import butterknife.BindView; +import butterknife.ButterKnife; +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.GeneralCryptoNetAccountSettingsFragment; +import cy.agorise.crystalwallet.fragments.GeneralSettingsFragment; +import cy.agorise.crystalwallet.fragments.SecuritySettingsFragment; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; + +/** + * Created by henry varona on 05/28/18. + * + */ + +public class CryptoNetAccountSettingsActivity extends AppCompatActivity{ + + @BindView(R.id.ivGoBack) + public ImageView ivGoBack; + + @BindView(R.id.pager) + public ViewPager mPager; + + public SettingsPagerAdapter settingsPagerAdapter; + + @BindView(R.id.surface_view) + public SurfaceView mSurfaceView; + + @BindView(R.id.tvBuildVersion) + public TextView tvBuildVersion; + + @BindView(R.id.tabs) + public TabLayout tabs; + + private CryptoNetAccount cryptoNetAccount; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.crypto_net_account_activity_settings); + ButterKnife.bind(this); + final CryptoNetAccountSettingsActivity thisActivity = this; + + long accountId = getIntent().getLongExtra("CRYPTO_NET_ACCOUNT_ID",-1); + + if (accountId > -1) { + CryptoNetAccountViewModel cryptoNetAccountViewModel = ViewModelProviders.of(this).get(CryptoNetAccountViewModel.class); + cryptoNetAccountViewModel.loadCryptoNetAccount(accountId); + LiveData cryptoNetAccountLiveData = cryptoNetAccountViewModel.getCryptoNetAccount(); + + cryptoNetAccountLiveData.observe(this, new Observer() { + @Override + public void onChanged(@Nullable CryptoNetAccount cryptoNetAccount) { + thisActivity.cryptoNetAccount = cryptoNetAccount; + + settingsPagerAdapter = new SettingsPagerAdapter(getSupportFragmentManager()); + mPager.setAdapter(settingsPagerAdapter); + + TabLayout tabLayout = findViewById(R.id.tabs); + + switch(cryptoNetAccount.getCryptoNet()){ + case BITSHARES: + tabLayout.addTab(tabLayout.newTab().setText("Bitshares")); + break; + } + mPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); + tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mPager)); + } + }); + + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + // Appbar animation + mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() { + @Override + public void surfaceCreated(SurfaceHolder surfaceHolder) { + //Log.d(TAG,"surfaceCreated"); + MediaPlayer mediaPlayer = MediaPlayer.create(CryptoNetAccountSettingsActivity.this, R.raw.appbar_background); + mediaPlayer.setDisplay(mSurfaceView.getHolder()); + mediaPlayer.setLooping(true); + mediaPlayer.start(); + } + + @Override + public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) { + //Log.d(TAG,"surfaceChanged"); + } + + @Override + public void surfaceDestroyed(SurfaceHolder surfaceHolder) { + //Log.d(TAG,"surfaceDestroyed"); + } + }); + + + } else { + this.finish(); + } + } + + private class SettingsPagerAdapter extends FragmentStatePagerAdapter { + SettingsPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int position) { + switch (position){ + case 0: + return GeneralCryptoNetAccountSettingsFragment.newInstance(cryptoNetAccount.getId()); + } + + if (cryptoNetAccount != null){ + switch (cryptoNetAccount.getCryptoNet()){ + case BITSHARES: + switch(position){ + case 1: + return BitsharesSettingsFragment.newInstance(cryptoNetAccount.getId()); + } + + break; + } + } + + return null; + } + + @Override + public int getCount() { + int tabCount = 1; + + if (cryptoNetAccount != null){ + switch (cryptoNetAccount.getCryptoNet()){ + case BITSHARES: + tabCount = tabCount+1; + break; + } + } + + return tabCount; + } + } + + @OnClick(R.id.ivGoBack) + public void goBack(){ + onBackPressed(); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java index d0c79ba..c6ef388 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -1,9 +1,11 @@ package cy.agorise.crystalwallet.dao; +import android.arch.persistence.db.SupportSQLiteDatabase; import android.arch.persistence.room.Database; import android.arch.persistence.room.Room; import android.arch.persistence.room.RoomDatabase; import android.arch.persistence.room.TypeConverters; +import android.arch.persistence.room.migration.Migration; import android.content.Context; import cy.agorise.crystalwallet.dao.converters.Converters; @@ -36,7 +38,7 @@ import cy.agorise.crystalwallet.models.GrapheneAccountInfo; BitsharesAssetInfo.class, CryptoCurrencyEquivalence.class, GeneralSetting.class -}, version = 2) +}, version = 3) @TypeConverters({Converters.class}) public abstract class CrystalDatabase extends RoomDatabase { @@ -59,8 +61,16 @@ public abstract class CrystalDatabase extends RoomDatabase { Room.databaseBuilder(context, CrystalDatabase.class, "CrystalWallet.db") .allowMainThreadQueries() + .addMigrations(MIGRATION_2_3) .build(); } return instance; } + + static final Migration MIGRATION_2_3 = new Migration(2, 3) { + @Override + public void migrate(SupportSQLiteDatabase database) { + database.execSQL("ALTER TABLE graphene_account ADD COLUMN upgraded_to_ltm INTEGER NOT NULL DEFAULT 0"); + } + }; } diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/BitsharesSettingsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/BitsharesSettingsFragment.java new file mode 100644 index 0000000..f748898 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/BitsharesSettingsFragment.java @@ -0,0 +1,152 @@ +package cy.agorise.crystalwallet.fragments; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; +import android.content.Intent; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.util.DisplayMetrics; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; +import android.widget.TextView; + +import com.vincent.filepicker.Constant; +import com.vincent.filepicker.activity.AudioPickActivity; +import com.vincent.filepicker.filter.entity.AudioFile; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Currency; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.OnItemSelected; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.enums.Language; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GeneralSetting; +import cy.agorise.crystalwallet.models.GrapheneAccount; +import cy.agorise.crystalwallet.models.GrapheneAccountInfo; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesLTMUpgradeRequest; +import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel; +import cy.agorise.crystalwallet.views.TimeZoneAdapter; + +import static android.app.Activity.RESULT_OK; +import static com.vincent.filepicker.activity.AudioPickActivity.IS_NEED_RECORDER; + + +/** + * Created by xd on 12/28/17. + */ + +public class BitsharesSettingsFragment extends Fragment { + + private GeneralSettingListViewModel generalSettingListViewModel; + private LiveData> generalSettingListLiveData; + + @BindView (R.id.tvUpgradeToLtm) + TextView tvUpgradeToLtm; + @BindView (R.id.btnUpgradeToLtm) + Button btnUpgradeToLtm; + @BindView (R.id.tvAlreadyLtm) + TextView tvAlreadyLtm; + + CryptoNetAccount cryptoNetAccount; + GrapheneAccountInfo grapheneAccountInfo; + GrapheneAccount grapheneAccount; + + public BitsharesSettingsFragment() { + if (getArguments() != null) { + long cryptoNetAcountId = getArguments().getLong("CRYPTO_NET_ACCOUNT_ID", -1); + + if (cryptoNetAcountId > -1) { + this.cryptoNetAccount = CrystalDatabase.getAppDatabase(getContext()).cryptoNetAccountDao().getById(cryptoNetAcountId); + this.grapheneAccountInfo = CrystalDatabase.getAppDatabase(getContext()).grapheneAccountInfoDao().getByAccountId(this.cryptoNetAccount.getId()); + this.grapheneAccount = new GrapheneAccount(this.cryptoNetAccount); + this.grapheneAccount.loadInfo(this.grapheneAccountInfo); + } + } + // Required empty public constructor + } + + public static BitsharesSettingsFragment newInstance(long cryptoNetAccountId) { + BitsharesSettingsFragment fragment = new BitsharesSettingsFragment(); + Bundle args = new Bundle(); + fragment.setArguments(args); + + if (cryptoNetAccountId > -1){ + fragment.cryptoNetAccount = CrystalDatabase.getAppDatabase(fragment.getContext()).cryptoNetAccountDao().getById(cryptoNetAccountId); + fragment.grapheneAccountInfo = CrystalDatabase.getAppDatabase(fragment.getContext()).grapheneAccountInfoDao().getByAccountId(fragment.cryptoNetAccount.getId()); + fragment.grapheneAccount = new GrapheneAccount(fragment.cryptoNetAccount); + fragment.grapheneAccount.loadInfo(fragment.grapheneAccountInfo); + } + + 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_bitshares_settings, container, false); + ButterKnife.bind(this, v); + + initAlreadyLtm(); + + return v; + } + + @OnClick (R.id.btnUpgradeToLtm) + public void upgradeAccountToLtm(){ + final ValidateBitsharesLTMUpgradeRequest request = new ValidateBitsharesLTMUpgradeRequest(this.getContext(),this.grapheneAccount); + + request.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + switch (request.getStatus()){ + case SUCCEEDED: + tvUpgradeToLtm.setVisibility(View.GONE); + btnUpgradeToLtm.setVisibility(View.GONE); + tvAlreadyLtm.setVisibility(View.VISIBLE); + break; + } + } + }); + + CryptoNetInfoRequests.getInstance().addRequest(request); + } + + public void initAlreadyLtm(){ + if (this.grapheneAccount.getUpgradedToLtm()){ + tvUpgradeToLtm.setVisibility(View.GONE); + btnUpgradeToLtm.setVisibility(View.GONE); + tvAlreadyLtm.setVisibility(View.VISIBLE); + } else { + tvUpgradeToLtm.setVisibility(View.VISIBLE); + btnUpgradeToLtm.setVisibility(View.VISIBLE); + tvAlreadyLtm.setVisibility(View.GONE); + } + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralCryptoNetAccountSettingsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralCryptoNetAccountSettingsFragment.java new file mode 100644 index 0000000..2c182a9 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/GeneralCryptoNetAccountSettingsFragment.java @@ -0,0 +1,86 @@ +package cy.agorise.crystalwallet.fragments; + +import android.arch.lifecycle.LiveData; +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 java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GeneralSetting; +import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel; + + +/** + * Created by xd on 12/28/17. + */ + +public class GeneralCryptoNetAccountSettingsFragment extends Fragment { + + @BindView(R.id.tvMnemonic) + TextView tvMnemonic; + + CryptoNetAccount cryptoNetAccount; + AccountSeed accountSeed; + + public GeneralCryptoNetAccountSettingsFragment() { + + 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 GeneralCryptoNetAccountSettingsFragment newInstance(long cryptoNetAccountId) { + GeneralCryptoNetAccountSettingsFragment fragment = new GeneralCryptoNetAccountSettingsFragment(); + 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); + + initAlreadyLtm(); + + return v; + } + + public void initAlreadyLtm(){ + if (this.cryptoNetAccount != null) { + tvMnemonic.setText(this.accountSeed.getMasterSeed()); + } + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java index 6acbc6a..beea120 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java @@ -7,6 +7,8 @@ import android.arch.persistence.room.ForeignKey; import android.arch.persistence.room.Ignore; import android.arch.persistence.room.Index; import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; +import android.support.v7.recyclerview.extensions.DiffCallback; import cy.agorise.crystalwallet.enums.CryptoNet; @@ -108,4 +110,31 @@ public class CryptoNetAccount { public String toString(){ return this.getName(); } + + public static final DiffCallback DIFF_CALLBACK = new DiffCallback() { + @Override + public boolean areItemsTheSame( + @NonNull CryptoNetAccount oldAccount, @NonNull CryptoNetAccount newAccount) { + return oldAccount.getId() == newAccount.getId(); + } + @Override + public boolean areContentsTheSame( + @NonNull CryptoNetAccount oldAccount, @NonNull CryptoNetAccount newAccount) { + return oldAccount.equals(newAccount); + } + }; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CryptoNetAccount that = (CryptoNetAccount) o; + + if (mId != that.mId) return false; + if (mSeedId != that.mSeedId) return false; + if (mAccountIndex != that.mAccountIndex) return false; + if (mCryptoNet != that.mCryptoNet) return false; + return mName != null ? mName.equals(that.mName) : that.mName == null; + } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java index 1ad3904..dfb4cb0 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java @@ -21,6 +21,7 @@ public class GrapheneAccount extends CryptoNetAccount { public static int subclass = 1; protected String name; protected String accountId; + protected boolean upgradedToLtm; public GrapheneAccount() { } @@ -32,6 +33,7 @@ public class GrapheneAccount extends CryptoNetAccount { public void loadInfo(GrapheneAccountInfo info){ this.name = info.getName(); this.accountId = info.getAccountId(); + this.upgradedToLtm = info.getUpgradedToLtm(); } public String getName() { @@ -50,6 +52,14 @@ public class GrapheneAccount extends CryptoNetAccount { this.accountId = accountId; } + public boolean getUpgradedToLtm() { + return this.upgradedToLtm; + } + + public void setUpgradedToLtm(boolean upgradedToLtm){ + this.upgradedToLtm = upgradedToLtm; + } + /** * Return the owner key, generates from the seed if it has not been generated. null if it can't be generated */ diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccountInfo.java b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccountInfo.java index 382242b..3b755e5 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccountInfo.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccountInfo.java @@ -36,6 +36,12 @@ public class GrapheneAccountInfo { @ColumnInfo(name = "account_id") protected String accountId; + /** + * If the bitshares account is upgraded to LTM + */ + @ColumnInfo(name = "upgraded_to_ltm") + protected boolean upgradedToLtm; + /** * Baisc constructor * @param cryptoNetAccountId The database ud of the CryptoNetAccount @@ -77,4 +83,12 @@ public class GrapheneAccountInfo { public void setAccountId(String accountId) { this.accountId = accountId; } + + public boolean getUpgradedToLtm(){ + return this.upgradedToLtm; + } + + public void setUpgradedToLtm(boolean upgradedToLtm){ + this.upgradedToLtm = upgradedToLtm; + } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetAccountListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetAccountListViewModel.java index 8beb01d..9945c33 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetAccountListViewModel.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetAccountListViewModel.java @@ -26,4 +26,8 @@ public class CryptoNetAccountListViewModel extends AndroidViewModel { public List getCryptoNetAccountList(){ return this.db.cryptoNetAccountDao().getAllCryptoNetAccount(); } + + public LiveData> getCryptoNetAccounts(){ + return this.db.cryptoNetAccountDao().getAll(); + } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountListAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountListAdapter.java new file mode 100644 index 0000000..b15f42e --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountListAdapter.java @@ -0,0 +1,39 @@ +package cy.agorise.crystalwallet.views; + + +import android.support.v7.recyclerview.extensions.ListAdapter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + +/** + * Created by Henry Varona on 05/27/2018. + */ + +public class CryptoNetAccountListAdapter extends ListAdapter { + + public CryptoNetAccountListAdapter() { + super(CryptoNetAccount.DIFF_CALLBACK); + } + + @Override + public CryptoNetAccountViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.crypto_net_account_list_item,parent,false); + + return new CryptoNetAccountViewHolder(v); + } + + @Override + public void onBindViewHolder(CryptoNetAccountViewHolder holder, int position) { + CryptoNetAccount cryptoNetAccount = getItem(position); + if (cryptoNetAccount != null) { + holder.bindTo(cryptoNetAccount); + } else { + holder.clear(); + } + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountListView.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountListView.java new file mode 100644 index 0000000..4a57e9f --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountListView.java @@ -0,0 +1,72 @@ +package cy.agorise.crystalwallet.views; + +import android.content.Context; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.RelativeLayout; + +import java.util.List; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel; +import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel; + +/** + * Created by Henry Varona on 05/27/2018. + */ + +public class CryptoNetAccountListView extends RelativeLayout { + + LayoutInflater mInflater; + + View rootView; + RecyclerView listView; + CryptoNetAccountListAdapter listAdapter; + + CryptoNetAccountListViewModel cryptoNetAccountListViewModel; + + public CryptoNetAccountListView(Context context){ + super(context); + this.mInflater = LayoutInflater.from(context); + init(); + } + + public CryptoNetAccountListView(Context context, AttributeSet attrs) { + super(context, attrs); + this.mInflater = LayoutInflater.from(context); + init(); + } + + public CryptoNetAccountListView(Context context, AttributeSet attrs, int defStyle){ + super(context, attrs, defStyle); + this.mInflater = LayoutInflater.from(context); + init(); + } + + public void init(){ + rootView = mInflater.inflate(R.layout.crypto_net_account_list, this, true); + this.listView = rootView.findViewById(R.id.cryptoNetAccountListView); + + final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext()); + this.listView.setLayoutManager(linearLayoutManager); + this.listView.setNestedScrollingEnabled(false); + } + + public void setData(List data){ + if (this.listAdapter == null) { + this.listAdapter = new CryptoNetAccountListAdapter(); + this.listView.setAdapter(this.listAdapter); + } + + if (data != null) { + this.listAdapter.setList(data); + } + } + + +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountViewHolder.java new file mode 100644 index 0000000..4a24698 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountViewHolder.java @@ -0,0 +1,49 @@ +package cy.agorise.crystalwallet.views; + +import android.content.Context; +import android.content.Intent; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.TextView; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.activities.BackupSeedActivity; +import cy.agorise.crystalwallet.activities.CryptoNetAccountSettingsActivity; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + +/** + * Created by Henry Varona on 17/9/2017. + */ + +public class CryptoNetAccountViewHolder extends RecyclerView.ViewHolder { + private TextView tvCryptoNetAccountName; + private Context context; + + public CryptoNetAccountViewHolder(View itemView) { + super(itemView); + tvCryptoNetAccountName = (TextView) itemView.findViewById(R.id.tvCryptoNetAccountName); + context = itemView.getContext(); + } + + public void clear(){ + tvCryptoNetAccountName.setText("loading..."); + } + + public void bindTo(final CryptoNetAccount cryptoNetAccount) { + if (cryptoNetAccount == null){ + tvCryptoNetAccountName.setText("loading..."); + } else { + tvCryptoNetAccountName.setText(cryptoNetAccount.getName()); + + tvCryptoNetAccountName.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(context, CryptoNetAccountSettingsActivity.class); + intent.putExtra("CRYPTO_NET_ACCOUNT_ID", cryptoNetAccount.getId()); + context.startActivity(intent); + } + }); + } + } +} diff --git a/app/src/main/res/layout/activity_accounts.xml b/app/src/main/res/layout/activity_accounts.xml index f1fcd94..7aac477 100644 --- a/app/src/main/res/layout/activity_accounts.xml +++ b/app/src/main/res/layout/activity_accounts.xml @@ -100,8 +100,8 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/secondView" /> --> - + app:layout_constraintBottom_toBottomOf="@id/vAccountList" + app:layout_constraintEnd_toEndOf="@id/vAccountList" + app:layout_constraintStart_toStartOf="@id/vAccountList" + app:layout_constraintTop_toTopOf="@id/vAccountList" /> + app:layout_constraintTop_toBottomOf="@id/vAccountList" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/crypto_net_account_list.xml b/app/src/main/res/layout/crypto_net_account_list.xml new file mode 100644 index 0000000..23cc7e7 --- /dev/null +++ b/app/src/main/res/layout/crypto_net_account_list.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/crypto_net_account_list_item.xml b/app/src/main/res/layout/crypto_net_account_list_item.xml new file mode 100644 index 0000000..6c2b38a --- /dev/null +++ b/app/src/main/res/layout/crypto_net_account_list_item.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bitshares_settings.xml b/app/src/main/res/layout/fragment_bitshares_settings.xml new file mode 100644 index 0000000..1c6606b --- /dev/null +++ b/app/src/main/res/layout/fragment_bitshares_settings.xml @@ -0,0 +1,48 @@ + + + + + + + +