예제 #1
0
 @Override
 public SynchronizedStateSavedList<ParcelableStatus, Long> loadInBackground() {
   if (isFirstLoad() && isHomeTab() && getClassName() != null) {
     try {
       final String path =
           SerializationUtil.getSerializationFilePath(
               getContext(), getClassName(), mAccountId, mUserId, mUserScreenName);
       final SynchronizedStateSavedList<ParcelableStatus, Long> statuses =
           SerializationUtil.read(path);
       setLastViewedId(statuses.getState());
       final SynchronizedStateSavedList<ParcelableStatus, Long> data = getData();
       if (data != null && statuses != null) {
         data.addAll(statuses);
         Collections.sort(data);
       }
       return data;
     } catch (final IOException e) {
       e.printStackTrace();
     } catch (final ClassNotFoundException e) {
       e.printStackTrace();
     } catch (final ClassCastException e) {
       e.printStackTrace();
     }
   }
   return super.loadInBackground();
 }
예제 #2
0
 public static void writeSerializableStatuses(
     final Object instance,
     final Context context,
     final SynchronizedStateSavedList<ParcelableStatus, Long> data,
     final long last_viewed_id,
     final Bundle args) {
   if (instance == null || context == null || data == null || args == null) return;
   final long account_id = args.getLong(INTENT_KEY_ACCOUNT_ID, -1);
   final long user_id = args.getLong(INTENT_KEY_USER_ID, -1);
   final String screen_name = args.getString(INTENT_KEY_SCREEN_NAME);
   final int items_limit =
       context
           .getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
           .getInt(PREFERENCE_KEY_DATABASE_ITEM_LIMIT, PREFERENCE_DEFAULT_DATABASE_ITEM_LIMIT);
   try {
     final int size = data.size();
     final SynchronizedStateSavedList<ParcelableStatus, Long> statuses =
         new SynchronizedStateSavedList<ParcelableStatus, Long>(
             data.subList(0, size > items_limit ? items_limit : size));
     if (last_viewed_id > 0) {
       statuses.setState(last_viewed_id);
     }
     final String path =
         SerializationUtil.getSerializationFilePath(
             context, instance.getClass().getSimpleName(), account_id, user_id, screen_name);
     SerializationUtil.write(statuses, path);
   } catch (final IOException e) {
   }
 }