Created SettingsFragmentViewModel to serve as an intermediary between the UserAccountRepository (db) and the SettingsFragment. Added the Accounts section to the Settings UI with a subsection to let the user upgrade its account to LTM. Added a listener that when the 'Upgrade to LTM' button is tapped, shows a dialog explaining what is needed to be LTM and its cost.
This commit is contained in:
parent
eb0ae56a26
commit
99e378d123
5 changed files with 85 additions and 2 deletions
|
@ -9,6 +9,7 @@ import android.util.Log
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.callbacks.onDismiss
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
|
@ -21,7 +22,9 @@ import cy.agorise.bitsybitshareswallet.adapters.FullNodesAdapter
|
|||
import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository
|
||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||
import cy.agorise.bitsybitshareswallet.utils.CryptoUtils
|
||||
import cy.agorise.bitsybitshareswallet.viewmodels.SettingsFragmentViewModel
|
||||
import cy.agorise.graphenej.BrainKey
|
||||
import cy.agorise.graphenej.UserAccount
|
||||
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
||||
import cy.agorise.graphenej.api.calls.GetDynamicGlobalProperties
|
||||
import cy.agorise.graphenej.models.DynamicGlobalProperties
|
||||
|
@ -44,6 +47,10 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
|
|||
private const val ACTION_SHOW_BRAINKEY = 2
|
||||
}
|
||||
|
||||
private lateinit var mViewModel: SettingsFragmentViewModel
|
||||
|
||||
private var mUserAccount: UserAccount? = null
|
||||
|
||||
// Dialog displaying the list of nodes and their latencies
|
||||
private var mNodesDialog: MaterialDialog? = null
|
||||
|
||||
|
@ -63,6 +70,19 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
|
|||
|
||||
Crashlytics.setString(Constants.CRASHLYTICS_KEY_LAST_SCREEN, TAG)
|
||||
|
||||
val userId = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "") ?: ""
|
||||
|
||||
// Configure ViewModel
|
||||
mViewModel= ViewModelProviders.of(this).get(SettingsFragmentViewModel::class.java)
|
||||
|
||||
mViewModel.getUserAccount(userId).observe(this,
|
||||
androidx.lifecycle.Observer<cy.agorise.bitsybitshareswallet.database.entities.UserAccount>{ userAccount ->
|
||||
if (userAccount != null) {
|
||||
mUserAccount = UserAccount(userAccount.id, userAccount.name)
|
||||
}
|
||||
})
|
||||
|
||||
initAutoCloseSwitch()
|
||||
|
||||
initNightModeSwitch()
|
||||
|
@ -106,6 +126,8 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
|
|||
tvSecurityLockSelected.setOnClickListener { onSecurityLockTextSelected() }
|
||||
|
||||
btnViewBrainKey.setOnClickListener { onShowBrainKeyButtonSelected() }
|
||||
|
||||
btnUpgradeToLTM.setOnClickListener { onUpgradeToLTMButtonSelected() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -203,7 +225,7 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
|
|||
}
|
||||
|
||||
/**
|
||||
* Encapsulated the logic required to do actions possibly locked by the Security Lock. If PIN/Pattern is selected
|
||||
* Encapsulates the logic required to do actions possibly locked by the Security Lock. If PIN/Pattern is selected
|
||||
* then it prompts for it.
|
||||
*
|
||||
* @param actionIdentifier Identifier used to know why a verify security lock was launched
|
||||
|
@ -355,6 +377,19 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
|
|||
}
|
||||
}
|
||||
|
||||
private fun onUpgradeToLTMButtonSelected() {
|
||||
context?.let { context ->
|
||||
val content = getString(R.string.msg__account_upgrade_dialog, mUserAccount?.name)
|
||||
MaterialDialog(context).show {
|
||||
message(text = content)
|
||||
negativeButton(android.R.string.cancel)
|
||||
positiveButton(android.R.string.ok) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
super.onServiceDisconnected(name)
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package cy.agorise.bitsybitshareswallet.viewmodels
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.LiveData
|
||||
import cy.agorise.bitsybitshareswallet.database.entities.UserAccount
|
||||
import cy.agorise.bitsybitshareswallet.repositories.UserAccountRepository
|
||||
|
||||
class SettingsFragmentViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private var mUserAccountRepository = UserAccountRepository(application)
|
||||
|
||||
internal fun getUserAccount(id: String): LiveData<UserAccount> {
|
||||
return mUserAccountRepository.getUserAccount(id)
|
||||
}
|
||||
}
|
|
@ -107,6 +107,31 @@
|
|||
android:layout_marginTop="@dimen/spacing_same_topic"
|
||||
android:text="@string/button__view_and_copy"/>
|
||||
|
||||
<!-- Accounts -->
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_different_section"
|
||||
android:text="@string/title__accounts"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_different_topic"
|
||||
android:text="@string/msg__upgrade_to_ltm"
|
||||
android:textAppearance="@style/TextAppearance.Bitsy.Body1"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnUpgradeToLTM"
|
||||
style="@style/Widget.Bitsy.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_same_topic"
|
||||
android:text="@string/button__upgrade_to_ltm"/>
|
||||
|
||||
<!-- Bugs or Ideas -->
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -133,6 +133,10 @@
|
|||
<string name="msg__brainkey_info">¡Escribe esto! Asegúrate de tener 2 copias de este BrainKey en 2 lugares seguros en caso de incendio o pérdida. ¡La seguridad primero! ¡Cualquiera con acceso a tu BrainKey puede acceder a los fondos en tu cuenta!</string>
|
||||
<string name="button__copied">Copiado</string>
|
||||
<string name="button__view_and_copy">Ver y Copiar</string>
|
||||
<string name="title__accounts">Cuentas</string>
|
||||
<string name="msg__upgrade_to_ltm">Actualiza a la membresía de por vida (LTM). Las cuentas LTM de Bitshares pagan las tarifas más bajas, obtienen un 80% de devolución de dinero y bonificaciones por referencias.</string>
|
||||
<string name="button__upgrade_to_ltm">Ascender a LTM</string>
|
||||
<string name="msg__account_upgrade_dialog">La membresía de por vida te permite operar con tarifas de red muy reducidas.\n\nTendrá efecto en la cuenta actual "%1$s"\n\nSin embargo, tiene un costo de alrededor de 100 USD pagados en Bitshares.\n\n¿Estás seguro de que deseas continuar?</string>
|
||||
<string name="title__bugs_or_ideas">Errores o Ideas?</string>
|
||||
<string name="msg__bugs_or_ideas">Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise</string>
|
||||
<string name="title__bitshares_nodes_dialog">Bloque: %1$s</string>
|
||||
|
|
|
@ -133,7 +133,11 @@
|
|||
<string name="msg__brainkey_description">BrainKey. Account recovery words that can be captured or copied, but not edited.</string>
|
||||
<string name="msg__brainkey_info">Write this down! Be sure you have 2 copies of this BrainKey in 2 secure locations in case of fire or loss. Security First! Anyone with access to your BrainKey can access the funds in your account!</string>
|
||||
<string name="button__copied">Copied</string>
|
||||
<string name="button__view_and_copy"><![CDATA[View & Copy]]></string>
|
||||
<string name="button__view_and_copy">View & Copy</string>
|
||||
<string name="title__accounts">Accounts</string>
|
||||
<string name="msg__upgrade_to_ltm">Upgrade to LifeTime Membership (LTM). Bitshares\' LTM accounts pay near-zero fees, get 80% cashback and bonuses for referrals.</string>
|
||||
<string name="button__upgrade_to_ltm">Upgrade to LTM</string>
|
||||
<string name="msg__account_upgrade_dialog">The Life Time Membership allows you to trade with a reduced set of network fees.\n\nIt will take effect to the current account "%1$s"\n\nIt does however come with a cost of around 100 USD paid in Bitshares.\n\nAre you sure you want to proceed?</string>
|
||||
<string name="title__bugs_or_ideas">Bugs or Ideas?</string>
|
||||
<string name="msg__bugs_or_ideas">Telegram: https://t.me/Agorise\nKeybase: https://keybase.io/team/Agorise</string>
|
||||
<string name="title__bitshares_nodes_dialog">Block: %1$s</string>
|
||||
|
|
Loading…
Reference in a new issue