-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NMA-615 | Contacts Page | Unregistered Users #519
Merged
HashEngineering
merged 21 commits into
dashpay:evonet-develop
from
desamtralized:dashpay-contacts-page-no-user
Oct 6, 2020
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0698f10
Removing wallet fragment before recreating activity
desamtralized 6f08871
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized 6bbb759
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized 42c99c4
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized af16683
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized 4dde9e0
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized 909ef0b
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized e4ce62c
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized 262c0bf
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized 80e5932
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized 088bbbb
Merge remote-tracking branch 'upstream/evonet-develop' into evonet-de…
desamtralized da1f349
Upgrade to Evolution page.
desamtralized de3d53e
Removed commented code
desamtralized 964b74e
Using Async version of db fetch
desamtralized a50998a
Fixed stuck contacts icon
desamtralized ef6db8a
Replaced old school callbacks-based communication model between activ…
tomasz-ludek 3cc66d3
Further improvements of MainActivityViewModel
tomasz-ludek 620cc98
Minor code refactoring
tomasz-ludek cd1d505
Merge branch 'master-into-evonet-develop' into dashpay-contacts-page-…
tomasz-ludek 5f7afd4
Merge branch 'evonet-develop' into dashpay-contacts-page-no-user
tomasz-ludek b912e2c
Final improvements of handling Join DashPay button visibility.
tomasz-ludek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
wallet/src/de/schildbach/wallet/ui/MainActivityViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.schildbach.wallet.ui | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.AndroidViewModel | ||
import androidx.lifecycle.liveData | ||
import de.schildbach.wallet.AppDatabase | ||
import de.schildbach.wallet.data.BlockchainIdentityBaseData | ||
import de.schildbach.wallet.data.BlockchainState | ||
import de.schildbach.wallet.livedata.Status | ||
import de.schildbach.wallet.ui.dashpay.PlatformRepo | ||
import kotlinx.coroutines.Dispatchers | ||
|
||
class MainActivityViewModel(application: Application) : AndroidViewModel(application) { | ||
|
||
private val platformRepo = PlatformRepo.getInstance() | ||
|
||
val isPlatformAvailableData = liveData(Dispatchers.IO) { | ||
val status = platformRepo.isPlatformAvailable() | ||
if (status.status == Status.SUCCESS && status.data != null) { | ||
emit(status.data) | ||
} else { | ||
emit(false) | ||
} | ||
} | ||
val isPlatformAvailable: Boolean | ||
get() = isPlatformAvailableData.value ?: false | ||
|
||
val blockchainStateData = AppDatabase.getAppDatabase().blockchainStateDao().load() | ||
val blockchainState: BlockchainState? | ||
get() = blockchainStateData.value | ||
|
||
val blockchainIdentityData = AppDatabase.getAppDatabase().blockchainIdentityDataDaoAsync().loadBase() | ||
val blockchainIdentity: BlockchainIdentityBaseData? | ||
get() = blockchainIdentityData.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +30,12 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout | |
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.Observer | ||
import androidx.lifecycle.ViewModelProviders | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.google.android.material.appbar.AppBarLayout | ||
import com.google.android.material.appbar.AppBarLayout.Behavior.DragCallback | ||
import de.schildbach.wallet.WalletApplication | ||
import de.schildbach.wallet.data.BlockchainIdentityBaseData | ||
import de.schildbach.wallet.data.BlockchainIdentityData | ||
import de.schildbach.wallet.data.BlockchainState | ||
import de.schildbach.wallet.data.PaymentIntent | ||
import de.schildbach.wallet.ui.CheckPinDialog.Companion.show | ||
import de.schildbach.wallet.ui.InputParser.StringInputParser | ||
|
@@ -64,10 +63,10 @@ import org.dash.wallet.integration.uphold.ui.UpholdAccountActivity | |
|
||
class WalletFragment : Fragment() { | ||
|
||
private lateinit var mainActivityViewModel: MainActivityViewModel | ||
|
||
private var clipboardManager: ClipboardManager? = null | ||
private var blockchainState: BlockchainState? = null | ||
private var syncComplete = false | ||
private var isPlatformAvailable = false | ||
private var noIdentityCreatedOrInProgress = true | ||
private var retryCreationIfInProgress = true | ||
|
||
|
@@ -87,6 +86,7 @@ class WalletFragment : Fragment() { | |
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
initViewModel() | ||
initView() | ||
clipboardManager = activity?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager? | ||
|
||
|
@@ -105,7 +105,20 @@ class WalletFragment : Fragment() { | |
}) | ||
|
||
registerOnCoinsSentReceivedListener() | ||
(requireActivity() as OnWalletFragmentViewCreatedListener).onWalletFragmentViewCreated() | ||
} | ||
|
||
fun initViewModel() { | ||
mainActivityViewModel = ViewModelProvider(requireActivity())[MainActivityViewModel::class.java] | ||
mainActivityViewModel.isPlatformAvailableData.observe(viewLifecycleOwner, Observer { | ||
showHideJoinDashPayAction() | ||
}) | ||
mainActivityViewModel.blockchainStateData.observe(viewLifecycleOwner, Observer { | ||
updateSyncState() | ||
showHideJoinDashPayAction() | ||
}) | ||
mainActivityViewModel.blockchainIdentityData.observe(viewLifecycleOwner, Observer { | ||
setBlockchainIdentity(it) | ||
}) | ||
} | ||
|
||
override fun onDestroyView() { | ||
|
@@ -119,27 +132,7 @@ class WalletFragment : Fragment() { | |
showHideJoinDashPayAction() | ||
} | ||
|
||
fun setBlockchainState(blockchainState: BlockchainState?) { | ||
this.blockchainState = blockchainState | ||
if (isDetached || !isVisible) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this shouldn't be needed when using LiveDatas |
||
return | ||
} | ||
updateSyncState() | ||
showHideJoinDashPayAction() | ||
} | ||
|
||
fun setPlatformAvailability(available: Boolean) { | ||
isPlatformAvailable = available | ||
if (isDetached || !isVisible) { | ||
return | ||
} | ||
showHideJoinDashPayAction() | ||
} | ||
|
||
fun setBlockchainIdentity(identityData: BlockchainIdentityBaseData?) { | ||
if (isDetached || !isVisible) { | ||
return | ||
} | ||
private fun setBlockchainIdentity(identityData: BlockchainIdentityBaseData?) { | ||
if (identityData != null) { | ||
noIdentityCreatedOrInProgress = identityData.creationState == BlockchainIdentityData.CreationState.NONE | ||
showHideJoinDashPayAction() | ||
|
@@ -166,17 +159,19 @@ class WalletFragment : Fragment() { | |
} | ||
|
||
private fun updateSyncState() { | ||
if (blockchainState == null) { | ||
if (mainActivityViewModel.blockchainState == null) { | ||
return | ||
} | ||
val blockchainState = mainActivityViewModel.blockchainState | ||
|
||
var percentage: Int = blockchainState!!.percentageSync | ||
if (blockchainState!!.replaying && blockchainState!!.percentageSync == 100) { | ||
if (blockchainState.replaying && blockchainState.percentageSync == 100) { | ||
//This is to prevent showing 100% when using the Rescan blockchain function. | ||
//The first few broadcasted blockchainStates are with percentage sync at 100% | ||
percentage = 0 | ||
} | ||
val syncProgressView = sync_status_progress | ||
if (blockchainState != null && blockchainState!!.syncFailed()) { | ||
if (blockchainState.syncFailed()) { | ||
updateSyncPaneVisibility(R.id.sync_status_pane, true) | ||
sync_progress_pane.visibility = View.GONE | ||
sync_error_pane.visibility = View.VISIBLE | ||
|
@@ -189,7 +184,7 @@ class WalletFragment : Fragment() { | |
syncProgressView.progress = percentage | ||
val syncPercentageView = sync_status_percentage | ||
syncPercentageView.text = "$percentage%" | ||
syncComplete = blockchainState!!.isSynced() | ||
syncComplete = blockchainState.isSynced() | ||
if (syncComplete) { | ||
syncPercentageView.setTextColor(resources.getColor(R.color.success_green)) | ||
syncStatusTitle.setText(R.string.sync_status_sync_title) | ||
|
@@ -216,7 +211,7 @@ class WalletFragment : Fragment() { | |
} | ||
|
||
fun showHideJoinDashPayAction() { | ||
if (noIdentityCreatedOrInProgress && syncComplete && isPlatformAvailable) { | ||
if (noIdentityCreatedOrInProgress && syncComplete && mainActivityViewModel.isPlatformAvailable) { | ||
val visible = wallet.canAffordIdentityCreation() && config.showJoinDashPay | ||
join_dashpay_action.visibility = if (visible) View.VISIBLE else View.GONE | ||
} else { | ||
|
@@ -231,7 +226,7 @@ class WalletFragment : Fragment() { | |
} | ||
|
||
private fun handleVerifySeed() { | ||
val checkPinSharedModel = ViewModelProviders.of(this)[CheckPinSharedModel::class.java] | ||
val checkPinSharedModel = ViewModelProvider(this)[CheckPinSharedModel::class.java] | ||
checkPinSharedModel.onCorrectPinCallback.observe(viewLifecycleOwner, Observer<Pair<Int?, String?>?> { data -> | ||
if (data?.second != null) { | ||
startVerifySeedActivity(data.second!!) | ||
|
@@ -346,8 +341,4 @@ class WalletFragment : Fragment() { | |
interface OnSelectPaymentTabListener { | ||
fun onSelectPaymentTab(mode: Int) | ||
} | ||
|
||
interface OnWalletFragmentViewCreatedListener { | ||
fun onWalletFragmentViewCreated() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those empty observers could be replaced by other way of triggering data loading but let's leave it as it is
I'll fix it when working on "JoinDash" shortcut when #516 in merged (it will be merged after this PR)