fixed account profile refresh

This commit is contained in:
Mariotaku Lee 2016-12-06 14:16:11 +08:00
parent 76a9088a7b
commit a964049df1
4 changed files with 24 additions and 23 deletions

View File

@ -19,7 +19,6 @@
package org.mariotaku.twidere.fragment
import android.content.Context
import android.graphics.Point
import android.graphics.drawable.Drawable
import android.os.Bundle
@ -58,7 +57,7 @@ class OpenStreetMapViewerFragment : BaseSupportFragment(), Constants {
mapView.isTilesScaledToDpi = true
val gp = GeoPoint(latitude, longitude)
val d = ResourcesCompat.getDrawable(resources, R.drawable.ic_map_marker, null)!!
val markers = Itemization(context, d)
val markers = Itemization(d)
val overlayItem = OverlayItem("", "", gp)
markers.addOverlay(overlayItem)
mapView.overlays.add(markers)
@ -90,7 +89,9 @@ class OpenStreetMapViewerFragment : BaseSupportFragment(), Constants {
mc.animateTo(gp)
}
internal class Itemization(context: Context, defaultMarker: Drawable) : ItemizedOverlay<OverlayItem>(context, OpenStreetMapViewerFragment.Itemization.boundCenterBottom(defaultMarker)) {
internal class Itemization(defaultMarker: Drawable) : ItemizedOverlay<OverlayItem>(defaultMarker.apply {
setBounds(-intrinsicWidth / 2, -intrinsicHeight, intrinsicWidth / 2, 0)
}) {
private val overlays = ArrayList<OverlayItem>()
@ -111,13 +112,5 @@ class OpenStreetMapViewerFragment : BaseSupportFragment(), Constants {
return overlays[i]
}
companion object {
private fun boundCenterBottom(d: Drawable): Drawable {
d.setBounds(-d.intrinsicWidth / 2, -d.intrinsicHeight, d.intrinsicWidth / 2, 0)
return d
}
}
}
}

View File

@ -35,8 +35,18 @@ fun Account.getAccountKey(am: AccountManager): UserKey {
return UserKey.valueOf(am.getUserData(this, ACCOUNT_USER_DATA_KEY))
}
fun Account.setAccountKey(am: AccountManager, accountKey: UserKey) {
am.setUserData(this, ACCOUNT_USER_DATA_KEY, accountKey.toString())
}
fun Account.getAccountUser(am: AccountManager): ParcelableUser {
return LoganSquare.parse(am.getUserData(this, ACCOUNT_USER_DATA_USER), ParcelableUser::class.java)
val user = LoganSquare.parse(am.getUserData(this, ACCOUNT_USER_DATA_USER), ParcelableUser::class.java)
user.is_cache = true
return user
}
fun Account.setAccountUser(am: AccountManager, user: ParcelableUser) {
am.setUserData(this, ACCOUNT_USER_DATA_USER, LoganSquare.serialize(user))
}
@ColorInt

View File

@ -110,9 +110,8 @@ class ParcelableUserLoader(
} else {
return SingleResponse()
}
val cur = resolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS,
where.sql, whereArgs, null)
if (cur != null) {
val cur = resolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, where.sql,
whereArgs, null)?.let { cur ->
try {
cur.moveToFirst()
val indices = ParcelableUserCursorIndices(cur)

View File

@ -7,12 +7,11 @@ import android.content.ContentValues
import android.content.Context
import android.support.v4.util.LongSparseArray
import android.text.TextUtils
import com.bluelinelabs.logansquare.LoganSquare
import org.mariotaku.abstask.library.AbstractTask
import org.mariotaku.sqliteqb.library.Expression
import org.mariotaku.twidere.TwidereConstants
import org.mariotaku.twidere.TwidereConstants.ACCOUNT_USER_DATA_KEY
import org.mariotaku.twidere.TwidereConstants.ACCOUNT_USER_DATA_USER
import org.mariotaku.twidere.extension.setAccountKey
import org.mariotaku.twidere.extension.setAccountUser
import org.mariotaku.twidere.model.*
import org.mariotaku.twidere.provider.TwidereDataStore.*
import java.io.IOException
@ -24,7 +23,7 @@ class UpdateAccountInfoTask(private val context: Context) : AbstractTask<Pair<Ac
override fun doLongOperation(params: Pair<AccountDetails, ParcelableUser>): Any? {
val resolver = context.contentResolver
val account = params.first
val details = params.first
val user = params.second
if (user.is_cache) {
return null
@ -34,14 +33,14 @@ class UpdateAccountInfoTask(private val context: Context) : AbstractTask<Pair<Ac
}
val am = AccountManager.get(context)
val account1 = Account(account.user.name, TwidereConstants.ACCOUNT_TYPE)
am.setUserData(account1, ACCOUNT_USER_DATA_USER, LoganSquare.serialize(user))
am.setUserData(account1, ACCOUNT_USER_DATA_KEY, user.key.toString())
val account = Account(details.account.name, TwidereConstants.ACCOUNT_TYPE)
account.setAccountUser(am, user)
account.setAccountKey(am, user.key)
val accountKeyValues = ContentValues()
accountKeyValues.put(AccountSupportColumns.ACCOUNT_KEY, user.key.toString())
val accountKeyWhere = Expression.equalsArgs(AccountSupportColumns.ACCOUNT_KEY).sql
val accountKeyWhereArgs = arrayOf(account.key.toString())
val accountKeyWhereArgs = arrayOf(details.key.toString())
resolver.update(Statuses.CONTENT_URI, accountKeyValues, accountKeyWhere, accountKeyWhereArgs)
resolver.update(Activities.AboutMe.CONTENT_URI, accountKeyValues, accountKeyWhere, accountKeyWhereArgs)