diff --git a/app/build.gradle b/app/build.gradle
index 14cce69..233f067 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -62,8 +62,9 @@ android {
}
dependencies {
- def lifecycle_version = "2.3.1"
def arch_version = "2.1.0"
+ def lifecycle_version = "2.3.1"
+ def preference_version = "1.1.1"
def room_version = "2.2.6"
def rx_bindings_version = '3.0.0'
def version_coroutine = '1.4.1'
@@ -75,6 +76,7 @@ dependencies {
// AndroidX
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
+ implementation "androidx.preference:preference-ktx:$preference_version"
// Google
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.google.code.gson:gson:2.8.6'
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt
index 371a5bb..395e16f 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/ConnectedActivity.kt
@@ -4,12 +4,13 @@ import android.content.pm.PackageManager
import android.os.AsyncTask
import android.os.Bundle
import android.os.Handler
-import android.preference.PreferenceManager
import android.util.Log
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
+import androidx.core.content.edit
import androidx.core.content.pm.PackageInfoCompat
+import androidx.preference.PreferenceManager
import com.google.firebase.crashlytics.FirebaseCrashlytics
import cy.agorise.bitsybitshareswallet.database.entities.Balance
import cy.agorise.bitsybitshareswallet.database.entities.Transfer
@@ -171,10 +172,9 @@ abstract class ConnectedActivity : AppCompatActivity() {
if (versionCode > 11 && !hasPurgedEquivalentValues) {
thread {
connectedActivityViewModel.purgeEquivalentValues()
- PreferenceManager.getDefaultSharedPreferences(this)
- .edit()
- .putBoolean(Constants.KEY_HAS_PURGED_EQUIVALENT_VALUES, true)
- .apply()
+ PreferenceManager.getDefaultSharedPreferences(this).edit {
+ putBoolean(Constants.KEY_HAS_PURGED_EQUIVALENT_VALUES, true)
+ }
}
}
}
@@ -388,8 +388,9 @@ abstract class ConnectedActivity : AppCompatActivity() {
dateFormat.timeZone = TimeZone.getTimeZone("GMT")
try {
- val date = dateFormat.parse(blockHeader.timestamp)
- transferViewModel.setBlockTime(blockNumber, date.time / 1000)
+ dateFormat.parse(blockHeader.timestamp)?.let { date ->
+ transferViewModel.setBlockTime(blockNumber, date.time / 1000)
+ }
} catch (e: ParseException) {
Log.e(TAG, "ParseException. Msg: " + e.message)
}
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/MainActivity.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/MainActivity.kt
index 9e43b8c..67a6bfc 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/MainActivity.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/activities/MainActivity.kt
@@ -2,7 +2,6 @@ package cy.agorise.bitsybitshareswallet.activities
import android.os.Bundle
import android.os.Handler
-import android.preference.PreferenceManager
import android.util.Log
import android.view.MenuItem
import androidx.navigation.findNavController
@@ -11,6 +10,7 @@ import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.onNavDestinationSelected
import androidx.navigation.ui.setupActionBarWithNavController
+import androidx.preference.PreferenceManager
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.databinding.ActivityMainBinding
import cy.agorise.bitsybitshareswallet.utils.Constants
@@ -36,6 +36,7 @@ class MainActivity : ConnectedActivity() {
) {
setTheme(R.style.Theme_Bitsy_Dark)
}
+
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt
index 4658729..5fda85e 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseAccountFragment.kt
@@ -1,7 +1,8 @@
package cy.agorise.bitsybitshareswallet.fragments
-import android.preference.PreferenceManager
+import androidx.core.content.edit
import androidx.navigation.fragment.findNavController
+import androidx.preference.PreferenceManager
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.activities.ConnectedActivity
import cy.agorise.bitsybitshareswallet.database.entities.Authority
@@ -36,10 +37,11 @@ abstract class BaseAccountFragment : ConnectedFragment() {
val hashedPIN = CryptoUtils.createSHA256Hash(salt + pin)
// Stores the user selected PIN, hashed
- PreferenceManager.getDefaultSharedPreferences(requireContext()).edit()
- .putString(Constants.KEY_HASHED_PIN_PATTERN, hashedPIN)
- .putString(Constants.KEY_PIN_PATTERN_SALT, salt)
- .putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 1).apply() // 1 -> PIN
+ PreferenceManager.getDefaultSharedPreferences(requireContext()).edit {
+ putString(Constants.KEY_HASHED_PIN_PATTERN, hashedPIN)
+ putString(Constants.KEY_PIN_PATTERN_SALT, salt)
+ putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 1) // 1 -> PIN
+ }
// Stores the accounts this key refers to
val id = accountProperties.id
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseSecurityLockDialog.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseSecurityLockDialog.kt
index c272618..83510fe 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseSecurityLockDialog.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BaseSecurityLockDialog.kt
@@ -2,11 +2,12 @@ package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
import android.os.CountDownTimer
-import android.preference.PreferenceManager
import android.view.View
import android.view.ViewGroup
+import androidx.core.content.edit
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
+import androidx.preference.PreferenceManager
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.utils.Constants
import io.reactivex.disposables.CompositeDisposable
@@ -118,10 +119,10 @@ abstract class BaseSecurityLockDialog : DialogFragment() {
incorrectSecurityLockTime = now
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .putInt(Constants.KEY_INCORRECT_SECURITY_LOCK_ATTEMPTS, ++incorrectSecurityLockAttempts)
- .putLong(Constants.KEY_INCORRECT_SECURITY_LOCK_TIME, now)
- .apply()
+ PreferenceManager.getDefaultSharedPreferences(context).edit {
+ putInt(Constants.KEY_INCORRECT_SECURITY_LOCK_ATTEMPTS, ++incorrectSecurityLockAttempts)
+ putLong(Constants.KEY_INCORRECT_SECURITY_LOCK_TIME, now)
+ }
}
/**
@@ -132,10 +133,10 @@ abstract class BaseSecurityLockDialog : DialogFragment() {
incorrectSecurityLockTime = 0
incorrectSecurityLockAttempts = 0
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .putInt(Constants.KEY_INCORRECT_SECURITY_LOCK_ATTEMPTS, incorrectSecurityLockAttempts)
- .putLong(Constants.KEY_INCORRECT_SECURITY_LOCK_TIME, incorrectSecurityLockTime)
- .apply()
+ PreferenceManager.getDefaultSharedPreferences(context).edit {
+ putInt(Constants.KEY_INCORRECT_SECURITY_LOCK_ATTEMPTS, incorrectSecurityLockAttempts)
+ putLong(Constants.KEY_INCORRECT_SECURITY_LOCK_TIME, incorrectSecurityLockTime)
+ }
}
protected fun startContDownTimer() {
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/EReceiptFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/EReceiptFragment.kt
index e4cacbb..58fcd72 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/EReceiptFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/EReceiptFragment.kt
@@ -5,15 +5,15 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Animatable
import android.os.Bundle
-import android.preference.PreferenceManager
-import android.text.Html
import android.text.method.LinkMovementMethod
import android.view.*
import androidx.core.content.ContextCompat
import androidx.core.os.ConfigurationCompat
+import androidx.core.text.HtmlCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.navArgs
+import androidx.preference.PreferenceManager
import com.google.firebase.crashlytics.FirebaseCrashlytics
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.database.joins.TransferDetail
@@ -130,12 +130,11 @@ class EReceiptFragment : Fragment() {
/** Formats the transfer TextView to show a link to explore the given transfer
* in a BitShares explorer */
private fun formatTransferTextView(transferId: String) {
- val tx = Html.fromHtml(
- getString(
- R.string.template__tx,
- "$transferId"
- )
+ val html = getString(
+ R.string.template__tx,
+ "$transferId"
)
+ val tx = HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_LEGACY)
binding.tvTransferID.text = tx
binding.tvTransferID.movementMethod = LinkMovementMethod.getInstance()
}
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt
index 327b8d6..60cc32b 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt
@@ -1,7 +1,6 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
-import android.preference.PreferenceManager
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
@@ -13,6 +12,7 @@ import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.viewModels
import androidx.navigation.Navigation
import androidx.navigation.fragment.findNavController
+import androidx.preference.PreferenceManager
import com.google.firebase.crashlytics.FirebaseCrashlytics
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.databinding.FragmentHomeBinding
@@ -135,7 +135,8 @@ class HomeFragment : Fragment() {
/**
* Pager adapter to create the placeholder fragments
*/
- private inner class PagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
+ private inner class PagerAdapter(fm: FragmentManager) :
+ FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getItem(position: Int): Fragment {
// getItem is called to instantiate the fragment for the given page.
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/LicenseFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/LicenseFragment.kt
index 91236e7..6ce1f6e 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/LicenseFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/LicenseFragment.kt
@@ -1,13 +1,14 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
-import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
+import androidx.core.content.edit
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
+import androidx.preference.PreferenceManager
import com.google.firebase.crashlytics.FirebaseCrashlytics
import cy.agorise.bitsybitshareswallet.R
import cy.agorise.bitsybitshareswallet.databinding.FragmentLicenseBinding
@@ -67,10 +68,10 @@ class LicenseFragment : Fragment() {
* sends the user to import/create account.
*/
private fun agree() {
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .putInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, Constants.CURRENT_LICENSE_VERSION)
- .apply()
+ PreferenceManager.getDefaultSharedPreferences(context).edit {
+ putInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, Constants.CURRENT_LICENSE_VERSION)
+ }
findNavController().navigate(R.id.import_brainkey_action)
}
-}
\ No newline at end of file
+}
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 5c89b4a..ec9f406 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MerchantsFragment.kt
@@ -6,7 +6,6 @@ import android.content.pm.PackageManager
import android.database.Cursor
import android.database.MatrixCursor
import android.os.Bundle
-import android.preference.PreferenceManager
import android.util.Log
import android.view.*
import android.widget.PopupWindow
@@ -19,6 +18,7 @@ import androidx.core.content.ContextCompat
import androidx.cursoradapter.widget.SimpleCursorAdapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
+import androidx.preference.PreferenceManager
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.google.android.gms.maps.CameraUpdateFactory
@@ -549,7 +549,7 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, SearchView.OnSuggestio
try {
mMap?.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100))
} catch (e: Exception) {
- Log.d(TAG, e.message)
+ Log.d(TAG, e.message ?: "")
}
}
return true
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PINSecurityLockDialog.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PINSecurityLockDialog.kt
index 2131380..eaaa293 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PINSecurityLockDialog.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PINSecurityLockDialog.kt
@@ -1,12 +1,13 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
-import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
+import androidx.core.content.edit
+import androidx.preference.PreferenceManager
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.jakewharton.rxbinding3.widget.textChanges
import cy.agorise.bitsybitshareswallet.R
@@ -100,10 +101,11 @@ class PINSecurityLockDialog : BaseSecurityLockDialog() {
val hashedPIN = CryptoUtils.createSHA256Hash(salt + pinConfirm)
// Stores the newly selected PIN, hashed
- PreferenceManager.getDefaultSharedPreferences(v.context).edit()
- .putString(Constants.KEY_HASHED_PIN_PATTERN, hashedPIN)
- .putString(Constants.KEY_PIN_PATTERN_SALT, salt)
- .putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 1).apply() // 1 -> PIN
+ PreferenceManager.getDefaultSharedPreferences(v.context).edit {
+ putString(Constants.KEY_HASHED_PIN_PATTERN, hashedPIN)
+ putString(Constants.KEY_PIN_PATTERN_SALT, salt)
+ putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 1) // 1 -> PIN
+ }
dismiss()
mCallback?.onPINPatternChanged()
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PatternSecurityLockDialog.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PatternSecurityLockDialog.kt
index 9fdb4e2..c278198 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PatternSecurityLockDialog.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/PatternSecurityLockDialog.kt
@@ -1,10 +1,11 @@
package cy.agorise.bitsybitshareswallet.fragments
import android.os.Bundle
-import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import androidx.core.content.edit
+import androidx.preference.PreferenceManager
import com.andrognito.patternlockview.PatternLockView
import com.andrognito.patternlockview.listener.PatternLockViewListener
import com.google.firebase.crashlytics.FirebaseCrashlytics
@@ -131,11 +132,11 @@ class PatternSecurityLockDialog : BaseSecurityLockDialog() {
val hashedPattern = CryptoUtils.createSHA256Hash(salt + patternConfirm)
// Stores the newly selected Pattern, encrypted
- PreferenceManager.getDefaultSharedPreferences(it).edit()
- .putString(Constants.KEY_HASHED_PIN_PATTERN, hashedPattern)
- .putString(Constants.KEY_PIN_PATTERN_SALT, salt)
- .putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 2)
- .apply() // 2 -> Pattern
+ PreferenceManager.getDefaultSharedPreferences(it).edit {
+ putString(Constants.KEY_HASHED_PIN_PATTERN, hashedPattern)
+ putString(Constants.KEY_PIN_PATTERN_SALT, salt)
+ putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 2) // 2 -> Pattern
+ }
dismiss()
mCallback?.onPINPatternChanged()
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt
index 7008e5b..8878238 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ReceiveTransactionFragment.kt
@@ -4,7 +4,6 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Animatable
import android.os.Bundle
-import android.preference.PreferenceManager
import android.util.Log
import android.view.*
import android.widget.AdapterView
@@ -12,6 +11,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.collection.LongSparseArray
import androidx.core.content.ContextCompat
import androidx.fragment.app.viewModels
+import androidx.preference.PreferenceManager
import com.google.common.primitives.UnsignedLong
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.jakewharton.rxbinding3.widget.textChanges
@@ -136,9 +136,7 @@ class ReceiveTransactionFragment : ConnectedFragment() {
)
)
- mAssets.sortWith(
- Comparator { a, b -> a.toString().compareTo(b.toString(), true) }
- )
+ mAssets.sortWith { a, b -> a.toString().compareTo(b.toString(), true) }
// Add an option at the end so the user can search for an asset other than the ones saved in the db
val asset = cy.agorise.bitsybitshareswallet.database.entities.Asset(
@@ -208,7 +206,7 @@ class ReceiveTransactionFragment : ConnectedFragment() {
binding.actvAsset.textChanges()
.skipInitialValue()
.debounce(500, TimeUnit.MILLISECONDS)
- .map { it.toString().trim().toUpperCase() }
+ .map { it.toString().trim().toUpperCase(Locale.getDefault()) }
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
if (!selectedInAutoCompleteTextView) {
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt
index cca7fbe..e03afca 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SendTransactionFragment.kt
@@ -3,7 +3,6 @@ package cy.agorise.bitsybitshareswallet.fragments
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Handler
-import android.preference.PreferenceManager
import android.provider.Settings
import android.util.Log
import android.view.*
@@ -15,6 +14,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
+import androidx.preference.PreferenceManager
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.google.android.material.snackbar.Snackbar
@@ -52,7 +52,6 @@ import java.text.DecimalFormatSymbols
import java.util.ArrayList
import java.util.Locale
import java.util.concurrent.TimeUnit
-import kotlin.Comparator
class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHandler,
BaseSecurityLockDialog.OnPINPatternEnteredListener {
@@ -186,9 +185,7 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
balanceDetailViewModel.getAll().observe(viewLifecycleOwner, { balancesDetails ->
mBalancesDetails.clear()
mBalancesDetails.addAll(balancesDetails)
- mBalancesDetails.sortWith(
- Comparator { a, b -> a.toString().compareTo(b.toString(), true) }
- )
+ mBalancesDetails.sortWith { a, b -> a.toString().compareTo(b.toString(), true) }
mBalancesDetailsAdapter = BalancesDetailsAdapter(
requireContext(),
android.R.layout.simple_spinner_item,
@@ -461,9 +458,11 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
// Try to select the invoice's Asset in the Assets spinner
for (i in 0 until (mBalancesDetailsAdapter?.count ?: 0)) {
- if (mBalancesDetailsAdapter?.getItem(i)?.symbol == invoice.currency.toUpperCase() ||
+ if (mBalancesDetailsAdapter?.getItem(i)?.symbol == invoice.currency
+ .toUpperCase(Locale.getDefault()) ||
(invoice.currency.startsWith("bit", true) &&
- invoice.currency.replaceFirst("bit", "").toUpperCase() ==
+ invoice.currency.replaceFirst("bit", "")
+ .toUpperCase(Locale.getDefault()) ==
mBalancesDetailsAdapter?.getItem(i)?.symbol)
) {
binding.spAsset.setSelection(i)
@@ -477,7 +476,10 @@ class SendTransactionFragment : ConnectedFragment(), ZXingScannerView.ResultHand
if (balanceDetail == null) {
Snackbar.make(
binding.rootView,
- getString(R.string.error__you_dont_own_asset, invoice.currency.toUpperCase()),
+ getString(
+ R.string.error__you_dont_own_asset,
+ invoice.currency.toUpperCase(Locale.getDefault())
+ ),
Snackbar.LENGTH_INDEFINITE
).setAction(android.R.string.ok) { }.show()
return
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt
index b963a76..5882cb2 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt
@@ -3,15 +3,16 @@ package cy.agorise.bitsybitshareswallet.fragments
import android.content.Context
import android.os.Bundle
import android.os.Handler
-import android.preference.PreferenceManager
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.collection.LongSparseArray
+import androidx.core.content.edit
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.viewModels
+import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onDismiss
@@ -485,9 +486,9 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
when (index) {
0 -> { /* None */
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 0)
- .apply() // 0 -> None
+ PreferenceManager.getDefaultSharedPreferences(context).edit {
+ putInt(Constants.KEY_SECURITY_LOCK_SELECTED, 0) // 0 -> None
+ }
// Call this function to update the UI
onPINPatternChanged()
@@ -564,8 +565,9 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
.cancelable(false)
.positiveButton(R.string.button__copied) {
val now = System.currentTimeMillis()
- PreferenceManager.getDefaultSharedPreferences(it.context).edit()
- .putLong(Constants.KEY_LAST_ACCOUNT_BACKUP, now).apply()
+ PreferenceManager.getDefaultSharedPreferences(it.context).edit {
+ putLong(Constants.KEY_LAST_ACCOUNT_BACKUP, now)
+ }
binding.tvBackupWarning.visibility = View.GONE
}
@@ -623,14 +625,12 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
// Clears the database.
viewModel.clearDatabase(context)
- // Clears the shared preferences.
- val pref = PreferenceManager.getDefaultSharedPreferences(context)
- pref.edit().clear().apply()
-
- // Marks the license as agreed, so that it is not shown to the user again.
- pref.edit().putInt(
- Constants.KEY_LAST_AGREED_LICENSE_VERSION, Constants.CURRENT_LICENSE_VERSION
- ).apply()
+ val pref = PreferenceManager.getDefaultSharedPreferences(context).edit {
+ // Clears the shared preferences.
+ clear()
+ // Marks the license as agreed, so that it is not shown to the user again.
+ putInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, Constants.CURRENT_LICENSE_VERSION)
+ }
// Restarts the activity, which will restart the whole application since it uses a
// single activity architecture.
@@ -639,4 +639,3 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
activity?.startActivity(intent)
}
}
-
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/TransactionsFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/TransactionsFragment.kt
index 9004951..c117d65 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/TransactionsFragment.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/TransactionsFragment.kt
@@ -5,13 +5,13 @@ import android.content.pm.PackageManager
import android.graphics.Point
import android.os.Bundle
import android.os.Environment
-import android.preference.PreferenceManager
import android.view.*
import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.viewModels
+import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsMultiChoice
@@ -26,6 +26,7 @@ import cy.agorise.bitsybitshareswallet.viewmodels.TransactionsViewModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.io.File
+import java.util.*
import java.util.concurrent.TimeUnit
/**
@@ -110,7 +111,7 @@ class TransactionsFragment : Fragment(), FilterOptionsDialog.OnFilterOptionsSele
searchView.queryTextChangeEvents()
.skipInitialValue()
.debounce(500, TimeUnit.MILLISECONDS)
- .map { it.queryText.toString().toLowerCase() }
+ .map { it.queryText.toString().toLowerCase(Locale.getDefault()) }
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
viewModel.setFilterQuery(it)
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/processors/TransfersLoader.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/processors/TransfersLoader.kt
index d6ef5ee..a56e432 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/processors/TransfersLoader.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/processors/TransfersLoader.kt
@@ -1,8 +1,8 @@
package cy.agorise.bitsybitshareswallet.processors
import android.content.Context
-import android.preference.PreferenceManager
import android.util.Log
+import androidx.preference.PreferenceManager
import cy.agorise.bitsybitshareswallet.database.entities.Transfer
import cy.agorise.bitsybitshareswallet.models.HistoricalOperationEntry
import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository
@@ -75,8 +75,8 @@ class TransfersLoader(private var mContext: Context?) {
transferRepository = TransferRepository(mContext!!)
authorityRepository = AuthorityRepository(mContext!!)
- val pref = PreferenceManager.getDefaultSharedPreferences(mContext)
- val userId = pref.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "") ?: ""
+ val userId = PreferenceManager.getDefaultSharedPreferences(mContext)
+ .getString(Constants.KEY_CURRENT_ACCOUNT_ID, "") ?: ""
if (userId != "") {
mCurrentAccount = UserAccount(userId)
mDisposables.add(
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/MerchantRepository.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/MerchantRepository.kt
index eaab376..80e5721 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/MerchantRepository.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/MerchantRepository.kt
@@ -2,9 +2,10 @@ package cy.agorise.bitsybitshareswallet.repositories
import android.content.Context
import android.os.AsyncTask
-import android.preference.PreferenceManager
import android.util.Log
+import androidx.core.content.edit
import androidx.lifecycle.LiveData
+import androidx.preference.PreferenceManager
import cy.agorise.bitsybitshareswallet.database.BitsyDatabase
import cy.agorise.bitsybitshareswallet.database.daos.MerchantDao
import cy.agorise.bitsybitshareswallet.database.entities.Merchant
@@ -41,7 +42,7 @@ class MerchantRepository internal constructor(val context: Context) : retrofit2.
.addConverterFactory(GsonConverterFactory.create())
.build()
- bitsyWebservice = retrofit.create(BitsyWebservice::class.java)
+ bitsyWebservice = retrofit.create(BitsyWebservice::class.java)
}
/** Returns a LiveData object directly from the database while the response from the WebService is obtained. */
@@ -79,8 +80,9 @@ class MerchantRepository internal constructor(val context: Context) : retrofit2.
updateMerchants(merchantsList)
val now = System.currentTimeMillis()
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .putLong(Constants.KEY_MERCHANTS_LAST_UPDATE, now).apply()
+ PreferenceManager.getDefaultSharedPreferences(context).edit {
+ putLong(Constants.KEY_MERCHANTS_LAST_UPDATE, now)
+ }
}
}
}
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TellerRepository.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TellerRepository.kt
index 9e757a2..6bb5b53 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TellerRepository.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TellerRepository.kt
@@ -2,9 +2,10 @@ package cy.agorise.bitsybitshareswallet.repositories
import android.content.Context
import android.os.AsyncTask
-import android.preference.PreferenceManager
import android.util.Log
+import androidx.core.content.edit
import androidx.lifecycle.LiveData
+import androidx.preference.PreferenceManager
import cy.agorise.bitsybitshareswallet.database.BitsyDatabase
import cy.agorise.bitsybitshareswallet.database.daos.TellerDao
import cy.agorise.bitsybitshareswallet.database.entities.Teller
@@ -79,8 +80,9 @@ class TellerRepository internal constructor(val context: Context) : retrofit2.Ca
updateTellers(tellersList)
val now = System.currentTimeMillis()
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .putLong(Constants.KEY_TELLERS_LAST_UPDATE, now).apply()
+ PreferenceManager.getDefaultSharedPreferences(context).edit {
+ putLong(Constants.KEY_TELLERS_LAST_UPDATE, now).apply()
+ }
}
}
}
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TransferRepository.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TransferRepository.kt
index 3b220d2..2b71235 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TransferRepository.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/repositories/TransferRepository.kt
@@ -1,9 +1,7 @@
package cy.agorise.bitsybitshareswallet.repositories
import android.content.Context
-import android.content.SharedPreferences
import android.os.AsyncTask
-import android.preference.PreferenceManager
import android.util.Log
import androidx.lifecycle.LiveData
import cy.agorise.bitsybitshareswallet.database.BitsyDatabase
@@ -27,20 +25,18 @@ class TransferRepository internal constructor(context: Context) {
private val mTransferDao: TransferDao
private val mEquivalentValuesDao: EquivalentValueDao
private val compositeDisposable = CompositeDisposable()
- private val mPreferences: SharedPreferences
init {
val db = BitsyDatabase.getDatabase(context)
mTransferDao = db!!.transferDao()
mEquivalentValuesDao = db.equivalentValueDao()
- mPreferences = PreferenceManager.getDefaultSharedPreferences(context)
}
fun insertAll(transfers: List) {
insertAllAsyncTask(mTransferDao).execute(transfers)
}
- fun update(transfer: Transfer){
+ fun update(transfer: Transfer) {
mTransferDao.insert(transfer)
}
@@ -82,11 +78,17 @@ class TransferRepository internal constructor(context: Context) {
compositeDisposable.add(mTransferDao.getTransfersWithMissingValueIn(symbol)
.map { transfer -> obtainFiatValue(transfer, symbol) }
.subscribe({
- if(it.value >= 0) mEquivalentValuesDao.insert(it)
- },{
- Log.e(TAG,"Error while trying to create a new equivalent value. Msg: ${it.message}")
- for(element in it.stackTrace){
- Log.e(TAG,"${element.className}#${element.methodName}:${element.lineNumber}")
+ if (it.value >= 0) mEquivalentValuesDao.insert(it)
+ }, {
+ Log.e(
+ TAG,
+ "Error while trying to create a new equivalent value. Msg: ${it.message}"
+ )
+ for (element in it.stackTrace) {
+ Log.e(
+ TAG,
+ "${element.className}#${element.methodName}:${element.lineNumber}"
+ )
}
})
)
@@ -107,20 +109,23 @@ class TransferRepository internal constructor(context: Context) {
val dateFormat = SimpleDateFormat("dd-MM-yyyy", Locale.ROOT)
val date = Date(transfer.timestamp * 1000)
val response = sg.getService(CoingeckoService::class.java)
- ?.getHistoricalValueSync("bitshares", dateFormat.format(date), false)
- ?.execute()
+ ?.getHistoricalValueSync("bitshares", dateFormat.format(date), false)
+ ?.execute()
var equivalentFiatValue = -1L
- if(response?.isSuccessful == true){
- val price: Double = response.body()?.market_data?.current_price?.get(symbol.toLowerCase()) ?: -1.0
- if(price > 0){
+ if (response?.isSuccessful == true) {
+ val price: Double = response.body()?.market_data?.current_price
+ ?.get(symbol.toLowerCase(Locale.getDefault())) ?: -1.0
+ if (price > 0) {
// The equivalent value is obtained by:
// 1- Dividing the base value by 100000 (BTS native precision)
// 2- Multiplying that BTS value by the unit price in the chosen fiat
// 3- Multiplying the resulting value by 100 in order to express it in cents
- equivalentFiatValue = Math.round(transfer.btsValue?.toFloat()?.div(1e5)?.times(price)?.times(100) ?: -1.0)
+ equivalentFiatValue = Math.round(
+ transfer.btsValue?.toFloat()?.div(1e5)?.times(price)?.times(100) ?: -1.0
+ )
}
- }else{
- Log.w(TAG,"Request was not successful. code: ${response?.code()}")
+ } else {
+ Log.w(TAG, "Request was not successful. code: ${response?.code()}")
}
return EquivalentValue(transfer.id, equivalentFiatValue, symbol)
}
@@ -160,7 +165,7 @@ class TransferRepository internal constructor(context: Context) {
* be cleared.
*/
fun onCleared() {
- if(!compositeDisposable.isDisposed)
+ if (!compositeDisposable.isDisposed)
compositeDisposable.clear()
}
}
\ No newline at end of file
diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/CryptoUtils.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/CryptoUtils.kt
index 152947b..b32835f 100644
--- a/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/CryptoUtils.kt
+++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/utils/CryptoUtils.kt
@@ -1,8 +1,9 @@
package cy.agorise.bitsybitshareswallet.utils
import android.content.Context
-import android.preference.PreferenceManager
import android.util.Base64
+import androidx.core.content.edit
+import androidx.preference.PreferenceManager
import com.moldedbits.r2d2.R2d2
import java.security.MessageDigest
@@ -32,11 +33,9 @@ object CryptoUtils {
fun put(context: Context, key: String, value: String) {
val r2d2 = R2d2(context)
val encrypted = r2d2.encryptData(value)
- PreferenceManager
- .getDefaultSharedPreferences(context)
- .edit()
- .putString(key, encrypted)
- .apply()
+ PreferenceManager.getDefaultSharedPreferences(context).edit {
+ putString(key, encrypted)
+ }
}
/**