Prevent calling the method to obtain account iformation when there is no longer missing account information.

This commit is contained in:
Severiano Jaramillo 2018-12-08 20:52:48 -06:00
parent 628b30ce54
commit 2b168180c6

View file

@ -99,7 +99,7 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
mUserAccountViewModel = ViewModelProviders.of(this).get(UserAccountViewModel::class.java) mUserAccountViewModel = ViewModelProviders.of(this).get(UserAccountViewModel::class.java)
mUserAccountViewModel.getMissingUserAccountIds().observe(this, Observer<List<String>>{ userAccountIds -> mUserAccountViewModel.getMissingUserAccountIds().observe(this, Observer<List<String>>{ userAccountIds ->
if (!userAccountIds.isEmpty()) { if (userAccountIds.isNotEmpty()) {
for (userAccountId in userAccountIds) for (userAccountId in userAccountIds)
missingUserAccounts.add(UserAccount(userAccountId)) missingUserAccounts.add(UserAccount(userAccountId))
@ -122,6 +122,7 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
} }
mUserAccountViewModel.insertAll(userAccounts) mUserAccountViewModel.insertAll(userAccounts)
missingUserAccounts.clear()
} }
/** /**
@ -131,7 +132,7 @@ abstract class ConnectedActivity : AppCompatActivity(), ServiceConnection {
override fun run() { override fun run() {
if (mNetworkService!!.isConnected) { if (mNetworkService!!.isConnected) {
mNetworkService!!.sendMessage(GetAccounts(missingUserAccounts), GetAccounts.REQUIRED_API) mNetworkService!!.sendMessage(GetAccounts(missingUserAccounts), GetAccounts.REQUIRED_API)
} else { } else if (missingUserAccounts.isNotEmpty()){
mHandler.postDelayed(this, Constants.NETWORK_SERVICE_RETRY_PERIOD) mHandler.postDelayed(this, Constants.NETWORK_SERVICE_RETRY_PERIOD)
} }
} }