fixed crashes

This commit is contained in:
Mariotaku Lee 2016-04-19 20:16:16 +08:00
parent 2a7d99e33c
commit 04fee627d4
4 changed files with 28 additions and 14 deletions

View File

@ -685,7 +685,7 @@ public final class MediaViewerActivity extends BaseActivity implements Constants
super.onDownloadStart(total, nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.setOpenedTime(System.currentTimeMillis());
mMediaDownloadEvent.setSize(nonce);
mMediaDownloadEvent.setSize(total);
}
}
@ -755,8 +755,8 @@ public final class MediaViewerActivity extends BaseActivity implements Constants
decodeBitmap(cr, uri, o);
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
final int targetSize = Math.min(1024, Math.max(dm.widthPixels, dm.heightPixels));
o.inSampleSize = TwidereMathUtils.nextPowerOf2((int) Math.max(1,
Math.ceil(Math.min(o.outHeight, o.outWidth) / (float) targetSize)));
o.inSampleSize = TwidereMathUtils.nextPowerOf2(Math.max(1,
Math.round(Math.min(o.outHeight, o.outWidth) / (float) targetSize)));
o.inJustDecodeBounds = false;
final Bitmap bitmap = decodeBitmap(cr, uri, o);
if (bitmap == null) throw new IOException();
@ -854,7 +854,7 @@ public final class MediaViewerActivity extends BaseActivity implements Constants
super.onDownloadStart(total, nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.setOpenedTime(System.currentTimeMillis());
mMediaDownloadEvent.setSize(nonce);
mMediaDownloadEvent.setSize(total);
}
}
@ -1153,7 +1153,7 @@ public final class MediaViewerActivity extends BaseActivity implements Constants
super.onDownloadStart(total, nonce);
if (mMediaDownloadEvent != null && mMediaDownloadEvent.getNonce() == nonce) {
mMediaDownloadEvent.setOpenedTime(System.currentTimeMillis());
mMediaDownloadEvent.setSize(nonce);
mMediaDownloadEvent.setSize(total);
}
}

View File

@ -208,7 +208,9 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment {
@Nullable
@Override
public long[] getMaxSortIds() {
return DataStoreUtils.getOldestActivityMaxSortPositions(getContext(),
final Context context = getContext();
if (context == null) return null;
return DataStoreUtils.getOldestActivityMaxSortPositions(context,
getContentUri(), getAccountKeys());
}
@ -243,7 +245,9 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment {
@Nullable
@Override
public long[] getSinceSortIds() {
return DataStoreUtils.getNewestActivityMaxSortPositions(getContext(),
final Context context = getContext();
if (context == null) return null;
return DataStoreUtils.getNewestActivityMaxSortPositions(context,
getContentUri(), getAccountKeys());
}
@ -266,7 +270,9 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment {
}
protected String[] getNewestActivityIds(UserKey[] accountKeys) {
return DataStoreUtils.getNewestActivityMaxPositions(getActivity(), getContentUri(), accountKeys);
final Context context = getContext();
if (context == null) return null;
return DataStoreUtils.getNewestActivityMaxPositions(context, getContentUri(), accountKeys);
}
protected abstract int getNotificationType();
@ -282,7 +288,9 @@ public abstract class CursorActivitiesFragment extends AbsActivitiesFragment {
}
protected String[] getOldestActivityIds(UserKey[] accountKeys) {
return DataStoreUtils.getOldestActivityMaxPositions(getActivity(), getContentUri(), accountKeys);
final Context context = getContext();
if (context == null) return null;
return DataStoreUtils.getOldestActivityMaxPositions(context, getContentUri(), accountKeys);
}
protected abstract boolean isFilterEnabled();

View File

@ -267,7 +267,9 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment {
@Nullable
@Override
public long[] getMaxSortIds() {
return DataStoreUtils.getOldestStatusSortIds(getContext(), getContentUri(),
final Context context = getContext();
if (context == null) return null;
return DataStoreUtils.getOldestStatusSortIds(context, getContentUri(),
getAccountKeys());
}
@ -307,7 +309,9 @@ public abstract class CursorStatusesFragment extends AbsStatusesFragment {
@Nullable
@Override
public long[] getSinceSortIds() {
return DataStoreUtils.getNewestStatusSortIds(getContext(), getContentUri(),
final Context context = getContext();
if (context == null) return null;
return DataStoreUtils.getNewestStatusSortIds(context, getContentUri(),
getAccountKeys());
}

View File

@ -131,7 +131,8 @@ public class CardPollFragment extends BaseSupportFragment implements
}
private void displayPoll(final ParcelableCardEntity card, final ParcelableStatus status) {
if (card == null || status == null) return;
final Context context = getContext();
if (card == null || status == null || context == null) return;
mCard = card;
final int choicesCount = getChoicesCount(card);
int votesSum = 0;
@ -199,7 +200,7 @@ public class CardPollFragment extends BaseSupportFragment implements
}
};
final int color = ContextCompat.getColor(getContext(), R.color.material_light_blue_a200);
final int color = ContextCompat.getColor(context, R.color.material_light_blue_a200);
final float radius = getResources().getDimension(R.dimen.element_spacing_small);
for (int i = 0; i < choicesCount; i++) {
final View pollItem = mPollContainer.getChildAt(i);
@ -237,12 +238,13 @@ public class CardPollFragment extends BaseSupportFragment implements
final String nVotes = getResources().getQuantityString(R.plurals.N_votes, votesSum, votesSum);
final CharSequence timeLeft = DateUtils.getRelativeTimeSpanString(getContext(),
final CharSequence timeLeft = DateUtils.getRelativeTimeSpanString(context,
endDatetimeUtc.getTime(), true);
mPollSummary.setText(getString(R.string.poll_summary_format, nVotes, timeLeft));
}
private void displayAndReloadPoll(ParcelableCardEntity result, ParcelableStatus status) {
if (getHost() == null) return;
displayPoll(result, status);
getLoaderManager().restartLoader(0, null, this);
}