From 0e35fa329a953a4ae02b9ec1a6fdad6d3ea9225d Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 8 Mar 2016 16:06:40 +0800 Subject: [PATCH] improved user info update --- .../java/org/mariotaku/twidere/model/Tab.java | 9 +++- .../twidere/task/UpdateAccountInfoTask.java | 41 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/Tab.java b/twidere/src/main/java/org/mariotaku/twidere/model/Tab.java index fb5c17d31..4785d7921 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/Tab.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/Tab.java @@ -12,8 +12,11 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Tabs; /** * Created by mariotaku on 16/3/6. */ -@CursorObject +@CursorObject(valuesCreator = true) public class Tab { + @CursorField(value = Tabs._ID, excludeWrite = true) + long id; + @CursorField(Tabs.NAME) String name; @@ -33,6 +36,10 @@ public class Tab { @CursorField(value = Tabs.EXTRAS, converter = TabExtrasFieldConverter.class) TabExtras extras; + public long getId() { + return id; + } + public String getName() { return name; } diff --git a/twidere/src/main/java/org/mariotaku/twidere/task/UpdateAccountInfoTask.java b/twidere/src/main/java/org/mariotaku/twidere/task/UpdateAccountInfoTask.java index f1342e22c..18622e7ca 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/task/UpdateAccountInfoTask.java +++ b/twidere/src/main/java/org/mariotaku/twidere/task/UpdateAccountInfoTask.java @@ -3,17 +3,25 @@ package org.mariotaku.twidere.task; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; +import android.database.Cursor; +import android.support.annotation.NonNull; +import android.support.v4.util.LongSparseArray; import android.util.Pair; import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.twidere.model.ParcelableUser; +import org.mariotaku.twidere.model.Tab; +import org.mariotaku.twidere.model.TabCursorIndices; +import org.mariotaku.twidere.model.TabValuesCreator; import org.mariotaku.twidere.model.UserKey; +import org.mariotaku.twidere.model.tab.argument.TabArguments; import org.mariotaku.twidere.provider.TwidereDataStore.AccountSupportColumns; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.provider.TwidereDataStore.Activities; import org.mariotaku.twidere.provider.TwidereDataStore.CachedRelationships; import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages; import org.mariotaku.twidere.provider.TwidereDataStore.Statuses; +import org.mariotaku.twidere.provider.TwidereDataStore.Tabs; import org.mariotaku.twidere.util.JsonSerializer; import org.mariotaku.twidere.util.Utils; @@ -59,6 +67,39 @@ public class UpdateAccountInfoTask extends AbstractTask values = new LongSparseArray<>(); + while (!tabsCursor.isAfterLast()) { + Tab tab = indices.newObject(tabsCursor); + TabArguments arguments = tab.getArguments(); + if (arguments != null) { + final long accountId = arguments.getAccountId(); + final UserKey[] keys = arguments.getAccountKeys(); + if (accountKey.getId() == accountId && keys == null) { + arguments.setAccountKeys(new UserKey[]{accountKey}); + values.put(tab.getId(), TabValuesCreator.create(tab)); + } + } + tabsCursor.moveToNext(); + } + final String where = Expression.equalsArgs(Tabs._ID).getSQL(); + for (int i = 0, j = values.size(); i < j; i++) { + final String[] whereArgs = {String.valueOf(values.keyAt(i))}; + resolver.update(Tabs.CONTENT_URI, values.valueAt(i), where, whereArgs); + } + } finally { + tabsCursor.close(); + } + } }