Android Open Source - Test-SimpleTwitterClient Timeline Adapter






From Project

Back to project page Test-SimpleTwitterClient.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project Test-SimpleTwitterClient listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.Twitter_Android.Fragments.Adapters;
//from  www .j  a v  a2  s.co m
import android.app.Activity;
import android.widget.BaseAdapter;
import com.example.Twitter_Android.Logic.Tweet;
import com.mass.cmassive.CMassive;

import java.util.List;

/**
 * ??????????? ??????? ??? ??????????? ?????? ?????? ??? ????????????? (? ?????????).
 * ????????? ????????? ????? ?????? ?????? ???????, ? ?????? ??? ? ????? ? ??????? ??????.
 *
 * @param <T> ??? ??????????? - ???????????? Tweet, Person
 */
public abstract class TimelineAdapter<T> extends BaseAdapter {
  private CMassive<T> items;
  private long maxID = -1;    //see max_id & since_id in TwitterAPI
  private long sinceID = -1;
  private final String TAG;

  @SuppressWarnings("unchecked")
  TimelineAdapter(List<? extends T> newItems, String tag) {
    items = new CMassive<>(newItems);
    TAG = tag;
    if (newItems.get(0) instanceof Tweet) {
      sinceID = ((Tweet) newItems.get(0)).getID();
      maxID = ((Tweet) newItems.get(newItems.size() - 1)).getID() - 1;
    }
  }

  @Override
  public int getCount() {
    return items.getDataSize();
  }
  //------------------------------------------------------------------------------------------------------------------

  @Override
  public T getItem(int position) {
    return items.getItem(position);
  }
  //------------------------------------------------------------------------------------------------------------------

  @Override
  public long getItemId(int position) {
    return items.getItem(position).hashCode();
  }
  //------------------------------------------------------------------------------------------------------------------

  /**
   * Add new items instead existing items
   *
   * @param newItems items to add
   */
  @SuppressWarnings("unchecked")
  public void addItemsInstead(List<? extends T> newItems) {
    items = new CMassive<>(newItems);
    if (newItems.get(0) instanceof Tweet) {
      sinceID = ((Tweet) newItems.get(0)).getID();
      maxID = ((Tweet) newItems.get(newItems.size() - 1)).getID() - 1;
    }
    notifyDataSetChanged();
  }

  /**
   * Add new items on top of the existing items array
   *
   * @param newItems items to add
   */
  @SuppressWarnings("unchecked")
  public void addItemsToTop(List<? extends T> newItems) {
    items.insertToStart(newItems);
    notifyDataSetChanged();
    if (newItems.get(0) instanceof Tweet) {
      sinceID = ((Tweet) newItems.get(0)).getID();
    }
  }

  /**
   * Add new items at the end of the existing items array
   *
   * @param newItems items to add
   */
  @SuppressWarnings("unchecked")
  public void addItemsToBottom(List<? extends T> newItems) {
    items.insertToEnd(newItems);
    notifyDataSetChanged();
    if (newItems.get(0) instanceof Tweet) {
      maxID = ((Tweet) newItems.get(newItems.size() - 1)).getID() - 1;
    }
  }

  //------------------------------------------------------------------------------------------------------------------

  /**
   * Remove item from array and compact array
   *
   * @param item item to remove
   */
  @SuppressWarnings("unchecked")
  public void removeItem(T item) {
    items.removeItem(item);
    notifyDataSetChanged();
  }

  /**
   * Remove item from position in array
   *
   * @param position item position to remove
   */
  @SuppressWarnings("unchecked")
  public void removeItem(int position) {
    items.removeItem(position);
    notifyDataSetChanged();
  }

  /**
   * Replace last added tweet. Using in PostTweetDialog
   *
   * @param tweet update tweet.
   */
  public void updateLastAddedTweet(T tweet) {
    items.updateItem(tweet, 0);
    notifyDataSetChanged();
  }

