mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Crash fixes.
This commit is contained in:
parent
24fd717621
commit
7dbc53c50f
5 changed files with 50 additions and 25 deletions
|
@ -80,27 +80,32 @@ public class FeedItemListFragment extends StoryItemListFragment implements Loade
|
|||
Uri feedUri = FeedProvider.FEEDS_URI.buildUpon().appendPath(feedId).build();
|
||||
Cursor feedCursor = contentResolver.query(feedUri, null, null, null, null);
|
||||
|
||||
if (feedCursor.getCount() > 0) {
|
||||
feedCursor.moveToFirst();
|
||||
Feed feed = Feed.fromCursor(feedCursor);
|
||||
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_READ, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar };
|
||||
|
||||
// create the adapter before starting the loader, since the callback updates the adapter
|
||||
adapter = new FeedItemsAdapter(getActivity(), feed, R.layout.row_item, storiesCursor, groupFrom, groupTo, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||
|
||||
getLoaderManager().initLoader(ITEMLIST_LOADER , null, this);
|
||||
|
||||
itemList.setOnScrollListener(this);
|
||||
|
||||
adapter.setViewBinder(new FeedItemViewBinder(getActivity()));
|
||||
itemList.setAdapter(adapter);
|
||||
itemList.setOnItemClickListener(this);
|
||||
itemList.setOnCreateContextMenuListener(this);
|
||||
} else {
|
||||
Log.w(this.getClass().getName(), "Feed not found in DB, can't load.");
|
||||
if (feedCursor.getCount() < 1) {
|
||||
// This shouldn't happen, but crash reports indicate that it does (very rarely).
|
||||
// If we are told to create an item list for a feed, but then can't find that feed ID in the DB,
|
||||
// something is very wrong, and we won't be able to recover, so just force the user back to the
|
||||
// feed list until we have a better understanding of how to prevent this.
|
||||
Log.w(this.getClass().getName(), "Feed not found in DB, can't create item list.");
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
feedCursor.moveToFirst();
|
||||
Feed feed = Feed.fromCursor(feedCursor);
|
||||
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_READ, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar };
|
||||
|
||||
// create the adapter before starting the loader, since the callback updates the adapter
|
||||
adapter = new FeedItemsAdapter(getActivity(), feed, R.layout.row_item, storiesCursor, groupFrom, groupTo, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||
|
||||
getLoaderManager().initLoader(ITEMLIST_LOADER , null, this);
|
||||
|
||||
itemList.setOnScrollListener(this);
|
||||
|
||||
adapter.setViewBinder(new FeedItemViewBinder(getActivity()));
|
||||
itemList.setAdapter(adapter);
|
||||
itemList.setOnItemClickListener(this);
|
||||
itemList.setOnCreateContextMenuListener(this);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
|
@ -241,9 +241,9 @@ public class FolderListFragment extends Fragment implements OnGroupClickListener
|
|||
resolver.update(FeedProvider.FEEDS_URI.buildUpon().appendPath(feedId).build(), values, null, null);
|
||||
}
|
||||
folderAdapter.notifyDataSetChanged();
|
||||
Toast.makeText(getActivity(), R.string.toast_marked_all_stories_as_read, Toast.LENGTH_SHORT).show();
|
||||
UIUtils.safeToast(getActivity(), R.string.toast_marked_all_stories_as_read, Toast.LENGTH_SHORT);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.toast_error_marking_feed_as_read, Toast.LENGTH_SHORT).show();
|
||||
UIUtils.safeToast(getActivity(), R.string.toast_error_marking_feed_as_read, Toast.LENGTH_SHORT);
|
||||
}
|
||||
};
|
||||
}.execute();
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.newsblur.domain.Story;
|
|||
import com.newsblur.domain.UserDetails;
|
||||
import com.newsblur.network.APIManager;
|
||||
import com.newsblur.util.PrefsUtils;
|
||||
import com.newsblur.util.UIUtils;
|
||||
|
||||
public class ShareDialogFragment extends DialogFragment {
|
||||
|
||||
|
@ -132,10 +133,10 @@ public class ShareDialogFragment extends DialogFragment {
|
|||
protected void onPostExecute(Boolean result) {
|
||||
if (result) {
|
||||
hasShared = true;
|
||||
Toast.makeText(getActivity(), R.string.shared, Toast.LENGTH_LONG).show();
|
||||
UIUtils.safeToast(getActivity(), R.string.shared, Toast.LENGTH_LONG);
|
||||
callback.sharedCallback(shareComment, hasBeenShared);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), R.string.error_sharing, Toast.LENGTH_LONG).show();
|
||||
UIUtils.safeToast(getActivity(), R.string.error_sharing, Toast.LENGTH_LONG);
|
||||
}
|
||||
v.setEnabled(true);
|
||||
ShareDialogFragment.this.dismiss();
|
||||
|
|
|
@ -45,7 +45,13 @@ public class ImageLoader {
|
|||
Bitmap bitmap = memoryCache.get(url);
|
||||
if (bitmap == null) {
|
||||
File f = fileCache.getFile(url);
|
||||
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
|
||||
try {
|
||||
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
Log.e(this.getClass().getName(), "error decoding image, using default.", e);
|
||||
// this can rarely happen if the device is low on memory and is not recoverable.
|
||||
// just leave bitmap null and the default placeholder image will be used
|
||||
}
|
||||
}
|
||||
if (bitmap != null) {
|
||||
if (doRound) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.graphics.PorterDuffXfermode;
|
|||
import android.graphics.RectF;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class UIUtils {
|
||||
|
||||
|
@ -88,4 +89,16 @@ public class UIUtils {
|
|||
v.setAlpha(alpha);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a toast in a circumstance where the context might be null. This can very
|
||||
* rarely happen when toasts are done from async tasks and the context is finished
|
||||
* before the task completes, resulting in a crash. This prevents the crash at the
|
||||
* cost of the toast not being shown.
|
||||
*/
|
||||
public static void safeToast(Context c, int rid, int duration) {
|
||||
if (c != null) {
|
||||
Toast.makeText(c, rid, duration).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue