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

View File

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

View File

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

View File

@ -131,7 +131,8 @@ public class CardPollFragment extends BaseSupportFragment implements
} }
private void displayPoll(final ParcelableCardEntity card, final ParcelableStatus status) { 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; mCard = card;
final int choicesCount = getChoicesCount(card); final int choicesCount = getChoicesCount(card);
int votesSum = 0; 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); final float radius = getResources().getDimension(R.dimen.element_spacing_small);
for (int i = 0; i < choicesCount; i++) { for (int i = 0; i < choicesCount; i++) {
final View pollItem = mPollContainer.getChildAt(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 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); endDatetimeUtc.getTime(), true);
mPollSummary.setText(getString(R.string.poll_summary_format, nVotes, timeLeft)); mPollSummary.setText(getString(R.string.poll_summary_format, nVotes, timeLeft));
} }
private void displayAndReloadPoll(ParcelableCardEntity result, ParcelableStatus status) { private void displayAndReloadPoll(ParcelableCardEntity result, ParcelableStatus status) {
if (getHost() == null) return;
displayPoll(result, status); displayPoll(result, status);
getLoaderManager().restartLoader(0, null, this); getLoaderManager().restartLoader(0, null, this);
} }