fixed NPEs
This commit is contained in:
parent
327442b349
commit
558491f4ee
|
@ -1,6 +1,5 @@
|
||||||
package org.mariotaku.twidere.model.util;
|
package org.mariotaku.twidere.model.util;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
@ -8,7 +7,6 @@ import android.text.TextUtils;
|
||||||
import org.mariotaku.microblog.library.twitter.model.User;
|
import org.mariotaku.microblog.library.twitter.model.User;
|
||||||
import org.mariotaku.twidere.model.ParcelableUser;
|
import org.mariotaku.twidere.model.ParcelableUser;
|
||||||
import org.mariotaku.twidere.model.UserKey;
|
import org.mariotaku.twidere.model.UserKey;
|
||||||
import org.mariotaku.twidere.util.DataStoreUtils;
|
|
||||||
import org.mariotaku.twidere.util.UriUtils;
|
import org.mariotaku.twidere.util.UriUtils;
|
||||||
|
|
||||||
import static org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM;
|
import static org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM;
|
||||||
|
@ -22,12 +20,7 @@ public class UserKeyUtils {
|
||||||
private UserKeyUtils() {
|
private UserKeyUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
public static UserKey fromUser(@NonNull User user) {
|
||||||
public static UserKey findById(Context context, String id) {
|
|
||||||
return DataStoreUtils.findAccountKey(context, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UserKey fromUser(User user) {
|
|
||||||
return new UserKey(user.getId(), getUserHost(user));
|
return new UserKey(user.getId(), getUserHost(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -851,7 +851,8 @@ public class DataStoreUtils implements Constants {
|
||||||
if (cur == null) return messageIds;
|
if (cur == null) return messageIds;
|
||||||
try {
|
try {
|
||||||
while (cur.moveToNext()) {
|
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);
|
int idx = ArrayUtils.indexOf(keys, accountKey);
|
||||||
if (idx < 0) continue;
|
if (idx < 0) continue;
|
||||||
creator.assign(messageIds, idx, cur, 1);
|
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,
|
public static int getInteractionsCount(@NonNull final Context context, @Nullable final Bundle extraArgs,
|
||||||
final UserKey[] accountIds, final long since, final String sinceColumn) {
|
final UserKey[] accountIds, final long since, final String sinceColumn) {
|
||||||
Expression extraWhere = null;
|
Expression extraWhere = null;
|
||||||
|
|
|
@ -249,7 +249,7 @@ public class UserColorNameManager implements TwidereConstants {
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) {
|
public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) {
|
||||||
final UserKey userId = UserKey.valueOf(key);
|
final UserKey userId = UserKey.valueOf(key);
|
||||||
if (mListener != null && userId != null) {
|
if (mListener != null) {
|
||||||
mListener.onUserColorChanged(userId, preferences.getInt(key, 0));
|
mListener.onUserColorChanged(userId, preferences.getInt(key, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ public class UserColorNameManager implements TwidereConstants {
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) {
|
public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) {
|
||||||
final UserKey userId = UserKey.valueOf(key);
|
final UserKey userId = UserKey.valueOf(key);
|
||||||
if (mListener != null && userId != null) {
|
if (mListener != null) {
|
||||||
mListener.onUserNicknameChanged(userId, preferences.getString(key, null));
|
mListener.onUserNicknameChanged(userId, preferences.getString(key, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ import kotlinx.android.synthetic.main.activity_home_content.*
|
||||||
import kotlinx.android.synthetic.main.layout_empty_tab_hint.*
|
import kotlinx.android.synthetic.main.layout_empty_tab_hint.*
|
||||||
import org.mariotaku.abstask.library.AbstractTask
|
import org.mariotaku.abstask.library.AbstractTask
|
||||||
import org.mariotaku.abstask.library.TaskStarter
|
import org.mariotaku.abstask.library.TaskStarter
|
||||||
|
import org.mariotaku.ktextension.convert
|
||||||
import org.mariotaku.twidere.Constants.*
|
import org.mariotaku.twidere.Constants.*
|
||||||
import org.mariotaku.twidere.R
|
import org.mariotaku.twidere.R
|
||||||
import org.mariotaku.twidere.activity.iface.IControlBarActivity
|
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
|
val tabType = if (uri != null) Utils.matchTabType(uri) else null
|
||||||
var initialTab = -1
|
var initialTab = -1
|
||||||
if (tabType != null) {
|
if (tabType != null) {
|
||||||
val accountKey = UserKey.valueOf(uri!!.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY))
|
val accountKey = uri?.getQueryParameter(QUERY_PARAM_ACCOUNT_KEY)?.convert(UserKey::valueOf)
|
||||||
for (i in 0 until pagerAdapter!!.count) {
|
val adapter = pagerAdapter!!
|
||||||
val tab = pagerAdapter!!.getTab(i)
|
for (i in 0 until adapter.count) {
|
||||||
|
val tab = adapter.getTab(i)
|
||||||
if (tabType == Tab.getTypeAlias(tab.type)) {
|
if (tabType == Tab.getTypeAlias(tab.type)) {
|
||||||
val args = tab.args
|
val args = tab.args
|
||||||
if (args != null && CustomTabUtils.hasAccountId(this, args,
|
if (args != null && CustomTabUtils.hasAccountId(this, args,
|
||||||
|
|
|
@ -396,7 +396,7 @@ abstract class BaseFiltersFragment : AbsContentListViewFragment<SimpleCursorAdap
|
||||||
super.bindView(view, context, cursor)
|
super.bindView(view, context, cursor)
|
||||||
val text1 = view.findViewById(android.R.id.text1) as TextView
|
val text1 = view.findViewById(android.R.id.text1) as TextView
|
||||||
val text2 = view.findViewById(android.R.id.text2) as TextView
|
val text2 = view.findViewById(android.R.id.text2) as TextView
|
||||||
val userId = UserKey.valueOf(cursor.getString(userIdIdx))!!
|
val userId = UserKey.valueOf(cursor.getString(userIdIdx))
|
||||||
val name = cursor.getString(nameIdx)
|
val name = cursor.getString(nameIdx)
|
||||||
val screenName = cursor.getString(screenNameIdx)
|
val screenName = cursor.getString(screenNameIdx)
|
||||||
val displayName = userColorNameManager.getDisplayName(userId, name, screenName,
|
val displayName = userColorNameManager.getDisplayName(userId, name, screenName,
|
||||||
|
|
Loading…
Reference in New Issue