From 3252062e74ee9b21eb5a2c5d34933eb5c3150525 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Fri, 25 May 2018 14:30:45 -0400 Subject: [PATCH] - Making LicenseActivity save the last version of the license accepted --- .../activities/IntroActivity.java | 31 ++++++++++--------- .../activities/LicenseActivity.java | 25 ++++++++++++++- .../application/CrystalApplication.java | 1 + .../crystalwallet/models/GeneralSetting.java | 1 + app/src/main/res/values/integers.xml | 5 +++ 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/values/integers.xml diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java index 5c82104..e95513e 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java @@ -25,6 +25,7 @@ import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GeneralSetting; import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoCoinBalanceGenerator; import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoNetAccountGenerator; import cy.agorise.crystalwallet.randomdatagenerators.RandomSeedGenerator; @@ -79,21 +80,23 @@ public class IntroActivity extends AppCompatActivity { this.getApplication().registerActivityLifecycleCallbacks(CrystalSecurityMonitor.getInstance(this)); - //Checks if the user has any seed created - AccountSeedListViewModel accountSeedListViewModel = ViewModelProviders.of(this).get(AccountSeedListViewModel.class); - if (accountSeedListViewModel.accountSeedsCount() == 0){ - //If the user doesn't have any seeds created, then - //send the user to create/import an account - //Intent intent = new Intent(this, AccountSeedsManagementActivity.class); - //Intent intent = new Intent(this, ImportSeedActivity.class); - //Intent intent = new Intent(this, CreateSeedActivity.class); - //startActivity(intent); - } else { - //Intent intent = new Intent(this, CreateSeedActivity.class); - Intent intent = new Intent(this, BoardActivity.class); - startActivity(intent); - } + + //Checks if the user has any seed created + AccountSeedListViewModel accountSeedListViewModel = ViewModelProviders.of(this).get(AccountSeedListViewModel.class); + + if (accountSeedListViewModel.accountSeedsCount() == 0) { + //If the user doesn't have any seeds created, then + //send the user to create/import an account + //Intent intent = new Intent(this, AccountSeedsManagementActivity.class); + //Intent intent = new Intent(this, ImportSeedActivity.class); + //Intent intent = new Intent(this, CreateSeedActivity.class); + //startActivity(intent); + } else { + //Intent intent = new Intent(this, CreateSeedActivity.class); + Intent intent = new Intent(this, BoardActivity.class); + startActivity(intent); + } /*CrystalDatabase db = CrystalDatabase.getAppDatabase(getApplicationContext()); List seeds = RandomSeedGenerator.generateSeeds(2); diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/LicenseActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/LicenseActivity.java index 2842601..8964738 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/LicenseActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/LicenseActivity.java @@ -1,5 +1,6 @@ package cy.agorise.crystalwallet.activities; +import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; @@ -9,11 +10,15 @@ 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.GeneralSetting; public class LicenseActivity extends AppCompatActivity { @BindView(R.id.wvEULA) WebView wvEULA; + CrystalDatabase db; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -24,11 +29,29 @@ public class LicenseActivity extends AppCompatActivity { String html = getString(R.string.licence_html); wvEULA.loadData(html, "text/html", "UTF-8"); + + db = CrystalDatabase.getAppDatabase(this.getApplicationContext()); + int licenseVersion = getResources().getInteger(R.integer.license_version); + GeneralSetting generalSettingLastLicenseRead = db.generalSettingDao().getSettingByName(GeneralSetting.SETTING_LAST_LICENSE_READ); + + if ((generalSettingLastLicenseRead != null) && (Integer.parseInt(generalSettingLastLicenseRead.getValue()) >= licenseVersion)) { + Intent intent = new Intent(this, IntroActivity.class); + startActivity(intent); + } } @OnClick(R.id.btnAgree) public void onAgree() { - // TODO send user to Intro activity if no active account or to Board activity otherwise + CrystalDatabase db = CrystalDatabase.getAppDatabase(this.getApplicationContext()); + GeneralSetting lastLicenseReadSetting = new GeneralSetting(); + lastLicenseReadSetting.setName(GeneralSetting.SETTING_LAST_LICENSE_READ); + lastLicenseReadSetting.setValue(""+getResources().getInteger(R.integer.license_version)); + + db.generalSettingDao().deleteByName(GeneralSetting.SETTING_LAST_LICENSE_READ); + db.generalSettingDao().insertGeneralSetting(lastLicenseReadSetting); + + Intent intent = new Intent(this, IntroActivity.class); + startActivity(intent); } @OnClick(R.id.btnDisAgree) diff --git a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java index b3d4504..238c515 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java +++ b/app/src/main/java/cy/agorise/crystalwallet/application/CrystalApplication.java @@ -10,6 +10,7 @@ import com.idescout.sql.SqlScoutServer; import java.util.Locale; +import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.models.BitsharesAsset; diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GeneralSetting.java b/app/src/main/java/cy/agorise/crystalwallet/models/GeneralSetting.java index 80edd47..5410cbb 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/GeneralSetting.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GeneralSetting.java @@ -22,6 +22,7 @@ public class GeneralSetting { public final static String SETTING_PASSWORD = "PASSWORD"; public final static String SETTING_PATTERN = "PATTERN"; public final static String SETTING_NAME_RECEIVED_FUNDS_SOUND_PATH = "RECEIVED_FUNDS_SOUND_PATH"; + public final static String SETTING_LAST_LICENSE_READ = "LAST_LICENSE_READ"; /** * The id on the database diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml new file mode 100644 index 0000000..c0e6681 --- /dev/null +++ b/app/src/main/res/values/integers.xml @@ -0,0 +1,5 @@ + + + 1 + + \ No newline at end of file