From 23d2cd6836a45fcc50846ac6efc667f94469d985 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 25 Apr 2019 21:14:42 -0500 Subject: [PATCH] Created a different layout to show the map pin's markers for tellers and merchants. Added more fields to the tellers db table, to include the newly added in the V2 of the webservice: Keybase, Whatsapp, Viber and Email and created a db migration to reflect that. Added the code to show the teller's newly added fields to the pin's markers if such fields exist and hide that field otherwise. --- .../4.json | 445 ++++++++++++++++++ .../database/BitsyDatabase.kt | 10 +- .../database/entities/Teller.kt | 4 + .../fragments/MerchantsFragment.kt | 34 +- ...indow.xml => marker_merch_info_window.xml} | 0 .../res/layout/marker_teller_info_window.xml | 88 ++++ 6 files changed, 577 insertions(+), 4 deletions(-) create mode 100644 app/schemas/cy.agorise.bitsybitshareswallet.database.BitsyDatabase/4.json rename app/src/main/res/layout/{marker_info_window.xml => marker_merch_info_window.xml} (100%) create mode 100644 app/src/main/res/layout/marker_teller_info_window.xml diff --git a/app/schemas/cy.agorise.bitsybitshareswallet.database.BitsyDatabase/4.json b/app/schemas/cy.agorise.bitsybitshareswallet.database.BitsyDatabase/4.json new file mode 100644 index 0000000..f947c30 --- /dev/null +++ b/app/schemas/cy.agorise.bitsybitshareswallet.database.BitsyDatabase/4.json @@ -0,0 +1,445 @@ +{ + "formatVersion": 1, + "database": { + "version": 4, + "identityHash": "4614e60ba10b66b28349657f75320694", + "entities": [ + { + "tableName": "assets", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `symbol` TEXT NOT NULL, `precision` INTEGER NOT NULL, `description` TEXT NOT NULL, `issuer` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "symbol", + "columnName": "symbol", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "precision", + "columnName": "precision", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "issuer", + "columnName": "issuer", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "authorities", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `user_id` TEXT NOT NULL, `authority_type` INTEGER NOT NULL, `encrypted_wif` TEXT NOT NULL, `encrypted_brain_key` TEXT NOT NULL, `encrypted_sequence_number` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "userId", + "columnName": "user_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "authorityType", + "columnName": "authority_type", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "encryptedWIF", + "columnName": "encrypted_wif", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "encryptedBrainKey", + "columnName": "encrypted_brain_key", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "encryptedSequenceNumber", + "columnName": "encrypted_sequence_number", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "balances", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`asset_id` TEXT NOT NULL, `asset_amount` INTEGER NOT NULL, `last_update` INTEGER NOT NULL, PRIMARY KEY(`asset_id`))", + "fields": [ + { + "fieldPath": "assetId", + "columnName": "asset_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "assetAmount", + "columnName": "asset_amount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "lastUpdate", + "columnName": "last_update", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "asset_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "equivalent_values", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`transfer_id` TEXT NOT NULL, `value` INTEGER NOT NULL, `symbol` TEXT NOT NULL, PRIMARY KEY(`transfer_id`, `symbol`), FOREIGN KEY(`transfer_id`) REFERENCES `transfers`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )", + "fields": [ + { + "fieldPath": "transferId", + "columnName": "transfer_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "symbol", + "columnName": "symbol", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "transfer_id", + "symbol" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [ + { + "table": "transfers", + "onDelete": "NO ACTION", + "onUpdate": "NO ACTION", + "columns": [ + "transfer_id" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "transfers", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `block_number` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `fee_amount` INTEGER NOT NULL, `fee_asset_id` TEXT NOT NULL, `source` TEXT NOT NULL, `destination` TEXT NOT NULL, `transfer_amount` INTEGER NOT NULL, `transfer_asset_id` TEXT NOT NULL, `memo` TEXT NOT NULL, `bts_value` INTEGER, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "blockNumber", + "columnName": "block_number", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timestamp", + "columnName": "timestamp", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "feeAmount", + "columnName": "fee_amount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "feeAssetId", + "columnName": "fee_asset_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "source", + "columnName": "source", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "destination", + "columnName": "destination", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "transferAmount", + "columnName": "transfer_amount", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "transferAssetId", + "columnName": "transfer_asset_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "memo", + "columnName": "memo", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "btsValue", + "columnName": "bts_value", + "affinity": "INTEGER", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "user_accounts", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `is_ltm` INTEGER NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "isLtm", + "columnName": "is_ltm", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "merchants", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `address` TEXT, `lat` REAL NOT NULL, `lon` REAL NOT NULL, `phone` TEXT, `telegram` TEXT, `website` TEXT, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "_id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "address", + "columnName": "address", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "lat", + "columnName": "lat", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "lon", + "columnName": "lon", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "phone", + "columnName": "phone", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "telegram", + "columnName": "telegram", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "website", + "columnName": "website", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "tellers", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `address` TEXT, `lat` REAL NOT NULL, `lon` REAL NOT NULL, `phone` TEXT, `telegram` TEXT, `keybase` TEXT, `whatsapp` TEXT, `viber` TEXT, `email` TEXT, `website` TEXT, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "_id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "gt_name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "address", + "columnName": "address", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "lat", + "columnName": "lat", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "lon", + "columnName": "lon", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "phone", + "columnName": "phone", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "telegram", + "columnName": "telegram", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "keybase", + "columnName": "keybase", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "whatsapp", + "columnName": "whatsapp", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "viber", + "columnName": "viber", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "email", + "columnName": "email", + "affinity": "TEXT", + "notNull": false + }, + { + "fieldPath": "url", + "columnName": "website", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "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, \"4614e60ba10b66b28349657f75320694\")" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/BitsyDatabase.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/BitsyDatabase.kt index 245da98..4106ae7 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/BitsyDatabase.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/BitsyDatabase.kt @@ -21,7 +21,7 @@ import cy.agorise.bitsybitshareswallet.database.joins.TransferDetailDao Merchant::class, Teller::class ], - version = 3, + version = 4, exportSchema = true) abstract class BitsyDatabase : RoomDatabase() { abstract fun assetDao(): AssetDao @@ -49,6 +49,7 @@ abstract class BitsyDatabase : RoomDatabase() { BitsyDatabase::class.java, "BiTSyWallet.db" ).addMigrations(MIGRATION_1_2) .addMigrations(MIGRATION_2_3) + .addMigrations(MIGRATION_3_4) .build() } } @@ -76,5 +77,12 @@ abstract class BitsyDatabase : RoomDatabase() { database.execSQL("CREATE TABLE IF NOT EXISTS assets (`id` TEXT NOT NULL, `symbol` TEXT NOT NULL, `precision` INTEGER NOT NULL, `description` TEXT NOT NULL, `issuer` TEXT NOT NULL, PRIMARY KEY(`id`))") } } + + val MIGRATION_3_4 = object : Migration(3,4) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("DROP TABLE tellers") + database.execSQL("CREATE TABLE IF NOT EXISTS tellers (id TEXT NOT NULL PRIMARY KEY, name TEXT NOT NULL, address TEXT, lat REAL NOT NULL, lon REAL NOT NULL, phone TEXT, telegram TEXT, keybase TEXT, whatsapp TEXT, viber TEXT, email TEXT, website TEXT)") + } + } } } diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/entities/Teller.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/entities/Teller.kt index 71adaee..76144f6 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/database/entities/Teller.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/database/entities/Teller.kt @@ -16,6 +16,10 @@ data class Teller( @ColumnInfo(name = "lon") val lon: Double, @ColumnInfo(name = "phone") val phone: String?, @ColumnInfo(name = "telegram") val telegram: String?, + @ColumnInfo(name = "keybase") val keybase: String?, + @ColumnInfo(name = "whatsapp") val whatsapp: String?, + @ColumnInfo(name = "viber") val viber: String?, + @ColumnInfo(name = "email") val email: String?, @ColumnInfo(name = "website") val url: String? ) : ClusterItem { override fun getSnippet(): String { diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt index 601e15f..7b5bb82 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt @@ -157,7 +157,7 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio } private fun setupPopupWindow() { - val popupView = layoutInflater?.inflate(R.layout.popup_menu_merchants, null, false) + val popupView = layoutInflater.inflate(R.layout.popup_menu_merchants, null, false) val switchMerchants = popupView?.findViewById(R.id.switchMerchants) switchMerchants?.isChecked = showMerchantsMarkers @@ -512,7 +512,7 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio override fun getInfoWindow(marker: Marker?): View { val infoWindowLayout: View = LayoutInflater.from(context).inflate( - R.layout.marker_info_window, null) + R.layout.marker_merch_info_window, null) val tvName = infoWindowLayout.findViewById(R.id.tvName) val tvAddress = infoWindowLayout.findViewById(R.id.tvAddress) val tvPhone = infoWindowLayout.findViewById(R.id.tvPhone) @@ -557,11 +557,15 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio override fun getInfoWindow(marker: Marker?): View { val infoWindowLayout: View = LayoutInflater.from(context).inflate( - R.layout.marker_info_window, null) + R.layout.marker_teller_info_window, null) val tvName = infoWindowLayout.findViewById(R.id.tvName) val tvAddress = infoWindowLayout.findViewById(R.id.tvAddress) val tvPhone = infoWindowLayout.findViewById(R.id.tvPhone) val tvTelegram = infoWindowLayout.findViewById(R.id.tvTelegram) + val tvKeybase = infoWindowLayout.findViewById(R.id.tvKeybase) + val tvWhatsapp = infoWindowLayout.findViewById(R.id.tvWhatsapp) + val tvViber = infoWindowLayout.findViewById(R.id.tvViber) + val tvEmail = infoWindowLayout.findViewById(R.id.tvEmail) val tvWebsite = infoWindowLayout.findViewById(R.id.tvWebsite) if (selectedTeller != null) { @@ -583,6 +587,30 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio } else tvTelegram.visibility = View.GONE + if (!selectedTeller?.keybase.equals("")) { + val keybase = "Keybase: ${selectedTeller?.keybase}" + tvKeybase.text = keybase + } else + tvKeybase.visibility = View.GONE + + if (!selectedTeller?.whatsapp.equals("")) { + val whatsapp = "WhatsApp: ${selectedTeller?.whatsapp}" + tvWhatsapp.text = whatsapp + } else + tvWhatsapp.visibility = View.GONE + + if (!selectedTeller?.viber.equals("")) { + val viber = "Viber: ${selectedTeller?.viber}" + tvViber.text = viber + } else + tvViber.visibility = View.GONE + + if (!selectedTeller?.email.equals("")) { + val email = "Email: ${selectedTeller?.email}" + tvEmail.text = email + } else + tvEmail.visibility = View.GONE + if (!selectedTeller?.url.equals("")) tvWebsite.text = selectedTeller?.url ?.removePrefix("http://")?.removePrefix("https://") diff --git a/app/src/main/res/layout/marker_info_window.xml b/app/src/main/res/layout/marker_merch_info_window.xml similarity index 100% rename from app/src/main/res/layout/marker_info_window.xml rename to app/src/main/res/layout/marker_merch_info_window.xml diff --git a/app/src/main/res/layout/marker_teller_info_window.xml b/app/src/main/res/layout/marker_teller_info_window.xml new file mode 100644 index 0000000..a066518 --- /dev/null +++ b/app/src/main/res/layout/marker_teller_info_window.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file