Removed ImportBrainkeyActivity and created ImportBrainkeyFragment instead, with this the app is now using a single activity and all the content is divided in fragments. All the navigation inside the app is now controlled by the AAC Navigation component.
This commit is contained in:
parent
58e1e0a575
commit
2dd843fe91
6 changed files with 67 additions and 72 deletions
|
@ -44,7 +44,6 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".activities.ImportBrainkeyActivity"/>
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.MainActivity"
|
android:name=".activities.MainActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
|
|
|
@ -111,4 +111,13 @@ class MainActivity : ConnectedActivity() {
|
||||||
override fun handleConnectionStatusUpdate(connectionStatusUpdate: ConnectionStatusUpdate) {
|
override fun handleConnectionStatusUpdate(connectionStatusUpdate: ConnectionStatusUpdate) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBackPressed() {
|
||||||
|
// Trick used to avoid crashes when the user is in the License or ImportBrainkey and presses the back button
|
||||||
|
val currentDestination=NavHostFragment.findNavController(navHostFragment).currentDestination
|
||||||
|
when(currentDestination?.id) {
|
||||||
|
R.id.license_dest, R.id.import_brainkey_dest -> finish()
|
||||||
|
else -> super.onBackPressed()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package cy.agorise.bitsybitshareswallet.activities
|
package cy.agorise.bitsybitshareswallet.fragments
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.widget.Toolbar
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.afollestad.materialdialogs.list.listItemsSingleChoice
|
import com.afollestad.materialdialogs.list.listItemsSingleChoice
|
||||||
import com.jakewharton.rxbinding3.widget.textChanges
|
import com.jakewharton.rxbinding3.widget.textChanges
|
||||||
|
@ -14,6 +17,7 @@ import cy.agorise.bitsybitshareswallet.repositories.AuthorityRepository
|
||||||
import cy.agorise.bitsybitshareswallet.repositories.UserAccountRepository
|
import cy.agorise.bitsybitshareswallet.repositories.UserAccountRepository
|
||||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||||
import cy.agorise.bitsybitshareswallet.utils.CryptoUtils
|
import cy.agorise.bitsybitshareswallet.utils.CryptoUtils
|
||||||
|
import cy.agorise.bitsybitshareswallet.utils.toast
|
||||||
import cy.agorise.graphenej.*
|
import cy.agorise.graphenej.*
|
||||||
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
||||||
import cy.agorise.graphenej.api.calls.GetAccounts
|
import cy.agorise.graphenej.api.calls.GetAccounts
|
||||||
|
@ -21,25 +25,20 @@ import cy.agorise.graphenej.api.calls.GetKeyReferences
|
||||||
import cy.agorise.graphenej.models.AccountProperties
|
import cy.agorise.graphenej.models.AccountProperties
|
||||||
import cy.agorise.graphenej.models.JsonRpcResponse
|
import cy.agorise.graphenej.models.JsonRpcResponse
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import kotlinx.android.synthetic.main.fragment_import_brainkey.*
|
||||||
import kotlinx.android.synthetic.main.activity_import_brainkey.*
|
|
||||||
import org.bitcoinj.core.ECKey
|
import org.bitcoinj.core.ECKey
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
// TODO add progress bar or something while the user waits for the import response from the node
|
class ImportBrainkeyFragment : ConnectedFragment() {
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "ImportBrainkeyActivity"
|
||||||
|
}
|
||||||
|
|
||||||
class ImportBrainkeyActivity : ConnectedActivity() {
|
/** Private variable that will hold an instance of the [BrainKey] class */
|
||||||
private val TAG = "ImportBrainkeyActivity"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private variable that will hold an instance of the [BrainKey] class
|
|
||||||
*/
|
|
||||||
private var mBrainKey: BrainKey? = null
|
private var mBrainKey: BrainKey? = null
|
||||||
|
|
||||||
/**
|
/** User account associated with the key derived from the brainkey that the user just typed in */
|
||||||
* User account associated with the key derived from the brainkey that the user just typed in
|
|
||||||
*/
|
|
||||||
private var mUserAccount: UserAccount? = null
|
private var mUserAccount: UserAccount? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,15 +52,20 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
private var keyReferencesRequestId: Long = 0
|
private var keyReferencesRequestId: Long = 0
|
||||||
private var getAccountsRequestId: Long = 0
|
private var getAccountsRequestId: Long = 0
|
||||||
|
|
||||||
private var mDisposables = CompositeDisposable()
|
|
||||||
|
|
||||||
private var isPINValid = false
|
private var isPINValid = false
|
||||||
private var isPINConfirmationValid = false
|
private var isPINConfirmationValid = false
|
||||||
private var isBrainKeyValid = false
|
private var isBrainKeyValid = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
super.onCreate(savedInstanceState)
|
// Remove up navigation icon from the toolbar
|
||||||
setContentView(R.layout.activity_import_brainkey)
|
val toolbar: Toolbar? = activity?.findViewById(R.id.toolbar)
|
||||||
|
toolbar?.navigationIcon = null
|
||||||
|
|
||||||
|
return inflater.inflate(R.layout.fragment_import_brainkey, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
// Use RxJava Debounce to update the PIN error only after the user stops writing for > 500 ms
|
// Use RxJava Debounce to update the PIN error only after the user stops writing for > 500 ms
|
||||||
mDisposables.add(
|
mDisposables.add(
|
||||||
|
@ -202,7 +206,7 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
} else {
|
} else {
|
||||||
if (accountList.isEmpty()) {
|
if (accountList.isEmpty()) {
|
||||||
//hideDialog()
|
//hideDialog()
|
||||||
Toast.makeText(applicationContext, R.string.error__invalid_brainkey, Toast.LENGTH_SHORT).show()
|
context?.toast(getString(R.string.error__invalid_brainkey))
|
||||||
} else {
|
} else {
|
||||||
if (accountList.size == 1) {
|
if (accountList.size == 1) {
|
||||||
// If we only found one account linked to this key, then we just proceed
|
// If we only found one account linked to this key, then we just proceed
|
||||||
|
@ -231,7 +235,7 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
candidates.add(accountProperties.name)
|
candidates.add(accountProperties.name)
|
||||||
}
|
}
|
||||||
// hideDialog()
|
// hideDialog()
|
||||||
MaterialDialog(this)
|
MaterialDialog(context!!)
|
||||||
.title(R.string.dialog__account_candidates_title)
|
.title(R.string.dialog__account_candidates_title)
|
||||||
.message(R.string.dialog__account_candidates_content)
|
.message(R.string.dialog__account_candidates_content)
|
||||||
.listItemsSingleChoice (items = candidates, initialSelection = -1) { _, index, _ ->
|
.listItemsSingleChoice (items = candidates, initialSelection = -1) { _, index, _ ->
|
||||||
|
@ -251,7 +255,7 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
} else if (accountPropertiesList.size == 1) {
|
} else if (accountPropertiesList.size == 1) {
|
||||||
onAccountSelected(accountPropertiesList[0])
|
onAccountSelected(accountPropertiesList[0])
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(applicationContext, R.string.error__try_again, Toast.LENGTH_SHORT).show()
|
context?.toast(getString(R.string.error__try_again))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,10 +277,10 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
private fun onAccountSelected(accountProperties: AccountProperties) {
|
private fun onAccountSelected(accountProperties: AccountProperties) {
|
||||||
mUserAccount!!.name = accountProperties.name
|
mUserAccount!!.name = accountProperties.name
|
||||||
|
|
||||||
val encryptedPIN = CryptoUtils.encrypt(this, tietPin.text!!.toString())
|
val encryptedPIN = CryptoUtils.encrypt(context!!, tietPin.text!!.toString())
|
||||||
|
|
||||||
// Stores the user selected PIN encrypted
|
// Stores the user selected PIN encrypted
|
||||||
PreferenceManager.getDefaultSharedPreferences(this)
|
PreferenceManager.getDefaultSharedPreferences(context!!)
|
||||||
.edit()
|
.edit()
|
||||||
.putString(Constants.KEY_ENCRYPTED_PIN, encryptedPIN)
|
.putString(Constants.KEY_ENCRYPTED_PIN, encryptedPIN)
|
||||||
.apply()
|
.apply()
|
||||||
|
@ -288,14 +292,12 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
|
|
||||||
val userAccount = cy.agorise.bitsybitshareswallet.database.entities.UserAccount(id, name, isLTM)
|
val userAccount = cy.agorise.bitsybitshareswallet.database.entities.UserAccount(id, name, isLTM)
|
||||||
|
|
||||||
val userAccountRepository = UserAccountRepository(application)
|
val userAccountRepository = UserAccountRepository(context!!.applicationContext)
|
||||||
userAccountRepository.insert(userAccount)
|
userAccountRepository.insert(userAccount)
|
||||||
|
|
||||||
// Stores the id of the currently active user account
|
// Stores the id of the currently active user account
|
||||||
PreferenceManager.getDefaultSharedPreferences(this)
|
PreferenceManager.getDefaultSharedPreferences(context!!).edit()
|
||||||
.edit()
|
.putString(Constants.KEY_CURRENT_ACCOUNT_ID, mUserAccount!!.objectId).apply()
|
||||||
.putString(Constants.KEY_CURRENT_ACCOUNT_ID, mUserAccount!!.objectId)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
// Trying to store all possible authorities (owner, active and memo) into the database
|
// Trying to store all possible authorities (owner, active and memo) into the database
|
||||||
val ownerAuthority = accountProperties.owner
|
val ownerAuthority = accountProperties.owner
|
||||||
|
@ -317,17 +319,8 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stores a flag into the SharedPreferences to tell the app there is an active account and there is no need
|
// Send the user back to HomeFragment
|
||||||
// to show this activity again, until the account is removed.
|
findNavController().popBackStack()
|
||||||
PreferenceManager.getDefaultSharedPreferences(this)
|
|
||||||
.edit()
|
|
||||||
.putBoolean(Constants.KEY_INITIAL_SETUP_DONE, true)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
// Send the user to the MainActivity
|
|
||||||
val intent = Intent(this, MainActivity::class.java)
|
|
||||||
startActivity(intent)
|
|
||||||
finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -338,19 +331,13 @@ class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
val wif = brainKey.walletImportFormat
|
val wif = brainKey.walletImportFormat
|
||||||
val sequenceNumber = brainKey.sequenceNumber
|
val sequenceNumber = brainKey.sequenceNumber
|
||||||
|
|
||||||
val encryptedBrainKey = CryptoUtils.encrypt(this, brainKeyWords)
|
val encryptedBrainKey = CryptoUtils.encrypt(context!!, brainKeyWords)
|
||||||
val encryptedSequenceNumber = CryptoUtils.encrypt(this, sequenceNumber.toString())
|
val encryptedSequenceNumber = CryptoUtils.encrypt(context!!, sequenceNumber.toString())
|
||||||
val encryptedWIF = CryptoUtils.encrypt(this, wif)
|
val encryptedWIF = CryptoUtils.encrypt(context!!, wif)
|
||||||
|
|
||||||
val authority = Authority(0, userId, authorityType, encryptedWIF, encryptedBrainKey, encryptedSequenceNumber)
|
val authority = Authority(0, userId, authorityType, encryptedWIF, encryptedBrainKey, encryptedSequenceNumber)
|
||||||
|
|
||||||
val authorityRepository = AuthorityRepository(this)
|
val authorityRepository = AuthorityRepository(context!!)
|
||||||
authorityRepository.insert(authority)
|
authorityRepository.insert(authority)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
|
|
||||||
if (!mDisposables.isDisposed) mDisposables.dispose()
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -43,24 +43,12 @@ class LicenseFragment : Fragment() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function stores the version of the current accepted license version into the Shared Preferences and
|
* This function stores the version of the current accepted license version into the Shared Preferences and
|
||||||
* sends the user to import/create account if there is no active account or to the MainActivity otherwise.
|
* sends the user to import/create account.
|
||||||
*/
|
*/
|
||||||
private fun agree() {
|
private fun agree() {
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||||
.putInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, Constants.CURRENT_LICENSE_VERSION).apply()
|
.putInt(Constants.KEY_LAST_AGREED_LICENSE_VERSION, Constants.CURRENT_LICENSE_VERSION).apply()
|
||||||
|
|
||||||
// val intent : Intent?
|
findNavController().navigate(R.id.import_brainkey_action)
|
||||||
//
|
|
||||||
// val initialSetupDone = PreferenceManager.getDefaultSharedPreferences(this)
|
|
||||||
// .getBoolean(Constants.KEY_INITIAL_SETUP_DONE, false)
|
|
||||||
//
|
|
||||||
// intent = if (!initialSetupDone)
|
|
||||||
// Intent(this, ImportBrainkeyActivity::class.java)
|
|
||||||
// else
|
|
||||||
// Intent(this, MainActivity::class.java)
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// startActivity(intent)
|
|
||||||
// finish()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".activities.ImportBrainkeyActivity">
|
tools:context=".fragments.ImportBrainkeyFragment">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/tilPin"
|
android:id="@+id/tilPin"
|
|
@ -38,9 +38,7 @@
|
||||||
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/setup_action"
|
android:id="@+id/setup_action"
|
||||||
app:destination="@id/navigation_setup"
|
app:destination="@id/navigation_setup"/>
|
||||||
app:popUpTo="@id/home_dest"
|
|
||||||
app:popUpToInclusive="true"/>
|
|
||||||
|
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
|
@ -87,8 +85,22 @@
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/license_dest"
|
android:id="@+id/license_dest"
|
||||||
android:name="cy.agorise.bitsybitshareswallet.fragments.LicenseFragment"
|
android:name="cy.agorise.bitsybitshareswallet.fragments.LicenseFragment"
|
||||||
android:label="LicenseFragment"
|
android:label="@string/app_name"
|
||||||
tools:layout="@layout/fragment_license"/>
|
tools:layout="@layout/fragment_license">
|
||||||
|
|
||||||
|
<action
|
||||||
|
android:id="@+id/import_brainkey_action"
|
||||||
|
app:destination="@id/import_brainkey_dest"
|
||||||
|
app:popUpTo="@id/license_dest"
|
||||||
|
app:popUpToInclusive="true"/>
|
||||||
|
|
||||||
|
</fragment>
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/import_brainkey_dest"
|
||||||
|
android:name="cy.agorise.bitsybitshareswallet.fragments.ImportBrainkeyFragment"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
tools:layout="@layout/fragment_import_brainkey"/>
|
||||||
|
|
||||||
</navigation>
|
</navigation>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue