Back to project page Test-SimpleTwitterClient.
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.
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; } }