diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e941a4d..d6fd2b7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -43,7 +43,6 @@ - ) { - if (response.result is List<*> && - (response.result as List<*>).size > 0 && - (response.result as List<*>)[0] is Asset) { - handlePlatformAssetBatch(response.result as List) - } - } - - override fun handleConnectionStatusUpdate(connectionStatusUpdate: ConnectionStatusUpdate) { - if (connectionStatusUpdate.updateCode == ConnectionStatusUpdate.API_UPDATE && - connectionStatusUpdate.api and ApiAccess.API_DATABASE == ApiAccess.API_DATABASE) { - hasDatabaseApiId = true - this.lastLowerBound = "" - sendAssetBatchRequest() - } - } - - /** - * Method that issues a request for the next 100 known assets, starting from the last known - * lower bound for the asset symbol. - */ - private fun sendAssetBatchRequest() { - if (mNetworkService != null && mNetworkService!!.isConnected) { - mNetworkService!!.sendMessage(ListAssets(lastLowerBound, ListAssets.LIST_ALL), ListAssets.REQUIRED_API) - } else { - Handler().postDelayed({ sendAssetBatchRequest() }, NETWORK_RETRY_PERIOD) - } - } - - /** - * Method that loads a new batch of platform assets into the database and decides whether to finish - * the procedure or to keep requesting for more assets. - * - * @param assetList The list of assets obtained in the last 'list_assets' API call. - */ - private fun handlePlatformAssetBatch(assetList: List) { - val assets = mutableListOf() - - // TODO find if there is a better way to convert to Bitsy Asset instances - for (_asset in assetList) { - val asset = cy.agorise.bitsybitshareswallet.database.entities.Asset( - _asset.objectId, - _asset.symbol, - _asset.precision, - _asset.description ?: "", - _asset.bitassetId ?: "" - ) - - assets.add(asset) - } - - mAssetRepository!!.insertAll(assets) - - loadedAssetsCounter += assetList.size - - tvLoadMessage.text = getString(R.string.text__loading_assets, loadedAssetsCounter) - - if (assetList.size < ListAssets.MAX_BATCH_SIZE) { - // We might have reached the end of the asset list - Log.d(TAG, "We might have reached the end!") - - // Storing the last asset update time and setting the database as loaded - PreferenceManager.getDefaultSharedPreferences(applicationContext) - .edit() - .putLong(Constants.KEY_LAST_ASSET_LIST_UPDATE, System.currentTimeMillis()) - .apply() - - onAssetsReady() - } else { - // Using the last asset symbol in the list as the new lower bound. - lastLowerBound = assetList[assetList.size - 1].symbol - sendAssetBatchRequest() - } - } - - private fun onAssetsReady() { - // Storing the last asset update time and setting the database as loaded - PreferenceManager.getDefaultSharedPreferences(applicationContext) - .edit() - .putBoolean(Constants.KEY_DATABASE_LOADED, true) - .apply() - - - mHandler!!.post { - progressBar.visibility = View.INVISIBLE - btnNext.isEnabled = true - tvLoadTitle.setText(R.string.title__assets_loaded) - tvLoadMessage.setText(R.string.text__assets_loaded) - - // Timer to automatically take user to the next activity - countDownTimer = object : CountDownTimer(5000, 1000) { - - override fun onTick(millisUntilFinished: Long) {} - - override fun onFinish() { - onNext() - } - }.start() - } - } - - /** - * Called whenever the user clicks on the 'next' button_light. This button_light will only be visible when - * the database loading procedure is done, OR if there was an error in it. - */ - fun onNext() { - // Cancel timer to avoid starting InitialSetupActivity twice - countDownTimer!!.cancel() - - val intent = Intent(applicationContext, ImportBrainkeyActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - startActivity(intent) -// overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left) - finish() - } - - override fun onServiceConnected(name: ComponentName?, service: IBinder?) { - super.onServiceConnected(name, service) - - hasDatabaseApiId = mNetworkService!!.hasApiId(ApiAccess.API_DATABASE) - if (hasDatabaseApiId) { - this.lastLowerBound = "" - sendAssetBatchRequest() - } - } -} \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/LicenseActivity.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/LicenseActivity.kt index e47d03e..5bf6d61 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/LicenseActivity.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/LicenseActivity.kt @@ -32,8 +32,7 @@ class LicenseActivity : AppCompatActivity() { /** * This function stores the version of the current accepted license version into the Shared Preferences and - * sends the user to load the assets database if they have not been loaded, import/create account if there is no - * active account or to the MainActivity otherwise. + * sends the user to import/create account if there is no active account or to the MainActivity otherwise. */ private fun agree() { PreferenceManager.getDefaultSharedPreferences(this).edit() @@ -41,15 +40,10 @@ class LicenseActivity : AppCompatActivity() { val intent : Intent? - val isDatabaseLoaded = PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(Constants.KEY_DATABASE_LOADED, false) - val initialSetupDone = PreferenceManager.getDefaultSharedPreferences(this) .getBoolean(Constants.KEY_INITIAL_SETUP_DONE, false) - intent = if (!isDatabaseLoaded) - Intent(this, DatabaseLoadActivity::class.java) - else if (!initialSetupDone) + intent = if (!initialSetupDone) Intent(this, ImportBrainkeyActivity::class.java) else Intent(this, MainActivity::class.java) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt index 990228d..f4e1eca 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/Constants.kt @@ -11,9 +11,6 @@ object Constants { /** Version of the currently used license */ const val CURRENT_LICENSE_VERSION = 1 - /** Key used to store if the assets database has been loaded or not */ - const val KEY_DATABASE_LOADED = "key_database_loaded" - /** * Key used to store a preference value used to keep track of the last time the assets in * database were updated. diff --git a/app/src/main/res/layout/activity_database_load.xml b/app/src/main/res/layout/activity_database_load.xml deleted file mode 100644 index 5c12977..0000000 --- a/app/src/main/res/layout/activity_database_load.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - -