From a964049df16f593c3fb5d8e2de02375ab9c90f88 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 6 Dec 2016 14:16:11 +0800 Subject: [PATCH] fixed account profile refresh --- .../fragment/OpenStreetMapViewerFragment.kt | 15 ++++----------- .../twidere/extension/AccountExtensions.kt | 12 +++++++++++- .../twidere/loader/ParcelableUserLoader.kt | 5 ++--- .../twidere/task/UpdateAccountInfoTask.kt | 15 +++++++-------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/twidere/src/fdroid/kotlin/org/mariotaku/twidere/fragment/OpenStreetMapViewerFragment.kt b/twidere/src/fdroid/kotlin/org/mariotaku/twidere/fragment/OpenStreetMapViewerFragment.kt index ba88e05c8..2aa6a3d45 100644 --- a/twidere/src/fdroid/kotlin/org/mariotaku/twidere/fragment/OpenStreetMapViewerFragment.kt +++ b/twidere/src/fdroid/kotlin/org/mariotaku/twidere/fragment/OpenStreetMapViewerFragment.kt @@ -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(context, OpenStreetMapViewerFragment.Itemization.boundCenterBottom(defaultMarker)) { + internal class Itemization(defaultMarker: Drawable) : ItemizedOverlay(defaultMarker.apply { + setBounds(-intrinsicWidth / 2, -intrinsicHeight, intrinsicWidth / 2, 0) + }) { private val overlays = ArrayList() @@ -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 - } - } - } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/AccountExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/AccountExtensions.kt index 41f3ad147..4a3e5a4a3 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/AccountExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/AccountExtensions.kt @@ -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 diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUserLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUserLoader.kt index 45b83bbb0..0cbc15e21 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUserLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUserLoader.kt @@ -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) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/UpdateAccountInfoTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/UpdateAccountInfoTask.kt index 277ee13a7..0182c51ff 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/UpdateAccountInfoTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/UpdateAccountInfoTask.kt @@ -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): 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