Skip to content

Commit

Permalink
fixed some crashes
Browse files Browse the repository at this point in the history
fixed build error
  • Loading branch information
mariotaku committed May 13, 2015
1 parent d56cda1 commit d529226
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.os.AsyncTask;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.multidex.MultiDexApplication;

import com.nostra13.universalimageloader.cache.disc.DiskCache;
Expand Down Expand Up @@ -202,6 +203,7 @@ public MediaLoaderWrapper getMediaLoaderWrapper() {
return mMediaLoaderWrapper = new MediaLoaderWrapper(getImageLoader(), getVideoLoader());
}

@Nullable
public Bus getMessageBus() {
return mMessageBus;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManagerTrojan;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
Expand Down Expand Up @@ -809,8 +810,8 @@ public void displayStatus(ParcelableStatus status) {
twitterCard.setCardSize(0, 0);
}
final Fragment cardFragment = TwitterCardUtils.createCardFragment(status.card);
if (cardFragment != null) {
final FragmentManager fm = fragment.getChildFragmentManager();
final FragmentManager fm = fragment.getChildFragmentManager();
if (cardFragment != null && !FragmentManagerTrojan.isStateSaved(fm)) {
final FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.twitter_card, cardFragment);
ft.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.SharedPreferences;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import org.mariotaku.twidere.Constants;
Expand Down Expand Up @@ -142,6 +143,7 @@ public static long[] getAutoRefreshEnabledAccountIds(final Context context, fina
return enabledIds;
}

@Nullable
public static AccountPreferences[] getNotificationEnabledPreferences(final Context context, final long[] accountIds) {
if (context == null || accountIds == null) return null;
final AccountPreferences[] temp = new AccountPreferences[accountIds.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,14 @@ public void run() {
private void notifyUnreadCountChanged(final int position) {
final Context context = getContext();
final Bus bus = TwidereApplication.getInstance(context).getMessageBus();
mHandler.post(new Runnable() {
@Override
public void run() {
bus.post(new UnreadCountUpdatedEvent(position));
}
});
if (bus != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
bus.post(new UnreadCountUpdatedEvent(position));
}
});
}
notifyContentObserver(UnreadCounts.CONTENT_URI);
}

Expand All @@ -779,13 +781,16 @@ private void onNewItemsInserted(final Uri uri, final int tableId, final ContentV
}

private void onNewItemsInserted(final Uri uri, final int tableId, final ContentValues[] valuesArray, final long[] newIds) {
if (uri == null || valuesArray == null || valuesArray.length == 0) return;
final Context context = getContext();
if (uri == null || valuesArray == null || valuesArray.length == 0 || context == null)
return;
preloadImages(valuesArray);
if (!uri.getBooleanQueryParameter(QUERY_PARAM_NOTIFY, true)) return;
switch (tableId) {
case TABLE_ID_STATUSES: {
final AccountPreferences[] prefs = AccountPreferences.getNotificationEnabledPreferences(getContext(),
getAccountIds(getContext()));
final AccountPreferences[] prefs = AccountPreferences.getNotificationEnabledPreferences(context,
getAccountIds(context));
assert prefs != null;
for (final AccountPreferences pref : prefs) {
if (!pref.isHomeTimelineNotificationEnabled()) continue;
showTimelineNotification(pref, getPositionTag(TAB_TYPE_HOME_TIMELINE, pref.getAccountId()));
Expand All @@ -794,8 +799,9 @@ private void onNewItemsInserted(final Uri uri, final int tableId, final ContentV
break;
}
case TABLE_ID_MENTIONS: {
final AccountPreferences[] prefs = AccountPreferences.getNotificationEnabledPreferences(getContext(),
getAccountIds(getContext()));
final AccountPreferences[] prefs = AccountPreferences.getNotificationEnabledPreferences(context,
getAccountIds(context));
assert prefs != null;
for (final AccountPreferences pref : prefs) {
if (!pref.isMentionsNotificationEnabled()) continue;
showMentionsNotification(pref, getPositionTag(TAB_TYPE_MENTIONS_TIMELINE, pref.getAccountId()));
Expand All @@ -804,8 +810,9 @@ private void onNewItemsInserted(final Uri uri, final int tableId, final ContentV
break;
}
case TABLE_ID_DIRECT_MESSAGES_INBOX: {
final AccountPreferences[] prefs = AccountPreferences.getNotificationEnabledPreferences(getContext(),
getAccountIds(getContext()));
final AccountPreferences[] prefs = AccountPreferences.getNotificationEnabledPreferences(context,
getAccountIds(context));
assert prefs != null;
for (final AccountPreferences pref : prefs) {
if (!pref.isDirectMessagesNotificationEnabled()) continue;
final StringLongPair[] pairs = mReadStateManager.getPositionPairs(TAB_TYPE_DIRECT_MESSAGES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ public static long getAccountId(final Context context, final String screen_name)
}
}

@NonNull
public static long[] getAccountIds(final Context context) {
if (context == null) return new long[0];
final Cursor cur = ContentResolverUtils.query(context.getContentResolver(), Accounts.CONTENT_URI,
Expand Down
2 changes: 1 addition & 1 deletion twidere/src/main/res/layout/layout_api_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
android:id="@+id/label_auth_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/authType"
android:text="@string/auth_type"
android:textAppearance="?android:attr/textAppearanceSmall" />

<HorizontalScrollView
Expand Down

0 comments on commit d529226

Please sign in to comment.