  //------------------------------------------------------------------------------------------------------------------
  public long getMaxID() {
    return maxID;
  }

  public long getSinceID() {
    return sinceID;
  }
  //------------------------------------------------------------------------------------------------------------------

  public abstract void updateContext(Activity context);

  public String getTag() {
    return TAG;
  }
}




Java Source Code List

com.example.Twitter_Android.AppActivity.ConcreteUserTimelineActivity.java
com.example.Twitter_Android.AppActivity.MainActivity.java
com.example.Twitter_Android.AppActivity.MessagesActivity.java
com.example.Twitter_Android.AppActivity.SearchableActivity.java
com.example.Twitter_Android.AppActivity.SettingsActivity.java
com.example.Twitter_Android.AsynkTasks.ImageDownloader.java
com.example.Twitter_Android.AsynkTasks.TaskDeleteTweet.java
com.example.Twitter_Android.AsynkTasks.TaskFollow.java
com.example.Twitter_Android.AsynkTasks.TaskPostTweet.java
com.example.Twitter_Android.AsynkTasks.TaskReply.java
com.example.Twitter_Android.AsynkTasks.TaskRetweet.java
com.example.Twitter_Android.AsynkTasks.TaskSendMessage.java
com.example.Twitter_Android.AsynkTasks.TaskUnfollow.java
com.example.Twitter_Android.Fragments.ConcreteUserTimelineFragment.java
com.example.Twitter_Android.Fragments.ConnectedUserTimelineFragment.java
com.example.Twitter_Android.Fragments.FollowersFragment.java
com.example.Twitter_Android.Fragments.FollowingsFragment.java
com.example.Twitter_Android.Fragments.HomeTimelineFragment.java
com.example.Twitter_Android.Fragments.TimelineFragment.java
com.example.Twitter_Android.Fragments.UserInfoFragment.java
com.example.Twitter_Android.Fragments.Adapters.ConcreteUserTimelineAdapter.java
com.example.Twitter_Android.Fragments.Adapters.FollowingsListAdapter.java
com.example.Twitter_Android.Fragments.Adapters.MessagesAdapter.java
com.example.Twitter_Android.Fragments.Adapters.TimelineAdapter.java
com.example.Twitter_Android.Fragments.Adapters.TweetAdapter.java
com.example.Twitter_Android.Fragments.Dialogs.DeleteTweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.DirectMessageDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ErrorDialog.java
com.example.Twitter_Android.Fragments.Dialogs.PostTweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ReplyDialog.java
com.example.Twitter_Android.Fragments.Dialogs.RetweetDialog.java
com.example.Twitter_Android.Fragments.Dialogs.ShowImageDialog.java
com.example.Twitter_Android.Fragments.Dialogs.UserInfoDialog.java
com.example.Twitter_Android.Fragments.Preferences.SettingsFragment.java
com.example.Twitter_Android.Loaders.AsyncUserInfoLoader.java
com.example.Twitter_Android.Loaders.FollowersLoader.java
com.example.Twitter_Android.Loaders.FollowingsLoader.java
com.example.Twitter_Android.Loaders.HomeTimelineLoader.java
com.example.Twitter_Android.Loaders.MessageLoader.java
com.example.Twitter_Android.Loaders.Task_LoadSearchedTweets.java
com.example.Twitter_Android.Loaders.Task_LoadSearchedUsers.java
com.example.Twitter_Android.Loaders.TweetLoader.java
com.example.Twitter_Android.Loaders.UserTimelineLoader.java
com.example.Twitter_Android.Logic.AppDatabase.java
com.example.Twitter_Android.Logic.Constants.java
com.example.Twitter_Android.Logic.DataCache.java
com.example.Twitter_Android.Logic.FileWorker.java
com.example.Twitter_Android.Logic.Person.java
com.example.Twitter_Android.Logic.Tweet.java
com.example.Twitter_Android.Net.Connector.java
com.example.Twitter_Android.Net.Parser.java
com.mass.cmassive.CMassive.java