From 558491f4ee84989fb83ee4de03403a0314857a21 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 5 Dec 2016 21:18:20 +0800 Subject: [PATCH] fixed NPEs --- .../mariotaku/twidere/model/util/UserKeyUtils.java | 9 +-------- .../org/mariotaku/twidere/util/DataStoreUtils.java | 11 ++--------- .../mariotaku/twidere/util/UserColorNameManager.java | 4 ++-- .../org/mariotaku/twidere/activity/HomeActivity.kt | 8 +++++--- .../mariotaku/twidere/fragment/BaseFiltersFragment.kt | 2 +- 5 files changed, 11 insertions(+), 23 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/UserKeyUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/UserKeyUtils.java index f793474ae..f882ebeed 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/UserKeyUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/UserKeyUtils.java @@ -1,6 +1,5 @@ package org.mariotaku.twidere.model.util; -import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; @@ -8,7 +7,6 @@ import android.text.TextUtils; import org.mariotaku.microblog.library.twitter.model.User; import org.mariotaku.twidere.model.ParcelableUser; import org.mariotaku.twidere.model.UserKey; -import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.UriUtils; import static org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM; @@ -22,12 +20,7 @@ public class UserKeyUtils { private UserKeyUtils() { } - @Nullable - public static UserKey findById(Context context, String id) { - return DataStoreUtils.findAccountKey(context, id); - } - - public static UserKey fromUser(User user) { + public static UserKey fromUser(@NonNull User user) { return new UserKey(user.getId(), getUserHost(user)); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java index 5939c95a1..8c64e879b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/DataStoreUtils.java @@ -851,7 +851,8 @@ public class DataStoreUtils implements Constants { if (cur == null) return messageIds; try { while (cur.moveToNext()) { - final UserKey accountKey = UserKey.valueOf(cur.getString(0)); + final String string = cur.getString(0); + final UserKey accountKey = string != null ? UserKey.valueOf(string) : null; int idx = ArrayUtils.indexOf(keys, accountKey); if (idx < 0) continue; creator.assign(messageIds, idx, cur, 1); @@ -1035,14 +1036,6 @@ public class DataStoreUtils implements Constants { } } - public static String getAccountType(@NonNull final Context context, @NonNull final UserKey accountKey) { - AccountManager am = AccountManager.get(context); - Account account = AccountUtils.findByAccountKey(am, accountKey); - if (account == null) return null; - - return AccountExtensionsKt.getAccountType(account, am); - } - public static int getInteractionsCount(@NonNull final Context context, @Nullable final Bundle extraArgs, final UserKey[] accountIds, final long since, final String sinceColumn) { Expression extraWhere = null; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/UserColorNameManager.java b/twidere/src/main/java/org/mariotaku/twidere/util/UserColorNameManager.java index 974802648..ba7cdde36 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/UserColorNameManager.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/UserColorNameManager.java @@ -249,7 +249,7 @@ public class UserColorNameManager implements TwidereConstants { @Override public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) { final UserKey userId = UserKey.valueOf(key); - if (mListener != null && userId != null) { + if (mListener != null) { mListener.onUserColorChanged(userId, preferences.getInt(key, 0)); } } @@ -267,7 +267,7 @@ public class UserColorNameManager implements TwidereConstants { @Override public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) { final UserKey userId = UserKey.valueOf(key); - if (mListener != null && userId != null) { + if (mListener != null) { mListener.onUserNicknameChanged(userId, preferences.getString(key, null)); } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt index f3edaabfc..93c33217d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/HomeActivity.kt @@ -57,6 +57,7 @@ import kotlinx.android.synthetic.main.activity_home_content.* import kotlinx.android.synthetic.main.layout_empty_tab_hint.* import org.mariotaku.abstask.library.AbstractTask import org.mariotaku.abstask.library.TaskStarter +import org.mariotaku.ktextension.convert import org.mariotaku.twidere.Constants.* import org.mariotaku.twidere.R import org.mariotaku.twidere.activity.iface.IControlBarActivity @@ -673,9 +674,10 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp val tabType = if (uri != null) Utils.matchTabType(uri) else null var initialTab = -1 if (tabType != null) { - val accountKey = UserKey.valueOf(uri!!.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)) - for (i in 0 until pagerAdapter!!.count) { - val tab = pagerAdapter!!.getTab(i) + val accountKey = uri?.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)?.convert(UserKey::valueOf) + val adapter = pagerAdapter!! + for (i in 0 until adapter.count) { + val tab = adapter.getTab(i) if (tabType == Tab.getTypeAlias(tab.type)) { val args = tab.args if (args != null && CustomTabUtils.hasAccountId(this, args, diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFiltersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFiltersFragment.kt index 39a379d00..ef27933ff 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFiltersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFiltersFragment.kt @@ -396,7 +396,7 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment