code cleanup

This commit is contained in:
Mariotaku Lee 2016-12-06 14:25:02 +08:00
parent a964049df1
commit 3d4d98862f
2 changed files with 8 additions and 14 deletions

View File

@ -181,7 +181,7 @@ class ParcelableUserLoader(
if (account != null) {
val task = UpdateAccountInfoTask(context)
task.params = Pair(account, user)
TaskStarter.execute<Pair<AccountDetails, ParcelableUser>, Any, Any>(task)
TaskStarter.execute(task)
}
}
}

View File

@ -19,17 +19,17 @@ import java.io.IOException
/**
* Created by mariotaku on 16/3/8.
*/
class UpdateAccountInfoTask(private val context: Context) : AbstractTask<Pair<AccountDetails, ParcelableUser>, Any, Any>() {
class UpdateAccountInfoTask(private val context: Context) : AbstractTask<Pair<AccountDetails, ParcelableUser>, Any, Unit>() {
override fun doLongOperation(params: Pair<AccountDetails, ParcelableUser>): Any? {
override fun doLongOperation(params: Pair<AccountDetails, ParcelableUser>) {
val resolver = context.contentResolver
val details = params.first
val user = params.second
if (user.is_cache) {
return null
return
}
if (!user.key.maybeEquals(user.account_key)) {
return null
return
}
val am = AccountManager.get(context)
@ -48,13 +48,10 @@ class UpdateAccountInfoTask(private val context: Context) : AbstractTask<Pair<Ac
resolver.update(DirectMessages.Outbox.CONTENT_URI, accountKeyValues, accountKeyWhere, accountKeyWhereArgs)
resolver.update(CachedRelationships.CONTENT_URI, accountKeyValues, accountKeyWhere, accountKeyWhereArgs)
updateTabs(context, resolver, user.key)
return null
updateTabs(resolver, user.key)
}
private fun updateTabs(context: Context, resolver: ContentResolver, accountKey: UserKey) {
private fun updateTabs(resolver: ContentResolver, accountKey: UserKey) {
val tabsCursor = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, null) ?: return
try {
val indices = TabCursorIndices(tabsCursor)
@ -74,12 +71,9 @@ class UpdateAccountInfoTask(private val context: Context) : AbstractTask<Pair<Ac
tabsCursor.moveToNext()
}
val where = Expression.equalsArgs(Tabs._ID).sql
var i = 0
val j = values.size()
while (i < j) {
for (i in 0 until values.size()) {
val whereArgs = arrayOf(values.keyAt(i).toString())
resolver.update(Tabs.CONTENT_URI, values.valueAt(i), where, whereArgs)
i++
}
} catch (e: IOException) {
// Ignore